use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlInsertTest_8 method test_0.
public void test_0() throws Exception {
String sql = "insert into dd.table1(d,e) select * from bb.table3";
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
MySqlInsertStatement insertStmt = (MySqlInsertStatement) stmt;
Assert.assertEquals(2, insertStmt.getColumns().size());
Assert.assertEquals(0, insertStmt.getValuesList().size());
Assert.assertEquals(1, statementList.size());
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
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(//
"INSERT INTO dd.table1 (d, e)" + //
"\nSELECT *" + //
"\nFROM bb.table3", SQLUtils.toMySqlString(insertStmt));
Assert.assertEquals(//
"insert into dd.table1 (d, e)" + //
"\nselect *" + //
"\nfrom bb.table3", SQLUtils.toMySqlString(insertStmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
}
use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlInsertTest_9 method test_0.
public void test_0() throws Exception {
String sql = "insert into sequence values('seq_wlb_order_log',268234128+10000000,now());";
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
SQLInsertStatement insertStmt = (SQLInsertStatement) stmt;
Assert.assertEquals(3, insertStmt.getValues().getValues().size());
Assert.assertEquals(0, insertStmt.getColumns().size());
Assert.assertEquals(1, statementList.size());
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
stmt.accept(visitor);
Assert.assertEquals("INSERT INTO sequence" + "\nVALUES ('seq_wlb_order_log', 268234128 + 10000000, now())", SQLUtils.toMySqlString(insertStmt));
}
use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateTableTest71 method test_one.
@Test
public void test_one() throws Exception {
String sql = //
"create table xx (id bigint unsigned not null comment 'aa' auto_increment," + //
"gmt_create datetime not null comment '创建时间'," + //
"gmt_modified datetime not null comment '修改时间', " + "primary key (id)) comment='re'";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseCreateTable();
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
stmt.accept(visitor);
Column column = visitor.getColumn("xx", "id");
Assert.assertNotNull(column);
Assert.assertEquals("bigint", column.getDataType());
{
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("CREATE TABLE xx (" + "\n\tid bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'aa', " + "\n\tgmt_create datetime NOT NULL COMMENT '创建时间', " + "\n\tgmt_modified datetime NOT NULL COMMENT '修改时间', " + "\n\tPRIMARY KEY (id)" + "\n) COMMENT = 're'", output);
}
{
String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
Assert.assertEquals("create table xx (" + "\n\tid bigint unsigned not null auto_increment comment 'aa', " + "\n\tgmt_create datetime not null comment '创建时间', " + "\n\tgmt_modified datetime not null comment '修改时间', " + "\n\tprimary key (id)" + "\n) comment = 're'", output);
}
}
use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateTableTest72 method test_one.
@Test
public void test_one() throws Exception {
String sql = "CREATE TABLE \"MessageInstance\" (" + " \"id\" int(11) NOT NULL AUTO_INCREMENT," + " \"messageId\" int(11) NOT NULL," + " PRIMARY KEY (\"id\")," + " KEY \"ix_messageId\" (\"messageId\")" + ")";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseCreateTable();
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
stmt.accept(visitor);
Column column = visitor.getColumn("MessageInstance", "id");
Assert.assertNotNull(column);
Assert.assertEquals("int", column.getDataType());
{
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("CREATE TABLE \"MessageInstance\" (" + "\n\t\"id\" int(11) NOT NULL AUTO_INCREMENT, " + "\n\t\"messageId\" int(11) NOT NULL, " + "\n\tPRIMARY KEY ('id'), " + "\n\tKEY \"ix_messageId\" ('messageId')" + "\n)", output);
}
{
String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
Assert.assertEquals("create table \"MessageInstance\" (" + "\n\t\"id\" int(11) not null auto_increment, " + "\n\t\"messageId\" int(11) not null, " + "\n\tprimary key ('id'), " + "\n\tkey \"ix_messageId\" ('messageId')" + "\n)", output);
}
}
use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.
the class MySqlCreateTableTest73 method test_one.
@Test
public void test_one() throws Exception {
String sql = "CREATE TABLE total (" + " id INT NOT NULL AUTO_INCREMENT," + " message CHAR(20), INDEX(a))" + " ENGINE=MERGE UNION=(t1,t2) INSERT_METHOD=LAST;";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseCreateTable();
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
stmt.accept(visitor);
Column column = visitor.getColumn("total", "id");
Assert.assertNotNull(column);
Assert.assertEquals("INT", column.getDataType());
{
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("CREATE TABLE total (" + "\n\tid INT NOT NULL AUTO_INCREMENT, " + "\n\tmessage CHAR(20), " + "\n\tINDEX(a)" + "\n) ENGINE = MERGE UNION = (t1, t2) INSERT_METHOD = LAST", output);
}
{
String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
Assert.assertEquals("create table total (" + "\n\tid INT not null auto_increment, " + "\n\tmessage CHAR(20), " + "\n\tindex(a)" + "\n) engine = MERGE union = (t1, t2) insert_method = LAST", output);
}
}
Aggregations