public void test_0() throws Exception { String sql = "select id, name, beanId, \"algLable.id\", \"algLable.name\"" + // ", \"algLable.schemaName\", \"algLable.tableName\", \"algLable.fieldName\"" + // " from cnres.function_select_algmodule_rule() " + // " as a( id text,name text,beanId text, \"algLable.id\" text,\"algLable.name\" text" + // ", \"algLable.schemaName\" text,\"algLable.tableName\" text, \"algLable.fieldName\" text)"; PGSQLStatementParser parser = new PGSQLStatementParser(sql); List<SQLStatement> statementList = parser.parseStatementList(); SQLStatement statemen = statementList.get(0); print(statementList); Assert.assertEquals(1, statementList.size()); PGSchemaStatVisitor visitor = new PGSchemaStatVisitor(); statemen.accept(visitor); System.out.println("Tables : " + visitor.getTables()); System.out.println("fields : " + visitor.getColumns()); System.out.println("coditions : " + visitor.getConditions()); Assert.assertEquals(8, visitor.getColumns().size()); Assert.assertEquals(0, visitor.getTables().size()); }
public void test_0() throws Exception { String sql = "INSERT INTO films SELECT * FROM tmp_films WHERE date_prod < '2004-05-07';"; PGSQLStatementParser parser = new PGSQLStatementParser(sql); List<SQLStatement> statementList = parser.parseStatementList(); SQLStatement statemen = statementList.get(0); print(statementList); Assert.assertEquals(1, statementList.size()); PGSchemaStatVisitor visitor = new PGSchemaStatVisitor(); statemen.accept(visitor); System.out.println("Tables : " + visitor.getTables()); System.out.println("fields : " + visitor.getColumns()); System.out.println("coditions : " + visitor.getConditions()); Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("films"))); Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("tmp_films"))); Assert.assertEquals(2, visitor.getColumns().size()); Assert.assertTrue( visitor.getColumns().contains(new TableStat.Column("tmp_films", "date_prod"))); Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("tmp_films", "*"))); }
public void test_0() throws Exception { String sql = "select pkvalue from dbtpktable where tablename = 'taturvisit' for update"; PGSQLStatementParser parser = new PGSQLStatementParser(sql); List<SQLStatement> statementList = parser.parseStatementList(); SQLStatement statemen = statementList.get(0); print(statementList); Assert.assertEquals(1, statementList.size()); PGSchemaStatVisitor visitor = new PGSchemaStatVisitor(); statemen.accept(visitor); System.out.println("Tables : " + visitor.getTables()); System.out.println("fields : " + visitor.getColumns()); System.out.println("coditions : " + visitor.getConditions()); Assert.assertEquals(2, visitor.getColumns().size()); Assert.assertEquals(1, visitor.getTables().size()); }
public void test_0() throws Exception { String sql = "SELECT * FROM t1 NATURAL INNER JOIN t2;"; PGSQLStatementParser parser = new PGSQLStatementParser(sql); List<SQLStatement> statementList = parser.parseStatementList(); SQLStatement statemen = statementList.get(0); print(statementList); Assert.assertEquals(1, statementList.size()); PGSchemaStatVisitor visitor = new PGSchemaStatVisitor(); statemen.accept(visitor); System.out.println("Tables : " + visitor.getTables()); System.out.println("fields : " + visitor.getColumns()); System.out.println("coditions : " + visitor.getConditions()); Assert.assertEquals(0, visitor.getColumns().size()); Assert.assertEquals(2, visitor.getTables().size()); }