Author: shawkins
Date: 2012-10-02 22:15:04 -0400 (Tue, 02 Oct 2012)
New Revision: 4506
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleTranslator.java
Log:
TEIID-2238 fixing native-query and non-prepared handling
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java
===================================================================
---
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java 2012-10-02
17:00:38 UTC (rev 4505)
+++
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java 2012-10-03
02:15:04 UTC (rev 4506)
@@ -198,9 +198,11 @@
if (obj.getArguments().get(i).getDirection() != Direction.IN) {
throw new
IllegalArgumentException(JDBCPlugin.Util.getString("SQLConversionVisitor.not_in_parameter",
i+1)); //$NON-NLS-1$
}
- buffer.append('?');
if (this.prepared) {
+ buffer.append('?');
this.preparedValues = obj.getArguments();
+ } else {
+ this.visit(obj.getArguments().get(i).getArgumentValue());
}
}
}
@@ -219,7 +221,7 @@
Pattern pattern = Pattern.compile("\\$+\\d+"); //$NON-NLS-1$
List<Object> parts = new LinkedList<Object>();
Matcher m = pattern.matcher(nativeQuery);
- for (int i = 0; i < nativeQuery.length(); i++) {
+ for (int i = 0; i < nativeQuery.length();) {
if (!m.find(i)) {
parts.add(nativeQuery.substring(i));
break;
Modified:
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleTranslator.java
===================================================================
---
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleTranslator.java 2012-10-02
17:00:38 UTC (rev 4505)
+++
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleTranslator.java 2012-10-03
02:15:04 UTC (rev 4506)
@@ -799,6 +799,7 @@
DataTypeManager.DefaultDataTypes.STRING,
};
RealMetadataFactory.createElements(x, elemNames, elemTypes);
+
List<Column> cols = RealMetadataFactory.createElements(table, elemNames,
elemTypes);
cols.get(1).setAutoIncremented(true);
cols.get(1).setNameInSource("ID:SEQUENCE=MYSEQUENCE.nextVal");
//$NON-NLS-1$
@@ -812,6 +813,11 @@
Procedure p = RealMetadataFactory.createStoredProcedure("proc", foo,
Arrays.asList(in1));
p.setResultSet(rs3);
p.setProperty(SQLConversionVisitor.TEIID_NATIVE_QUERY, "select x from y
where z = $1");
+
+ p = RealMetadataFactory.createStoredProcedure("proc1", foo,
Arrays.asList(RealMetadataFactory.createParameter("in1", SPParameter.IN,
DataTypeManager.DefaultDataTypes.STRING)));
+ p.setResultSet(RealMetadataFactory.createResultSet("proc.rs1", new
String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER }));
//$NON-NLS-1$ //$NON-NLS-2$
+ p.setProperty(SQLConversionVisitor.TEIID_NATIVE_QUERY, "select $1 from
y");
+ p.setProperty(SQLConversionVisitor.TEIID_NON_PREPARED, "true");
CompositeMetadataStore store = new CompositeMetadataStore(metadataStore);
return new TransformationMetadata(null, store, null,
RealMetadataFactory.SFM.getSystemFunctions(), null);
@@ -920,6 +926,15 @@
helpTestVisitor(metadata, input, EMPTY_CONTEXT, null, output);
}
+ @Test public void testNativeQueryProcNonPrepared() throws Exception {
+ String input = "call proc1('col')"; //$NON-NLS-1$
+ String output = "select 'col' from y"; //$NON-NLS-1$
+
+ QueryMetadataInterface metadata = getOracleSpecificMetadata();
+
+ helpTestVisitor(metadata, input, EMPTY_CONTEXT, null, output);
+ }
+
@Test public void testNativeQueryProcPreparedExecution() throws Exception {
CommandBuilder commandBuilder = new CommandBuilder(getOracleSpecificMetadata());
Command command = commandBuilder.getCommand("call proc(2)");
Show replies by date