Ejemplo n.º 1
0
  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 =
        "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")));
  }
Ejemplo n.º 3
0
  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);
  }