Java Code Examples for net.sf.jsqlparser.statement.delete.Delete#getWhere()
The following examples show how to use
net.sf.jsqlparser.statement.delete.Delete#getWhere() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CRUDParseUtils.java From WeBASE-Front with Apache License 2.0 | 6 votes |
public static void parseRemove(String sql, Table table, Condition condition) throws JSQLParserException, FrontException { Statement statement = CCJSqlParserUtil.parse(sql); Delete delete = (Delete) statement; // parse table name net.sf.jsqlparser.schema.Table sqlTable = delete.getTable(); table.setTableName(sqlTable.getName()); // parse where clause Expression where = delete.getWhere(); if (where != null) { BinaryExpression expr = (BinaryExpression) (where); handleExpression(condition, expr); } Limit limit = delete.getLimit(); parseLimit(condition, limit); }
Example 2
Source File: CloudSpannerPreparedStatement.java From spanner-jdbc with MIT License | 6 votes |
private Mutation createDeleteMutation(Delete delete, boolean generateParameterMetaData) throws SQLException { String table = unquoteIdentifier(delete.getTable().getFullyQualifiedName()); getParameterStore().setTable(table); Expression where = delete.getWhere(); if (where == null) { // Delete all return Mutation.delete(table, KeySet.all()); } else { // Delete one DeleteKeyBuilder keyBuilder = new DeleteKeyBuilder(getConnection().getTable(table), generateParameterMetaData); visitDeleteWhereClause(where, keyBuilder, generateParameterMetaData); return Mutation.delete(table, keyBuilder.getKeyBuilder().build()); } }
Example 3
Source File: TablesNamesFinder.java From evosql with Apache License 2.0 | 5 votes |
@Override public void visit(Delete delete) { tables.add(delete.getTable().getName()); if (delete.getWhere() != null) { delete.getWhere().accept(this); } }
Example 4
Source File: TableRenameVisitor.java From compass with Apache License 2.0 | 5 votes |
@Override public void visit(Delete delete) { delete.getTable().accept(this); if (delete.getWhere() != null) { delete.getWhere().accept(this); } }
Example 5
Source File: CloudSpannerPreparedStatement.java From spanner-jdbc with MIT License | 4 votes |
private Mutations createMutations(String sql, boolean forceUpdate, boolean generateParameterMetaData) throws SQLException { try { if (getConnection().isReadOnly()) { throw new CloudSpannerSQLException(NO_MUTATIONS_IN_READ_ONLY_MODE_EXCEPTION, Code.FAILED_PRECONDITION); } if (isDDLStatement()) { throw new CloudSpannerSQLException( "Cannot create mutation for DDL statement. Expected INSERT, UPDATE or DELETE", Code.INVALID_ARGUMENT); } Statement statement = CCJSqlParserUtil.parse(sanitizeSQL(sql)); if (statement instanceof Insert) { Insert insertStatement = (Insert) statement; if (generateParameterMetaData || insertStatement.getSelect() == null) return new Mutations(createInsertMutation(insertStatement, generateParameterMetaData)); return new Mutations(createInsertWithSelectStatement(insertStatement, forceUpdate)); } else if (statement instanceof Update) { Update updateStatement = (Update) statement; if (updateStatement.getSelect() != null) throw new CloudSpannerSQLException( "UPDATE statement using SELECT is not supported. Try to re-write the statement as an INSERT INTO ... SELECT A, B, C FROM TABLE WHERE ... ON DUPLICATE KEY UPDATE", Code.INVALID_ARGUMENT); if (updateStatement.getTables().size() > 1) throw new CloudSpannerSQLException( "UPDATE statement using multiple tables is not supported. Try to re-write the statement as an INSERT INTO ... SELECT A, B, C FROM TABLE WHERE ... ON DUPLICATE KEY UPDATE", Code.INVALID_ARGUMENT); if (generateParameterMetaData || isSingleRowWhereClause( getConnection() .getTable(unquoteIdentifier(updateStatement.getTables().get(0).getName())), updateStatement.getWhere())) return new Mutations(createUpdateMutation(updateStatement, generateParameterMetaData)); // Translate into an 'INSERT ... SELECT ... ON DUPLICATE KEY // UPDATE'-statement String insertSQL = createInsertSelectOnDuplicateKeyUpdateStatement(updateStatement); return createMutations(insertSQL, true, false); } else if (statement instanceof Delete) { Delete deleteStatement = (Delete) statement; if (generateParameterMetaData || deleteStatement.getWhere() == null || isSingleRowWhereClause( getConnection().getTable(unquoteIdentifier(deleteStatement.getTable().getName())), deleteStatement.getWhere())) return new Mutations(createDeleteMutation(deleteStatement, generateParameterMetaData)); return new Mutations(createDeleteWorker(deleteStatement)); } else { throw new CloudSpannerSQLException( "Unrecognized or unsupported SQL-statment: Expected one of INSERT, UPDATE or DELETE. Please note that batching of prepared statements is not supported for SELECT-statements.", Code.INVALID_ARGUMENT); } } catch (JSQLParserException | IllegalArgumentException | TokenMgrException e) { throw new CloudSpannerSQLException(PARSE_ERROR + sql + ": " + e.getLocalizedMessage(), Code.INVALID_ARGUMENT, e); } }
Example 6
Source File: SQLCommandInfoHolder.java From sql-to-mongo-db-query-converter with Apache License 2.0 | 4 votes |
public Builder setDelete(Delete delete) throws com.github.vincentrussell.query.mongodb.sql.converter.ParseException, ParseException { SqlUtils.isTrue(delete.getTables().size() == 0, "there should only be on table specified for deletes"); from = generateFromHolder(new FromHolder(this.defaultFieldType,this.fieldNameToFieldTypeMapping),delete.getTable(),null); whereClause = delete.getWhere(); return this; }