use of net.sf.jsqlparser.statement.update.Update in project herddb by diennea.
the class SQLPlanner method plan.
@Override
public ExecutionPlan plan(String defaultTableSpace, net.sf.jsqlparser.statement.Statement stmt, boolean scan, boolean returnValues, int maxRows) {
verifyJdbcParametersIndexes(stmt);
ExecutionPlan result;
if (stmt instanceof CreateTable) {
result = ExecutionPlan.simple(buildCreateTableStatement(defaultTableSpace, (CreateTable) stmt));
} else if (stmt instanceof CreateIndex) {
result = ExecutionPlan.simple(buildCreateIndexStatement(defaultTableSpace, (CreateIndex) stmt));
} else if (stmt instanceof Insert) {
result = buildInsertStatement(defaultTableSpace, (Insert) stmt, returnValues);
} else if (stmt instanceof Delete) {
result = buildDeleteStatement(defaultTableSpace, (Delete) stmt, returnValues);
} else if (stmt instanceof Update) {
result = buildUpdateStatement(defaultTableSpace, (Update) stmt, returnValues);
} else if (stmt instanceof Select) {
result = buildSelectStatement(defaultTableSpace, (Select) stmt, scan, maxRows);
} else if (stmt instanceof Execute) {
result = ExecutionPlan.simple(buildExecuteStatement(defaultTableSpace, (Execute) stmt));
} else if (stmt instanceof Alter) {
result = ExecutionPlan.simple(buildAlterStatement(defaultTableSpace, (Alter) stmt));
} else if (stmt instanceof Drop) {
result = ExecutionPlan.simple(buildDropStatement(defaultTableSpace, (Drop) stmt));
} else if (stmt instanceof Truncate) {
result = ExecutionPlan.simple(buildTruncateStatement(defaultTableSpace, (Truncate) stmt));
} else {
return null;
}
return result;
}
use of net.sf.jsqlparser.statement.update.Update in project herddb by diennea.
the class TableSpaceMapper method getTableSpace.
public String getTableSpace(Statement statement) throws ScriptException {
String tableName = null;
if (statement instanceof Insert) {
Insert st = (Insert) statement;
tableName = st.getTable().getFullyQualifiedName();
} else if (statement instanceof Update) {
Update st = (Update) statement;
tableName = st.getTables().get(0).getFullyQualifiedName();
} else if (statement instanceof Delete) {
Delete st = (Delete) statement;
tableName = st.getTables().get(0).getFullyQualifiedName();
} else if (statement instanceof Truncate) {
Truncate st = (Truncate) statement;
tableName = st.getTable().getFullyQualifiedName();
} else if (statement instanceof Drop) {
Drop st = (Drop) statement;
tableName = st.getName().getFullyQualifiedName();
} else if (statement instanceof CreateTable) {
CreateTable st = (CreateTable) statement;
tableName = st.getTable().getFullyQualifiedName();
} else if (statement instanceof Alter) {
Alter st = (Alter) statement;
tableName = st.getTable().getFullyQualifiedName();
} else {
return null;
}
return mapTableNameToSchema(tableName);
}
use of net.sf.jsqlparser.statement.update.Update in project JSqlParser by JSQLParser.
the class UpdateTest method testUpdate.
@Test
public void testUpdate() throws JSQLParserException {
String statement = "UPDATE mytable set col1='as', col2=?, col3=565 Where o >= 3";
Update update = (Update) parserManager.parse(new StringReader(statement));
assertEquals("mytable", update.getTables().get(0).getName());
assertEquals(3, update.getColumns().size());
assertEquals("col1", ((Column) update.getColumns().get(0)).getColumnName());
assertEquals("col2", ((Column) update.getColumns().get(1)).getColumnName());
assertEquals("col3", ((Column) update.getColumns().get(2)).getColumnName());
assertEquals("as", ((StringValue) update.getExpressions().get(0)).getValue());
assertTrue(update.getExpressions().get(1) instanceof JdbcParameter);
assertEquals(565, ((LongValue) update.getExpressions().get(2)).getValue());
assertTrue(update.getWhere() instanceof GreaterThanEquals);
}
use of net.sf.jsqlparser.statement.update.Update in project JSqlParser by JSQLParser.
the class TablesNamesFinderTest method testGetTableListFromUpdate3.
@Test
public void testGetTableListFromUpdate3() throws Exception {
String sql = "UPDATE MY_TABLE1 SET a = 5 FROM MY_TABLE1 INNER JOIN MY_TABLE2 on MY_TABLE1.C = MY_TABLE2.D WHERE 0 < (SELECT COUNT(b) FROM MY_TABLE3)";
net.sf.jsqlparser.statement.Statement statement = pm.parse(new StringReader(sql));
Update updateStatement = (Update) statement;
TablesNamesFinder tablesNamesFinder = new TablesNamesFinder();
List<String> tableList = tablesNamesFinder.getTableList(updateStatement);
assertEquals(3, tableList.size());
assertTrue(tableList.contains("MY_TABLE1"));
assertTrue(tableList.contains("MY_TABLE2"));
assertTrue(tableList.contains("MY_TABLE3"));
}
use of net.sf.jsqlparser.statement.update.Update in project JSqlParser by JSQLParser.
the class TablesNamesFinderTest method testUpdateGetTableListIssue295.
@Test
public void testUpdateGetTableListIssue295() throws JSQLParserException {
Update statement = (Update) CCJSqlParserUtil.parse("UPDATE component SET col = 0 WHERE (component_id,ver_num) IN (SELECT component_id,ver_num FROM component_temp)");
TablesNamesFinder tablesNamesFinder = new TablesNamesFinder();
List<String> tableList = tablesNamesFinder.getTableList(statement);
assertEquals(2, tableList.size());
assertTrue(tableList.contains("component"));
assertTrue(tableList.contains("component_temp"));
}
Aggregations