use of net.sf.jsqlparser.statement.insert.Insert 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.insert.Insert 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.getTable().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.insert.Insert in project JSqlParser by JSQLParser.
the class TablesNamesFinderTest method testInsertSelect.
@Test
public void testInsertSelect() throws Exception {
String sql = "INSERT INTO mytable (mycolumn) SELECT mycolumn FROM mytable2";
net.sf.jsqlparser.statement.Statement statement = pm.parse(new StringReader(sql));
Insert insertStatement = (Insert) statement;
TablesNamesFinder tablesNamesFinder = new TablesNamesFinder();
List<String> tableList = tablesNamesFinder.getTableList(insertStatement);
assertEquals(2, tableList.size());
assertTrue(tableList.contains("mytable"));
assertTrue(tableList.contains("mytable2"));
}
use of net.sf.jsqlparser.statement.insert.Insert in project JSqlParser by JSQLParser.
the class TablesNamesFinderTest method testInsertSubSelect.
@Test
public void testInsertSubSelect() throws JSQLParserException {
String sql = "INSERT INTO Customers (CustomerName, Country) SELECT SupplierName, Country FROM Suppliers WHERE Country='Germany'";
Insert insert = (Insert) pm.parse(new StringReader(sql));
TablesNamesFinder tablesNamesFinder = new TablesNamesFinder();
List<String> tableList = tablesNamesFinder.getTableList(insert);
assertEquals(2, tableList.size());
assertTrue(tableList.contains("Customers"));
assertTrue(tableList.contains("Suppliers"));
}
use of net.sf.jsqlparser.statement.insert.Insert in project JSqlParser by JSQLParser.
the class TablesNamesFinderTest method testGetTableListFromInsert.
@Test
public void testGetTableListFromInsert() throws Exception {
String sql = "INSERT INTO MY_TABLE1 (a) VALUES ((SELECT a from MY_TABLE2 WHERE a = 1))";
net.sf.jsqlparser.statement.Statement statement = pm.parse(new StringReader(sql));
Insert insertStatement = (Insert) statement;
TablesNamesFinder tablesNamesFinder = new TablesNamesFinder();
List<String> tableList = tablesNamesFinder.getTableList(insertStatement);
assertEquals(2, tableList.size());
assertTrue(tableList.contains("MY_TABLE1"));
assertTrue(tableList.contains("MY_TABLE2"));
}
Aggregations