Author: shawkins
Date: 2012-07-31 14:44:07 -0400 (Tue, 31 Jul 2012)
New Revision: 4282
Modified:
trunk/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java
trunk/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java
Log:
TEIID-2096 fix for inappropriate cast handling
Modified: trunk/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java 2012-07-31
17:19:19 UTC (rev 4281)
+++ trunk/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java 2012-07-31
18:44:07 UTC (rev 4282)
@@ -69,6 +69,8 @@
public class ODBCServerRemoteImpl implements ODBCServerRemote {
private static final String UNNAMED = "UNNAMED"; //$NON-NLS-1$
+ private static Pattern pgToastLiteral =
Pattern.compile("'pg_toast'");//$NON-NLS-1$
+ private static Pattern pgCast =
Pattern.compile("(\\s[^']+)::[A-Za-z0-9]*"); //$NON-NLS-1$
private static Pattern setPattern =
Pattern.compile("set\\s+(\\w+)\\s+to\\s+((?:'[^']*')+)",
Pattern.DOTALL|Pattern.CASE_INSENSITIVE);//$NON-NLS-1$
private static Pattern pkPattern = Pattern.compile("select ta.attname, ia.attnum,
ic.relname, n.nspname, tc.relname " +//$NON-NLS-1$
@@ -618,8 +620,9 @@
return "SELECT 0"; //$NON-NLS-1$
}
//these are somewhat dangerous
- modified = modified.replaceAll("::[A-Za-z0-9]*", " ");
//$NON-NLS-1$ //$NON-NLS-2$
- modified = modified.replaceAll("'pg_toast'",
"'SYS'"); //$NON-NLS-1$ //$NON-NLS-2$
+ modified = pgCast.matcher(modified).replaceAll("$1"); //$NON-NLS-1$
+ //TODO: use an appropriate cast
+ modified = pgToastLiteral.matcher(modified).replaceAll("'SYS'");
//$NON-NLS-1$
return modified;
}
Modified:
trunk/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java
===================================================================
---
trunk/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java 2012-07-31
17:19:19 UTC (rev 4281)
+++
trunk/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java 2012-07-31
18:44:07 UTC (rev 4282)
@@ -372,4 +372,16 @@
assertTrue(rs.next());
assertEquals("", rs.getString(1));
}
+
+ @Test public void testColons() throws Exception {
+ Statement s = conn.createStatement();
+ //make sure that we aren't mishandling the ::
+ ResultSet rs = s.executeQuery("select 'a::b'");
+ assertTrue(rs.next());
+ assertEquals("a::b", rs.getString(1));
+
+ rs = s.executeQuery("select name::varchar from tables where name =
'Columns'");
+ assertTrue(rs.next());
+ assertEquals("Columns", rs.getString(1));
+ }
}
Show replies by date