public void test_0() { String sql = "SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED"; SQLServerStatementParser parser = new SQLServerStatementParser(sql); List<SQLStatement> stmtList = parser.parseStatementList(); SQLStatement stmt = stmtList.get(0); Assert.assertEquals(1, stmtList.size()); 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()); Assert.assertEquals(0, visitor.getTables().size()); Assert.assertEquals(0, visitor.getColumns().size()); Assert.assertEquals(0, visitor.getConditions().size()); String text = SQLUtils.toSQLString(stmtList, JdbcUtils.SQL_SERVER); Assert.assertEquals("SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED", text); }
public void test_0() throws Exception { String sql = "SELECT * FROM DSN81010.EMP;"; DB2StatementParser parser = new DB2StatementParser(sql); List<SQLStatement> statementList = parser.parseStatementList(); SQLStatement stmt = statementList.get(0); print(statementList); Assert.assertEquals(1, statementList.size()); DB2SchemaStatVisitor visitor = new DB2SchemaStatVisitor(); 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()); Assert.assertEquals(1, visitor.getTables().size()); Assert.assertEquals(1, visitor.getColumns().size()); Assert.assertEquals(0, visitor.getConditions().size()); Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("DSN81010.EMP"))); // Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "last_name"))); // Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "first_name"))); // Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "full_name"))); String output = SQLUtils.toSQLString(stmt, JdbcConstants.DB2); Assert.assertEquals( "SELECT *" // + "\nFROM DSN81010.EMP", // output); }
public void test_0() throws Exception { String sql = // "CREATE TRIGGER \"AO_4AEACD_WEBHOOK_D367380484\" " // + "BEFORE INSERT" // + " ON \"AO_4AEACD_WEBHOOK_DAO\" FOR EACH ROW " // + "BEGIN" // + " SELECT \"AO_4AEACD_WEBHOOK_DAO_ID_SEQ\".NEXTVAL INTO :NEW.\"ID\" FROM DUAL;" // + "END;"; OracleStatementParser parser = new OracleStatementParser(sql); List<SQLStatement> statementList = parser.parseStatementList(); SQLStatement stmt = statementList.get(0); print(statementList); Assert.assertEquals(1, statementList.size()); Assert.assertEquals( "CREATE TRIGGER \"AO_4AEACD_WEBHOOK_D367380484\"" // + "\n\tBEFORE INSERT" // + "\n\tON \"AO_4AEACD_WEBHOOK_DAO\"" // + "\n\tFOR EACH ROW" // + "\nBEGIN" // + "\n\tSELECT \"AO_4AEACD_WEBHOOK_DAO_ID_SEQ\".NEXTVAL" // + "\n\tINTO :NEW.\"ID\"" // + "\n\tFROM DUAL;" + "\nEND", // SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE)); OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor(); stmt.accept(visitor); System.out.println("Tables : " + visitor.getTables()); System.out.println("fields : " + visitor.getColumns()); System.out.println("coditions : " + visitor.getConditions()); System.out.println("relationships : " + visitor.getRelationships()); System.out.println("orderBy : " + visitor.getOrderByColumns()); Assert.assertEquals(0, visitor.getTables().size()); // Assert.assertTrue(visitor.getTables().containsKey(new // TableStat.Name("cdc.en_complaint_ipr_stat_fdt0"))); Assert.assertEquals(0, visitor.getColumns().size()); // Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "*"))); // Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", // "YEAR"))); // Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", // "order_mode"))); }
public void test_0() throws Exception { String sql = "CREATE TABLE dbo.customfieldoption (" // + "ID NUMERIC NOT NULL, CUSTOMFIELD NUMERIC, CUSTOMFIELDCONFIG NUMERIC, " // + "PARENTOPTIONID NUMERIC, SEQUENCE NUMERIC, customvalue NVARCHAR(255), " // + "optiontype NVARCHAR(60), disabled NVARCHAR(60), " // + "CONSTRAINT PK_customfieldoption PRIMARY KEY (ID))"; SQLServerStatementParser parser = new SQLServerStatementParser(sql); List<SQLStatement> statementList = parser.parseStatementList(); SQLCreateTableStatement stmt = (SQLCreateTableStatement) statementList.get(0); Assert.assertEquals(1, statementList.size()); String output = SQLUtils.toSQLString(stmt, JdbcConstants.SQL_SERVER); Assert.assertEquals( "CREATE TABLE dbo.customfieldoption (" // + "\n\tID NUMERIC NOT NULL," // + "\n\tCUSTOMFIELD NUMERIC," // + "\n\tCUSTOMFIELDCONFIG NUMERIC," // + "\n\tPARENTOPTIONID NUMERIC," // + "\n\tSEQUENCE NUMERIC," // + "\n\tcustomvalue NVARCHAR(255)," // + "\n\toptiontype NVARCHAR(60)," // + "\n\tdisabled NVARCHAR(60)," // + "\n\tCONSTRAINT PK_customfieldoption PRIMARY KEY (ID)" // + "\n)", output); 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()); Assert.assertEquals(1, visitor.getTables().size()); Assert.assertEquals(9, visitor.getColumns().size()); Assert.assertEquals(0, visitor.getConditions().size()); Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("dbo.customfieldoption"))); Assert.assertTrue(visitor.getColumns().contains(new Column("dbo.customfieldoption", "ID"))); Assert.assertTrue( visitor.getColumns().contains(new Column("dbo.customfieldoption", "CUSTOMFIELD"))); Assert.assertTrue( visitor.getColumns().contains(new Column("dbo.customfieldoption", "CUSTOMFIELDCONFIG"))); }
public static Object eval( String dbType, SQLObject sqlObject, List<Object> parameters, boolean throwError) { SQLEvalVisitor visitor = createEvalVisitor(dbType); visitor.setParameters(parameters); sqlObject.accept(visitor); Object value = getValue(sqlObject); if (value == null) { if (throwError && !sqlObject.getAttributes().containsKey(EVAL_VALUE)) { throw new DruidRuntimeException("eval error : " + SQLUtils.toSQLString(sqlObject, dbType)); } } return value; }
public void test_3() { String sql = "SET @state = N'Oregon'"; SQLServerStatementParser parser = new SQLServerStatementParser(sql); List<SQLStatement> stmtList = parser.parseStatementList(); SQLStatement stmt = stmtList.get(0); Assert.assertEquals(1, stmtList.size()); SQLServerSchemaStatVisitor visitor = new SQLServerSchemaStatVisitor(); stmt.accept(visitor); Assert.assertEquals(0, visitor.getTables().size()); Assert.assertEquals(0, visitor.getColumns().size()); Assert.assertEquals(0, visitor.getConditions().size()); String text = SQLUtils.toSQLString(stmtList, JdbcUtils.SQL_SERVER); Assert.assertEquals("SET @state = N'Oregon'", text); }
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()); }