Search in sources :

Example 1 with SQLTableLike

use of com.alibaba.druid.sql.ast.statement.SQLTableLike in project druid by alibaba.

the class MySqlCreateTableTest160 method test_1.

public void test_1() throws Exception {
    // for ADB
    String sql = "CREATE TABLE IF NOT EXISTS bar2 (c TIMESTAMP, LIKE bar, d DATE)";
    MySqlCreateTableStatement stmt = (MySqlCreateTableStatement) SQLUtils.parseSingleMysqlStatement(sql);
    assertTrue(stmt.getTableElementList().get(1) instanceof SQLTableLike);
    assertEquals("CREATE TABLE IF NOT EXISTS bar2 (\n" + "\tc TIMESTAMP,\n" + "\tLIKE bar,\n" + "\td DATE\n" + ")", stmt.toString());
}
Also used : MySqlCreateTableStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement) SQLTableLike(com.alibaba.druid.sql.ast.statement.SQLTableLike)

Example 2 with SQLTableLike

use of com.alibaba.druid.sql.ast.statement.SQLTableLike in project druid by alibaba.

the class MySqlCreateTable_like_test method test_0.

public void test_0() throws Exception {
    String sql = "CREATE TABLE like_test (LIKE t1)";
    List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.MYSQL, true);
    assertEquals(1, statementList.size());
    MySqlCreateTableStatement stmt = (MySqlCreateTableStatement) statementList.get(0);
    SQLExprTableSource like = stmt.getLike();
    assertTrue(stmt.getTableElementList().size() == 1);
    assertTrue(like == null);
    assertTrue(stmt.getTableElementList().get(0) instanceof SQLTableLike);
    assertEquals("CREATE TABLE like_test (\n" + "\tLIKE t1\n" + ")", stmt.toString());
}
Also used : SQLExprTableSource(com.alibaba.druid.sql.ast.statement.SQLExprTableSource) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) MySqlCreateTableStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement) SQLTableLike(com.alibaba.druid.sql.ast.statement.SQLTableLike)

Example 3 with SQLTableLike

use of com.alibaba.druid.sql.ast.statement.SQLTableLike in project druid by alibaba.

the class MySqlCreateTableTest160 method test_0.

public void test_0() throws Exception {
    // for ADB
    String sql = "CREATE TABLE IF NOT EXISTS bar (LIKE a INCLUDING PROPERTIES)";
    MySqlCreateTableStatement stmt = (MySqlCreateTableStatement) SQLUtils.parseSingleMysqlStatement(sql);
    assertTrue(stmt.getTableElementList().get(0) instanceof SQLTableLike);
    assertEquals("CREATE TABLE IF NOT EXISTS bar (\n" + "\tLIKE a INCLUDING PROPERTIES\n" + ")", stmt.toString());
}
Also used : MySqlCreateTableStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement) SQLTableLike(com.alibaba.druid.sql.ast.statement.SQLTableLike)

Aggregations

SQLTableLike (com.alibaba.druid.sql.ast.statement.SQLTableLike)3 MySqlCreateTableStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement)3 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)1 SQLExprTableSource (com.alibaba.druid.sql.ast.statement.SQLExprTableSource)1