{
if (batch == null)
batch = new Vector();
- batch.addElement(p_sql);
+ Object[] l_statement = new Object[] {new String[] {p_sql}, new Object[0], new String[0]};
+ batch.addElement(l_statement);
}
public void clearBatch() throws SQLException
int i = 0;
try
{
- for (i = 0;i < size;i++)
- result[i] = this.executeUpdate((String)batch.elementAt(i));
+ //copy current state of statement
+ String[] l_origSqlFragments = m_sqlFragments;
+ Object[] l_origBinds = m_binds;
+ String[] l_origBindTypes = m_bindTypes;
+
+ for (i = 0;i < size;i++) {
+ //set state from batch
+ Object[] l_statement = (Object[])batch.elementAt(i);
+ this.m_sqlFragments = (String[])l_statement[0];
+ this.m_binds = (Object[])l_statement[1];
+ this.m_bindTypes = (String[])l_statement[2];
+ result[i] = this.executeUpdate();
+ }
+
+ //restore state of statement
+ String[] m_sqlFragments = l_origSqlFragments;
+ Object[] m_binds = l_origBinds;
+ String[] m_bindTypes = l_origBindTypes;
+
}
catch (SQLException e)
{
public void addBatch() throws SQLException
{
- addBatch(this.toString());
+ if (batch == null)
+ batch = new Vector();
+
+ //we need to create copies, otherwise the values can be changed
+ Object[] l_newSqlFragments = null;
+ if (m_sqlFragments != null) {
+ l_newSqlFragments = new String[m_sqlFragments.length];
+ System.arraycopy(m_sqlFragments,0,l_newSqlFragments,0,m_sqlFragments.length);
+ }
+ Object[] l_newBinds = new String[m_binds.length];
+ System.arraycopy(m_binds,0,l_newBinds,0,m_binds.length);
+ String[] l_newBindTypes = new String[m_bindTypes.length];
+ System.arraycopy(m_bindTypes,0,l_newBindTypes,0,m_bindTypes.length);
+ Object[] l_statement = new Object[] {l_newSqlFragments, l_newBinds, l_newBindTypes};
+ batch.addElement(l_statement);
}
public java.sql.ResultSetMetaData getMetaData() throws SQLException