# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: C:\dev\java\proj\pgjdbc\pgjdbc # 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: org/postgresql/jdbc2/AbstractJdbc2Statement.java *** C:\dev\java\proj\pgjdbc\pgjdbc\org\postgresql\jdbc2\AbstractJdbc2Statement.java Base (1.104) --- C:\dev\java\proj\pgjdbc\pgjdbc\org\postgresql\jdbc2\AbstractJdbc2Statement.java Locally Modified (Based On 1.104) *************** *** 286,291 **** --- 286,318 ---- } /* + * Execute a SQL INSERT, UPDATE or DELETE statement. In addition + * SQL statements that return nothing such as SQL DDL statements + * can be executed + * + * @param sql a SQL statement + * @return either a row count, or 0 for SQL commands + * @exception SQLException if a database access error occurs + */ + protected int executeUpdateGetResults(String p_sql) throws SQLException + { + if (preparedQuery != null) + throw new PSQLException(GT.tr("Can''t use query methods that take a query string on a PreparedStatement."), + PSQLState.WRONG_OBJECT_TYPE); + if( isFunction ) + { + executeWithFlags(p_sql, 0); + return 0; + } + checkClosed(); + p_sql = replaceProcessing(p_sql); + Query simpleQuery = connection.getQueryExecutor().createSimpleQuery(p_sql); + execute(simpleQuery, null, 0); + this.lastSimpleQuery = simpleQuery; + return getUpdateCount(); + } + + /* * Execute a SQL INSERT, UPDATE or DELETE statement. In addition, * SQL statements that return nothing such as SQL DDL statements can * be executed. Index: org/postgresql/jdbc3/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) *************** *** 11,16 **** --- 11,17 ---- import java.math.BigDecimal; import java.sql.*; + import java.util.ArrayList; import java.util.Calendar; import java.util.Vector; *************** *** 19,24 **** --- 20,28 ---- import org.postgresql.core.QueryExecutor; import org.postgresql.core.Field; import org.postgresql.core.BaseConnection; + import org.postgresql.core.Utils; + import org.postgresql.jdbc2.AbstractJdbc2Connection; + import org.postgresql.jdbc2.AbstractJdbc2Statement.StatementResultHandler; import org.postgresql.util.GT; /** *************** *** 28,33 **** --- 32,38 ---- */ public abstract class AbstractJdbc3Statement extends org.postgresql.jdbc2.AbstractJdbc2Statement { + private final int rsHoldability; public AbstractJdbc3Statement (AbstractJdbc3Connection c, int rsType, int rsConcurrency, int rsHoldability) throws SQLException *************** *** 106,112 **** */ public ResultSet getGeneratedKeys() throws SQLException { ! return createDriverResultSet(new Field[0], new Vector()); } /** --- 111,119 ---- */ 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); } --- 142,148 ---- { 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); } *************** *** 159,172 **** */ public int executeUpdate(String sql, int columnIndexes[]) throws SQLException { ! if (columnIndexes.length == 0) return executeUpdate(sql); ! ! throw new PSQLException(GT.tr("Returning autogenerated keys is not supported."), PSQLState.NOT_IMPLEMENTED); } /** --- 166,206 ---- */ public int executeUpdate(String sql, int columnIndexes[]) throws SQLException { ! if (columnIndexes==null || columnIndexes.length == 0) return executeUpdate(sql); ! String prefix = sql.substring(0,10).toLowerCase(); ! if (columnIndexes==null || prefix.indexOf("insert")==-1) ! { ! return executeUpdateGetResults(sql); } + int start = Utils.position(sql, "INTO", 0); + ArrayList args = Utils.getInsertIds(sql, start); + String pgCols = + "SELECT column_name "+ + "FROM information_schema.columns "+ + "WHERE table_catalog='"+args.get(0)+"' AND table_schema='"+args.get(1)+"' AND table_name='"+args.get(2)+"' "+ + "ORDER BY ordinal_position"; + ResultSet rs = null; + String[] columnNames = new String[columnIndexes.length]; + try { + rs = this.executeQuery(pgCols); + } catch (SQLException ex) { + throw new PSQLException(GT.tr("Could not translate column name indexes.")+" "+ex, PSQLState.UNEXPECTED_ERROR); + } finally { + if (rs!=null) rs.close(); + } + int j=0; + try { + for (; j1 && in.charAt(0)=='"' && in.charAt(len-1)=='"'; + if (already && len==2) + throw new PSQLException(GT.tr("Empty quoted value"), PSQLState.INVALID_PARAMETER_VALUE); + int end = len-1; + for (int i=1; icatalog.schema.table identifiers appear + * @return ArrayList who first element is the left-most identifiers, and right-most is the table name. + * @author Ken Johanon ken2006@onnet.cc + */ + public static ArrayList getInsertIds(String sql, int start) + { + if (start<0) + throw new IllegalArgumentException("getInsertIds: invalid start index: "+start); + start += 4; + //advance to first alnum + for (; startfind in String in, case insensitive. + * If in is empty, return -1. If find is empty, return 0. + * @param in + * @param find - string to find + * @param pos - starting position to search + * @return int location, or -1 if not found + * @author Ken Johanon ken2006@onnet.cc + */ + public static int position(CharSequence in, String find, int pos) + { + boolean c = in==null || in.length()==0; + boolean d = find==null || find.length()==0; + if (d || c && d) + return 0; + if (c) + return -1; + int a = in.length(); + int b = find.length(); + int count = 0; + //if (pos>a-b) + // return -1; + char c1, c2; + for (int i=pos; i