Search in sources :

Example 51 with SQLServerStatementParser

use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.

the class SQLServerAlterTableTest_9 method test_alter_first.

public void test_alter_first() throws Exception {
    String sql = "ALTER TABLE dbo.doc_exy ALTER COLUMN column_a DECIMAL (5, 2) ;";
    SQLServerStatementParser parser = new SQLServerStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    SQLServerSchemaStatVisitor visitor = new SQLServerSchemaStatVisitor();
    stmt.accept(visitor);
    // System.out.println("Tables : " + visitor.getTables());
    // System.out.println("fields : " + visitor.getColumns());
    // System.out.println("coditions : " + visitor.getConditions());
    // System.out.println("orderBy : " + visitor.getOrderByColumns());
    String output = SQLUtils.toSQLString(stmt, JdbcConstants.SQL_SERVER);
    Assert.assertEquals(// 
    "ALTER TABLE dbo.doc_exy" + "\n\tALTER COLUMN column_a DECIMAL(5, 2);", output);
    Assert.assertEquals(1, visitor.getTables().size());
    Assert.assertEquals(1, visitor.getColumns().size());
}
Also used : SQLServerSchemaStatVisitor(com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerSchemaStatVisitor) SQLServerStatementParser(com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 52 with SQLServerStatementParser

use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.

the class SQLServerCommitTest method test_2.

public void test_2() {
    String sql = "COMMIT TRANSACTION @tran_name_variable  WITH ( DELAYED_DURABILITY = OFF )";
    SQLServerStatementParser parser = new SQLServerStatementParser(sql);
    List<SQLStatement> stmtList = parser.parseStatementList();
    Assert.assertEquals(1, stmtList.size());
    String text = SQLUtils.toSQLString(stmtList, JdbcUtils.SQL_SERVER);
    Assert.assertEquals("COMMIT TRANSACTION @tran_name_variable WITH ( DELAYED_DURABILITY = OFF )", text);
}
Also used : SQLServerStatementParser(com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 53 with SQLServerStatementParser

use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.

the class SQLServerCreateIndexTest_4 method test_0.

public void test_0() throws Exception {
    String sql = "CREATE UNIQUE NONCLUSTERED INDEX ACT_IDX_EVENT_DEF_UNIQ " + "ON FLW_EVENT_DEFINITION(KEY_, VERSION_, TENANT_ID_)";
    SQLServerStatementParser parser = new SQLServerStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLCreateIndexStatement stmt = (SQLCreateIndexStatement) statementList.get(0);
    assertEquals(1, statementList.size());
    assertEquals(// 
    "CREATE UNIQUE NONCLUSTERED INDEX ACT_IDX_EVENT_DEF_UNIQ ON FLW_EVENT_DEFINITION (KEY_, VERSION_, TENANT_ID_)", SQLUtils.toSQLString(stmt, DbType.sqlserver));
    SQLServerSchemaStatVisitor visitor = new SQLServerSchemaStatVisitor();
    stmt.accept(visitor);
    // System.out.println("Tables : " + visitor.getTables());
    // System.out.println("fields : " + visitor.getColumns());
    // System.out.println("coditions : " + visitor.getConditions());
    // System.out.println("orderBy : " + visitor.getOrderByColumns());
    assertEquals(1, visitor.getTables().size());
    assertEquals(3, visitor.getColumns().size());
    assertEquals(0, visitor.getConditions().size());
    assertTrue(visitor.containsColumn("FLW_EVENT_DEFINITION", "KEY_"));
    assertTrue(visitor.containsColumn("FLW_EVENT_DEFINITION", "VERSION_"));
    assertTrue(visitor.containsColumn("FLW_EVENT_DEFINITION", "TENANT_ID_"));
}
Also used : SQLServerSchemaStatVisitor(com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerSchemaStatVisitor) SQLServerStatementParser(com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser) SQLCreateIndexStatement(com.alibaba.druid.sql.ast.statement.SQLCreateIndexStatement) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 54 with SQLServerStatementParser

use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.

the class SQLServerDropIndex_Test method test_alter_first.

public void test_alter_first() throws Exception {
    String sql = "DROP INDEX async_measure_snapshots.async_m_s_snapshot_id";
    SQLServerStatementParser parser = new SQLServerStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    SQLServerSchemaStatVisitor visitor = new SQLServerSchemaStatVisitor();
    stmt.accept(visitor);
    // System.out.println("Tables : " + visitor.getTables());
    // System.out.println("fields : " + visitor.getColumns());
    // System.out.println("coditions : " + visitor.getConditions());
    // System.out.println("orderBy : " + visitor.getOrderByColumns());
    String output = SQLUtils.toSQLString(stmt, JdbcConstants.SQL_SERVER);
    Assert.assertEquals("DROP INDEX async_measure_snapshots.async_m_s_snapshot_id", output);
    Assert.assertEquals(0, visitor.getTables().size());
    Assert.assertEquals(0, visitor.getColumns().size());
}
Also used : SQLServerSchemaStatVisitor(com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerSchemaStatVisitor) SQLServerStatementParser(com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 55 with SQLServerStatementParser

use of com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser in project druid by alibaba.

the class SQLServerAlterTableTest_1 method test_alter_first.

public void test_alter_first() throws Exception {
    String sql = "ALTER TABLE dependencies ALTER COLUMN id bigint";
    SQLServerStatementParser parser = new SQLServerStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    SQLServerSchemaStatVisitor visitor = new SQLServerSchemaStatVisitor();
    stmt.accept(visitor);
    // System.out.println("Tables : " + visitor.getTables());
    // System.out.println("fields : " + visitor.getColumns());
    // System.out.println("coditions : " + visitor.getConditions());
    // System.out.println("orderBy : " + visitor.getOrderByColumns());
    String output = SQLUtils.toSQLString(stmt, JdbcConstants.SQL_SERVER);
    Assert.assertEquals(// 
    "ALTER TABLE dependencies" + "\n\tALTER COLUMN id bigint", output);
    Assert.assertEquals(1, visitor.getTables().size());
    Assert.assertEquals(1, visitor.getColumns().size());
}
Also used : SQLServerSchemaStatVisitor(com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerSchemaStatVisitor) SQLServerStatementParser(com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Aggregations

SQLServerStatementParser (com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser)152 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)145 SQLServerSchemaStatVisitor (com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerSchemaStatVisitor)64 Column (com.alibaba.druid.stat.TableStat.Column)21 SQLCreateTableStatement (com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement)17 SQLSelectStatement (com.alibaba.druid.sql.ast.statement.SQLSelectStatement)9 SQLServerSelectQueryBlock (com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelectQueryBlock)8 SQLServerInsertStatement (com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerInsertStatement)8 SQLCreateIndexStatement (com.alibaba.druid.sql.ast.statement.SQLCreateIndexStatement)4 SQLSelect (com.alibaba.druid.sql.ast.statement.SQLSelect)4 SQLOrderBy (com.alibaba.druid.sql.ast.SQLOrderBy)2 SQLCreateViewStatement (com.alibaba.druid.sql.ast.statement.SQLCreateViewStatement)2 SQLSelectQuery (com.alibaba.druid.sql.ast.statement.SQLSelectQuery)2 DB2StatementParser (com.alibaba.druid.sql.dialect.db2.parser.DB2StatementParser)2 MySqlSelectQueryBlock (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock)2 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)2 OracleStatementParser (com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser)2 PGSelectQueryBlock (com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock)2 PGSQLStatementParser (com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser)2 SQLMergeStatement (com.alibaba.druid.sql.ast.statement.SQLMergeStatement)1