Search in sources :

Example 76 with SQLStatement

use of com.alibaba.druid.sql.ast.SQLStatement in project druid by alibaba.

the class DMLInsertParserTest method testInsert_1.

public void testInsert_1() throws Exception {
    String sql = "insErt  IGNORE test.t1 seT t1.id1:=? oN dupLicatE key UPDATE ex.col1=?, col2=12";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    String output = SQLUtils.toMySqlString(stmt);
    Assert.assertEquals(//
    "INSERT IGNORE INTO test.t1 (t1.id1)\nVALUES (?)" + "\nON DUPLICATE KEY UPDATE ex.col1 = ?, col2 = 12", output);
}
Also used : MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 77 with SQLStatement

use of com.alibaba.druid.sql.ast.SQLStatement in project druid by alibaba.

the class DMLInsertParserTest method testInsert_3.

public void testInsert_3() throws Exception {
    String sql = "insErt LOW_PRIORITY t1 valueS (12e-2,1,2), (?),(default)";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    String output = SQLUtils.toMySqlString(stmt);
    Assert.assertEquals(//
    "INSERT LOW_PRIORITY INTO t1\nVALUES (0.12, 1, 2)," + //
    "\n\t(?)," + "\n\t(DEFAULT)", output);
}
Also used : MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 78 with SQLStatement

use of com.alibaba.druid.sql.ast.SQLStatement in project druid by alibaba.

the class DDLParserTest method testAlterTable_3.

public void testAlterTable_3() throws Exception {
    String sql = "ALTER TABLE `test`.`tb1` DROP COLUMN `name` ;";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    String output = SQLUtils.toMySqlString(stmt);
    Assert.assertEquals(//
    "ALTER TABLE `test`.`tb1`" + "\n\tDROP COLUMN `name`", output);
}
Also used : MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 79 with SQLStatement

use of com.alibaba.druid.sql.ast.SQLStatement in project druid by alibaba.

the class DDLParserTest method test_createIndex_2.

public void test_createIndex_2() throws Exception {
    String sql = "CREATE INDEX id_index ON lookup (id) USING BTREE;";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    String output = SQLUtils.toMySqlString(stmt);
    Assert.assertEquals("CREATE INDEX id_index ON lookup (id) USING BTREE", output);
}
Also used : MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 80 with SQLStatement

use of com.alibaba.druid.sql.ast.SQLStatement in project druid by alibaba.

the class DDLParserTest method testTruncate_1.

public void testTruncate_1() throws Exception {
    String sql = "Truncate tb1";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    String output = SQLUtils.toMySqlString(stmt);
    Assert.assertEquals("TRUNCATE TABLE tb1", output);
}
Also used : MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Aggregations

SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)1652 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)915 SQLStatementParser (com.alibaba.druid.sql.parser.SQLStatementParser)431 MySqlSchemaStatVisitor (com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor)346 OracleStatementParser (com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser)273 OracleSchemaStatVisitor (com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor)254 Column (com.alibaba.druid.stat.TableStat.Column)122 PGSQLStatementParser (com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser)109 PGSchemaStatVisitor (com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor)107 SQLServerStatementParser (com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser)100 SchemaStatVisitor (com.alibaba.druid.sql.visitor.SchemaStatVisitor)67 MySqlOutputVisitor (com.alibaba.druid.sql.dialect.mysql.visitor.MySqlOutputVisitor)60 SQLServerSchemaStatVisitor (com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerSchemaStatVisitor)46 OdpsStatementParser (com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser)44 DB2SchemaStatVisitor (com.alibaba.druid.sql.dialect.db2.visitor.DB2SchemaStatVisitor)34 DB2StatementParser (com.alibaba.druid.sql.dialect.db2.parser.DB2StatementParser)33 Test (org.junit.Test)31 MysqlTest (com.alibaba.druid.sql.MysqlTest)29 ArrayList (java.util.ArrayList)29 SQLASTOutputVisitor (com.alibaba.druid.sql.visitor.SQLASTOutputVisitor)28