Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit54bc3b6

Browse files
author
Barry Lind
committed
Fixed bug reported by Marko Strukelj and Keith Wannamaker. Using executeBatch
on a preparedStatement would reset the prepared statment causing subsequentuses of the preparedStatement to fail (i.e. the following series of callswould fail: addBatch() executeBatch() addBatch() executBatch()). This isa regression from 7.2 where this worked correctly. The regression test hasalso been modified to explicitly test for this case. Modified Files: jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java jdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java jdbc/org/postgresql/test/jdbc2/BatchExecuteTest.java
1 parentb60be3f commit54bc3b6

File tree

3 files changed

+49
-9
lines changed

3 files changed

+49
-9
lines changed

‎src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
importorg.postgresql.largeobject.*;
99
importorg.postgresql.util.*;
1010

11-
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.13 2002/11/14 05:35:45 barry Exp $
11+
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.14 2002/11/20 07:34:32 barry Exp $
1212
* This class defines methods of the jdbc1 specification. This class is
1313
* extended by org.postgresql.jdbc2.AbstractJdbc2Statement which adds the jdbc2
1414
* methods. The real Statement class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Statement
@@ -47,7 +47,7 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
4747
privateString[]m_origSqlFragments;
4848
privateString[]m_executeSqlFragments;
4949
protectedObject[]m_binds =newObject[0];
50-
privateString[]m_bindTypes =newString[0];
50+
protectedString[]m_bindTypes =newString[0];
5151
privateStringm_statementName =null;
5252
privatebooleanm_useServerPrepare =false;
5353
privatestaticintm_preparedCount =1;

‎src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
importorg.postgresql.largeobject.*;
99
importorg.postgresql.util.PSQLException;
1010

11-
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2Statement.java,v 1.8 2002/10/30 04:33:29 barry Exp $
11+
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2Statement.java,v 1.9 2002/11/20 07:34:32 barry Exp $
1212
* This class defines methods of the jdbc2 specification. This class extends
1313
* org.postgresql.jdbc1.AbstractJdbc1Statement which provides the jdbc1
1414
* methods. The real Statement class (for jdbc2) is org.postgresql.jdbc2.Jdbc2Statement
@@ -59,7 +59,8 @@ public void addBatch(String p_sql) throws SQLException
5959
{
6060
if (batch ==null)
6161
batch =newVector();
62-
batch.addElement(p_sql);
62+
Object[]l_statement =newObject[] {newString[] {p_sql},newObject[0],newString[0]};
63+
batch.addElement(l_statement);
6364
}
6465

6566
publicvoidclearBatch()throwsSQLException
@@ -76,8 +77,25 @@ public int[] executeBatch() throws SQLException
7677
inti =0;
7778
try
7879
{
79-
for (i =0;i <size;i++)
80-
result[i] =this.executeUpdate((String)batch.elementAt(i));
80+
//copy current state of statement
81+
String[]l_origSqlFragments =m_sqlFragments;
82+
Object[]l_origBinds =m_binds;
83+
String[]l_origBindTypes =m_bindTypes;
84+
85+
for (i =0;i <size;i++) {
86+
//set state from batch
87+
Object[]l_statement = (Object[])batch.elementAt(i);
88+
this.m_sqlFragments = (String[])l_statement[0];
89+
this.m_binds = (Object[])l_statement[1];
90+
this.m_bindTypes = (String[])l_statement[2];
91+
result[i] =this.executeUpdate();
92+
}
93+
94+
//restore state of statement
95+
String[]m_sqlFragments =l_origSqlFragments;
96+
Object[]m_binds =l_origBinds;
97+
String[]m_bindTypes =l_origBindTypes;
98+
8199
}
82100
catch (SQLExceptione)
83101
{
@@ -150,7 +168,21 @@ public void setResultSetType(int value) throws SQLException
150168

151169
publicvoidaddBatch()throwsSQLException
152170
{
153-
addBatch(this.toString());
171+
if (batch ==null)
172+
batch =newVector();
173+
174+
//we need to create copies, otherwise the values can be changed
175+
Object[]l_newSqlFragments =null;
176+
if (m_sqlFragments !=null) {
177+
l_newSqlFragments =newString[m_sqlFragments.length];
178+
System.arraycopy(m_sqlFragments,0,l_newSqlFragments,0,m_sqlFragments.length);
179+
}
180+
Object[]l_newBinds =newString[m_binds.length];
181+
System.arraycopy(m_binds,0,l_newBinds,0,m_binds.length);
182+
String[]l_newBindTypes =newString[m_bindTypes.length];
183+
System.arraycopy(m_bindTypes,0,l_newBindTypes,0,m_bindTypes.length);
184+
Object[]l_statement =newObject[] {l_newSqlFragments,l_newBinds,l_newBindTypes};
185+
batch.addElement(l_statement);
154186
}
155187

156188
publicjava.sql.ResultSetMetaDatagetMetaData()throwsSQLException

‎src/interfaces/jdbc/org/postgresql/test/jdbc2/BatchExecuteTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,19 @@ public void testPreparedStatement() throws Exception
157157
pstmt.executeBatch();
158158
assertCol1HasValue(7);
159159

160-
con.commit();
160+
//now test to see that we can still use the statement after the execute
161+
pstmt.setInt(1,3);
162+
pstmt.addBatch();
161163
assertCol1HasValue(7);
162164

165+
pstmt.executeBatch();
166+
assertCol1HasValue(10);
167+
168+
con.commit();
169+
assertCol1HasValue(10);
170+
163171
con.rollback();
164-
assertCol1HasValue(7);
172+
assertCol1HasValue(10);
165173

166174
pstmt.close();
167175
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp