Re: patch: fix a couple of server-prepared-statement bugs

From: Barry Lind <blind(at)xythos(dot)com>
To: Oliver Jowett <oliver(at)opencloud(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: patch: fix a couple of server-prepared-statement bugs
Date: 2003-08-24 22:11:34
Message-ID: 3F493816.7040901@xythos.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Patch applied.

thanks,
--Barry

Oliver Jowett wrote:
> This patch fixes two bugs related to setUseServerPrepare() (and adds
> unit tests for them):
>
> 1. Turning server-prepare from on to off before a query is executed results
> in an invalid "DEALLOCATE null" query being sent to the backend.
>
> 2. setBytes() uses a type of 'text' not 'bytea' when generating a PREPARE,
> resulting in typecasting problems.
>
> -O
>
>
> ------------------------------------------------------------------------
>
> Index: src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java
> ===================================================================
> RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java,v
> retrieving revision 1.31
> diff -u -c -r1.31 AbstractJdbc1Statement.java
> *** src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java 11 Aug 2003 21:12:00 -0000 1.31
> --- src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java 16 Aug 2003 05:26:48 -0000
> ***************
> *** 1088,1094 ****
> }
> else
> {
> ! setString(parameterIndex, PGbytea.toPGString(x), PG_TEXT);
> }
> }
> else
> --- 1088,1094 ----
> }
> else
> {
> ! setString(parameterIndex, PGbytea.toPGString(x), PG_BYTEA);
> }
> }
> else
> ***************
> *** 2055,2061 ****
> if (connection.haveMinimumServerVersion("7.3")) {
> //If turning server prepared statements off deallocate statement
> //and reset statement name
> ! if (m_useServerPrepare != flag && !flag)
> connection.execSQL("DEALLOCATE " + m_statementName);
> m_statementName = null;
> m_useServerPrepare = flag;
> --- 2055,2061 ----
> if (connection.haveMinimumServerVersion("7.3")) {
> //If turning server prepared statements off deallocate statement
> //and reset statement name
> ! if (m_useServerPrepare != flag && !flag && m_statementName != null)
> connection.execSQL("DEALLOCATE " + m_statementName);
> m_statementName = null;
> m_useServerPrepare = flag;
> Index: src/interfaces/jdbc/org/postgresql/test/jdbc2/ServerPreparedStmtTest.java
> ===================================================================
> RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/test/jdbc2/ServerPreparedStmtTest.java,v
> retrieving revision 1.3
> diff -u -c -r1.3 ServerPreparedStmtTest.java
> *** src/interfaces/jdbc/org/postgresql/test/jdbc2/ServerPreparedStmtTest.java 29 May 2003 04:39:48 -0000 1.3
> --- src/interfaces/jdbc/org/postgresql/test/jdbc2/ServerPreparedStmtTest.java 16 Aug 2003 05:26:48 -0000
> ***************
> *** 153,156 ****
> --- 153,178 ----
> pstmt.close();
> }
>
> + public void testSPSToggle() throws Exception
> + {
> + // Verify we can toggle UseServerPrepare safely before a query is executed.
> + PreparedStatement pstmt = con.prepareStatement("SELECT * FROM testsps WHERE id = 2");
> + ((PGStatement)pstmt).setUseServerPrepare(true);
> + ((PGStatement)pstmt).setUseServerPrepare(false);
> + }
> +
> + public void testBytea() throws Exception
> + {
> + // Verify we can use setBytes() with a server-prepared update.
> + try {
> + TestUtil.createTable(con, "testsps_bytea", "data bytea");
> +
> + PreparedStatement pstmt = con.prepareStatement("INSERT INTO testsps_bytea(data) VALUES (?)");
> + ((PGStatement)pstmt).setUseServerPrepare(true);
> + pstmt.setBytes(1, new byte[100]);
> + pstmt.executeUpdate();
> + } finally {
> + TestUtil.dropTable(con, "testsps_bytea");
> + }
> + }
> }
>
>
> ------------------------------------------------------------------------
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faqs/FAQ.html

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Barry Lind 2003-08-24 22:13:05 Re: SetMaxFieldSize
Previous Message Barry Lind 2003-08-24 22:11:06 Re: patch: fix 'compile' target to do correct dependency checking