Search in sources :

Example 21 with Column

use of com.alibaba.druid.stat.TableStat.Column in project druid by alibaba.

the class MySqlCreateTableTest15 method test_0.

public void test_0() throws Exception {
    String sql = //
    "CREATE TABLE `xxx` (" + //
    "                `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID'," + //
    "                `create_date` datetime DEFAULT NULL," + //
    "                `update_date` datetime DEFAULT NULL," + //
    "                `product_id` int(11) NOT NULL COMMENT '产品ID'," + //
    "                `memeber_id` int(11) NOT NULL COMMENT '用户ID'," + //
    "                `name` varchar(50) DEFAULT NULL COMMENT '姓名'," + //
    "                `address` varchar(500) DEFAULT NULL COMMENT '地址'," + //
    "                `mobile` varchar(50) DEFAULT NULL COMMENT '手机'," + //
    "                `amount` int(11) DEFAULT NULL COMMENT '兑换数量'," + //
    "                PRIMARY KEY (`id`)" + //
    "              ) ENGINE=InnoDB DEFAULT CHARSET=gbk;" + "";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement statemen = statementList.get(0);
    //        print(statementList);
    Assert.assertEquals(1, statementList.size());
    MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
    statemen.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("xxx")));
    Assert.assertTrue(visitor.getColumns().contains(new Column("xxx", "id")));
    Assert.assertTrue(visitor.getColumns().contains(new Column("xxx", "amount")));
}
Also used : MySqlSchemaStatVisitor(com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor) Column(com.alibaba.druid.stat.TableStat.Column) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 22 with Column

use of com.alibaba.druid.stat.TableStat.Column in project druid by alibaba.

the class MySqlCreateTableTest4 method test_0.

public void test_0() throws Exception {
    String sql = //
    "create table t_temp_11593685fc3244cf81468209484078a0 (" + //
    "id int not null auto_increment, " + //
    "score float not null, " + //
    "student bigint not null, " + //
    "primary key(id)," + //
    "key score(score), " + "key student(student))";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement statemen = statementList.get(0);
    //        print(statementList);
    Assert.assertEquals(1, statementList.size());
    MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
    statemen.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(3, visitor.getColumns().size());
    Assert.assertEquals(0, visitor.getConditions().size());
    Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("t_temp_11593685fc3244cf81468209484078a0")));
    Assert.assertTrue(visitor.getColumns().contains(new Column("t_temp_11593685fc3244cf81468209484078a0", "id")));
    Assert.assertTrue(visitor.getColumns().contains(new Column("t_temp_11593685fc3244cf81468209484078a0", "score")));
    Assert.assertTrue(visitor.getColumns().contains(new Column("t_temp_11593685fc3244cf81468209484078a0", "student")));
}
Also used : MySqlSchemaStatVisitor(com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor) Column(com.alibaba.druid.stat.TableStat.Column) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 23 with Column

use of com.alibaba.druid.stat.TableStat.Column in project druid by alibaba.

the class MySqlCreateProcedureTest2 method test_1.

public void test_1() throws Exception {
    String sql = "create or replace procedure sp_name(level int,age int)" + " begin" + " declare x,y,z int;" + " lable_1: begin" + " insert into test values(id,age);" + " end lable_1;" + " end";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement statemen = statementList.get(0);
    //    	print(statementList);
    Assert.assertEquals(1, statementList.size());
    MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
    statemen.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(2, visitor.getColumns().size());
    Assert.assertEquals(0, visitor.getConditions().size());
    Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("test")));
    Assert.assertTrue(visitor.getColumns().contains(new Column("test", "id")));
    Assert.assertTrue(visitor.getColumns().contains(new Column("test", "age")));
}
Also used : MySqlSchemaStatVisitor(com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor) Column(com.alibaba.druid.stat.TableStat.Column) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 24 with Column

use of com.alibaba.druid.stat.TableStat.Column in project druid by alibaba.

the class MySqlCreateProcedureTest2 method test_2.

public void test_2() throws Exception {
    String sql = "create or replace procedure sp_name(level int,age int)" + " begin" + " declare x,y,z int;" + " lable_1: loop" + " insert into test values(id,age);" + " end loop lable_1;" + " end";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement statemen = statementList.get(0);
    //    	print(statementList);
    Assert.assertEquals(1, statementList.size());
    MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
    statemen.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(2, visitor.getColumns().size());
    Assert.assertEquals(0, visitor.getConditions().size());
    Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("test")));
    Assert.assertTrue(visitor.getColumns().contains(new Column("test", "id")));
    Assert.assertTrue(visitor.getColumns().contains(new Column("test", "age")));
}
Also used : MySqlSchemaStatVisitor(com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor) Column(com.alibaba.druid.stat.TableStat.Column) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 25 with Column

use of com.alibaba.druid.stat.TableStat.Column in project druid by alibaba.

the class MySqlCreateProcedureTest3 method test_0.

public void test_0() throws Exception {
    String sql = "create or replace procedure sp_name(level int,age int)" + " begin" + " declare x,y,z int;" + " lable_1: while x do" + " insert into test values(id,age);" + " leave lable_1;" + " end while lable_1;" + " end";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement statemen = statementList.get(0);
    //    	print(statementList);
    Assert.assertEquals(1, statementList.size());
    MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
    statemen.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(2, visitor.getColumns().size());
    Assert.assertEquals(0, visitor.getConditions().size());
    Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("test")));
    Assert.assertTrue(visitor.getColumns().contains(new Column("test", "id")));
    Assert.assertTrue(visitor.getColumns().contains(new Column("test", "age")));
}
Also used : MySqlSchemaStatVisitor(com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor) Column(com.alibaba.druid.stat.TableStat.Column) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Aggregations

Column (com.alibaba.druid.stat.TableStat.Column)134 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)122 MySqlSchemaStatVisitor (com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor)74 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)73 OracleStatementParser (com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser)19 OracleSchemaStatVisitor (com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor)19 SQLServerStatementParser (com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser)12 SQLServerSchemaStatVisitor (com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerSchemaStatVisitor)12 SQLCreateTableStatement (com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement)10 DB2StatementParser (com.alibaba.druid.sql.dialect.db2.parser.DB2StatementParser)8 DB2SchemaStatVisitor (com.alibaba.druid.sql.dialect.db2.visitor.DB2SchemaStatVisitor)8 SchemaStatVisitor (com.alibaba.druid.sql.visitor.SchemaStatVisitor)8 OracleOutputVisitor (com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor)6 MysqlTest (com.alibaba.druid.sql.MysqlTest)5 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)5 SQLObject (com.alibaba.druid.sql.ast.SQLObject)5 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)5 Test (org.junit.Test)5 SQLCreateViewStatement (com.alibaba.druid.sql.ast.statement.SQLCreateViewStatement)4 MySqlCreateTableStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement)4