Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id C071B9FB781 for ; Thu, 15 Feb 2007 00:31:52 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-new, port 10024) with ESMTP id 35091-04 for ; Thu, 15 Feb 2007 00:31:44 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from www01.kensystem.com (www01.kensystem.com [72.19.170.120]) by postgresql.org (Postfix) with ESMTP id 6B4939FB77A for ; Thu, 15 Feb 2007 00:31:44 -0400 (AST) Received: from 192.168.0.3 by www01.kensystem.com (SMTPD); id s20070215043143.57803; Thu, 15 Feb 2007 04:31:43 Message-ID: <45D3E22F.9050009@kensystem.com> Date: Wed, 14 Feb 2007 21:31:43 -0700 From: Ken Johanson User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) MIME-Version: 1.0 To: Kris Jurka CC: pgsql-jdbc@postgresql.org Subject: Re: Synthesize support for Statement.getGeneratedKeys()? References: <4580E681.3080106@kensystem.com> <45B9A9D6.2080100@kensystem.com> <45BECBA1.8080508@kensystem.com> <45D24BF2.6010405@kensystem.com> In-Reply-To: Content-Type: multipart/mixed; boundary="------------000101030301060202030602" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.002 tagged_above=0 required=5 tests=BAYES_50, UNPARSEABLE_RELAY X-Spam-Level: X-Archive-Number: 200702/70 X-Sequence-Number: 16626 This is a multi-part message in MIME format. --------------000101030301060202030602 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Kris Jurka wrote: > > > On Tue, 13 Feb 2007, Ken Johanson wrote: > >> I have not tested this exhaustively, nor given though about the >> correctness of the null-normalization below; is this enough for you or >> someone to commit the changes? >> > > No, you've provided the sketch of a solution, but it's not appropriate > for the driver until you've resolved things like quoting column names, > putting in a version check for a server that supports RETURNING, and > added some test cases. Some or all of this can be done by the > committer, but the more work the committer must do the less likely it's > going to happen. > > Kris Jurka > This patch adds server version checking and only basic quoting to AbstractJdbc3Statement. No test cases. It only checks for server version 8 or newer as I couldn't easily find the threshold for the RETURNING support. It also only quotes the key array if it contains spaces. Doe anyone know if there is a scanner method to check for quotable identifiers? Did server 8 first implement RETURNING? What other concerns should I apply to this? Thanks, ken --------------000101030301060202030602 Content-Type: text/plain; name="AbstractJdbc3Statement.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="AbstractJdbc3Statement.patch" # This patch file was generated by NetBeans IDE # Following Index: paths are relative to: C:\dev\java\proj\pgjdbc\pgjdbc\org\postgresql\jdbc3 # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: AbstractJdbc3Statement.java *** C:\dev\java\proj\pgjdbc\pgjdbc\org\postgresql\jdbc3\AbstractJdbc3Statement.java Base (1.21) --- C:\dev\java\proj\pgjdbc\pgjdbc\org\postgresql\jdbc3\AbstractJdbc3Statement.java Locally Modified (Based On 1.21) *************** *** 19,24 **** --- 19,26 ---- import org.postgresql.core.QueryExecutor; import org.postgresql.core.Field; import org.postgresql.core.BaseConnection; + import org.postgresql.jdbc2.AbstractJdbc2Connection; + import org.postgresql.jdbc2.AbstractJdbc2Statement.StatementResultHandler; import org.postgresql.util.GT; /** *************** *** 106,112 **** */ public ResultSet getGeneratedKeys() throws SQLException { ! return createDriverResultSet(new Field[0], new Vector()); } /** --- 108,116 ---- */ public ResultSet getGeneratedKeys() throws SQLException { ! return result==null ? ! createDriverResultSet(new Field[0], new Vector()) ! : result.getResultSet(); } /** *************** *** 135,141 **** { if (autoGeneratedKeys == Statement.NO_GENERATED_KEYS) return executeUpdate(sql); ! throw new PSQLException(GT.tr("Returning autogenerated keys is not supported."), PSQLState.NOT_IMPLEMENTED); } --- 139,145 ---- { if (autoGeneratedKeys == Statement.NO_GENERATED_KEYS) return executeUpdate(sql); ! //fix me : impl NO_GENERATED_KEYS & RETURN_GENERATED_KEYS throw new PSQLException(GT.tr("Returning autogenerated keys is not supported."), PSQLState.NOT_IMPLEMENTED); } *************** *** 184,198 **** */ public int executeUpdate(String sql, String columnNames[]) throws SQLException { ! if (columnNames.length == 0) return executeUpdate(sql); ! ! throw new PSQLException(GT.tr("Returning autogenerated keys is not supported."), PSQLState.NOT_IMPLEMENTED); } /** * Executes the given SQL statement, which may return multiple results, --- 188,230 ---- */ public int executeUpdate(String sql, String columnNames[]) throws SQLException { ! //fix me : columnNames only quoted if contain 0x20 ! //fix me : if super changes, will break (need interface to get server verion): ! String prefix = sql.substring(0,10).toLowerCase(); ! if (prefix.indexOf("insert")==-1) ! return executeUpdateGetResults(sql); ! if (!(connection instanceof AbstractJdbc2Connection)) ! { ! throw new PSQLException(GT.tr("Driver version does not support returning generated keys.")+" "+connection.getClass().getName(), PSQLState.NOT_IMPLEMENTED); ! } ! AbstractJdbc2Connection con = (AbstractJdbc2Connection)connection; ! int major = con.getServerMajorVersion(); ! if (major<8) ! throw new PSQLException(GT.tr("Server version does not support returning generated keys.")+" ("+major+" < "+8+")", PSQLState.NOT_IMPLEMENTED); ! if (columnNames==null || columnNames.length==0) return executeUpdate(sql); ! StringBuffer s = new StringBuffer(sql.length()+(columnNames.length*32)); ! s.append(sql); ! s.append('\n'); ! s.append("RETURNING"); ! s.append(' '); ! boolean needsQuote; ! for (int i=0; i