Author: jolee
Date: 2013-05-08 14:29:01 -0400 (Wed, 08 May 2013)
New Revision: 4563
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:
BZ961071: Issue with date format parsing using ODBC Driver
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 2013-05-06
14:30:47 UTC (rev 4562)
+++
branches/7.7.x/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java 2013-05-08
18:29:01 UTC (rev 4563)
@@ -70,6 +70,7 @@
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 pgCastLiterals =
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$
@@ -628,6 +629,8 @@
}
//these are somewhat dangerous
modified = pgCast.matcher(modified).replaceAll("$1"); //$NON-NLS-1$
+ modified = pgCastLiterals.matcher(modified).replaceAll(" cast($1 as $2)");
//$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 2013-05-06
14:30:47 UTC (rev 4562)
+++
branches/7.7.x/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java 2013-05-08
18:29:01 UTC (rev 4563)
@@ -357,4 +357,13 @@
assertTrue(rs.next());
assertEquals("Columns", rs.getString(1));
}
+
+ @Test public void testPGCastLiteralDate() throws Exception {
+ Statement s = conn.createStatement();
+ //make sure that we aren't mishandling the ::
+ ResultSet rs = s.executeQuery("select '2011-01-01'::date as
mydate");
+ assertTrue(rs.next());
+ assertEquals("2011-01-01", rs.getString(1));
+
+ }
}
Show replies by date