Search in sources :

Example 21 with SchemaObject

use of com.alibaba.druid.sql.repository.SchemaObject in project druid by alibaba.

the class CanalSQLSchemaTest method test_json_index.

@Test
public void test_json_index() throws Throwable {
    SchemaRepository repository = new SchemaRepository(JdbcConstants.MYSQL);
    String sql = " CREATE TABLE `articles` ( \n" + " \t`article_id` bigint NOT NULL AUTO_INCREMENT, \n" + " \t`tags` json DEFAULT NULL, PRIMARY KEY (`article_id`), \n" + " \tKEY `articles_tags` (\n" + " \t\t(\n" + " \t\t\tcast(json_extract(`tags`,_utf8mb4'$[*]') \n" + " \t\t\t\tas char(40) array)\n" + " \t\t)\n" + " \t)\n" + " ) ENGINE=InnoDB AUTO_INCREMENT=1054 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci";
    repository.console(sql);
    repository.setDefaultSchema("test");
    SchemaObject table = repository.findTable("articles");
    Assert.assertTrue(table.findColumn("article_id") != null);
}
Also used : SchemaObject(com.alibaba.druid.sql.repository.SchemaObject) SchemaRepository(com.alibaba.druid.sql.repository.SchemaRepository) Test(org.junit.Test)

Example 22 with SchemaObject

use of com.alibaba.druid.sql.repository.SchemaObject in project druid by alibaba.

the class MySqlCreateTable_showColumns_test_3 method test_0.

public void test_0() throws Exception {
    SchemaRepository repository = new SchemaRepository(JdbcConstants.MYSQL);
    String sql = "create table yushitai_test.card_record ( id bigint auto_increment) auto_increment=256 " + "alter table yushitai_test.card_record add index index_name(name) ;" + "alter table yushitai_test.card_record add index index_name(name) ;" + "alter table yushitai_test.card_record add Constraint pk_id PRIMARY KEY (id);" + "alter table yushitai_test.card_record add Constraint pk_id PRIMARY KEY (id);";
    repository.console(sql);
    repository.setDefaultSchema("yushitai_test");
    SchemaObject table = repository.findTable("card_record");
    assertEquals("CREATE TABLE card_record (\n" + "\tid bigint AUTO_INCREMENT,\n" + "\tINDEX index_name(name),\n" + "\tPRIMARY KEY (id)\n" + ") AUTO_INCREMENT = 256", table.getStatement().toString());
}
Also used : SchemaObject(com.alibaba.druid.sql.repository.SchemaObject) SchemaRepository(com.alibaba.druid.sql.repository.SchemaRepository)

Example 23 with SchemaObject

use of com.alibaba.druid.sql.repository.SchemaObject in project druid by alibaba.

the class MySqlCreateTable_showColumns_test_2 method test_0.

public void test_0() throws Exception {
    SchemaRepository repository = new SchemaRepository(JdbcConstants.MYSQL);
    String sql = "create table yushitai_test.card_record ( id bigint auto_increment) auto_increment=256 " + "; alter table yushitai_test.card_record add column customization_id bigint unsigned NOT NULL COMMENT 'TEST' ;" + "; alter table yushitai_test.card_record add column customization_id bigint unsigned NOT NULL COMMENT 'TEST' ;";
    repository.console(sql);
    repository.setDefaultSchema("yushitai_test");
    SchemaObject table = repository.findTable("card_record");
    assertEquals("CREATE TABLE card_record (\n" + "\tid bigint AUTO_INCREMENT,\n" + "\tcustomization_id bigint UNSIGNED NOT NULL COMMENT 'TEST'\n" + ") AUTO_INCREMENT = 256", table.getStatement().toString());
}
Also used : SchemaObject(com.alibaba.druid.sql.repository.SchemaObject) SchemaRepository(com.alibaba.druid.sql.repository.SchemaRepository)

Aggregations

SchemaObject (com.alibaba.druid.sql.repository.SchemaObject)23 SchemaRepository (com.alibaba.druid.sql.repository.SchemaRepository)13 Test (org.junit.Test)10 Column (com.alibaba.druid.stat.TableStat.Column)3 Schema (com.alibaba.druid.sql.repository.Schema)2 SQLObject (com.alibaba.druid.sql.ast.SQLObject)1 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)1 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)1 SQLCreateTableStatement (com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement)1 SQLExprTableSource (com.alibaba.druid.sql.ast.statement.SQLExprTableSource)1 SQLSelectItem (com.alibaba.druid.sql.ast.statement.SQLSelectItem)1 Token (com.alibaba.druid.sql.parser.Token)1 SQLASTOutputVisitor (com.alibaba.druid.sql.visitor.SQLASTOutputVisitor)1 TableMeta (com.alibaba.otter.canal.parse.inbound.TableMeta)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1