logo       

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

db.postgresql.jdbc

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

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



---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@xxxxxxxxxxxxxx so that your
message can get through to the mailing list cleanly



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise