Re: Possible bug / regression from generated keys

Поиск
Список
Период
Сортировка
От Peter Cooner
Тема Re: Possible bug / regression from generated keys
Дата
Msg-id CAHVZnpHHfGncEfo9qM8VZvSmC+v5X0bt-aKttgR_3XBq1fSw1w@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Possible bug / regression from generated keys  (dmp <danap@ttc-cmc.net>)
Ответы Re: Possible bug / regression from generated keys  (Kris Jurka <books@ejurka.com>)
Список pgsql-jdbc
I tried to write a test case for a few days before I mailed the list
and was unable to produce the problem :(

The following code pulls its connection from a SimpleDataSource()
object. Its a mess because I ripped all code that used DbUtils and
DBCP in the critical path. Despite the code being ripped up, it still
works and produces the problem when the 1001 driver is used.



        public List<Long> batchPos(int batchNumber, String sql,
Object[]... params) throws SQLException {
            Check.notNull("sql", sql);
            Check.notNull("params", params);

            Connection conn = null;
            PreparedStatement stmt = null;
            ResultSet rs = null;
            List<Long> result = null;
            Object[] row = null;

            try {
                conn = ds.getConnection();
                stmt = conn.prepareStatement(sql,
                        Statement.RETURN_GENERATED_KEYS);
                ParameterMetaData pmd = stmt.getParameterMetaData();

                for (int p = 0; p < params.length; p++) {
                    row = params[p];

                    if (pmd.getParameterCount() != row.length) {
                        throw new SQLException("Bad param length");
                    }

                    for (int r = 0; r < row.length; r++) {
                        if (row[r] != null) {
                            stmt.setObject(r + 1, row[r]);
                        } else {
                            stmt.setNull(r + 1, pmd.getParameterType(r + 1));
                        }
                    }

                    //this.fillStatement(stmt, row);
                    stmt.addBatch();
                }
                stmt.executeBatch();

                rs = stmt.getGeneratedKeys();
                result = new LinkedList<Long>();

                while (rs.next()) {

                    ResultSetMetaData meta = rs.getMetaData();
                    for (int i=1; i<=meta.getColumnCount(); i++) {
                        log.debug("[%d][%d] %s %s",
                                batchNumber,
                                i,
                                meta.getColumnTypeName(i),
                                meta.getColumnName(i)
                                );
                        Object obj = rs.getObject(i);
                        log.debug("[%d][%d] Object %s (%s)",
                                batchNumber,
                                i,
                                obj,
                                (obj!=null ?
obj.getClass().getSimpleName() : "null")
                                );
                    }

                    String column = meta.getColumnName(1);
                    if (!column.equals("position_id")) {
                        log.warn("Column 1 is not id, is %s", column);
                    }

                    result.add(rs.getLong(1));
                }

            } catch (Exception e) {
                log.error(e, "Batch %d general failure!", batchNumber);
                this.rethrow(new SQLException(e), sql, row);

            } finally {
                DbUtils.closeQuietly(conn, stmt, rs);
            }

            return result;
        }

2012-Nov-08 12:48:01 tdbd: ERROR (DbData.batchPos:533) Batch 3 general failure!
java.lang.ArrayIndexOutOfBoundsException: 4
    at org.postgresql.util.ByteConverter.int8(ByteConverter.java:29)
    at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getLong(AbstractJdbc2ResultSet.java:2150)
    at org.postgresql.jdbc2.AbstractJdbc2ResultSet.internalGetObject(AbstractJdbc2ResultSet.java:142)
    at org.postgresql.jdbc3.AbstractJdbc3ResultSet.internalGetObject(AbstractJdbc3ResultSet.java:36)
    at org.postgresql.jdbc4.AbstractJdbc4ResultSet.internalGetObject(AbstractJdbc4ResultSet.java:296)
    at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getObject(AbstractJdbc2ResultSet.java:2703)
    at com.heheh.service.database.DbData$BatchRunner.batchPos(DbData.java:515)






On Thu, Nov 8, 2012 at 10:57 AM, dmp <danap@ttc-cmc.net> wrote:
> Ater some thought I'm in agreement with Dave. The backend must be sending
> an unexpected value that can not be converted.
>
> Peter can you please send a post of the core prepare commit code that is
> used to create these batches along with the exact place in your code
> before the PSQLExceptions codes are given. I assume from your original post
> that would include the getGeneratedKeys() that you indicated is the place
> the error occurs for the ResultSet?
>
> A simple test code case to recreate the error would be of course best.
>
> danap.
>


В списке pgsql-jdbc по дате отправления:

Предыдущее
От: dmp
Дата:
Сообщение: Re: Possible bug / regression from generated keys
Следующее
От: Peter Cooner
Дата:
Сообщение: Re: Possible bug / regression from generated keys