Search in sources :

Example 1 with MultiSqlParser

use of com.developmentontheedge.dbms.MultiSqlParser in project be5 by DevelopmentOnTheEdge.

the class SqlTest method testTrigger.

public void testTrigger() {
    String sql = "DROP TRIGGER IF EXISTS makeSearchCompanyNameFields ON utilitySupplierChecks;\n" + "CREATE TRIGGER makeSearchCompanyNameFields\n" + "BEFORE INSERT OR UPDATE OF companyName ON utilitySupplierChecks\n" + "FOR EACH ROW\n" + "BEGIN\n" + "   :new.\"___searchCompanyName\" := TRIM( REGEXP_REPLACE( REGEXP_REPLACE( REPLACE( UPPER( :new.companyName ),'Ё','Е' ), '([^A-ZА-Я0-9]*)([A-ZА-Я0-9]+)', '\\2 ' ), '^([A-ZА-Я0-9 ]+)([^A-ZА-Я0-9]*)$', '\\1 ' ) );\n" + "END;";
    MultiSqlParser multiSqlParser = new MultiSqlParser(DbmsType.DB2, sql);
    assertEquals("DROP TRIGGER IF EXISTS makeSearchCompanyNameFields ON utilitySupplierChecks", multiSqlParser.nextStatement());
    assertEquals("CREATE TRIGGER makeSearchCompanyNameFields BEFORE INSERT OR UPDATE OF companyName ON utilitySupplierChecks FOR EACH ROW " + "BEGIN :new.\"___searchCompanyName\" := TRIM( REGEXP_REPLACE( REGEXP_REPLACE( REPLACE( UPPER( :new.companyName ),'Ё','Е' ), '([^A-ZА-Я0-9]*)([A-ZА-Я0-9]+)', '\\2 ' ), '^([A-ZА-Я0-9 ]+)([^A-ZА-Я0-9]*)$', '\\1 ' ) ); END", multiSqlParser.nextStatement());
    assertNull(multiSqlParser.nextStatement());
}
Also used : MultiSqlParser(com.developmentontheedge.dbms.MultiSqlParser)

Example 2 with MultiSqlParser

use of com.developmentontheedge.dbms.MultiSqlParser in project be5 by DevelopmentOnTheEdge.

the class SqlTest method testMultiSqlParser.

public void testMultiSqlParser() {
    String sql = "-- cool statement\nSELECT 'a=''' || \na||'''; b='''||/*b value*/b   FROM \"myTable\";" + "SELECT -- select starts here\nb,c,d-- add more columns in future\nFROM ttt;\n\n-- second section --\n" + "SELECT blahblah;;;;SELECT '/* comment in ''quotes''*/';;";
    MultiSqlParser multiSqlParser = new MultiSqlParser(DbmsType.DB2, sql);
    assertEquals("SELECT 'a=''' || a||'''; b='''|| b FROM \"myTable\"", multiSqlParser.nextStatement());
    assertEquals("SELECT b,c,d FROM ttt", multiSqlParser.nextStatement());
    assertEquals("SELECT blahblah", multiSqlParser.nextStatement());
    assertEquals("SELECT '/* comment in ''quotes''*/'", multiSqlParser.nextStatement());
    assertNull(multiSqlParser.nextStatement());
}
Also used : MultiSqlParser(com.developmentontheedge.dbms.MultiSqlParser)

Aggregations

MultiSqlParser (com.developmentontheedge.dbms.MultiSqlParser)2