Author: jolee
Date: 2012-09-10 09:31:50 -0400 (Mon, 10 Sep 2012)
New Revision: 4414
Modified:
branches/7.7.x/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java
branches/7.7.x/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java
Log:
TEIID-2096: Colons need to be escaped
Modified: branches/7.7.x/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java
===================================================================
---
branches/7.7.x/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java 2012-09-10
13:02:09 UTC (rev 4413)
+++
branches/7.7.x/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java 2012-09-10
13:31:50 UTC (rev 4414)
@@ -68,7 +68,9 @@
public class ODBCServerRemoteImpl implements ODBCServerRemote {
private static final String UNNAMED = "UNNAMED"; //$NON-NLS-1$
- private static Pattern setPattern =
Pattern.compile("(SET|set)\\s+(\\w+)\\s+(TO|to)\\s+'(\\w+\\d*)'");//$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$
"from pg_catalog.pg_attribute ta, pg_catalog.pg_attribute ia, pg_catalog.pg_class
tc, pg_catalog.pg_index i, " +//$NON-NLS-1$
@@ -625,8 +627,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:
branches/7.7.x/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java
===================================================================
---
branches/7.7.x/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java 2012-09-10
13:02:09 UTC (rev 4413)
+++
branches/7.7.x/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java 2012-09-10
13:31:50 UTC (rev 4414)
@@ -345,4 +345,16 @@
assertTrue(s.execute("select * from tables order by name"));
TestMMDatabaseMetaData.compareResultSet("TestODBCSocketTransport/testSelect",
s.getResultSet());
}
+
+ @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