mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql parser.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package com.alibaba.druid.bvt.bug;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLJoinTableSource;
|
||||
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.util.JdbcConstants;
|
||||
import com.alibaba.druid.wall.WallCheckResult;
|
||||
import com.alibaba.druid.wall.spi.OracleWallProvider;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by wenshao on 12/07/2017.
|
||||
*/
|
||||
public class Issue2049 extends TestCase {
|
||||
public void test_0() throws Exception {
|
||||
String sql = "select * from emp a,dmp b;";
|
||||
|
||||
List<SQLStatement> stmtList = SQLUtils.parseStatements(sql, JdbcConstants.MYSQL);
|
||||
|
||||
SQLSelectStatement stmt = (SQLSelectStatement) stmtList.get(0);
|
||||
SQLSelectQueryBlock queryBlock = stmt.getSelect().getQueryBlock();
|
||||
SQLJoinTableSource joinTableSource = (SQLJoinTableSource) queryBlock.getFrom();
|
||||
|
||||
assertEquals("a", joinTableSource.getLeft().getAlias());
|
||||
assertEquals("b", joinTableSource.getRight().getAlias());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OracleCreateSynonymTest_0 extends OracleTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = //
|
||||
"CREATE PUBLIC SYNONYM emp_table \n" +
|
||||
" FOR hr.employees@remote.us.oracle.com;";
|
||||
|
||||
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.ORACLE);
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.ORACLE);
|
||||
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("CREATE PUBLIC SYNONYM emp_table FOR hr.employees@remote.us.oracle.com;"
|
||||
, SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
|
||||
|
||||
assertEquals(0, visitor.getTables().size());
|
||||
|
||||
// assertTrue(visitor.getTables().containsKey(new TableStat.Name("t1")));
|
||||
|
||||
assertEquals(0, visitor.getColumns().size());
|
||||
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("xwarehouses", "sales_rep_id")));
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "YEAR")));
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "order_mode")));
|
||||
}
|
||||
}
|
||||
@@ -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.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.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OracleCreateSynonymTest_1 extends OracleTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = //
|
||||
"CREATE SYNONYM offices \n" +
|
||||
" FOR hr.locations;";
|
||||
|
||||
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.ORACLE);
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.ORACLE);
|
||||
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("CREATE SYNONYM offices FOR hr.locations;"
|
||||
, SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
|
||||
|
||||
assertEquals(0, visitor.getTables().size());
|
||||
|
||||
// assertTrue(visitor.getTables().containsKey(new TableStat.Name("t1")));
|
||||
|
||||
assertEquals(0, visitor.getColumns().size());
|
||||
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("xwarehouses", "sales_rep_id")));
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "YEAR")));
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "order_mode")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OracleCreateSynonymTest_2 extends OracleTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = //
|
||||
"CREATE OR REPLACE SYNONYM CSCLIENT.ECC_CUST_AREA_INFO FOR ECC_CUST.ECC_CUST_AREA_INFO";
|
||||
|
||||
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.ORACLE);
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.ORACLE);
|
||||
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("CREATE OR REPLACE SYNONYM CSCLIENT.ECC_CUST_AREA_INFO FOR ECC_CUST.ECC_CUST_AREA_INFO"
|
||||
, SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
|
||||
|
||||
assertEquals(0, visitor.getTables().size());
|
||||
|
||||
// assertTrue(visitor.getTables().containsKey(new TableStat.Name("t1")));
|
||||
|
||||
assertEquals(0, visitor.getColumns().size());
|
||||
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("xwarehouses", "sales_rep_id")));
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "YEAR")));
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "order_mode")));
|
||||
}
|
||||
}
|
||||
@@ -58,23 +58,27 @@ public class OracleCreateTypeTest1 extends OracleTest {
|
||||
{
|
||||
String text = SQLUtils.toOracleString(stmt);
|
||||
|
||||
assertEquals("CREATE OR REPLACE TYPE \"STRCAT_TYPE\" AS OBJECT (\n" +
|
||||
"\tSTATIC FUNCTION ODCIAggregateInitialize (cs_ctx IN OUT strcat_type) RETURN numberBEGIN\n" +
|
||||
assertEquals("CREATE OR REPLACE TYPE BODY \"STRCAT_TYPE\" IS\n" +
|
||||
"\tSTATIC FUNCTION ODCIAggregateInitialize (cs_ctx IN OUT strcat_type) RETURN number\n" +
|
||||
"\tIS\n" +
|
||||
"\tBEGIN\n" +
|
||||
"\t\tcs_ctx := strcat_type(NULL);\n" +
|
||||
"\t\tRETURN ODCIConst.Success;\n" +
|
||||
"\tEND;\n" +
|
||||
")", text);
|
||||
"END", text);
|
||||
}
|
||||
|
||||
{
|
||||
String text = SQLUtils.toOracleString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
|
||||
|
||||
assertEquals("create or replace type \"STRCAT_TYPE\" AS OBJECT (\n" +
|
||||
"\tstatic function ODCIAggregateInitialize (cs_ctx in out strcat_type) return numberbegin\n" +
|
||||
assertEquals("create or replace type body \"STRCAT_TYPE\" is\n" +
|
||||
"\tstatic function ODCIAggregateInitialize (cs_ctx in out strcat_type) return number\n" +
|
||||
"\tis\n" +
|
||||
"\tbegin\n" +
|
||||
"\t\tcs_ctx := strcat_type(null);\n" +
|
||||
"\t\treturn ODCIConst.Success;\n" +
|
||||
"\tend;\n" +
|
||||
")", text);
|
||||
"END", text);
|
||||
}
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("acduser.vw_acd_info", "xzqh")));
|
||||
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* 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 OracleCreateTypeTest10 extends OracleTest {
|
||||
|
||||
public void test_types() throws Exception {
|
||||
String sql = "CREATE OR REPLACE type body connstrBycomma is\n" +
|
||||
" static function ODCIAggregateInitialize(sctx IN OUT connstrBycomma)\t\n" +
|
||||
" return number is\n" +
|
||||
" begin\n" +
|
||||
" sctx := connstrBycomma('',',');\n" +
|
||||
" return ODCIConst.Success;\n" +
|
||||
" end;\n" +
|
||||
" member function ODCIAggregateIterate(self IN OUT connstrBycomma, value IN VARCHAR2) return number is\n" +
|
||||
" begin\n" +
|
||||
" if self.currentstr is null then\n" +
|
||||
" self.currentstr := value;\n" +
|
||||
" else\n" +
|
||||
" self.currentstr := self.currentstr ||currentseprator || value;\n" +
|
||||
" end if;\n" +
|
||||
" return ODCIConst.Success;\n" +
|
||||
" end;\n" +
|
||||
" member function ODCIAggregateTerminate(self IN connstrBycomma, returnValue OUT VARCHAR2, flags IN number) return number is\n" +
|
||||
" begin\n" +
|
||||
" returnValue := self.currentstr;\n" +
|
||||
" return ODCIConst.Success;\n" +
|
||||
" end;\n" +
|
||||
" member function ODCIAggregateMerge(self IN OUT connstrBycomma, ctx2 IN connstrBycomma) return number is\n" +
|
||||
" begin\n" +
|
||||
" if ctx2.currentstr is null then\n" +
|
||||
" self.currentstr := self.currentstr;\n" +
|
||||
" elsif self.currentstr is null then\n" +
|
||||
" self.currentstr := ctx2.currentstr;\n" +
|
||||
" else\n" +
|
||||
" self.currentstr := self.currentstr || currentseprator || ctx2.currentstr;\n" +
|
||||
" end if;\n" +
|
||||
" return ODCIConst.Success;\n" +
|
||||
" end;\n" +
|
||||
" end;";
|
||||
|
||||
System.out.println(sql);
|
||||
|
||||
|
||||
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 TYPE BODY connstrBycomma IS\n" +
|
||||
"\tSTATIC FUNCTION ODCIAggregateInitialize (sctx IN OUT connstrBycomma) RETURN number\n" +
|
||||
"\tIS\n" +
|
||||
"\tBEGIN\n" +
|
||||
"\t\tsctx := connstrBycomma(NULL, ',');\n" +
|
||||
"\t\tRETURN ODCIConst.Success;\n" +
|
||||
"\tEND;\n" +
|
||||
"\tMEMBER FUNCTION ODCIAggregateIterate (self IN OUT connstrBycomma, value IN VARCHAR2) RETURN number\n" +
|
||||
"\tIS\n" +
|
||||
"\tBEGIN\n" +
|
||||
"\t\tIF self.currentstr IS NULL THEN\n" +
|
||||
"\t\t\tself.currentstr := value;\n" +
|
||||
"\t\tELSE\n" +
|
||||
"\t\t\tself.currentstr := self.currentstr || currentseprator || value;\n" +
|
||||
"\t\tEND IF;\n" +
|
||||
"\t\tRETURN ODCIConst.Success;\n" +
|
||||
"\tEND;\n" +
|
||||
"\tMEMBER FUNCTION ODCIAggregateTerminate (self IN connstrBycomma, returnValue OUT VARCHAR2, flags IN number) RETURN number\n" +
|
||||
"\tIS\n" +
|
||||
"\tBEGIN\n" +
|
||||
"\t\treturnValue := self.currentstr;\n" +
|
||||
"\t\tRETURN ODCIConst.Success;\n" +
|
||||
"\tEND;\n" +
|
||||
"\tMEMBER FUNCTION ODCIAggregateMerge (self IN OUT connstrBycomma, ctx2 IN connstrBycomma) RETURN number\n" +
|
||||
"\tIS\n" +
|
||||
"\tBEGIN\n" +
|
||||
"\t\tIF ctx2.currentstr IS NULL THEN\n" +
|
||||
"\t\t\tself.currentstr := self.currentstr;\n" +
|
||||
"\t\tELSE IF self.currentstr IS NULL THEN\n" +
|
||||
"\t\t\tself.currentstr := ctx2.currentstr;\n" +
|
||||
"\t\tELSE\n" +
|
||||
"\t\t\tself.currentstr := self.currentstr || currentseprator || ctx2.currentstr;\n" +
|
||||
"\t\tEND IF;\n" +
|
||||
"\t\tRETURN ODCIConst.Success;\n" +
|
||||
"\tEND;\n" +
|
||||
"END",//
|
||||
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());
|
||||
|
||||
assertEquals(0, visitor.getTables().size());
|
||||
|
||||
assertEquals(0, visitor.getColumns().size());
|
||||
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("orders", "order_total")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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 OracleCreateTypeTest11 extends OracleTest {
|
||||
|
||||
public void test_types() throws Exception {
|
||||
String sql = "CREATE TYPE BODY rational\n" +
|
||||
" IS\n" +
|
||||
" MAP MEMBER FUNCTION rat_to_real RETURN REAL IS\n" +
|
||||
" BEGIN\n" +
|
||||
" RETURN numerator/denominator;\n" +
|
||||
" END;\n" +
|
||||
"\n" +
|
||||
" MEMBER PROCEDURE normalize IS\n" +
|
||||
" gcd NUMBER := integer_operations.greatest_common_divisor\n" +
|
||||
" (numerator, denominator);\n" +
|
||||
" BEGIN\n" +
|
||||
" numerator := numerator/gcd;\n" +
|
||||
" denominator := denominator/gcd;\n" +
|
||||
" END;\n" +
|
||||
"\n" +
|
||||
" MEMBER FUNCTION plus(x rational) RETURN rational IS\n" +
|
||||
" r rational := rational_operations.make_rational\n" +
|
||||
" (numerator*x.denominator +\n" +
|
||||
" x.numerator*denominator,\n" +
|
||||
" denominator*x.denominator);\n" +
|
||||
" BEGIN\n" +
|
||||
" RETURN r;\n" +
|
||||
" END;\n" +
|
||||
"\n" +
|
||||
" END;";
|
||||
|
||||
System.out.println(sql);
|
||||
|
||||
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
assertEquals("CREATE TYPE BODY rational IS\n" +
|
||||
"\tMAP MEMBER FUNCTION rat_to_real () RETURN REAL\n" +
|
||||
"\tIS\n" +
|
||||
"\tBEGIN\n" +
|
||||
"\t\tRETURN numerator / denominator;\n" +
|
||||
"\tEND;\n" +
|
||||
"\tMEMBER PROCEDURE normalize\n" +
|
||||
"\tIS\n" +
|
||||
"\tgcd NUMBER := integer_operations.greatest_common_divisor(numerator, denominator);\n" +
|
||||
"\tBEGIN\n" +
|
||||
"\t\tnumerator := numerator / gcd;\n" +
|
||||
"\t\tdenominator := denominator / gcd;\n" +
|
||||
"\tEND;\n" +
|
||||
"\tMEMBER FUNCTION plus (x rational) RETURN rational\n" +
|
||||
"\tIS\n" +
|
||||
"\tr rational := rational_operations.make_rational(numerator * x.denominator + x.numerator * denominator, denominator * x.denominator);\n" +
|
||||
"\tBEGIN\n" +
|
||||
"\t\tRETURN r;\n" +
|
||||
"\tEND;\n" +
|
||||
"END;",//
|
||||
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());
|
||||
|
||||
assertEquals(0, visitor.getTables().size());
|
||||
|
||||
assertEquals(0, visitor.getColumns().size());
|
||||
|
||||
SQLUtils.toPGString(stmt);
|
||||
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("orders", "order_total")));
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ public class OracleCreateTypeTest3 extends OracleTest {
|
||||
|
||||
assertEquals("CREATE TYPE data_typ1 AS OBJECT (\n" +
|
||||
"\tyear NUMBER, \n" +
|
||||
"\tFUNCTION prod (invent NUMBER) RETURN NUMBER\n" +
|
||||
"\tMEMBER FUNCTION prod (invent NUMBER) RETURN NUMBER\n" +
|
||||
");", text);
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class OracleCreateTypeTest3 extends OracleTest {
|
||||
|
||||
assertEquals("create type data_typ1 AS OBJECT (\n" +
|
||||
"\tyear NUMBER, \n" +
|
||||
"\tfunction prod (invent NUMBER) return NUMBER\n" +
|
||||
"\tmember function prod (invent NUMBER) return NUMBER\n" +
|
||||
");", text);
|
||||
}
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("acduser.vw_acd_info", "xzqh")));
|
||||
|
||||
+3
-9
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.not_support.sql.oracle;
|
||||
package com.alibaba.druid.bvt.sql.oracle.create;
|
||||
|
||||
import com.alibaba.druid.sql.OracleTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
@@ -53,19 +53,13 @@ public class OracleCreateTypeTest4 extends OracleTest {
|
||||
{
|
||||
String text = SQLUtils.toOracleString(stmt);
|
||||
|
||||
assertEquals("CREATE TYPE data_typ1 AS OBJECT (\n" +
|
||||
"\tyear NUMBER, \n" +
|
||||
"\tFUNCTION prod (invent NUMBER) RETURN NUMBER\n" +
|
||||
");", text);
|
||||
assertEquals("CREATE OR REPLACE TYPE cms_contract_config_obj_TABLE AS TABLE OF ECC_CPR.cms_contract_config_obj", 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);
|
||||
assertEquals("create or replace type cms_contract_config_obj_TABLE as table of ECC_CPR.cms_contract_config_obj", text);
|
||||
}
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("acduser.vw_acd_info", "xzqh")));
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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 OracleCreateTypeTest5 extends OracleTest {
|
||||
|
||||
public void test_types() throws Exception {
|
||||
String sql = "CREATE OR REPLACE TYPE T_PMINFO_LOAN_OBJECT \n" +
|
||||
"is object(\n" +
|
||||
" prj_id number(10), --椤圭洰 Id\n" +
|
||||
" prj_code varchar2(200), --椤圭洰 缂栧彿\n" +
|
||||
" prj_name varchar2(200), --椤圭洰 鍚嶇О\n" +
|
||||
" forecast_our_money number, --棰勮\uE178鎴戝徃閲戦\uE582\n" +
|
||||
" cust_id number(10), --瀹㈡埛 Id\n" +
|
||||
" cust_name varchar2(256), --瀹㈡埛 鍚嶇О\n" +
|
||||
" carriert_type varchar2(20), --杩愯惀鍟嗙被鍨�\n" +
|
||||
" dept_id number(10) --閮ㄩ棬\n" +
|
||||
") not final instantiable;";
|
||||
|
||||
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 TYPE T_PMINFO_LOAN_OBJECT AS OBJECT (\n" +
|
||||
"\tprj_id number(10), \n" +
|
||||
"\tprj_code varchar2(200), \n" +
|
||||
"\tprj_name varchar2(200), \n" +
|
||||
"\tforecast_our_money number, \n" +
|
||||
"\tcust_id number(10), \n" +
|
||||
"\tcust_name varchar2(256), \n" +
|
||||
"\tcarriert_type varchar2(20), \n" +
|
||||
"\tdept_id number(10)\n" +
|
||||
") NOT FINAL INSTANTIABLE;",//
|
||||
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());
|
||||
|
||||
assertEquals(0, visitor.getTables().size());
|
||||
|
||||
assertEquals(0, visitor.getColumns().size());
|
||||
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("orders", "order_total")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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 OracleCreateTypeTest6 extends OracleTest {
|
||||
|
||||
public void test_types() throws Exception {
|
||||
String sql = "CREATE OR REPLACE TYPE \"VARRAY_DEPT_TYPE\"\n" +
|
||||
" AS varray(7000) OF NUMBER(10) ";
|
||||
|
||||
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 TYPE \"VARRAY_DEPT_TYPE\" VARRAY (7000) OF NUMBER(10)",//
|
||||
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());
|
||||
|
||||
assertEquals(0, visitor.getTables().size());
|
||||
|
||||
assertEquals(0, visitor.getColumns().size());
|
||||
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("orders", "order_total")));
|
||||
}
|
||||
}
|
||||
@@ -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.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 OracleCreateTypeTest7 extends OracleTest {
|
||||
|
||||
public void test_types() throws Exception {
|
||||
String sql = "CREATE OR REPLACE TYPE histogram_entry_type AUTHID CURRENT_USER AS OBJECT\n" +
|
||||
" (count NUMBER\n" +
|
||||
" ,value NUMBER(5)\n" +
|
||||
" )";
|
||||
|
||||
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 TYPE histogram_entry_type AUTHID CURRENT_USER AS OBJECT (\n" +
|
||||
"\tcount NUMBER, \n" +
|
||||
"\tvalue NUMBER(5)\n" +
|
||||
")",//
|
||||
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());
|
||||
|
||||
assertEquals(0, visitor.getTables().size());
|
||||
|
||||
assertEquals(0, visitor.getColumns().size());
|
||||
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("orders", "order_total")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* 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 OracleCreateTypeTest8 extends OracleTest {
|
||||
|
||||
public void test_types() throws Exception {
|
||||
String sql = "CREATE OR REPLACE TYPE dmbanimp AUTHID CURRENT_USER AS OBJECT (\n" +
|
||||
" key RAW(4),\n" +
|
||||
" shared_ctx RAW(8),\n" +
|
||||
" STATIC FUNCTION ODCITablePrepare (\n" +
|
||||
" sctx IN OUT dmbanimp,\n" +
|
||||
" tf_info SYS.ODCITabFuncInfo,\n" +
|
||||
" qkn_ptr IN RAW,\n" +
|
||||
" heap_ptr IN RAW,\n" +
|
||||
" query_sequence IN CLOB,\n" +
|
||||
" seqdb_cursor SYS_REFCURSOR,\n" +
|
||||
" subsequence_from IN PLS_INTEGER DEFAULT 1,\n" +
|
||||
" subsequence_to IN PLS_INTEGER DEFAULT -1,\n" +
|
||||
" filter_low_complexity IN PLS_INTEGER DEFAULT 0,\n" +
|
||||
" mask_lower_case IN PLS_INTEGER DEFAULT 0,\n" +
|
||||
" expect_value IN NUMBER DEFAULT 10,\n" +
|
||||
" open_gap_cost IN PLS_INTEGER DEFAULT 5,\n" +
|
||||
" extend_gap_cost IN PLS_INTEGER DEFAULT 2,\n" +
|
||||
" mismatch_cost IN PLS_INTEGER DEFAULT -3,\n" +
|
||||
" match_reward IN PLS_INTEGER DEFAULT 1,\n" +
|
||||
" word_size IN PLS_INTEGER DEFAULT 11,\n" +
|
||||
" xdropoff IN PLS_INTEGER DEFAULT 30,\n" +
|
||||
" final_x_dropoff IN PLS_INTEGER DEFAULT 50\n" +
|
||||
" ) RETURN PLS_INTEGER,\n" +
|
||||
" STATIC FUNCTION ODCITableStart (\n" +
|
||||
" sctx IN OUT dmbanimp,\n" +
|
||||
" rws_ptr IN RAW,\n" +
|
||||
" query_sequence IN CLOB,\n" +
|
||||
" seqdb_cursor SYS_REFCURSOR,\n" +
|
||||
" subsequence_from IN PLS_INTEGER DEFAULT 1,\n" +
|
||||
" subsequence_to IN PLS_INTEGER DEFAULT -1,\n" +
|
||||
" filter_low_complexity IN PLS_INTEGER DEFAULT 0,\n" +
|
||||
" mask_lower_case IN PLS_INTEGER DEFAULT 0,\n" +
|
||||
" expect_value IN NUMBER DEFAULT 10,\n" +
|
||||
" open_gap_cost IN PLS_INTEGER DEFAULT 5,\n" +
|
||||
" extend_gap_cost IN PLS_INTEGER DEFAULT 2,\n" +
|
||||
" mismatch_cost IN PLS_INTEGER DEFAULT -3,\n" +
|
||||
" match_reward IN PLS_INTEGER DEFAULT 1,\n" +
|
||||
" word_size IN PLS_INTEGER DEFAULT 11,\n" +
|
||||
" xdropoff IN PLS_INTEGER DEFAULT 30,\n" +
|
||||
" final_x_dropoff IN PLS_INTEGER DEFAULT 50\n" +
|
||||
" ) RETURN NUMBER,\n" +
|
||||
" MEMBER FUNCTION ODCITableFetch (\n" +
|
||||
" self IN OUT dmbanimp,\n" +
|
||||
" nrows IN NUMBER,\n" +
|
||||
" outset OUT dmbaos\n" +
|
||||
" ) RETURN NUMBER,\n" +
|
||||
" MEMBER FUNCTION ODCITableClose (\n" +
|
||||
" self IN dmbanimp\n" +
|
||||
" ) RETURN NUMBER,\n" +
|
||||
" STATIC FUNCTION dmbanPrepareStub (\n" +
|
||||
" sctx IN OUT dmbanimp,\n" +
|
||||
" tf_info SYS.ODCITabFuncInfo,\n" +
|
||||
" qkn_ptr IN RAW,\n" +
|
||||
" heap_ptr IN RAW,\n" +
|
||||
" query_sequence IN CLOB,\n" +
|
||||
" seqdb_cursor SYS_REFCURSOR,\n" +
|
||||
" subsequence_from IN PLS_INTEGER,\n" +
|
||||
" subsequence_to IN PLS_INTEGER,\n" +
|
||||
" filter_low_complexity IN PLS_INTEGER,\n" +
|
||||
" mask_lower_case IN PLS_INTEGER,\n" +
|
||||
" expect_value IN NUMBER,\n" +
|
||||
" open_gap_cost IN PLS_INTEGER,\n" +
|
||||
" extend_gap_cost IN PLS_INTEGER,\n" +
|
||||
" mismatch_cost IN PLS_INTEGER,\n" +
|
||||
" match_reward IN PLS_INTEGER,\n" +
|
||||
" word_size IN PLS_INTEGER,\n" +
|
||||
" xdropoff IN PLS_INTEGER,\n" +
|
||||
" final_x_dropoff IN PLS_INTEGER\n" +
|
||||
" ) RETURN PLS_INTEGER,\n" +
|
||||
" STATIC FUNCTION dmbanStartStub (\n" +
|
||||
" sctx IN OUT dmbanimp,\n" +
|
||||
" rws_ptr IN RAW,\n" +
|
||||
" query_sequence IN CLOB,\n" +
|
||||
" seqdb_cursor SYS_REFCURSOR,\n" +
|
||||
" subsequence_from IN PLS_INTEGER,\n" +
|
||||
" subsequence_to IN PLS_INTEGER,\n" +
|
||||
" filter_low_complexity IN PLS_INTEGER,\n" +
|
||||
" mask_lower_case IN PLS_INTEGER,\n" +
|
||||
" expect_value IN NUMBER,\n" +
|
||||
" open_gap_cost IN PLS_INTEGER,\n" +
|
||||
" extend_gap_cost IN PLS_INTEGER,\n" +
|
||||
" mismatch_cost IN PLS_INTEGER,\n" +
|
||||
" match_reward IN PLS_INTEGER,\n" +
|
||||
" word_size IN PLS_INTEGER,\n" +
|
||||
" xdropoff IN PLS_INTEGER,\n" +
|
||||
" final_x_dropoff IN PLS_INTEGER\n" +
|
||||
" ) RETURN NUMBER,\n" +
|
||||
" MEMBER FUNCTION dmbanFetchStub (\n" +
|
||||
" self IN OUT dmbanimp,\n" +
|
||||
" nrows IN NUMBER,\n" +
|
||||
" outset OUT dmbaos\n" +
|
||||
" ) RETURN NUMBER,\n" +
|
||||
" MEMBER FUNCTION dmbanCloseStub (\n" +
|
||||
" self IN dmbanimp\n" +
|
||||
" ) RETURN NUMBER\n" +
|
||||
");";
|
||||
|
||||
|
||||
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 TYPE dmbanimp AUTHID CURRENT_USER AS OBJECT (\n" +
|
||||
"\tkey RAW(4), \n" +
|
||||
"\tshared_ctx RAW(8), \n" +
|
||||
"\tSTATIC FUNCTION ODCITablePrepare (sctx IN OUT dmbanimp, tf_info SYS.ODCITabFuncInfo, qkn_ptr IN RAW, heap_ptr IN RAW, query_sequence IN CLOB, seqdb_cursor SYS_REFCURSOR, subsequence_from IN PLS_INTEGER := 1, subsequence_to IN PLS_INTEGER := -1, filter_low_complexity IN PLS_INTEGER := 0, mask_lower_case IN PLS_INTEGER := 0, expect_value IN NUMBER := 10, open_gap_cost IN PLS_INTEGER := 5, extend_gap_cost IN PLS_INTEGER := 2, mismatch_cost IN PLS_INTEGER := -3, match_reward IN PLS_INTEGER := 1, word_size IN PLS_INTEGER := 11, xdropoff IN PLS_INTEGER := 30, final_x_dropoff IN PLS_INTEGER := 50) RETURN PLS_INTEGER, \n" +
|
||||
"\tSTATIC FUNCTION ODCITableStart (sctx IN OUT dmbanimp, rws_ptr IN RAW, query_sequence IN CLOB, seqdb_cursor SYS_REFCURSOR, subsequence_from IN PLS_INTEGER := 1, subsequence_to IN PLS_INTEGER := -1, filter_low_complexity IN PLS_INTEGER := 0, mask_lower_case IN PLS_INTEGER := 0, expect_value IN NUMBER := 10, open_gap_cost IN PLS_INTEGER := 5, extend_gap_cost IN PLS_INTEGER := 2, mismatch_cost IN PLS_INTEGER := -3, match_reward IN PLS_INTEGER := 1, word_size IN PLS_INTEGER := 11, xdropoff IN PLS_INTEGER := 30, final_x_dropoff IN PLS_INTEGER := 50) RETURN NUMBER, \n" +
|
||||
"\tMEMBER FUNCTION ODCITableFetch (self IN OUT dmbanimp, nrows IN NUMBER, outset OUT dmbaos) RETURN NUMBER, \n" +
|
||||
"\tMEMBER FUNCTION ODCITableClose (self IN dmbanimp) RETURN NUMBER, \n" +
|
||||
"\tSTATIC FUNCTION dmbanPrepareStub (sctx IN OUT dmbanimp, tf_info SYS.ODCITabFuncInfo, qkn_ptr IN RAW, heap_ptr IN RAW, query_sequence IN CLOB, seqdb_cursor SYS_REFCURSOR, subsequence_from IN PLS_INTEGER, subsequence_to IN PLS_INTEGER, filter_low_complexity IN PLS_INTEGER, mask_lower_case IN PLS_INTEGER, expect_value IN NUMBER, open_gap_cost IN PLS_INTEGER, extend_gap_cost IN PLS_INTEGER, mismatch_cost IN PLS_INTEGER, match_reward IN PLS_INTEGER, word_size IN PLS_INTEGER, xdropoff IN PLS_INTEGER, final_x_dropoff IN PLS_INTEGER) RETURN PLS_INTEGER, \n" +
|
||||
"\tSTATIC FUNCTION dmbanStartStub (sctx IN OUT dmbanimp, rws_ptr IN RAW, query_sequence IN CLOB, seqdb_cursor SYS_REFCURSOR, subsequence_from IN PLS_INTEGER, subsequence_to IN PLS_INTEGER, filter_low_complexity IN PLS_INTEGER, mask_lower_case IN PLS_INTEGER, expect_value IN NUMBER, open_gap_cost IN PLS_INTEGER, extend_gap_cost IN PLS_INTEGER, mismatch_cost IN PLS_INTEGER, match_reward IN PLS_INTEGER, word_size IN PLS_INTEGER, xdropoff IN PLS_INTEGER, final_x_dropoff IN PLS_INTEGER) RETURN NUMBER, \n" +
|
||||
"\tMEMBER FUNCTION dmbanFetchStub (self IN OUT dmbanimp, nrows IN NUMBER, outset OUT dmbaos) RETURN NUMBER, \n" +
|
||||
"\tMEMBER FUNCTION dmbanCloseStub (self IN dmbanimp) RETURN NUMBER\n" +
|
||||
");",//
|
||||
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());
|
||||
|
||||
assertEquals(0, visitor.getTables().size());
|
||||
|
||||
assertEquals(0, visitor.getColumns().size());
|
||||
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("orders", "order_total")));
|
||||
}
|
||||
}
|
||||
@@ -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 OracleCreateTypeTest9 extends OracleTest {
|
||||
|
||||
public void test_types() throws Exception {
|
||||
String sql = "CREATE OR REPLACE TYPE \"T_EVA_PM_INFO_OBJECT\" \n" +
|
||||
"under ecc_pm.t_pminfo_loan_object(\n" +
|
||||
" marster_dept_id number,\n" +
|
||||
" marster_dept_name varchar2(500), --鎵�灞炲姙浜嬪\uE629\n" +
|
||||
" area_id number,\n" +
|
||||
" area_name varchar2(500), --鎵�灞炲浗瀹舵垨鍦板尯\n" +
|
||||
" cust2_id2 number(10), --鏈�缁堝\uE179鎴� Id\n" +
|
||||
" cust2_name2 varchar2(256), --鏈�缁堝\uE179鎴� 鍚嶇О\n" +
|
||||
" finalUsage2 varchar2(256), --鏈�缁堢敤閫�\n" +
|
||||
" sanctionedParty12 varchar2(256), --椤圭洰瀹㈡埛鍙楀埗瑁佷富浣�\n" +
|
||||
" sanctionedParty22 varchar2(256) --鏈�缁堝\uE179鎴峰彈鍒惰\uE5C6涓讳綋\n" +
|
||||
" );";
|
||||
|
||||
System.out.println(sql);
|
||||
|
||||
|
||||
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 TYPE \"T_EVA_PM_INFO_OBJECT\" UNDER ecc_pm.t_pminfo_loan_object (\n" +
|
||||
"\tmarster_dept_id number, \n" +
|
||||
"\tmarster_dept_name varchar2(500), \n" +
|
||||
"\tarea_id number, \n" +
|
||||
"\tarea_name varchar2(500), \n" +
|
||||
"\tcust2_id2 number(10), \n" +
|
||||
"\tcust2_name2 varchar2(256), \n" +
|
||||
"\tfinalUsage2 varchar2(256), \n" +
|
||||
"\tsanctionedParty12 varchar2(256), \n" +
|
||||
"\tsanctionedParty22 varchar2(256)\n" +
|
||||
");",//
|
||||
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());
|
||||
|
||||
assertEquals(0, visitor.getTables().size());
|
||||
|
||||
assertEquals(0, visitor.getColumns().size());
|
||||
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("orders", "order_total")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OracleDropSynonymTest_0 extends OracleTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = //
|
||||
"DROP PUBLIC SYNONYM customers;";
|
||||
|
||||
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.ORACLE);
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.ORACLE);
|
||||
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("DROP PUBLIC SYNONYM customers;"
|
||||
, SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
|
||||
|
||||
assertEquals(0, visitor.getTables().size());
|
||||
|
||||
// assertTrue(visitor.getTables().containsKey(new TableStat.Name("t1")));
|
||||
|
||||
assertEquals(0, visitor.getColumns().size());
|
||||
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("xwarehouses", "sales_rep_id")));
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "YEAR")));
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "order_mode")));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user