mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved oracle sql parser.
This commit is contained in:
+65
@@ -0,0 +1,65 @@
|
||||
package com.alibaba.druid.bvt.sql.mysql.param;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.parser.SQLParserUtils;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTOutputVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by wenshao on 16/8/23.
|
||||
*/
|
||||
public class MySqlParameterizedOutputVisitorTest_56 extends TestCase {
|
||||
public void test_for_parameterize() throws Exception {
|
||||
final String dbType = JdbcConstants.MYSQL;
|
||||
String sql = "/* 0b802ab415058233338893940e1882/0.1.2.23//abd5b625/ */select `ktv_resource`.`RESOURCE_ID`,`ktv_resource`.`RESOURCE_PROVIDER`,`ktv_resource`.`KTV_ID`,`ktv_resource`.`RESOURCE_TYPE`,`ktv_resource`.`SUB_RESOURCE_TYPE`,`ktv_resource`.`STATUS`,`ktv_resource`.`START_TIME`,`ktv_resource`.`END_TIME`,`ktv_resource`.`FEATURE`,`ktv_resource`.`GMT_CREATED`,`ktv_resource`.`GMT_MODIFIED`,`ktv_resource`.`source`,`ktv_resource`.`seller_id`,`ktv_resource`.`original_Resource_Id`,`ktv_resource`.`business_unit`,`ktv_resource`.`resource_code`,`ktv_resource`.`OPTIONS`,`ktv_resource`.`AVAILABLE_COUNT`,`ktv_resource`.`TOTAL_COUNT`,`ktv_resource`.`OUT_INSTANCE_ID`,`ktv_resource`.`CONSUME_ID`,`ktv_resource`.`GROUP_ID`,`ktv_resource`.`BUSINESS_ID`,`ktv_resource`.`rule`,`ktv_resource`.`market_place`,`ktv_resource`.`VERSION` from `ktv_resource_0062` `ktv_resource` where ((`ktv_resource`.`KTV_ID` = 880693310) AND (`ktv_resource`.`STATUS` = 1) AND (`ktv_resource`.`START_TIME` <= '2017-09-19 20:15:34.199') AND (`ktv_resource`.`END_TIME` >= '2017-09-19 20:15:34.199') AND (`ktv_resource`.`seller_id` IN (2680068332)) AND (`ktv_resource`.`AVAILABLE_COUNT` IS NULL OR (`ktv_resource`.`AVAILABLE_COUNT` > 0) OR (`ktv_resource`.`AVAILABLE_COUNT` = -1))) limit 0,30";
|
||||
|
||||
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType);
|
||||
List<SQLStatement> stmtList = parser.parseStatementList();
|
||||
SQLStatement statement = stmtList.get(0);
|
||||
|
||||
StringBuilder out = new StringBuilder();
|
||||
SQLASTOutputVisitor visitor = SQLUtils.createOutputVisitor(out, JdbcConstants.MYSQL);
|
||||
List<Object> parameters = new ArrayList<Object>();
|
||||
visitor.setParameterized(true);
|
||||
visitor.setParameterizedMergeInList(true);
|
||||
visitor.setParameters(parameters);
|
||||
/*visitor.setPrettyFormat(false);*/
|
||||
statement.accept(visitor);
|
||||
/* JSONArray array = new JSONArray();
|
||||
for(String table : visitor.getTables()){
|
||||
array.add(table.replaceAll("`",""));
|
||||
}*/
|
||||
|
||||
String psql = out.toString();
|
||||
|
||||
System.out.println(psql);
|
||||
|
||||
|
||||
assertEquals("SELECT `ktv_resource`.`RESOURCE_ID`, `ktv_resource`.`RESOURCE_PROVIDER`, `ktv_resource`.`KTV_ID`, `ktv_resource`.`RESOURCE_TYPE`, `ktv_resource`.`SUB_RESOURCE_TYPE`\n" +
|
||||
"\t, `ktv_resource`.`STATUS`, `ktv_resource`.`START_TIME`, `ktv_resource`.`END_TIME`, `ktv_resource`.`FEATURE`, `ktv_resource`.`GMT_CREATED`\n" +
|
||||
"\t, `ktv_resource`.`GMT_MODIFIED`, `ktv_resource`.`source`, `ktv_resource`.`seller_id`, `ktv_resource`.`original_Resource_Id`, `ktv_resource`.`business_unit`\n" +
|
||||
"\t, `ktv_resource`.`resource_code`, `ktv_resource`.`OPTIONS`, `ktv_resource`.`AVAILABLE_COUNT`, `ktv_resource`.`TOTAL_COUNT`, `ktv_resource`.`OUT_INSTANCE_ID`\n" +
|
||||
"\t, `ktv_resource`.`CONSUME_ID`, `ktv_resource`.`GROUP_ID`, `ktv_resource`.`BUSINESS_ID`, `ktv_resource`.`rule`, `ktv_resource`.`market_place`\n" +
|
||||
"\t, `ktv_resource`.`VERSION`\n" +
|
||||
"FROM ktv_resource `ktv_resource`\n" +
|
||||
"WHERE `ktv_resource`.`KTV_ID` = ?\n" +
|
||||
"\tAND `ktv_resource`.`STATUS` = ?\n" +
|
||||
"\tAND `ktv_resource`.`START_TIME` <= ?\n" +
|
||||
"\tAND `ktv_resource`.`END_TIME` >= ?\n" +
|
||||
"\tAND `ktv_resource`.`seller_id` IN (?)\n" +
|
||||
"\tAND (`ktv_resource`.`AVAILABLE_COUNT` IS NULL\n" +
|
||||
"\t\tOR `ktv_resource`.`AVAILABLE_COUNT` > ?\n" +
|
||||
"\t\tOR `ktv_resource`.`AVAILABLE_COUNT` = ?)\n" +
|
||||
"LIMIT ?, ?", psql);
|
||||
|
||||
String rsql = SQLUtils.format(psql, JdbcConstants.MYSQL, parameters);
|
||||
System.out.println(rsql);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.alter;
|
||||
|
||||
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 OracleAlterFunctionTest0 extends OracleTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = //
|
||||
"ALTER FUNCTION \"ZEUS\".\"STRCAT\" COMPILE REUSE SETTINGS;";
|
||||
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
Assert.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());
|
||||
|
||||
Assert.assertEquals(0, visitor.getTables().size());
|
||||
|
||||
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("cdc.en_complaint_ipr_stat_fdt0")));
|
||||
|
||||
Assert.assertEquals(0, visitor.getColumns().size());
|
||||
|
||||
assertEquals("ALTER FUNCTION \"ZEUS\".\"STRCAT\" REUSE SETTINGS;",//
|
||||
SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
|
||||
|
||||
assertEquals("alter function \"ZEUS\".\"STRCAT\" reuse settings;",//
|
||||
SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
|
||||
|
||||
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "*")));
|
||||
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "YEAR")));
|
||||
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "order_mode")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.alter;
|
||||
|
||||
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 OracleAlterTypeTest0 extends OracleTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = //
|
||||
"ALTER TYPE \"ZEUS\".\"STRCAT_TYPE\" COMPILE BODY REUSE SETTINGS;";
|
||||
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
Assert.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());
|
||||
|
||||
Assert.assertEquals(0, visitor.getTables().size());
|
||||
|
||||
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("cdc.en_complaint_ipr_stat_fdt0")));
|
||||
|
||||
Assert.assertEquals(0, visitor.getColumns().size());
|
||||
|
||||
assertEquals("ALTER TYPE \"ZEUS\".\"STRCAT_TYPE\" COMPILE BODY REUSE SETTINGS;",//
|
||||
SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
|
||||
|
||||
assertEquals("alter type \"ZEUS\".\"STRCAT_TYPE\" compile body reuse settings;",//
|
||||
SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
|
||||
|
||||
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "*")));
|
||||
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "YEAR")));
|
||||
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "order_mode")));
|
||||
}
|
||||
}
|
||||
@@ -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.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.stat.TableStat;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OracleCreateFunctionTest_1 extends OracleTest {
|
||||
|
||||
public void test_types() throws Exception {
|
||||
String sql = //
|
||||
"CREATE OR REPLACE FUNCTION STRCAT(input varchar2 )\n" +
|
||||
"RETURN varchar2\n" +
|
||||
"PARALLEL_ENABLE AGGREGATE USING strcat_type;";
|
||||
|
||||
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 FUNCTION STRCAT (\n" +
|
||||
"\tinput varchar2\n" +
|
||||
")\n" +
|
||||
"RETURN varchar2\n" +
|
||||
"PARALLEL_ENABLE\n" +
|
||||
"AGGREGATE\n" +
|
||||
"USING strcat_type;",//
|
||||
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,101 @@
|
||||
/*
|
||||
* 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 org.junit.Assert;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OracleCreateTypeTest0 extends OracleTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = //
|
||||
"CREATE TYPE customer_typ_demo AS OBJECT\n" +
|
||||
" ( customer_id NUMBER(6)\n" +
|
||||
" , cust_first_name VARCHAR2(20)\n" +
|
||||
" , cust_last_name VARCHAR2(20)\n" +
|
||||
" , cust_address CUST_ADDRESS_TYP\n" +
|
||||
" , phone_numbers PHONE_LIST_TYP\n" +
|
||||
" , nls_language VARCHAR2(3)\n" +
|
||||
" , nls_territory VARCHAR2(30)\n" +
|
||||
" , credit_limit NUMBER(9,2)\n" +
|
||||
" , cust_email VARCHAR2(30)\n" +
|
||||
" , cust_orders ORDER_LIST_TYP\n" +
|
||||
" ) ;"; //
|
||||
|
||||
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 customer_typ_demo AS OBJECT (\n" +
|
||||
"\tcustomer_id NUMBER(6), \n" +
|
||||
"\tcust_first_name VARCHAR2(20), \n" +
|
||||
"\tcust_last_name VARCHAR2(20), \n" +
|
||||
"\tcust_address CUST_ADDRESS_TYP, \n" +
|
||||
"\tphone_numbers PHONE_LIST_TYP, \n" +
|
||||
"\tnls_language VARCHAR2(3), \n" +
|
||||
"\tnls_territory VARCHAR2(30), \n" +
|
||||
"\tcredit_limit NUMBER(9, 2), \n" +
|
||||
"\tcust_email VARCHAR2(30), \n" +
|
||||
"\tcust_orders ORDER_LIST_TYP\n" +
|
||||
");", text);
|
||||
}
|
||||
|
||||
{
|
||||
String text = SQLUtils.toOracleString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
|
||||
|
||||
assertEquals("create type customer_typ_demo AS OBJECT (\n" +
|
||||
"\tcustomer_id NUMBER(6), \n" +
|
||||
"\tcust_first_name VARCHAR2(20), \n" +
|
||||
"\tcust_last_name VARCHAR2(20), \n" +
|
||||
"\tcust_address CUST_ADDRESS_TYP, \n" +
|
||||
"\tphone_numbers PHONE_LIST_TYP, \n" +
|
||||
"\tnls_language VARCHAR2(3), \n" +
|
||||
"\tnls_territory VARCHAR2(30), \n" +
|
||||
"\tcredit_limit NUMBER(9, 2), \n" +
|
||||
"\tcust_email VARCHAR2(30), \n" +
|
||||
"\tcust_orders ORDER_LIST_TYP\n" +
|
||||
");", text);
|
||||
}
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("acduser.vw_acd_info", "xzqh")));
|
||||
|
||||
// assertTrue(visitor.getOrderByColumns().contains(new TableStat.Column("employees", "last_name")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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 java.util.List;
|
||||
|
||||
public class OracleCreateTypeTest1 extends OracleTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = //
|
||||
"CREATE OR REPLACE TYPE BODY \"STRCAT_TYPE\" is\n" +
|
||||
" static function ODCIAggregateInitialize(cs_ctx IN OUT strcat_type) return number\n" +
|
||||
" is\n" +
|
||||
" begin\n" +
|
||||
" cs_ctx := strcat_type( null );\n" +
|
||||
" return ODCIConst.Success;\n" +
|
||||
" end;"; //
|
||||
|
||||
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 OR REPLACE TYPE \"STRCAT_TYPE\" AS OBJECT (\n" +
|
||||
"\tSTATIC FUNCTION ODCIAggregateInitialize (cs_ctx IN OUT strcat_type) RETURN numberBEGIN\n" +
|
||||
"\t\tcs_ctx := strcat_type(NULL);\n" +
|
||||
"\t\tRETURN ODCIConst.Success;\n" +
|
||||
"\tEND;\n" +
|
||||
")", 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" +
|
||||
"\t\tcs_ctx := strcat_type(null);\n" +
|
||||
"\t\treturn ODCIConst.Success;\n" +
|
||||
"\tend;\n" +
|
||||
")", text);
|
||||
}
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("acduser.vw_acd_info", "xzqh")));
|
||||
|
||||
// assertTrue(visitor.getOrderByColumns().contains(new TableStat.Column("employees", "last_name")));
|
||||
}
|
||||
}
|
||||
+1
-7
@@ -1,5 +1,5 @@
|
||||
package com.alibaba.druid.bvt.sql.oracle.visitor;
|
||||
|
||||
package com.alibaba.druid.bvt.sql.oracle.visitor;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
@@ -46,10 +46,4 @@ public class OracleParameterizedOutputVisitorTest_01 extends TestCase {
|
||||
"\tAND dd.owner = 'EAIREP'", tempResult);
|
||||
}
|
||||
|
||||
static void f() {
|
||||
String ip = "";
|
||||
String port = "";
|
||||
String[] ins = new String[]{ip, "_", port};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package com.alibaba.druid.bvt.sql.oracle.visitor;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.parser.SQLParserUtils;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTOutputVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by wenshao on 16/8/23.
|
||||
*/
|
||||
public class OracleParameterizedOutputVisitorTest_02 extends TestCase {
|
||||
public void test_for_parameterize() throws Exception {
|
||||
String sql = "/*\n" +
|
||||
" The name + type results of these queries will be used by the Code Assistant\n" +
|
||||
" if the \"Describe Context\" option is enabled. After typing 3 or more characters\n" +
|
||||
" the Code Assistant will show a list of matching names.\n" +
|
||||
" Separate multiple queries with semi-colons and use the :schema bind variable\n" +
|
||||
" to restrict names to the currently connected user.\n" +
|
||||
" In case of an error the query results will be omitted. No error message will\n" +
|
||||
" be displayed.\n" +
|
||||
" Place this file in the PL/SQL Developer installation directory for all users,\n" +
|
||||
" or in the \"%APPDATA%\\PLSQL Developer\" directory for a specific user.\n" +
|
||||
"*/\n" +
|
||||
"SELECT object_name, object_type\n" +
|
||||
"FROM sys.all_objects o\n" +
|
||||
"WHERE o.owner = :schema\n" +
|
||||
" AND o.object_type IN (?)";
|
||||
|
||||
List<Object> parameters = new ArrayList<Object>();
|
||||
parameters.add(3);
|
||||
parameters.add(4);
|
||||
String rsql = SQLUtils.format(sql, JdbcConstants.ORACLE, parameters);
|
||||
assertEquals("/*\n" +
|
||||
" The name + type results of these queries will be used by the Code Assistant\n" +
|
||||
" if the \"Describe Context\" option is enabled. After typing 3 or more characters\n" +
|
||||
" the Code Assistant will show a list of matching names.\n" +
|
||||
" Separate multiple queries with semi-colons and use the :schema bind variable\n" +
|
||||
" to restrict names to the currently connected user.\n" +
|
||||
" In case of an error the query results will be omitted. No error message will\n" +
|
||||
" be displayed.\n" +
|
||||
" Place this file in the PL/SQL Developer installation directory for all users,\n" +
|
||||
" or in the \"%APPDATA%\\PLSQL Developer\" directory for a specific user.\n" +
|
||||
"*/\n" +
|
||||
"SELECT object_name, object_type\n" +
|
||||
"FROM sys.all_objects o\n" +
|
||||
"WHERE o.owner = 3\n" +
|
||||
"\tAND o.object_type IN (4)", rsql);
|
||||
}
|
||||
}
|
||||
+7
@@ -34,4 +34,11 @@ public class Oracle2PG_DataTypeTest_datetime extends TestCase {
|
||||
SQLDataType pgDataType = SQLTransformUtils.transformOracleToPostgresql(dataType);
|
||||
assertEquals("TIMESTAMP", pgDataType.toString());
|
||||
}
|
||||
|
||||
public void test_oracle2pg_timestamp2() throws Exception {
|
||||
String sql = "TIMESTAMP WITH TIME ZONE";
|
||||
SQLDataType dataType = SQLParserUtils.createExprParser(sql, JdbcConstants.ORACLE).parseDataType();
|
||||
SQLDataType pgDataType = SQLTransformUtils.transformOracleToPostgresql(dataType);
|
||||
assertEquals("TIMESTAMP WITH TIME ZONE", pgDataType.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user