use of net.sf.jsqlparser.statement.drop.Drop 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.drop.Drop 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.drop.Drop in project JSqlParser by JSQLParser.
the class DropTest method testDrop.
@Test
public void testDrop() throws JSQLParserException {
String statement = "DROP TABLE mytab";
Drop drop = (Drop) parserManager.parse(new StringReader(statement));
assertEquals("TABLE", drop.getType());
assertEquals("mytab", drop.getName().getFullyQualifiedName());
assertEquals(statement, "" + drop);
statement = "DROP INDEX myindex CASCADE";
drop = (Drop) parserManager.parse(new StringReader(statement));
assertEquals("INDEX", drop.getType());
assertEquals("myindex", drop.getName().getFullyQualifiedName());
assertEquals("CASCADE", drop.getParameters().get(0));
assertEquals(statement, "" + drop);
}
use of net.sf.jsqlparser.statement.drop.Drop in project JSqlParser by JSQLParser.
the class DropTest method testDrop2.
@Test
public void testDrop2() throws JSQLParserException {
Drop drop = (Drop) parserManager.parse(new StringReader("DROP TABLE \"testtable\""));
assertEquals("TABLE", drop.getType());
assertEquals("\"testtable\"", drop.getName().getFullyQualifiedName());
}
use of net.sf.jsqlparser.statement.drop.Drop in project dbeaver by serge-rider.
the class SQLQuery method parseQuery.
private void parseQuery() {
if (parsed) {
return;
}
parsed = true;
try {
if (CommonUtils.isEmpty(text)) {
this.statement = null;
this.parseError = new DBException("Empty query");
return;
}
statement = SQLSemanticProcessor.parseQuery(dataSource == null ? null : dataSource.getSQLDialect(), text);
if (statement instanceof Select) {
type = SQLQueryType.SELECT;
// Detect single source table (no joins, no group by, no sub-selects)
SelectBody selectBody = ((Select) statement).getSelectBody();
if (selectBody instanceof PlainSelect) {
PlainSelect plainSelect = (PlainSelect) selectBody;
if (plainSelect.getFromItem() instanceof Table && CommonUtils.isEmpty(plainSelect.getJoins()) && (plainSelect.getGroupBy() == null || CommonUtils.isEmpty(plainSelect.getGroupBy().getGroupByExpressions())) && CommonUtils.isEmpty(plainSelect.getIntoTables())) {
boolean hasSubSelects = false;
for (SelectItem si : plainSelect.getSelectItems()) {
if (si instanceof SelectExpressionItem && ((SelectExpressionItem) si).getExpression() instanceof SubSelect) {
hasSubSelects = true;
break;
}
}
if (!hasSubSelects) {
fillSingleSource((Table) plainSelect.getFromItem());
}
}
// Extract select items info
final List<SelectItem> items = plainSelect.getSelectItems();
if (items != null && !items.isEmpty()) {
selectItems = new ArrayList<>();
for (SelectItem item : items) {
selectItems.add(new SQLSelectItem(item));
}
}
}
} else if (statement instanceof Insert) {
type = SQLQueryType.INSERT;
fillSingleSource(((Insert) statement).getTable());
} else if (statement instanceof Update) {
type = SQLQueryType.UPDATE;
Table table = ((Update) statement).getTable();
if (table != null) {
fillSingleSource(table);
}
} else if (statement instanceof Delete) {
type = SQLQueryType.DELETE;
if (((Delete) statement).getTable() != null) {
fillSingleSource(((Delete) statement).getTable());
} else {
List<Table> tables = ((Delete) statement).getTables();
if (tables != null && tables.size() == 1) {
fillSingleSource(tables.get(0));
}
}
} else if (statement instanceof Alter || statement instanceof CreateTable || statement instanceof CreateView || statement instanceof Drop || statement instanceof CreateIndex) {
type = SQLQueryType.DDL;
} else {
type = SQLQueryType.UNKNOWN;
}
} catch (Throwable e) {
this.type = SQLQueryType.UNKNOWN;
this.parseError = e;
// log.debug("Error parsing SQL query [" + query + "]:" + CommonUtils.getRootCause(e).getMessage());
}
}
Aggregations