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