Search in sources :

Example 1 with TokenMgrError

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;
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(net.sf.jsqlparser.statement.Statement) JSQLParserException(net.sf.jsqlparser.JSQLParserException) Select(net.sf.jsqlparser.statement.select.Select) TokenMgrError(net.sf.jsqlparser.parser.TokenMgrError) CloudSpannerSQLException(nl.topicus.jdbc.exception.CloudSpannerSQLException)

Example 2 with TokenMgrError

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;
    }
}
Also used : Statement(net.sf.jsqlparser.statement.Statement) JSQLParserException(net.sf.jsqlparser.JSQLParserException) PlainSelect(net.sf.jsqlparser.statement.select.PlainSelect) SubSelect(net.sf.jsqlparser.statement.select.SubSelect) Select(net.sf.jsqlparser.statement.select.Select) TokenMgrError(net.sf.jsqlparser.parser.TokenMgrError) CloudSpannerSQLException(nl.topicus.jdbc.exception.CloudSpannerSQLException)

Example 3 with TokenMgrError

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);
}
Also used : Statement(net.sf.jsqlparser.statement.Statement) JSQLParserException(net.sf.jsqlparser.JSQLParserException) TokenMgrError(net.sf.jsqlparser.parser.TokenMgrError) CloudSpannerSQLException(nl.topicus.jdbc.exception.CloudSpannerSQLException) ReadContext(com.google.cloud.spanner.ReadContext) PlainSelect(net.sf.jsqlparser.statement.select.PlainSelect) SubSelect(net.sf.jsqlparser.statement.select.SubSelect) Select(net.sf.jsqlparser.statement.select.Select) CloudSpannerResultSet(nl.topicus.jdbc.resultset.CloudSpannerResultSet)

Aggregations

JSQLParserException (net.sf.jsqlparser.JSQLParserException)3 TokenMgrError (net.sf.jsqlparser.parser.TokenMgrError)3 Statement (net.sf.jsqlparser.statement.Statement)3 Select (net.sf.jsqlparser.statement.select.Select)3 CloudSpannerSQLException (nl.topicus.jdbc.exception.CloudSpannerSQLException)3 PlainSelect (net.sf.jsqlparser.statement.select.PlainSelect)2 SubSelect (net.sf.jsqlparser.statement.select.SubSelect)2 ReadContext (com.google.cloud.spanner.ReadContext)1 PreparedStatement (java.sql.PreparedStatement)1 CloudSpannerResultSet (nl.topicus.jdbc.resultset.CloudSpannerResultSet)1