X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 272593A4D8F for ; Mon, 24 Jan 2005 15:35:39 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 45088-08 for ; Mon, 24 Jan 2005 15:35:23 +0000 (GMT) Received: from kraid.nerim.net (smtp-101-monday.nerim.net [62.4.16.101]) by svr1.postgresql.org (Postfix) with ESMTP id 64EDF3A53AF for ; Mon, 24 Jan 2005 15:35:26 +0000 (GMT) Received: from [192.168.0.185] (secure.openpricer.com [80.65.224.34]) by kraid.nerim.net (Postfix) with ESMTP id D5EBE4160C for ; Mon, 24 Jan 2005 16:35:24 +0100 (CET) Message-ID: <41F515BC.8020901@free.fr> Date: Mon, 24 Jan 2005 16:35:24 +0100 From: "Xavier Poinsard" User-Agent: Mozilla Thunderbird 0.9 (X11/20041124) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-jdbc Subject: Patch to implement Connection.nativeSQL Content-Type: multipart/mixed; boundary="------------090400040503050602020405" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.073 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200501/228 X-Sequence-Number: 12108 This is a multi-part message in MIME format. --------------090400040503050602020405 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Thanks to Kris remark, here is a tiny patch implementing Connection.nativeSQL --------------090400040503050602020405 Content-Type: text/plain; name="patchNativeSql.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="patchNativeSql.txt" 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'}")); } /* --------------090400040503050602020405--