/** * Parse a statement or a list of statements, and prepare it for execution. * * @param sql the SQL statement to parse * @return the command object */ public Command prepareCommand(String sql) { try { Prepared p = parse(sql); boolean hasMore = isToken(";"); if (!hasMore && currentTokenType != END) { throw getSyntaxError(); } p.prepare(); Command c = new CommandContainer(this, sql, p); if (hasMore) { String remaining = originalSQL.substring(parseIndex); if (remaining.trim().length() != 0) { c = new CommandList(this, sql, c, remaining); } } return c; } catch (DbException e) { throw e.addSQL(originalSQL); } }
@Override public int update() { recompileIfRequired(); setProgress(DatabaseEventListener.STATE_STATEMENT_START); start(); session.setLastScopeIdentity(ValueNull.INSTANCE); prepared.checkParameters(); int updateCount = prepared.update(); prepared.trace(startTimeNanos, updateCount); setProgress(DatabaseEventListener.STATE_STATEMENT_END); return updateCount; }
@Override public void prepareJoinBatch() { if (session.isJoinBatchEnabled()) { prepareJoinBatch(prepared); } }
public int update() throws SQLException { recompileIfRequired(); // TODO query time: should keep lock time separate from running time start(); prepared.checkParameters(); int updateCount = prepared.update(); prepared.trace(startTime, updateCount); return updateCount; }
public LocalResult query(int maxrows) throws SQLException { recompileIfRequired(); // TODO query time: should keep lock time separate from running time start(); prepared.checkParameters(); LocalResult result = prepared.query(maxrows); prepared.trace(startTime, result.getRowCount()); return result; }
@Override public ResultInterface query(int maxrows) { recompileIfRequired(); setProgress(DatabaseEventListener.STATE_STATEMENT_START); start(); prepared.checkParameters(); ResultInterface result = prepared.query(maxrows); prepared.trace(startTimeNanos, result.isLazy() ? 0 : result.getRowCount()); setProgress(DatabaseEventListener.STATE_STATEMENT_END); return result; }
private static void prepareJoinBatch(Prepared prepared) { if (prepared.isQuery()) { int type = prepared.getType(); if (type == CommandInterface.SELECT) { ((Query) prepared).prepareJoinBatch(); } else if (type == CommandInterface.EXPLAIN || type == CommandInterface.EXPLAIN_ANALYZE) { prepareJoinBatch(((Explain) prepared).getCommand()); } } }
Command c = new CommandContainer(this, sql, p); if (hasMore) { String remaining = originalSQL.substring(parseIndex);
@Override public int update() { recompileIfRequired(); setProgress(DatabaseEventListener.STATE_STATEMENT_START); start(); session.setLastScopeIdentity(ValueNull.INSTANCE); prepared.checkParameters(); int updateCount = prepared.update(); prepared.trace(startTime, updateCount); setProgress(DatabaseEventListener.STATE_STATEMENT_END); return updateCount; }
private void recompileIfRequired() { if (prepared.needRecompile()) { // TODO test with 'always recompile' prepared.setModificationMetaId(0); String sql = prepared.getSQL(); ArrayList<Parameter> oldParams = prepared.getParameters(); Parser parser = new Parser(session); prepared = parser.parse(sql); long mod = prepared.getModificationMetaId(); prepared.setModificationMetaId(0); ArrayList<Parameter> newParams = prepared.getParameters(); for (int i = 0, size = newParams.size(); i < size; i++) { Parameter old = oldParams.get(i); if (old.isValueSet()) { Value v = old.getValue(session); Parameter p = newParams.get(i); p.setValue(v); } } prepared.prepare(); prepared.setModificationMetaId(mod); prepareJoinBatch(); } }
Command c = new CommandContainer(this, sql, p); if (hasMore) { String remaining = originalSQL.substring(parseIndex);
@Override public ResultInterface query(int maxrows) { recompileIfRequired(); setProgress(DatabaseEventListener.STATE_STATEMENT_START); start(); prepared.checkParameters(); ResultInterface result = prepared.query(maxrows); prepared.trace(startTimeNanos, result.getRowCount()); setProgress(DatabaseEventListener.STATE_STATEMENT_END); return result; }
@Override public void prepareJoinBatch() { if (session.isJoinBatchEnabled()) { prepareJoinBatch(prepared); } }
Prepared p = parse(sql); p.prepare(); Command c = new CommandContainer(this, sql, p); p.setCommand(c); if (isToken(";")) {
@Override public int update() { recompileIfRequired(); setProgress(DatabaseEventListener.STATE_STATEMENT_START); start(); session.setLastScopeIdentity(ValueNull.INSTANCE); prepared.checkParameters(); int updateCount = prepared.update(); prepared.trace(startTimeNanos, updateCount); setProgress(DatabaseEventListener.STATE_STATEMENT_END); return updateCount; }
@Override public void prepareJoinBatch() { if (session.isJoinBatchEnabled()) { prepareJoinBatch(prepared); } }
@Override public ResultInterface query(int maxrows) { recompileIfRequired(); setProgress(DatabaseEventListener.STATE_STATEMENT_START); start(); prepared.checkParameters(); ResultInterface result = prepared.query(maxrows); prepared.trace(startTime, result.getRowCount()); setProgress(DatabaseEventListener.STATE_STATEMENT_END); return result; }
private static void prepareJoinBatch(Prepared prepared) { if (prepared.isQuery()) { if (prepared.getType() == CommandInterface.SELECT) { ((Query) prepared).prepareJoinBatch(); } else if (prepared.getType() == CommandInterface.EXPLAIN) { prepareJoinBatch(((Explain) prepared).getCommand()); } } }
private static void prepareJoinBatch(Prepared prepared) { if (prepared.isQuery()) { if (prepared.getType() == CommandInterface.SELECT) { ((Query) prepared).prepareJoinBatch(); } else if (prepared.getType() == CommandInterface.EXPLAIN) { prepareJoinBatch(((Explain) prepared).getCommand()); } } }
private void recompileIfRequired() { if (prepared.needRecompile()) { // TODO test with 'always recompile' prepared.setModificationMetaId(0); String sql = prepared.getSQL(); ArrayList<Parameter> oldParams = prepared.getParameters(); Parser parser = new Parser(session); prepared = parser.parse(sql); long mod = prepared.getModificationMetaId(); prepared.setModificationMetaId(0); ArrayList<Parameter> newParams = prepared.getParameters(); for (int i = 0, size = newParams.size(); i < size; i++) { Parameter old = oldParams.get(i); if (old.isValueSet()) { Value v = old.getValue(session); Parameter p = newParams.get(i); p.setValue(v); } } prepared.prepare(); prepared.setModificationMetaId(mod); prepareJoinBatch(); } }