mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
imporoved sql parser.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package com.alibaba.druid.bvt.sql.mysql;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
|
||||
public class AntlrMySqlTest extends TestCase {
|
||||
public void test_for_antlr_examples() throws Exception {
|
||||
String path = "bvt/parser/antlr_grammers_v4_mysql/examples/";
|
||||
URL resource = Thread.currentThread().getContextClassLoader().getResource(path);
|
||||
File dir = new File(resource.getFile());
|
||||
for (File file : dir.listFiles()) {
|
||||
System.out.println(file);
|
||||
String sql = FileUtils.readFileToString(file);
|
||||
SQLUtils.parseStatements(sql, JdbcConstants.MYSQL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOutFileExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlUserName;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.CobarShowStatus;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableChangeColumn;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableCharacter;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterCharacter;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableDiscardTablespace;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableImportTablespace;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableModifyColumn;
|
||||
@@ -161,7 +161,7 @@ public class MySqlASTVisitorAdapterTest extends TestCase {
|
||||
new MySqlUnlockTablesStatement().accept(adapter);
|
||||
new MySqlForceIndexHint().accept(adapter);
|
||||
new MySqlAlterTableChangeColumn().accept(adapter);
|
||||
new MySqlAlterTableCharacter().accept(adapter);
|
||||
new SQLAlterCharacter().accept(adapter);
|
||||
new MySqlAlterTableOption().accept(adapter);
|
||||
new MySqlCreateTableStatement().accept(adapter);
|
||||
new MySqlCharExpr().accept(adapter);
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.alter;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.parser.Token;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class MySqlAlterViewTest_0 extends TestCase {
|
||||
|
||||
public void test_alter_first() throws Exception {
|
||||
String sql = "alter definer = 'ivan'@'%' view my_view3 as select count(*) from t3;";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
SQLStatement stmt = parser.parseStatementList().get(0);
|
||||
parser.match(Token.EOF);
|
||||
|
||||
assertEquals("ALTER DEFINER = 'ivan'@'%'\n" +
|
||||
"\tVIEW my_view3\n" +
|
||||
"AS\n" +
|
||||
"SELECT COUNT(*)\n" +
|
||||
"FROM t3;", SQLUtils.toMySqlString(stmt));
|
||||
assertEquals("atler definer = 'ivan'@'%'\n" +
|
||||
"\tview my_view3\n" +
|
||||
"as\n" +
|
||||
"select count(*)\n" +
|
||||
"from t3;", SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
|
||||
}
|
||||
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.create;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlCreateAddLogFileGroupTest extends MysqlTest {
|
||||
|
||||
@Test
|
||||
public void test_one() throws Exception {
|
||||
String sql = "CREATE LOGFILE GROUP lg1 ADD UNDOFILE 'undo.dat' INITIAL_SIZE = 10M ENGINE = InnoDB;";
|
||||
|
||||
List<SQLStatement> stmtList = SQLUtils.toStatementList(sql, JdbcConstants.MYSQL);
|
||||
|
||||
SQLStatement stmt = stmtList.get(0);
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("CREATE LOGFILE GROUP lg1 ADD UNDOFILE 'undo.dat' INITIAL_SIZE 10M ENGINE InnoDB;", output);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.create;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlCreateDatabaseTest4 extends MysqlTest {
|
||||
|
||||
@Test
|
||||
public void test_one() throws Exception {
|
||||
String sql = "create database super default character set utf8 collate = utf8_bin character set utf8 collate utf8_bin;";
|
||||
|
||||
List<SQLStatement> stmtList = SQLUtils.toStatementList(sql, JdbcConstants.MYSQL);
|
||||
|
||||
SQLStatement stmt = stmtList.get(0);
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("CREATE DATABASE super CHARACTER SET utf8 COLLATE utf8_bin;", output);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.create;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlCreateEventTest extends MysqlTest {
|
||||
|
||||
@Test
|
||||
public void test_one() throws Exception {
|
||||
String sql = "create definer = current_user event if not exists someevent on schedule at current_timestamp + interval 30 minute\n" +
|
||||
"on completion preserve do begin insert into test.t1 values (33), (111);select * from test.t1; end; -- //";
|
||||
|
||||
List<SQLStatement> stmtList = SQLUtils.toStatementList(sql, JdbcConstants.MYSQL);
|
||||
|
||||
SQLStatement stmt = stmtList.get(0);
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("CREATE DEFINER = EVENT IF NOT EXISTS someevent ON SCHEDULE AT current_timestamp + INTERVAL 30 MINUTE\n" +
|
||||
"DO\n" +
|
||||
"BEGIN\n" +
|
||||
"\tINSERT INTO test.t1\n" +
|
||||
"\tVALUES (33),\n" +
|
||||
"\t\t(111);\n" +
|
||||
"\tSELECT *\n" +
|
||||
"\tFROM test.t1;\n" +
|
||||
"END;", output);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.create;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlCreateEventTest1 extends MysqlTest {
|
||||
|
||||
@Test
|
||||
public void test_one() throws Exception {
|
||||
String sql = "create definer = 'ivan'@'%' event testevent1 on schedule every 1 hour ends '2016-11-05 23:59:00'\n" +
|
||||
"do begin select * from test.t2; end; -- //";
|
||||
|
||||
List<SQLStatement> stmtList = SQLUtils.toStatementList(sql, JdbcConstants.MYSQL);
|
||||
|
||||
SQLStatement stmt = stmtList.get(0);
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("CREATE DEFINER = EVENT testevent1 ON SCHEDULE EVERY 1 HOUR ENDS '2016-11-05 23:59:00'\n" +
|
||||
"DO\n" +
|
||||
"BEGIN\n" +
|
||||
"\tSELECT *\n" +
|
||||
"\tFROM test.t2;\n" +
|
||||
"END;", output);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.create;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlCreateIndexTest extends MysqlTest {
|
||||
|
||||
@Test
|
||||
public void test_one() throws Exception {
|
||||
String sql = "create index index1 on t1(col1) comment 'test index' comment 'some test' using btree;";
|
||||
|
||||
List<SQLStatement> stmtList = SQLUtils.toStatementList(sql, JdbcConstants.MYSQL);
|
||||
|
||||
SQLStatement stmt = stmtList.get(0);
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("CREATE INDEX index1 ON t1 (col1) USING BTREE COMMENT 'some test';", output);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.create;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlCreateServerTest extends MysqlTest {
|
||||
|
||||
@Test
|
||||
public void test_one() throws Exception {
|
||||
String sql = "-- Create server\n" +
|
||||
"-- http://dev.mysql.com/doc/refman/5.6/en/create-server.html\n" +
|
||||
"CREATE SERVER s\n" +
|
||||
"FOREIGN DATA WRAPPER mysql\n" +
|
||||
"OPTIONS (USER 'Remote', HOST '192.168.1.106', DATABASE 'test');";
|
||||
|
||||
List<SQLStatement> stmtList = SQLUtils.toStatementList(sql, JdbcConstants.MYSQL);
|
||||
|
||||
SQLStatement stmt = stmtList.get(0);
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("CREATE SERVER s FOREIGN DATA WRAPPER mysql OPTIONS(HOST '192.168.1.106', DATABASE 'test', USER 'Remote');", output);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.create;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlCreateTableSpaceTest extends MysqlTest {
|
||||
|
||||
@Test
|
||||
public void test_one() throws Exception {
|
||||
String sql = "create tablespace tblsp1 add datafile 'tblsp_work1' use logfile group lg_1 initial_size = 4G engine MYISAM;";
|
||||
|
||||
List<SQLStatement> stmtList = SQLUtils.toStatementList(sql, JdbcConstants.MYSQL);
|
||||
|
||||
SQLStatement stmt = stmtList.get(0);
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("CREATE TABLESPACE tblsp1 FILE_BLOCK_SIZE = lg_1 INITIAL_SIZE = 4G;", output);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.create;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlCreateTriggerTest3 extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "-- Create trigger 1\n" +
|
||||
"-- delimiter //\n" +
|
||||
"create trigger trg_my1 before delete on test.t1 for each row begin insert into log_table values (\"delete row from test.t1\"); insert into t4 values (old.col1, old.col1 + 5, old.col1 + 7); end; -- //-- delimiter ;";
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> stmtList = parser.parseStatementList();
|
||||
// print(statementList);
|
||||
|
||||
assertEquals(1, stmtList.size());
|
||||
|
||||
SQLStatement stmt = stmtList.get(0);
|
||||
|
||||
assertEquals("CREATE TRIGGER trg_my1\n" +
|
||||
"\tBEFORE DELETE\n" +
|
||||
"\tON test.t1\n" +
|
||||
"\tFOR EACH ROW\n" +
|
||||
"BEGIN\n" +
|
||||
"\tINSERT INTO log_table\n" +
|
||||
"\tVALUES (\"delete row from test.t1\");\n" +
|
||||
"\tINSERT INTO t4\n" +
|
||||
"\tVALUES (old.col1, old.col1 + 5, old.col1 + 7);\n" +
|
||||
"END;", stmt.toString());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.create;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlCreateTriggerTest4 extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "create definer = current_user() trigger trg_my2 after insert on test.t2 for each row insert into log_table values (concat(\"inserted into table test.t2 values: (1c, _) = (\", cast(NEW.col1 as char(100)), \", \", convert(new.`_`, char(100)), \")\"));";
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> stmtList = parser.parseStatementList();
|
||||
// print(statementList);
|
||||
|
||||
assertEquals(1, stmtList.size());
|
||||
|
||||
SQLStatement stmt = stmtList.get(0);
|
||||
|
||||
assertEquals("CREATE TRIGGER trg_my2\n" +
|
||||
"\tAFTER INSERT\n" +
|
||||
"\tON test.t2\n" +
|
||||
"\tFOR EACH ROW\n" +
|
||||
"INSERT INTO log_table\n" +
|
||||
"VALUES (concat(\"inserted into table test.t2 values: (1c, _) = (\", CAST(NEW.col1 AS char(100)), \", \", convert(new.`_`, char(100)), \")\"));", stmt.toString());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public class MySqlCreateViewTest1 extends MysqlTest {
|
||||
stmt.accept(visitor);
|
||||
|
||||
assertEquals("CREATE ALGORITHM = UNDEFINED\n" +
|
||||
"\tDEFINER = root\n" +
|
||||
"\tDEFINER = root@localhost\n" +
|
||||
"\tSQL SECURITY = DEFINER\n" +
|
||||
"\tVIEW view_audit_enroll\n" +
|
||||
"AS\n" +
|
||||
@@ -81,7 +81,7 @@ public class MySqlCreateViewTest1 extends MysqlTest {
|
||||
SQLUtils.toMySqlString(stmt));
|
||||
|
||||
Assert.assertEquals("create algorithm = UNDEFINED\n" +
|
||||
"\tdefiner = root\n" +
|
||||
"\tdefiner = root@localhost\n" +
|
||||
"\tsql security = DEFINER\n" +
|
||||
"\tview view_audit_enroll\n" +
|
||||
"as\n" +
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.create;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateViewStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
import com.alibaba.druid.stat.TableStat.Column;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlCreateViewTest3 extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "create algorithm = merge view my_view2(col1, col2) as select * from t2 with check option;\n";
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLCreateViewStatement stmt = (SQLCreateViewStatement) statementList.get(0);
|
||||
// print(statementList);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
assertEquals("CREATE ALGORITHM = merge\n" +
|
||||
"\tVIEW my_view2 (\n" +
|
||||
"\tcol1, \n" +
|
||||
"\tcol2\n" +
|
||||
")\n" +
|
||||
"AS\n" +
|
||||
"SELECT *\n" +
|
||||
"FROM t2\n" +
|
||||
"WITH CHECK OPTION;", //
|
||||
SQLUtils.toMySqlString(stmt));
|
||||
|
||||
Assert.assertEquals("create algorithm = merge\n" +
|
||||
"\tview my_view2 (\n" +
|
||||
"\tcol1, \n" +
|
||||
"\tcol2\n" +
|
||||
")\n" +
|
||||
"as\n" +
|
||||
"select *\n" +
|
||||
"from t2\n" +
|
||||
"with check option;", //
|
||||
SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
|
||||
|
||||
// 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(1, visitor.getColumns().size());
|
||||
Assert.assertEquals(0, visitor.getConditions().size());
|
||||
|
||||
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("t2")));
|
||||
|
||||
Assert.assertTrue(visitor.getColumns().contains(new Column("t2", "*")));
|
||||
// Assert.assertTrue(visitor.getColumns().contains(new Column("t2", "l_suppkey")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.create;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateViewStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
import com.alibaba.druid.stat.TableStat.Column;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlCreateViewTest4 extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "create or replace definer = 'ivan'@'%' view my_view3 as select count(*) from t3;";
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLCreateViewStatement stmt = (SQLCreateViewStatement) statementList.get(0);
|
||||
// print(statementList);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
assertEquals("CREATE OR REPLACE DEFINER = 'ivan'@'%'\n" +
|
||||
"\tVIEW my_view3\n" +
|
||||
"AS\n" +
|
||||
"SELECT COUNT(*)\n" +
|
||||
"FROM t3;", //
|
||||
SQLUtils.toMySqlString(stmt));
|
||||
|
||||
Assert.assertEquals("create or replace definer = 'ivan'@'%'\n" +
|
||||
"\tview my_view3\n" +
|
||||
"as\n" +
|
||||
"select count(*)\n" +
|
||||
"from t3;", //
|
||||
SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
|
||||
|
||||
// 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(1, visitor.getColumns().size());
|
||||
Assert.assertEquals(0, visitor.getConditions().size());
|
||||
|
||||
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("t3")));
|
||||
|
||||
Assert.assertTrue(visitor.getColumns().contains(new Column("t3", "*")));
|
||||
// Assert.assertTrue(visitor.getColumns().contains(new Column("t2", "l_suppkey")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.create;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateViewStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
import com.alibaba.druid.stat.TableStat.Column;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlCreateViewTest5 extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "create or replace definer = current_user sql security invoker view my_view4(c1, 1c, _, c1_2) \n" +
|
||||
"\tas select * from (t1 as tt1, t2 as tt2) inner join t1 on t1.col1 = tt1.col1;";
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLCreateViewStatement stmt = (SQLCreateViewStatement) statementList.get(0);
|
||||
// print(statementList);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
assertEquals("CREATE OR REPLACE DEFINER = current_user\n" +
|
||||
"\tSQL SECURITY = invoker\n" +
|
||||
"\tVIEW my_view4 (\n" +
|
||||
"\tc1, \n" +
|
||||
"\t1c, \n" +
|
||||
"\t_, \n" +
|
||||
"\tc1_2\n" +
|
||||
")\n" +
|
||||
"AS\n" +
|
||||
"SELECT *\n" +
|
||||
"FROM (t1 tt1, t2 tt2)\n" +
|
||||
"\tINNER JOIN t1 ON t1.col1 = tt1.col1;", //
|
||||
SQLUtils.toMySqlString(stmt));
|
||||
|
||||
Assert.assertEquals("create or replace definer = current_user\n" +
|
||||
"\tsql security = invoker\n" +
|
||||
"\tview my_view4 (\n" +
|
||||
"\tc1, \n" +
|
||||
"\t1c, \n" +
|
||||
"\t_, \n" +
|
||||
"\tc1_2\n" +
|
||||
")\n" +
|
||||
"as\n" +
|
||||
"select *\n" +
|
||||
"from (t1 tt1, t2 tt2)\n" +
|
||||
"\tinner join t1 on t1.col1 = tt1.col1;", //
|
||||
SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
|
||||
|
||||
// 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(2, visitor.getTables().size());
|
||||
Assert.assertEquals(1, visitor.getColumns().size());
|
||||
Assert.assertEquals(1, visitor.getConditions().size());
|
||||
|
||||
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("t1")));
|
||||
|
||||
Assert.assertTrue(visitor.getColumns().contains(new Column("t1", "col1")));
|
||||
// Assert.assertTrue(visitor.getColumns().contains(new Column("t2", "l_suppkey")));
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -125,7 +125,7 @@ public class MySqlCreateTableTest54 extends MysqlTest {
|
||||
+ "\n\tPRIMARY KEY (`id`),"
|
||||
+ "\n\tKEY `canvas_id` (`canvas_id`),"
|
||||
+ "\n\tKEY `sid_ty_time` (`sellerId`, `node_type`, `start_time`),"
|
||||
+ "\n\tCONSTRAINT `t_activity_node_ibfk_1` FOREIGN KEY (`canvas_id`) REFERENCES `t_activity_canvas` (`id`) ON DELETE CASCADE ON UPDATE CASCADE"
|
||||
+ "\n\tCONSTRAINT `t_activity_node_ibfk_1` FOREIGN KEY (`canvas_id`) REFERENCES `t_activity_canvas` (`id`) ON DELETE CASCADE"
|
||||
+ "\n) ENGINE = InnoDB CHARSET = utf8", output);
|
||||
}
|
||||
{
|
||||
@@ -157,7 +157,7 @@ public class MySqlCreateTableTest54 extends MysqlTest {
|
||||
+ "\n\tprimary key (`id`),"
|
||||
+ "\n\tkey `canvas_id` (`canvas_id`),"
|
||||
+ "\n\tkey `sid_ty_time` (`sellerId`, `node_type`, `start_time`),"
|
||||
+ "\n\tconstraint `t_activity_node_ibfk_1` foreign key (`canvas_id`) references `t_activity_canvas` (`id`) on delete cascade on update cascade"
|
||||
+ "\n\tconstraint `t_activity_node_ibfk_1` foreign key (`canvas_id`) references `t_activity_canvas` (`id`) on delete cascade"
|
||||
+ "\n) engine = InnoDB charset = utf8", output);
|
||||
}
|
||||
}
|
||||
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.createTable;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
import com.alibaba.druid.sql.parser.SQLParserFeature;
|
||||
import com.alibaba.druid.sql.repository.SchemaRepository;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
public class MySqlCreateTableTest84 extends MysqlTest {
|
||||
|
||||
public void test_one() throws Exception {
|
||||
String sql = "CREATE TABLE `test` (\n" +
|
||||
" `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',\n" +
|
||||
" `c_tinyint` tinyint(4) DEFAULT '1' COMMENT 'tinyint',\n" +
|
||||
" `c_smallint` smallint(6) DEFAULT 0 COMMENT 'smallint',\n" +
|
||||
" `c_mediumint` mediumint(9) DEFAULT NULL COMMENT 'mediumint',\n" +
|
||||
" `c_int` int(11) DEFAULT NULL COMMENT 'int',\n" +
|
||||
" `c_bigint` bigint(20) DEFAULT NULL COMMENT 'bigint',\n" +
|
||||
" `c_decimal` decimal(10,3) DEFAULT NULL COMMENT 'decimal',\n" +
|
||||
" `c_date` date DEFAULT '0000-00-00' COMMENT 'date',\n" +
|
||||
" `c_datetime` datetime DEFAULT '0000-00-00 00:00:00' COMMENT 'datetime',\n" +
|
||||
" `c_timestamp` timestamp NULL DEFAULT NULL COMMENT 'timestamp',\n" +
|
||||
" `c_time` time DEFAULT NULL COMMENT 'time',\n" +
|
||||
" `c_char` char(10) DEFAULT NULL COMMENT 'char',\n" +
|
||||
" `c_varchar` varchar(10) DEFAULT 'hello' COMMENT 'varchar',\n" +
|
||||
" `c_blob` blob COMMENT 'blob',\n" +
|
||||
" `c_text` text COMMENT 'text',\n" +
|
||||
" `c_mediumtext` mediumtext COMMENT 'mediumtext',\n" +
|
||||
" `c_longblob` longblob COMMENT 'longblob',\n" +
|
||||
" PRIMARY KEY (`id`),\n" +
|
||||
" UNIQUE KEY `uk_a` (`c_tinyint`),\n" +
|
||||
" KEY `k_b` (`c_smallint`),\n" +
|
||||
" KEY `k_c` (`c_mediumint`,`c_int`)\n" +
|
||||
") ENGINE=InnoDB AUTO_INCREMENT=1769503 DEFAULT CHARSET=utf8mb4 COMMENT='10000000';";
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql, SQLParserFeature.KeepComments);
|
||||
SQLStatement stmt = parser.parseCreateTable();
|
||||
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
//
|
||||
// Column column = visitor.getColumn("tb_custom_vip_show_message", "custom_vip_show_message_seq");
|
||||
// assertNotNull(column);
|
||||
// assertEquals("INT", column.getDataType());
|
||||
System.out.println(stmt);
|
||||
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
assertEquals("CREATE TABLE `test` (\n" +
|
||||
"\t`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'id',\n" +
|
||||
"\t`c_tinyint` tinyint(4) DEFAULT '1' COMMENT 'tinyint',\n" +
|
||||
"\t`c_smallint` smallint(6) DEFAULT 0 COMMENT 'smallint',\n" +
|
||||
"\t`c_mediumint` mediumint(9) DEFAULT NULL COMMENT 'mediumint',\n" +
|
||||
"\t`c_int` int(11) DEFAULT NULL COMMENT 'int',\n" +
|
||||
"\t`c_bigint` bigint(20) DEFAULT NULL COMMENT 'bigint',\n" +
|
||||
"\t`c_decimal` decimal(10, 3) DEFAULT NULL COMMENT 'decimal',\n" +
|
||||
"\t`c_date` date DEFAULT '0000-00-00' COMMENT 'date',\n" +
|
||||
"\t`c_datetime` datetime DEFAULT '0000-00-00 00:00:00' COMMENT 'datetime',\n" +
|
||||
"\t`c_timestamp` timestamp NULL DEFAULT NULL COMMENT 'timestamp',\n" +
|
||||
"\t`c_time` time DEFAULT NULL COMMENT 'time',\n" +
|
||||
"\t`c_char` char(10) DEFAULT NULL COMMENT 'char',\n" +
|
||||
"\t`c_varchar` varchar(10) DEFAULT 'hello' COMMENT 'varchar',\n" +
|
||||
"\t`c_blob` blob COMMENT 'blob',\n" +
|
||||
"\t`c_text` text COMMENT 'text',\n" +
|
||||
"\t`c_mediumtext` mediumtext COMMENT 'mediumtext',\n" +
|
||||
"\t`c_longblob` longblob COMMENT 'longblob',\n" +
|
||||
"\tPRIMARY KEY (`id`),\n" +
|
||||
"\tUNIQUE `uk_a` (`c_tinyint`),\n" +
|
||||
"\tKEY `k_b` (`c_smallint`),\n" +
|
||||
"\tKEY `k_c` (`c_mediumint`, `c_int`)\n" +
|
||||
") ENGINE = InnoDB AUTO_INCREMENT = 1769503 CHARSET = utf8mb4 COMMENT '10000000'", output);
|
||||
}
|
||||
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
|
||||
assertEquals("create table `test` (\n" +
|
||||
"\t`id` bigint(20) unsigned not null auto_increment comment 'id',\n" +
|
||||
"\t`c_tinyint` tinyint(4) default '1' comment 'tinyint',\n" +
|
||||
"\t`c_smallint` smallint(6) default 0 comment 'smallint',\n" +
|
||||
"\t`c_mediumint` mediumint(9) default null comment 'mediumint',\n" +
|
||||
"\t`c_int` int(11) default null comment 'int',\n" +
|
||||
"\t`c_bigint` bigint(20) default null comment 'bigint',\n" +
|
||||
"\t`c_decimal` decimal(10, 3) default null comment 'decimal',\n" +
|
||||
"\t`c_date` date default '0000-00-00' comment 'date',\n" +
|
||||
"\t`c_datetime` datetime default '0000-00-00 00:00:00' comment 'datetime',\n" +
|
||||
"\t`c_timestamp` timestamp null default null comment 'timestamp',\n" +
|
||||
"\t`c_time` time default null comment 'time',\n" +
|
||||
"\t`c_char` char(10) default null comment 'char',\n" +
|
||||
"\t`c_varchar` varchar(10) default 'hello' comment 'varchar',\n" +
|
||||
"\t`c_blob` blob comment 'blob',\n" +
|
||||
"\t`c_text` text comment 'text',\n" +
|
||||
"\t`c_mediumtext` mediumtext comment 'mediumtext',\n" +
|
||||
"\t`c_longblob` longblob comment 'longblob',\n" +
|
||||
"\tprimary key (`id`),\n" +
|
||||
"\tunique `uk_a` (`c_tinyint`),\n" +
|
||||
"\tkey `k_b` (`c_smallint`),\n" +
|
||||
"\tkey `k_c` (`c_mediumint`, `c_int`)\n" +
|
||||
") engine = InnoDB auto_increment = 1769503 charset = utf8mb4 comment '10000000'", output);
|
||||
}
|
||||
|
||||
SchemaRepository repository = new SchemaRepository(JdbcConstants.MYSQL);
|
||||
repository.console(sql);
|
||||
assertEquals("CREATE TABLE `test` (\n" +
|
||||
"\t`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'id',\n" +
|
||||
"\t`c_tinyint` tinyint(4) DEFAULT '1' COMMENT 'tinyint',\n" +
|
||||
"\t`c_smallint` smallint(6) DEFAULT 0 COMMENT 'smallint',\n" +
|
||||
"\t`c_mediumint` mediumint(9) DEFAULT NULL COMMENT 'mediumint',\n" +
|
||||
"\t`c_int` int(11) DEFAULT NULL COMMENT 'int',\n" +
|
||||
"\t`c_bigint` bigint(20) DEFAULT NULL COMMENT 'bigint',\n" +
|
||||
"\t`c_decimal` decimal(10, 3) DEFAULT NULL COMMENT 'decimal',\n" +
|
||||
"\t`c_date` date DEFAULT '0000-00-00' COMMENT 'date',\n" +
|
||||
"\t`c_datetime` datetime DEFAULT '0000-00-00 00:00:00' COMMENT 'datetime',\n" +
|
||||
"\t`c_timestamp` timestamp NULL DEFAULT NULL COMMENT 'timestamp',\n" +
|
||||
"\t`c_time` time DEFAULT NULL COMMENT 'time',\n" +
|
||||
"\t`c_char` char(10) DEFAULT NULL COMMENT 'char',\n" +
|
||||
"\t`c_varchar` varchar(10) DEFAULT 'hello' COMMENT 'varchar',\n" +
|
||||
"\t`c_blob` blob COMMENT 'blob',\n" +
|
||||
"\t`c_text` text COMMENT 'text',\n" +
|
||||
"\t`c_mediumtext` mediumtext COMMENT 'mediumtext',\n" +
|
||||
"\t`c_longblob` longblob COMMENT 'longblob',\n" +
|
||||
"\tPRIMARY KEY (`id`),\n" +
|
||||
"\tUNIQUE `uk_a` (`c_tinyint`),\n" +
|
||||
"\tKEY `k_b` (`c_smallint`),\n" +
|
||||
"\tKEY `k_c` (`c_mediumint`, `c_int`)\n" +
|
||||
") ENGINE = InnoDB AUTO_INCREMENT = 1769503 CHARSET = utf8mb4 COMMENT '10000000'"
|
||||
, repository.console("show create table test"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.createTable;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
import com.alibaba.druid.sql.parser.SQLParserFeature;
|
||||
|
||||
public class MySqlCreateTableTest85 extends MysqlTest {
|
||||
|
||||
public void test_one() throws Exception {
|
||||
String sql = "create table `some table $$`(id int auto_increment key, class varchar(10), data binary) engine=MYISAM;";
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql, SQLParserFeature.KeepComments);
|
||||
SQLStatement stmt = parser.parseCreateTable();
|
||||
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
//
|
||||
// Column column = visitor.getColumn("tb_custom_vip_show_message", "custom_vip_show_message_seq");
|
||||
// assertNotNull(column);
|
||||
// assertEquals("INT", column.getDataType());
|
||||
System.out.println(stmt);
|
||||
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
assertEquals("CREATE TABLE `some table $$` (\n" +
|
||||
"\tid int UNIQUE AUTO_INCREMENT,\n" +
|
||||
"\tclass varchar(10),\n" +
|
||||
"\tdata binary\n" +
|
||||
") ENGINE = MYISAM", output);
|
||||
}
|
||||
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
|
||||
assertEquals("create table `some table $$` (\n" +
|
||||
"\tid int unique auto_increment,\n" +
|
||||
"\tclass varchar(10),\n" +
|
||||
"\tdata binary\n" +
|
||||
") engine = MYISAM", output);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.createTable;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
import com.alibaba.druid.sql.parser.SQLParserFeature;
|
||||
|
||||
public class MySqlCreateTableTest86 extends MysqlTest {
|
||||
|
||||
public void test_one() throws Exception {
|
||||
String sql = "create table child_table(id int unsigned auto_increment primary key, id_parent int references parent_table(id) match full on update cascade on delete set null) engine=InnoDB;";
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql, SQLParserFeature.KeepComments);
|
||||
SQLStatement stmt = parser.parseCreateTable();
|
||||
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
//
|
||||
// Column column = visitor.getColumn("tb_custom_vip_show_message", "custom_vip_show_message_seq");
|
||||
// assertNotNull(column);
|
||||
// assertEquals("INT", column.getDataType());
|
||||
System.out.println(stmt);
|
||||
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
assertEquals("CREATE TABLE child_table (\n" +
|
||||
"\tid int UNSIGNED PRIMARY KEY AUTO_INCREMENT,\n" +
|
||||
"\tid_parent int REFERENCES parent_table (id) MATCH FULL ON DELETE SET NULL ON UPDATE CASCADE\n" +
|
||||
") ENGINE = InnoDB", output);
|
||||
}
|
||||
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
|
||||
assertEquals("create table child_table (\n" +
|
||||
"\tid int unsigned primary key auto_increment,\n" +
|
||||
"\tid_parent int references parent_table (id) match full on delete set null on update cascade\n" +
|
||||
") engine = InnoDB", output);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.createTable;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
import com.alibaba.druid.sql.parser.SQLParserFeature;
|
||||
|
||||
public class MySqlCreateTableTest87 extends MysqlTest {
|
||||
|
||||
public void test_one() throws Exception {
|
||||
String sql = "CREATE TABLE `test_4` (\n" +
|
||||
" `id` bigint(20) zerofill unsigNed NOT NULL AUTO_INCREMENT COMMENT 'id',\n" +
|
||||
" `c_tinyint` tinyint(4) DEFAULT '1' COMMENT 'tinyint',\n" +
|
||||
" PRIMARY KEY (`id`)\n" +
|
||||
") ENGINE=InnoDB AUTO_INCREMENT=1769531 DEFAULT CHARSET=utf8mb4 COMMENT='10000000'";
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql, SQLParserFeature.KeepComments);
|
||||
SQLStatement stmt = parser.parseCreateTable();
|
||||
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
//
|
||||
// Column column = visitor.getColumn("tb_custom_vip_show_message", "custom_vip_show_message_seq");
|
||||
// assertNotNull(column);
|
||||
// assertEquals("INT", column.getDataType());
|
||||
System.out.println(stmt);
|
||||
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
assertEquals("CREATE TABLE `test_4` (\n" +
|
||||
"\t`id` bigint(20) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT COMMENT 'id',\n" +
|
||||
"\t`c_tinyint` tinyint(4) DEFAULT '1' COMMENT 'tinyint',\n" +
|
||||
"\tPRIMARY KEY (`id`)\n" +
|
||||
") ENGINE = InnoDB AUTO_INCREMENT = 1769531 CHARSET = utf8mb4 COMMENT '10000000'", output);
|
||||
}
|
||||
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
|
||||
assertEquals("create table `test_4` (\n" +
|
||||
"\t`id` bigint(20) unsigned zerofill not null auto_increment comment 'id',\n" +
|
||||
"\t`c_tinyint` tinyint(4) default '1' comment 'tinyint',\n" +
|
||||
"\tprimary key (`id`)\n" +
|
||||
") engine = InnoDB auto_increment = 1769531 charset = utf8mb4 comment '10000000'", output);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.drop;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropIndexStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlDropIndexTest1 extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "drop index index1 on t1 algorithm=default;";
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLDropIndexStatement stmt = (SQLDropIndexStatement) statementList.get(0);
|
||||
// print(statementList);
|
||||
|
||||
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(1, visitor.getTables().size());
|
||||
Assert.assertEquals(0, visitor.getColumns().size());
|
||||
Assert.assertEquals(0, visitor.getConditions().size());
|
||||
|
||||
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("t1")));
|
||||
TableStat tableStat = visitor.getTables().get(new TableStat.Name("t1"));
|
||||
Assert.assertEquals(1, tableStat.getDropIndexCount());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.drop;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropIndexStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlDropIndexTest2 extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "drop index index2 on t2 algorithm=default lock none;";
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLDropIndexStatement stmt = (SQLDropIndexStatement) statementList.get(0);
|
||||
// print(statementList);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
assertEquals("DROP INDEX index2 ON t2 ALGORITHM DEFAULT LOCK none;", stmt.toString());
|
||||
|
||||
// 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(0, visitor.getColumns().size());
|
||||
Assert.assertEquals(0, visitor.getConditions().size());
|
||||
|
||||
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("t2")));
|
||||
TableStat tableStat = visitor.getTables().get(new TableStat.Name("t2"));
|
||||
Assert.assertEquals(1, tableStat.getDropIndexCount());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.drop;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropIndexStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlDropTablespace extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "drop tablespace tblsp1 engine = NDB;";
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
// print(statementList);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
assertEquals("DROP TABLESPACE tblsp1 ENGINE NDB;", stmt.toString());
|
||||
|
||||
// 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(0, visitor.getTables().size());
|
||||
Assert.assertEquals(0, visitor.getColumns().size());
|
||||
Assert.assertEquals(0, visitor.getConditions().size());
|
||||
|
||||
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("t2")));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.insert;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlInsertStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlInsertTest_16_hint extends MysqlTest {
|
||||
|
||||
public void test_insert_rollback_on_fail() throws Exception {
|
||||
String sql = "insert into mytable /*!(col2, col3, col1) */ values (load_file('sompath'), 'str1', 2);";
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
parser.setParseCompleteValues(false);
|
||||
parser.setParseValuesSize(3);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
|
||||
MySqlInsertStatement insertStmt = (MySqlInsertStatement) stmt;
|
||||
|
||||
Assert.assertEquals(1, insertStmt.getValuesList().size());
|
||||
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);
|
||||
|
||||
// System.out.println("Tables : " + visitor.getTables());
|
||||
// System.out.println("fields : " + visitor.getColumns());
|
||||
// System.out.println("coditions : " + visitor.getConditions());
|
||||
// System.out.println("relationships : " + visitor.getRelationships());
|
||||
//
|
||||
assertTrue(visitor.containsTable("mytable"));
|
||||
|
||||
String formatSql = "INSERT INTO mytable\n" +
|
||||
"VALUES (load_file('sompath'), 'str1', 2);";
|
||||
Assert.assertEquals(formatSql, SQLUtils.toMySqlString(insertStmt));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.select;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.parser.SQLParserFeature;
|
||||
import com.alibaba.druid.sql.parser.SQLParserUtils;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlSelectTest_70_nchar extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "select n'abc' as tstConstrN;";
|
||||
|
||||
System.out.println(sql);
|
||||
|
||||
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, JdbcConstants.MYSQL, SQLParserFeature.OptimizedForParameterized);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.MYSQL);
|
||||
stmt.accept(visitor);
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
assertEquals("SELECT N'abc' AS tstConstrN;", //
|
||||
output);
|
||||
}
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
|
||||
assertEquals("select n'abc' as tstConstrN;", //
|
||||
output);
|
||||
}
|
||||
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, new SQLUtils.FormatOption(true, true, true));
|
||||
assertEquals("SELECT ? AS tstConstrN;", //
|
||||
output);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.select;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.parser.SQLParserFeature;
|
||||
import com.alibaba.druid.sql.parser.SQLParserUtils;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlSelectTest_71_concat extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "select 'afdf' \"erwhg\" \"ads\" 'dgs' \"rter\" as tstDiffQuoteConcat;";
|
||||
|
||||
System.out.println(sql);
|
||||
|
||||
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, JdbcConstants.MYSQL, SQLParserFeature.OptimizedForParameterized);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.MYSQL);
|
||||
stmt.accept(visitor);
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
assertEquals("SELECT CONCAT('afdf', 'erwhg', 'ads', 'dgs', 'rter') AS tstDiffQuoteConcat;", //
|
||||
output);
|
||||
}
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
|
||||
assertEquals("select CONCAT('afdf', 'erwhg', 'ads', 'dgs', 'rter') as tstDiffQuoteConcat;", //
|
||||
output);
|
||||
}
|
||||
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, new SQLUtils.FormatOption(true, true, true));
|
||||
assertEquals("SELECT CONCAT(?, ?, ?, ?, ?) AS tstDiffQuoteConcat;", //
|
||||
output);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.select;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.parser.SQLParserFeature;
|
||||
import com.alibaba.druid.sql.parser.SQLParserUtils;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlSelectTest_72_nchar extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "select N'abc' \"bcd\" 'asdfasdf' as tstConstNAndConcat;";
|
||||
|
||||
System.out.println(sql);
|
||||
|
||||
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, JdbcConstants.MYSQL, SQLParserFeature.OptimizedForParameterized);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.MYSQL);
|
||||
stmt.accept(visitor);
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
assertEquals("SELECT CONCAT(N'abc', 'bcd', 'asdfasdf') AS tstConstNAndConcat;", //
|
||||
output);
|
||||
}
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
|
||||
assertEquals("select CONCAT(n'abc', 'bcd', 'asdfasdf') as tstConstNAndConcat;", //
|
||||
output);
|
||||
}
|
||||
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, new SQLUtils.FormatOption(true, true, true));
|
||||
assertEquals("SELECT CONCAT(?, ?, ?) AS tstConstNAndConcat;", //
|
||||
output);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.select;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.parser.SQLParserFeature;
|
||||
import com.alibaba.druid.sql.parser.SQLParserUtils;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlSelectTest_73_null extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "select \\N;";
|
||||
|
||||
System.out.println(sql);
|
||||
|
||||
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, JdbcConstants.MYSQL, SQLParserFeature.OptimizedForParameterized);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.MYSQL);
|
||||
stmt.accept(visitor);
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
assertEquals("SELECT NULL;", //
|
||||
output);
|
||||
}
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
|
||||
assertEquals("select null;", //
|
||||
output);
|
||||
}
|
||||
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, new SQLUtils.FormatOption(true, true, true));
|
||||
assertEquals("SELECT NULL;", //
|
||||
output);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.select;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.parser.SQLParserFeature;
|
||||
import com.alibaba.druid.sql.parser.SQLParserUtils;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlSelectTest_74_latin extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "select * from t1 inner join (t1 as tt1, t2 as tt2) on t1.col1 = tt1.col1;";
|
||||
|
||||
System.out.println(sql);
|
||||
|
||||
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, JdbcConstants.MYSQL, SQLParserFeature.OptimizedForParameterized);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.MYSQL);
|
||||
stmt.accept(visitor);
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
assertEquals("SELECT *\n" +
|
||||
"FROM t1\n" +
|
||||
"\tINNER JOIN (t1 tt1, t2 tt2) ON t1.col1 = tt1.col1;", //
|
||||
output);
|
||||
}
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
|
||||
assertEquals("select *\n" +
|
||||
"from t1\n" +
|
||||
"\tinner join (t1 tt1, t2 tt2) on t1.col1 = tt1.col1;", //
|
||||
output);
|
||||
}
|
||||
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, new SQLUtils.FormatOption(true, true, true));
|
||||
assertEquals("SELECT *\n" +
|
||||
"FROM t1\n" +
|
||||
"\tINNER JOIN (t1 tt1, t2 tt2) ON t1.col1 = tt1.col1;", //
|
||||
output);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.select;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.parser.SQLParserFeature;
|
||||
import com.alibaba.druid.sql.parser.SQLParserUtils;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlSelectTest_75_select extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "select CONVERT( LEFT( CONVERT( '自動下書き' USING binary ), 100 ) USING utf8 ) AS x_0;";
|
||||
|
||||
System.out.println(sql);
|
||||
|
||||
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, JdbcConstants.MYSQL, SQLParserFeature.OptimizedForParameterized);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.MYSQL);
|
||||
stmt.accept(visitor);
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
assertEquals("SELECT CONVERT(LEFT(CONVERT('自動下書き' USING binary), 100) USING utf8) AS x_0;", //
|
||||
output);
|
||||
}
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
|
||||
assertEquals("select CONVERT(LEFT(CONVERT('自動下書き' using binary), 100) using utf8) as x_0;", //
|
||||
output);
|
||||
}
|
||||
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, new SQLUtils.FormatOption(true, true, true));
|
||||
assertEquals("SELECT CONVERT(LEFT(CONVERT(? USING binary), ?) USING utf8) AS x_0;", //
|
||||
output);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.select;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.parser.SQLParserFeature;
|
||||
import com.alibaba.druid.sql.parser.SQLParserUtils;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlSelectTest_76_union extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "((select 1 as a1, 10 as a2)) union all (((select 2, 20))) union distinct (select 3, 30);";
|
||||
|
||||
System.out.println(sql);
|
||||
|
||||
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, JdbcConstants.MYSQL, SQLParserFeature.OptimizedForParameterized);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.MYSQL);
|
||||
stmt.accept(visitor);
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
assertEquals("(SELECT 1 AS a1, 10 AS a2)\n" +
|
||||
"UNION ALL\n" +
|
||||
"(SELECT 2, 20)\n" +
|
||||
"UNION DISTINCT\n" +
|
||||
"(SELECT 3, 30);", //
|
||||
output);
|
||||
}
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
|
||||
assertEquals("(select 1 as a1, 10 as a2)\n" +
|
||||
"union all\n" +
|
||||
"(select 2, 20)\n" +
|
||||
"union distinct\n" +
|
||||
"(select 3, 30);", //
|
||||
output);
|
||||
}
|
||||
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, new SQLUtils.FormatOption(true, true, true));
|
||||
assertEquals("(SELECT ? AS a1, ? AS a2)\n" +
|
||||
"UNION ALL\n" +
|
||||
"(SELECT ?, ?)\n" +
|
||||
"UNION DISTINCT\n" +
|
||||
"(SELECT ?, ?);", //
|
||||
output);
|
||||
}
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.select;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.parser.SQLParserFeature;
|
||||
import com.alibaba.druid.sql.parser.SQLParserUtils;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlSelectTest_77_is_unkown extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "select 0 in (20 = any (select col1 from t1)) is not null is not unknown as t;";
|
||||
|
||||
System.out.println(sql);
|
||||
|
||||
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, JdbcConstants.MYSQL, SQLParserFeature.OptimizedForParameterized);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.MYSQL);
|
||||
stmt.accept(visitor);
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
assertEquals("SELECT 0 IN (20 = ANY (\n" +
|
||||
"\t\tSELECT col1\n" +
|
||||
"\t\tFROM t1\n" +
|
||||
"\t)) IS NOT NULL IS NOT unknown AS t;", //
|
||||
output);
|
||||
}
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
|
||||
assertEquals("select 0 in (20 = any (\n" +
|
||||
"\t\tselect col1\n" +
|
||||
"\t\tfrom t1\n" +
|
||||
"\t)) is not null is not unknown as t;", //
|
||||
output);
|
||||
}
|
||||
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, new SQLUtils.FormatOption(true, true, true));
|
||||
assertEquals("SELECT ? IN (? = ANY (\n" +
|
||||
"\t\tSELECT col1\n" +
|
||||
"\t\tFROM t1\n" +
|
||||
"\t)) IS NOT NULL IS NOT unknown AS t;", //
|
||||
output);
|
||||
}
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.select;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.parser.SQLParserFeature;
|
||||
import com.alibaba.druid.sql.parser.SQLParserUtils;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlSelectTest_78_is_unkown extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "select 20 = any (select col1 from t1) is not unknown as t;";
|
||||
|
||||
System.out.println(sql);
|
||||
|
||||
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, JdbcConstants.MYSQL, SQLParserFeature.OptimizedForParameterized);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.MYSQL);
|
||||
stmt.accept(visitor);
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
assertEquals("SELECT 20 = ANY (\n" +
|
||||
"\t\tSELECT col1\n" +
|
||||
"\t\tFROM t1\n" +
|
||||
"\t) IS NOT unknown AS t;", //
|
||||
output);
|
||||
}
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
|
||||
assertEquals("select 20 = any (\n" +
|
||||
"\t\tselect col1\n" +
|
||||
"\t\tfrom t1\n" +
|
||||
"\t) is not unknown as t;", //
|
||||
output);
|
||||
}
|
||||
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, new SQLUtils.FormatOption(true, true, true));
|
||||
assertEquals("SELECT ? = ANY (\n" +
|
||||
"\t\tSELECT col1\n" +
|
||||
"\t\tFROM t1\n" +
|
||||
"\t) IS NOT unknown AS t;", //
|
||||
output);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.select;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.parser.SQLParserFeature;
|
||||
import com.alibaba.druid.sql.parser.SQLParserUtils;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlSelectTest_79_between extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "select 1 = 16/4 between 3 and 5 as c;";
|
||||
|
||||
System.out.println(sql);
|
||||
|
||||
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, JdbcConstants.MYSQL, SQLParserFeature.OptimizedForParameterized);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.MYSQL);
|
||||
stmt.accept(visitor);
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
assertEquals("SELECT 1 = 16 / 4 BETWEEN 3 AND 5 AS c;", //
|
||||
output);
|
||||
}
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
|
||||
assertEquals("select 1 = 16 / 4 between 3 and 5 as c;", //
|
||||
output);
|
||||
}
|
||||
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, new SQLUtils.FormatOption(true, true, true));
|
||||
assertEquals("SELECT ? = ? / ? BETWEEN ? AND ? AS c;", //
|
||||
output);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.select;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.parser.SQLParserFeature;
|
||||
import com.alibaba.druid.sql.parser.SQLParserUtils;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlSelectTest_80_hints extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "select 1 /*!, ' hello' */, 2 /*! union select 5, ' world', 10 */;";
|
||||
|
||||
System.out.println(sql);
|
||||
|
||||
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, JdbcConstants.MYSQL, SQLParserFeature.OptimizedForParameterized);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.MYSQL);
|
||||
stmt.accept(visitor);
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
assertEquals("SELECT 1 /*!, ' hello' */\n" +
|
||||
"\t, 2 /*! union select 5, ' world', 10 */;", //
|
||||
output);
|
||||
}
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
|
||||
assertEquals("select 1 /*!, ' hello' */\n" +
|
||||
"\t, 2 /*! union select 5, ' world', 10 */;", //
|
||||
output);
|
||||
}
|
||||
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, new SQLUtils.FormatOption(true, true, true));
|
||||
assertEquals("SELECT ? /*!, ' hello' */\n" +
|
||||
"\t, ? /*! union select 5, ' world', 10 */;", //
|
||||
output);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.select;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.parser.SQLParserFeature;
|
||||
import com.alibaba.druid.sql.parser.SQLParserUtils;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlSelectTest_81_hints extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "select * from t /*! where col = somefunc(col2) order by sortcol */;";
|
||||
|
||||
System.out.println(sql);
|
||||
|
||||
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, JdbcConstants.MYSQL, SQLParserFeature.OptimizedForParameterized);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.MYSQL);
|
||||
stmt.accept(visitor);
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
assertEquals("SELECT *\n" +
|
||||
"FROM t/*! where col = somefunc(col2) order by sortcol */;", //
|
||||
output);
|
||||
}
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
|
||||
assertEquals("select *\n" +
|
||||
"from t/*! where col = somefunc(col2) order by sortcol */;", //
|
||||
output);
|
||||
}
|
||||
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, new SQLUtils.FormatOption(true, true, true));
|
||||
assertEquals("SELECT *\n" +
|
||||
"FROM t/*! where col = somefunc(col2) order by sortcol */;", //
|
||||
output);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.update;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
import com.alibaba.druid.stat.TableStat.Column;
|
||||
import com.alibaba.druid.wall.WallUtils;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlUpdateTest_11_using extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "update t1, t2, t3 inner join t4 using (col_name1, col_name2)\n" +
|
||||
"set t1.value_col = t3.new_value_col, t4.`some-col*` = `t2`.`***` * 2\n" +
|
||||
"where t1.pk = t2.fk_t1_pk and t2.id = t4.fk_id_entity;";
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
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(4, visitor.getTables().size());
|
||||
Assert.assertEquals(8, visitor.getColumns().size());
|
||||
// Assert.assertEquals(2, visitor.getConditions().size());
|
||||
|
||||
Assert.assertTrue(visitor.containsTable("t4"));
|
||||
|
||||
Assert.assertTrue(visitor.getColumns().contains(new Column("t1", "value_col")));
|
||||
Assert.assertTrue(visitor.getColumns().contains(new Column("t1", "pk")));
|
||||
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("UPDATE (t1, t2, t3)\n" +
|
||||
"\tINNER JOIN t4 USING (col_name1, col_name2)\n" +
|
||||
"SET t1.value_col = t3.new_value_col, t4.`some-col*` = `t2`.`***` * 2\n" +
|
||||
"WHERE t1.pk = t2.fk_t1_pk\n" +
|
||||
"\tAND t2.id = t4.fk_id_entity;", //
|
||||
output);
|
||||
}
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
|
||||
Assert.assertEquals("update (t1, t2, t3)\n" +
|
||||
"\tinner join t4 using (col_name1, col_name2)\n" +
|
||||
"set t1.value_col = t3.new_value_col, t4.`some-col*` = `t2`.`***` * 2\n" +
|
||||
"where t1.pk = t2.fk_t1_pk\n" +
|
||||
"\tand t2.id = t4.fk_id_entity;", //
|
||||
output);
|
||||
}
|
||||
|
||||
assertTrue(WallUtils.isValidateMySql(sql));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.oracle.create;
|
||||
|
||||
import com.alibaba.druid.sql.OracleTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OracleCreatePackageTest1 extends OracleTest {
|
||||
|
||||
public void test_types() throws Exception {
|
||||
String sql = //
|
||||
"CREATE OR REPLACE PACKAGE ACHIEVE_CONTRACT_SPECIMEN IS\n" +
|
||||
" -- Author : 榫氬己\n" +
|
||||
" -- Created : 2011-08-07\n" +
|
||||
" -- Purpose : 涓氱哗鍒掑垎鏍锋湰鍚堝悓寮傚父鍚堝悓鏇存柊\n" +
|
||||
" PROCEDURE STARTUPDATE(MODULUS_ID_VALUE NUMBER);\n" +
|
||||
"END ACHIEVE_CONTRACT_SPECIMEN;";
|
||||
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
assertEquals("CREATE OR REPLACE PACKAGE ACHIEVE_CONTRACT_SPECIMEN\n" +
|
||||
"\tPROCEDURE STARTUPDATE (\n" +
|
||||
"\t\tMODULUS_ID_VALUE NUMBER\n" +
|
||||
"\t)\n" +
|
||||
"\t;\n" +
|
||||
"END ACHIEVE_CONTRACT_SPECIMEN;",//
|
||||
SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
|
||||
|
||||
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
System.out.println("relationships : " + visitor.getRelationships());
|
||||
System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
// Assert.assertEquals(2, visitor.getTables().size());
|
||||
//
|
||||
// Assert.assertEquals(5, visitor.getColumns().size());
|
||||
//
|
||||
// Assert.assertTrue(visitor.containsColumn("employees", "employee_id"));
|
||||
// Assert.assertTrue(visitor.containsColumn("employees", "*"));
|
||||
// Assert.assertTrue(visitor.containsColumn("departments", "department_id"));
|
||||
// Assert.assertTrue(visitor.containsColumn("employees", "salary"));
|
||||
// Assert.assertTrue(visitor.containsColumn("employees", "commission_pct"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.oracle.create;
|
||||
|
||||
import com.alibaba.druid.sql.OracleTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OracleCreatePackageTest2 extends OracleTest {
|
||||
|
||||
public void test_types() throws Exception {
|
||||
String sql = //
|
||||
"CREATE OR REPLACE package PKG_ECC_CAL_TASK_ACCOMPLISH\n" +
|
||||
"AS\n" +
|
||||
" TYPE CURSOR_CAL_TASK_ACCOMPLISH IS REF CURSOR;\n" +
|
||||
" PROCEDURE ECC_CAL_TASK_ACCOMPLISH_PROC(\n" +
|
||||
" p_rc OUT CURSOR_CAL_TASK_ACCOMPLISH,\n" +
|
||||
" dealerID IN NUMBER,\n" +
|
||||
" dealerType IN VARCHAR2,\n" +
|
||||
" profitType IN NUMBER,\n" +
|
||||
" profitDate IN VARCHAR2);\n" +
|
||||
"end PKG_ECC_CAL_TASK_ACCOMPLISH;";
|
||||
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
assertEquals("CREATE OR REPLACE PACKAGE PKG_ECC_CAL_TASK_ACCOMPLISH\n" +
|
||||
"\tCURSOR_CAL_TASK_ACCOMPLISH REF CURSOR;\n" +
|
||||
"\tPROCEDURE ECC_CAL_TASK_ACCOMPLISH_PROC (\n" +
|
||||
"\t\tp_rc OUT CURSOR_CAL_TASK_ACCOMPLISH, \n" +
|
||||
"\t\tdealerID IN NUMBER, \n" +
|
||||
"\t\tdealerType IN VARCHAR2, \n" +
|
||||
"\t\tprofitType IN NUMBER, \n" +
|
||||
"\t\tprofitDate IN VARCHAR2\n" +
|
||||
"\t)\n" +
|
||||
"\t;\n" +
|
||||
"END PKG_ECC_CAL_TASK_ACCOMPLISH;",//
|
||||
SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
|
||||
|
||||
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
System.out.println("relationships : " + visitor.getRelationships());
|
||||
System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
// Assert.assertEquals(2, visitor.getTables().size());
|
||||
//
|
||||
// Assert.assertEquals(5, visitor.getColumns().size());
|
||||
//
|
||||
// Assert.assertTrue(visitor.containsColumn("employees", "employee_id"));
|
||||
// Assert.assertTrue(visitor.containsColumn("employees", "*"));
|
||||
// Assert.assertTrue(visitor.containsColumn("departments", "department_id"));
|
||||
// Assert.assertTrue(visitor.containsColumn("employees", "salary"));
|
||||
// Assert.assertTrue(visitor.containsColumn("employees", "commission_pct"));
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -189,7 +189,7 @@ public class OracleCreateProcedureTest4 extends OracleTest {
|
||||
|
||||
assertTrue(visitor.getTables().containsKey(new TableStat.Name("fact_brand_provider")));
|
||||
|
||||
assertEquals(22, visitor.getColumns().size());
|
||||
assertEquals(23, visitor.getColumns().size());
|
||||
assertEquals(6, visitor.getConditions().size());
|
||||
assertEquals(4, visitor.getRelationships().size());
|
||||
|
||||
|
||||
+15
-6
@@ -22,6 +22,7 @@ import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAggregateExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor;
|
||||
@@ -96,8 +97,13 @@ public class OracleSelectTest97_wmsys_wmconat extends OracleTest {
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
SQLBinaryOpExpr expr = (SQLBinaryOpExpr) stmt.getSelect().getQueryBlock().getSelectList().get(0).getExpr();
|
||||
assertTrue(expr.getLeft() instanceof SQLAggregateExpr);
|
||||
SQLSelectQueryBlock queryBlock = stmt.getSelect()
|
||||
.getQueryBlock();
|
||||
|
||||
SQLMethodInvokeExpr nvl = (SQLMethodInvokeExpr) queryBlock.getSelectList()
|
||||
.get(0).getExpr();
|
||||
SQLMethodInvokeExpr toChar =(SQLMethodInvokeExpr) nvl.getParameters().get(0);
|
||||
assertTrue(toChar.getParameters().get(0) instanceof SQLAggregateExpr);
|
||||
|
||||
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
@@ -105,8 +111,11 @@ public class OracleSelectTest97_wmsys_wmconat extends OracleTest {
|
||||
{
|
||||
String text = SQLUtils.toOracleString(stmt);
|
||||
|
||||
assertEquals("SELECT WMSYS.WM_CONCAT(name) + 1\n" +
|
||||
"FROM emp", text);
|
||||
assertEquals("SELECT NVL(TO_CHAR(WMSYS.WM_CONCAT(NVL(O.CHILD_ITEM_CODE, O.ITEM_CODE))), ?)\n" +
|
||||
"FROM ECC_CPR.CCG_GTS_OSG3A_V O\n" +
|
||||
"WHERE O.ENABLED_FLAG = ?\n" +
|
||||
"\tAND NVL(O.PRICE, ?) = ?\n" +
|
||||
"\tAND O.CONTRACT_HEADER_ID = :B1", text);
|
||||
}
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
@@ -116,8 +125,8 @@ public class OracleSelectTest97_wmsys_wmconat extends OracleTest {
|
||||
System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
assertEquals(1, visitor.getTables().size());
|
||||
assertEquals(1, visitor.getColumns().size());
|
||||
assertEquals(0, visitor.getConditions().size());
|
||||
assertEquals(5, visitor.getColumns().size());
|
||||
assertEquals(2, visitor.getConditions().size());
|
||||
assertEquals(0, visitor.getRelationships().size());
|
||||
assertEquals(0, visitor.getOrderByColumns().size());
|
||||
}
|
||||
|
||||
+4
-4
@@ -38,7 +38,7 @@ import com.alibaba.druid.sql.dialect.oracle.ast.expr.OracleIsSetExpr;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.expr.OracleRangeExpr;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.expr.OracleSizeExpr;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleAlterIndexStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleAlterProcedureStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterProcedureStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleAlterSessionStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleAlterSynonymStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleAlterTableDropPartition;
|
||||
@@ -59,7 +59,7 @@ import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleDropDbLinkStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleExceptionStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleExitStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleExplainStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleExprStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleFileSpecification;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleForStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleGotoStatement;
|
||||
@@ -142,7 +142,7 @@ public class OracleASTVisitorAdapterTest extends TestCase {
|
||||
new SQLBlockStatement().accept(adapter);
|
||||
new OracleLockTableStatement().accept(adapter);
|
||||
new OracleAlterSessionStatement().accept(adapter);
|
||||
new OracleExprStatement().accept(adapter);
|
||||
new SQLExprStatement().accept(adapter);
|
||||
new OracleDatetimeExpr().accept(adapter);
|
||||
new OracleExceptionStatement().accept(adapter);
|
||||
new OracleExceptionStatement.Item().accept(adapter);
|
||||
@@ -157,7 +157,7 @@ public class OracleASTVisitorAdapterTest extends TestCase {
|
||||
new SQLFetchStatement().accept(adapter);
|
||||
new OracleExitStatement().accept(adapter);
|
||||
new OracleExplainStatement().accept(adapter);
|
||||
new OracleAlterProcedureStatement().accept(adapter);
|
||||
new SQLAlterProcedureStatement().accept(adapter);
|
||||
new OracleAlterTableDropPartition().accept(adapter);
|
||||
new OracleAlterTableTruncatePartition().accept(adapter);
|
||||
new OracleAlterTableSplitPartition.TableSpaceItem().accept(adapter);
|
||||
|
||||
+2
-2
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql.select;
|
||||
package com.alibaba.druid.not_support.sql.mysql;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
@@ -28,7 +28,7 @@ import java.util.List;
|
||||
|
||||
public class MySqlSelectTest_69_mysql8_windows_function extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
public static void test_0() throws Exception {
|
||||
String sql = "SELECT\n" +
|
||||
" val,\n" +
|
||||
" ROW_NUMBER() OVER w AS 'row_number',\n" +
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.not_support.sql.oracle;
|
||||
|
||||
import com.alibaba.druid.sql.OracleTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OracleCreateTypeTest4 extends OracleTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = //
|
||||
"CREATE OR REPLACE TYPE cms_contract_config_obj_TABLE\n" +
|
||||
"AS TABLE OF ECC_CPR.cms_contract_config_obj"; //
|
||||
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
// System.out.println("Tables : " + visitor.getTables());
|
||||
// System.out.println("fields : " + visitor.getColumns());
|
||||
// System.out.println("coditions : " + visitor.getConditions());
|
||||
// System.out.println("relationships : " + visitor.getRelationships());
|
||||
// System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
assertEquals(0, visitor.getTables().size());
|
||||
|
||||
assertEquals(0, visitor.getColumns().size());
|
||||
|
||||
{
|
||||
String text = SQLUtils.toOracleString(stmt);
|
||||
|
||||
assertEquals("CREATE TYPE data_typ1 AS OBJECT (\n" +
|
||||
"\tyear NUMBER, \n" +
|
||||
"\tFUNCTION prod (invent NUMBER) RETURN NUMBER\n" +
|
||||
");", text);
|
||||
}
|
||||
|
||||
{
|
||||
String text = SQLUtils.toOracleString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
|
||||
|
||||
assertEquals("create type data_typ1 AS OBJECT (\n" +
|
||||
"\tyear NUMBER, \n" +
|
||||
"\tfunction prod (invent NUMBER) return NUMBER\n" +
|
||||
");", text);
|
||||
}
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("acduser.vw_acd_info", "xzqh")));
|
||||
|
||||
// assertTrue(visitor.getOrderByColumns().contains(new TableStat.Column("employees", "last_name")));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user