提交 4dba6d13 authored 作者: Niklas Mehner's avatar Niklas Mehner

Disable literals check if compiling gernerated query, since these may contain…

Disable literals check if compiling gernerated query, since these may contain artificially generated literals.
上级 73f1e9b4
......@@ -224,6 +224,7 @@ public class Parser {
private ArrayList<String> expectedList;
private boolean rightsChecked;
private boolean recompileAlways;
private boolean literalsChecked;
private ArrayList<Parameter> indexedParameterList;
private int orderInFrom;
private ArrayList<Parameter> suppliedParameterList;
......@@ -3507,7 +3508,7 @@ public class Parser {
}
private void checkLiterals(boolean text) {
if (!session.getAllowLiterals()) {
if (!literalsChecked && !session.getAllowLiterals()) {
int allowed = database.getAllowLiterals();
if (allowed == Constants.ALLOW_LITERALS_NONE ||
(text && allowed != Constants.ALLOW_LITERALS_ALL)) {
......@@ -4980,11 +4981,11 @@ public class Parser {
// then we just compile it again.
TableView view = new TableView(schema, id, tempViewName, querySQL,
parameters, columnTemplateList.toArray(new Column[0]), session,
true/* recursive */);
true/* recursive */, false);
if (!view.isRecursiveQueryDetected()) {
view = new TableView(schema, id, tempViewName, querySQL, parameters,
columnTemplateList.toArray(new Column[0]), session,
false/* recursive */);
false/* recursive */, false);
}
view.setTableExpression(true);
view.setTemporary(true);
......@@ -6434,6 +6435,10 @@ public class Parser {
return s;
}
public void setLiteralsChecked(boolean literalsChecked) {
this.literalsChecked = literalsChecked;
}
public void setRightsChecked(boolean rightsChecked) {
this.rightsChecked = rightsChecked;
}
......
......@@ -116,9 +116,9 @@ public class CreateView extends SchemaCommand {
}
}
view = new TableView(getSchema(), id, viewName, querySQL, null,
columnTemplates, sysSession, false);
columnTemplates, sysSession, false, false);
} else {
view.replace(querySQL, sysSession, false, force);
view.replace(querySQL, sysSession, false, force, false);
view.setModified();
}
} finally {
......
......@@ -527,7 +527,20 @@ public class Session extends SessionWithState {
* @return the prepared statement
*/
public Prepared prepare(String sql) {
return prepare(sql, false);
return prepare(sql, false, false);
}
/**
* Parse and prepare the given SQL statement. This method also checks the
* rights.
*
* @param sql the SQL statement
* @param literalsChecked true if the sql string has already been checked for literals (only used if
* ALLOW_LITERALS NONE is set).
* @return the prepared statement
*/
public Prepared prepare(String sql, boolean literalsChecked) {
return prepare(sql, false, literalsChecked);
}
/**
......@@ -535,11 +548,14 @@ public class Session extends SessionWithState {
*
* @param sql the SQL statement
* @param rightsChecked true if the rights have already been checked
* @param literalsChecked true if the sql string has already been checked for literals (only used if
* ALLOW_LITERALS NONE is set).
* @return the prepared statement
*/
public Prepared prepare(String sql, boolean rightsChecked) {
public Prepared prepare(String sql, boolean rightsChecked, boolean literalsChecked) {
Parser parser = new Parser(this);
parser.setRightsChecked(rightsChecked);
parser.setLiteralsChecked(literalsChecked);
return parser.prepare(sql);
}
......
......@@ -61,9 +61,9 @@ public class TableView extends Table {
public TableView(Schema schema, int id, String name, String querySQL,
ArrayList<Parameter> params, Column[] columnTemplates, Session session,
boolean recursive) {
boolean recursive, boolean literalsChecked) {
super(schema, id, name, false, true);
init(querySQL, params, columnTemplates, session, recursive);
init(querySQL, params, columnTemplates, session, recursive, literalsChecked);
}
/**
......@@ -76,34 +76,34 @@ public class TableView extends Table {
* @param force if errors should be ignored
*/
public void replace(String querySQL, Session session,
boolean recursive, boolean force) {
boolean recursive, boolean force, boolean literalsChecked) {
String oldQuerySQL = this.querySQL;
Column[] oldColumnTemplates = this.columnTemplates;
boolean oldRecursive = this.recursive;
init(querySQL, null, columnTemplates, session, recursive);
init(querySQL, null, columnTemplates, session, recursive, literalsChecked);
DbException e = recompile(session, force, true);
if (e != null) {
init(oldQuerySQL, null, oldColumnTemplates, session, oldRecursive);
init(oldQuerySQL, null, oldColumnTemplates, session, oldRecursive, literalsChecked);
recompile(session, true, false);
throw e;
}
}
private synchronized void init(String querySQL, ArrayList<Parameter> params,
Column[] columnTemplates, Session session, boolean recursive) {
Column[] columnTemplates, Session session, boolean recursive, boolean literalsChecked) {
this.querySQL = querySQL;
this.columnTemplates = columnTemplates;
this.recursive = recursive;
this.isRecursiveQueryDetected = false;
index = new ViewIndex(this, querySQL, params, recursive);
initColumnsAndTables(session);
initColumnsAndTables(session, literalsChecked);
}
private static Query compileViewQuery(Session session, String sql) {
private static Query compileViewQuery(Session session, String sql, boolean literalsChecked) {
Prepared p;
session.setParsingView(true);
try {
p = session.prepare(sql);
p = session.prepare(sql, literalsChecked);
} finally {
session.setParsingView(false);
}
......@@ -125,7 +125,7 @@ public class TableView extends Table {
public synchronized DbException recompile(Session session, boolean force,
boolean clearIndexCache) {
try {
compileViewQuery(session, querySQL);
compileViewQuery(session, querySQL, false);
} catch (DbException e) {
if (!force) {
return e;
......@@ -135,7 +135,7 @@ public class TableView extends Table {
if (views != null) {
views = New.arrayList(views);
}
initColumnsAndTables(session);
initColumnsAndTables(session, false);
if (views != null) {
for (TableView v : views) {
DbException e = v.recompile(session, force, false);
......@@ -150,11 +150,11 @@ public class TableView extends Table {
return force ? null : createException;
}
private void initColumnsAndTables(Session session) {
private void initColumnsAndTables(Session session, boolean literalsChecked) {
Column[] cols;
removeViewFromTables();
try {
Query query = compileViewQuery(session, querySQL);
Query query = compileViewQuery(session, querySQL, literalsChecked);
this.querySQL = query.getPlanSQL();
tables = New.arrayList(query.getTables());
ArrayList<Expression> expressions = query.getExpressions();
......@@ -539,7 +539,7 @@ public class TableView extends Table {
String querySQL = query.getPlanSQL();
TableView v = new TableView(mainSchema, 0, name,
querySQL, query.getParameters(), null, session,
false);
false, true /* literals have already been checked when parsing original query */);
if (v.createException != null) {
throw v.createException;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论