Обсуждение: Patch to implement Connection.nativeSQL

Поиск
Список
Период
Сортировка

Patch to implement Connection.nativeSQL

От
"Xavier Poinsard"
Дата:
Thanks to Kris remark, here is a tiny patch implementing
Connection.nativeSQL
Index: jdbc2/AbstractJdbc2Connection.java
===================================================================
RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Connection.java,v
retrieving revision 1.25
diff -u -r1.25 AbstractJdbc2Connection.java
--- jdbc2/AbstractJdbc2Connection.java    14 Jan 2005 01:20:19 -0000    1.25
+++ jdbc2/AbstractJdbc2Connection.java    24 Jan 2005 15:27:36 -0000
@@ -502,7 +502,9 @@
      */
     public String nativeSQL(String sql) throws SQLException
     {
-        return sql;
+        StringBuffer buf = new StringBuffer(sql.length());
+        AbstractJdbc2Statement.parseSql(sql,0,buf,false);
+        return buf.toString();
     }

     /*
Index: jdbc2/AbstractJdbc2Statement.java
===================================================================
RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java,v
retrieving revision 1.64
diff -u -r1.64 AbstractJdbc2Statement.java
--- jdbc2/AbstractJdbc2Statement.java    18 Jan 2005 21:33:17 -0000    1.64
+++ jdbc2/AbstractJdbc2Statement.java    24 Jan 2005 15:27:42 -0000
@@ -718,7 +718,7 @@
      * @param stopOnComma should we stop after hitting the first comma in sql text?
      * @return the position we stopped processing at
      */
-    private int parseSql(String p_sql,int i,StringBuffer newsql, boolean stopOnComma)throws SQLException{
+    protected static int parseSql(String p_sql,int i,StringBuffer newsql, boolean stopOnComma)throws SQLException{
         short state = IN_SQLCODE;
         int len = p_sql.length();
         int nestedParenthesis=0;
@@ -848,7 +848,7 @@
      * @param args the arguments for this functin
      * @return the right postgreSql sql
      */
-    protected String escapeFunction(String functionName, String args) throws SQLException{
+    protected static String escapeFunction(String functionName, String args) throws SQLException{
         // parse function arguments
         int len = args.length();
         int i=0;
Index: test/jdbc2/ConnectionTest.java
===================================================================
RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/test/jdbc2/ConnectionTest.java,v
retrieving revision 1.19
diff -u -r1.19 ConnectionTest.java
--- test/jdbc2/ConnectionTest.java    11 Jan 2005 08:25:48 -0000    1.19
+++ test/jdbc2/ConnectionTest.java    24 Jan 2005 15:27:44 -0000
@@ -100,9 +100,11 @@
     /*
      * Test nativeSQL
      */
-    public void testNativeSQL()
+    public void testNativeSQL() throws SQLException
     {
-        // For now do nothing as it returns itself
+        // test a simple escape
+        Connection con = TestUtil.openDB();
+        assertEquals("DATE  '2005-01-24'",con.nativeSQL("{d '2005-01-24'}"));
     }

     /*

Re: Patch to implement Connection.nativeSQL

От
Kris Jurka
Дата:

On Mon, 24 Jan 2005, Xavier Poinsard wrote:

> Thanks to Kris remark, here is a tiny patch implementing
> Connection.nativeSQL
>

Applied.

Also I've removed the mapping for the difference function.  Levenshtein
does sort of the same thing (roughly estimating the similarity of two
strings), but it's not the same.  I've submitted a patch to fuzzystrmatch
to implement the soundex difference function, but that won't be widely
available any time soon (or perhaps even ever).  In any case if applied
there is no need for a translation process, so it should just work.

http://archives.postgresql.org/pgsql-patches/2005-01/msg00268.php

Kris Jurka