*** AbstractJdbc3Connection.java	23 Dec 2009 10:28:40 +0200	1.21
--- AbstractJdbc3Connection.java	23 Apr 2010 18:49:44 +0300	
***************
*** 359,364 ****
--- 359,381 ----
      throws SQLException
      {
          checkClosed();
+
+ 	/*
+ 	 * We implement fetching auto-generated keys by tacking a
+ 	 * " RETURNING *" to the end of the string. Don't try to do that
+ 	 * with other statements than INSERT/UPDATE/DELETE.
+ 	 *
+ 	 * XXX this gets fooled by comments at the beginning of the SQL string
+ 	 */
+         if (autoGeneratedKeys != Statement.NO_GENERATED_KEYS)
+         {
+ 	    String trimmedSql = sql.trim();
+ 	    if (!trimmedSql.regionMatches(true, 0, "INSERT", 0, 6) &&
+ 		!trimmedSql.regionMatches(true, 0, "UPDATE", 0, 6) &&
+ 		!trimmedSql.regionMatches(true, 0, "DELETE", 0, 6))
+ 		autoGeneratedKeys = Statement.NO_GENERATED_KEYS;
+ 	}
+
          if (autoGeneratedKeys != Statement.NO_GENERATED_KEYS)
              sql = AbstractJdbc3Statement.addReturning(this, sql, new
