Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 3B19BB5DC5B for ; Fri, 16 Sep 2011 10:28:04 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 11647-02-3 for ; Fri, 16 Sep 2011 13:27:57 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from auth-smtp.nebula.fi (auth-smtp.nebula.fi [217.30.180.105]) by mail.postgresql.org (Postfix) with ESMTP id C3714B5DD26 for ; Fri, 16 Sep 2011 10:27:37 -0300 (ADT) Received: from quadvadis.localdomain (gw.nitor.fi [83.145.228.24]) (authenticated bits=0) by auth-smtp.nebula.fi (8.13.4/8.13.4) with ESMTP id p8GDEI5n007787 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 16 Sep 2011 16:14:19 +0300 Message-ID: <4E734BAB.9000406@nitorcreations.com> Date: Fri, 16 Sep 2011 16:14:19 +0300 From: Mikko Tiihonen User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:6.0.2) Gecko/20110906 Thunderbird/6.0.2 MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: Binary transfer support [3/7] - debugging Content-Type: multipart/mixed; boundary="------------070407030104010708080409" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201109/42 X-Sequence-Number: 22160 This is a multi-part message in MIME format. --------------070407030104010708080409 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit --------------070407030104010708080409 Content-Type: text/plain; name="debugging.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="debugging.patch" Index: pgjdbc.tmp8/org/postgresql/core/Field.java =================================================================== --- pgjdbc.tmp8.orig/org/postgresql/core/Field.java +++ pgjdbc.tmp8/org/postgresql/core/Field.java @@ -197,4 +197,9 @@ public class Field return schemaName; } + public String toString() { + return "Field("+ (columnName != null ? columnName : "") + "," + + Oid.toString(oid) + "," + length + "," + + (format == TEXT_FORMAT ? 'T' : 'B') + ")"; + } } Index: pgjdbc.tmp8/org/postgresql/core/Oid.java =================================================================== --- pgjdbc.tmp8.orig/org/postgresql/core/Oid.java +++ pgjdbc.tmp8/org/postgresql/core/Oid.java @@ -9,6 +9,8 @@ */ package org.postgresql.core; +import java.lang.reflect.Field; + /** * Provides constants for well-known backend OIDs for the types we commonly * use. @@ -67,4 +69,24 @@ public class Oid { public static final int XML = 142; public static final int XML_ARRAY = 143; + /** + * Returns the name of the oid as string. + * + * @param oid The oid to convert to name. + * @return The name of the oid or "" if oid no constant for + * oid value has been defined. + */ + public static String toString(int oid) { + try { + Field[] fields = Oid.class.getFields(); + for (int i = 0; i < fields.length; ++i) { + if (fields[i].getInt(null) == oid) { + return fields[i].getName(); + } + } + } catch (IllegalAccessException e) { + // never happens + } + return ""; + } } Index: pgjdbc.tmp8/org/postgresql/core/v3/QueryExecutorImpl.java =================================================================== --- pgjdbc.tmp8.orig/org/postgresql/core/v3/QueryExecutorImpl.java +++ pgjdbc.tmp8/org/postgresql/core/v3/QueryExecutorImpl.java @@ -1851,7 +1851,7 @@ public class QueryExecutorImpl implement break; case 'D': // Data Transfer (ongoing Execute response) - Object tuple = null; + byte[][] tuple = null; try { tuple = pgStream.ReceiveTupleV3(); } catch(OutOfMemoryError oome) { @@ -1868,8 +1868,19 @@ public class QueryExecutorImpl implement tuples.addElement(tuple); } - if (logger.logDebug()) - logger.debug(" <=BE DataRow"); + if (logger.logDebug()) { + int length; + if (tuple == null) { + length = -1; + } else { + length = 0; + for (int i=0; i< tuple.length; ++i) { + if (tuple[i] == null) continue; + length += tuple[i].length; + } + } + logger.debug(" <=BE DataRow(len=" + length + ")"); + } break; case 'E': // Error Response (response to pretty much everything; backend then skips until Sync) @@ -2112,6 +2123,9 @@ public class QueryExecutorImpl implement "", /* name not yet determined */ typeOid, typeLength, typeModifier, tableOid, positionInTable); fields[i].setFormat(formatType); + + if (logger.logDebug()) + logger.debug(" " + fields[i]); } return fields; Index: pgjdbc.tmp8/org/postgresql/core/v3/SimpleQuery.java =================================================================== --- pgjdbc.tmp8.orig/org/postgresql/core/v3/SimpleQuery.java +++ pgjdbc.tmp8/org/postgresql/core/v3/SimpleQuery.java @@ -120,9 +120,21 @@ class SimpleQuery implements V3Query { return encodedStatementName; } + /** + * Sets the fields that this query will return. + * + * @param fields The fields that this query will return. + */ void setFields(Field[] fields) { this.fields = fields; } + + /** + * Returns the fields that this query will return. If the result set fields + * are not known returns null. + * + * @return the fields that this query will return. + */ Field[] getFields() { return fields; } @@ -171,6 +183,10 @@ class SimpleQuery implements V3Query { private final ProtocolConnectionImpl protoConnection; private String statementName; private byte[] encodedStatementName; + /** + * The stored fields from previous query of a prepared statement, + * if executed before. Always null for non-prepared statements. + */ private Field[] fields; private boolean portalDescribed; private boolean statementDescribed; Index: pgjdbc.tmp8/org/postgresql/jdbc2/AbstractJdbc2Connection.java =================================================================== --- pgjdbc.tmp8.orig/org/postgresql/jdbc2/AbstractJdbc2Connection.java +++ pgjdbc.tmp8/org/postgresql/jdbc2/AbstractJdbc2Connection.java @@ -158,6 +158,8 @@ public abstract class AbstractJdbc2Conne logger.debug(" compatible = " + compatible); logger.debug(" loglevel = " + logLevel); logger.debug(" prepare threshold = " + prepareThreshold); + logger.debug(" types using binary send = " + oidsToString(useBinarySendForOids)); + logger.debug(" types using binary receive = " + oidsToString(useBinaryReceiveForOids)); } // @@ -204,6 +206,21 @@ public abstract class AbstractJdbc2Conne } } + private String oidsToString(BitSet oids) { + StringBuffer sb = new StringBuffer(); + int oid = -1; + while ((oid = oids.nextSetBit(oid + 1)) != -1) { + sb.append(Oid.toString(oid)); + sb.append(','); + } + if (sb.length() > 0) { + sb.setLength(sb.length() - 1); + } else { + sb.append(" "); + } + return sb.toString(); + } + private final TimestampUtils timestampUtils; public TimestampUtils getTimestampUtils() { return timestampUtils; } --------------070407030104010708080409--