use of net.sf.jsqlparser.parser.TokenMgrError in project spanner-jdbc by olavloite.
the class CloudSpannerStatement method execute.
@Override
public boolean execute(String sql) throws SQLException {
String[] sqlTokens = getTokens(sql);
CustomDriverStatement custom = getCustomDriverStatement(sqlTokens);
if (custom != null)
return custom.execute(sqlTokens);
Statement statement = null;
boolean ddl = isDDLStatement(sqlTokens);
if (!ddl) {
try {
statement = CCJSqlParserUtil.parse(sanitizeSQL(sql));
} catch (JSQLParserException | TokenMgrError e) {
throw new CloudSpannerSQLException("Error while parsing sql statement " + sql + ": " + e.getLocalizedMessage(), Code.INVALID_ARGUMENT, e);
}
}
if (!ddl && statement instanceof Select) {
lastResultSet = executeQuery(sql);
lastUpdateCount = -1;
return true;
} else {
lastUpdateCount = executeUpdate(sql);
lastResultSet = null;
return false;
}
}
use of net.sf.jsqlparser.parser.TokenMgrError in project spanner-jdbc by olavloite.
the class CloudSpannerPreparedStatement method execute.
@Override
public boolean execute() throws SQLException {
CustomDriverStatement custom = getCustomDriverStatement(sqlTokens);
if (custom != null)
return custom.execute(sqlTokens);
Statement statement = null;
boolean ddl = isDDLStatement();
if (!ddl) {
try {
statement = CCJSqlParserUtil.parse(sanitizeSQL(sql));
} catch (JSQLParserException | TokenMgrError e) {
throw new CloudSpannerSQLException(PARSE_ERROR + sql + ": " + e.getLocalizedMessage(), Code.INVALID_ARGUMENT, e);
}
}
if (!ddl && statement instanceof Select) {
lastResultSet = executeQuery();
lastUpdateCount = -1;
return true;
} else {
lastUpdateCount = executeUpdate();
lastResultSet = null;
return false;
}
}
use of net.sf.jsqlparser.parser.TokenMgrError in project spanner-jdbc by olavloite.
the class CloudSpannerPreparedStatement method executeQuery.
@Override
public ResultSet executeQuery() throws SQLException {
CustomDriverStatement custom = getCustomDriverStatement(sqlTokens);
if (custom != null && custom.isQuery()) {
return custom.executeQuery(sqlTokens);
}
Statement statement;
try {
statement = CCJSqlParserUtil.parse(sanitizeSQL(sql));
} catch (JSQLParserException | TokenMgrError e) {
throw new CloudSpannerSQLException(PARSE_ERROR + sql + ": " + e.getLocalizedMessage(), Code.INVALID_ARGUMENT, e);
}
if (statement instanceof Select) {
determineForceSingleUseReadContext((Select) statement);
com.google.cloud.spanner.Statement.Builder builder = createSelectBuilder(statement, sql);
try (ReadContext context = getReadContext()) {
com.google.cloud.spanner.ResultSet rs = context.executeQuery(builder.build());
return new CloudSpannerResultSet(this, rs);
}
}
throw new CloudSpannerSQLException("SQL statement not suitable for executeQuery. Expected SELECT-statement.", Code.INVALID_ARGUMENT);
}
Aggregations