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 4C831329C82 for ; Sat, 25 Sep 2004 18:04:39 +0100 (BST) 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 70272-07 for ; Sat, 25 Sep 2004 17:04:35 +0000 (GMT) Received: from uniclear.com (unknown [69.10.136.215]) by svr1.postgresql.org (Postfix) with SMTP id 3EB96329C63 for ; Sat, 25 Sep 2004 18:04:34 +0100 (BST) Received: (qmail 6506 invoked from network); 25 Sep 2004 17:04:58 -0000 Received: from dsl-nvan-209-115-184-207-van.nucleus.com (HELO uniclear.com) (209.115.184.207) by h69-10-136-215.n-01.net with SMTP; 25 Sep 2004 17:04:58 -0000 Message-ID: <4155A54D.10002@uniclear.com> Date: Sat, 25 Sep 2004 10:05:17 -0700 From: Nathan Crause User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Gecko/20040113 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: PreparedStatement Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.6 tagged_above=0.0 required=5.0 tests=HTML_MESSAGE, HTML_TITLE_EMPTY, MIME_HTML_ONLY X-Spam-Level: X-Archive-Number: 200409/190 X-Sequence-Number: 11080 Hi guys,

First time posting to this mailing list, so please be patient with me.

I have a need for the Connection.prepareStatement(String sql, int autoGeneratedKeys) method to be functional. Obviously, such keys would only ever be generated during an INSERT (as per the Java API specification: "This parameter is ignored if the SQL statement is not an INSERT statement").

Unless someone strongly objects, I am going to be looking into coding such functionality. I do have several questions, though. Now, I personally have only ever seen INSERT statements for a single table. Is it even vaguely possible for an INSERT statement to directly affect more than one table (by directly, I mean excluding any tables which may be affected by a trigger)?

If not, then what I am proposing is for the Connection.prepareStatement() method to use regular expression parsing (via the java.util.regex package) to extract the table name being inserted into, and querying the system tables to check for an int (or bigint) columns which contain a default which refers to the "NEXTVAL" function, and which do NOT form part of the actual insert statement (i.e. the default value will be inserted, hence using the sequence number system).

I would obviously need to create a special PreparedStatement implentation which would store these column names. Upon execution of this prepared statement, the class would then internally execute all "CURRVAL()" queries for the columns known to have been autogenerated.

So, I'm thinking that someone is probably wondering why the heck I want to do this? Surely I could just code the "CURRVAL()" queries right within my program. Well, my motivation is that the company I am working for is trying to move our systems from a MySQL database to PostgreSQL. Many of the data insertion areas on the system use the auto-generated-keys resultset feature, and I personally don't want to fish through all the programs and change them. Hehehe - lazy dude :-P