mirror of
https://github.com/postgres/postgres.git
synced 2025-07-17 06:41:09 +03:00
Fix updatable ResultSets stream methods (ascii, character, binary).
The existing code didn't correctly allocate data arrays, and it failed to loop when a stream didn't provide the full amount of data requested of it. Reported by Jan de Visser.
This commit is contained in:
@ -9,7 +9,7 @@
|
||||
* Copyright (c) 2003, PostgreSQL Global Development Group
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2ResultSet.java,v 1.25.2.6 2004/06/16 05:11:44 jurka Exp $
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2ResultSet.java,v 1.25.2.7 2004/06/21 02:01:11 jurka Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -18,6 +18,8 @@ package org.postgresql.jdbc2;
|
||||
import java.io.CharArrayReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.*;
|
||||
import java.util.Enumeration;
|
||||
@ -210,6 +212,7 @@ public abstract class AbstractJdbc2ResultSet extends org.postgresql.jdbc1.Abstra
|
||||
|
||||
rowBuffer = new byte[this_row.length][];
|
||||
System.arraycopy(this_row, 0, rowBuffer, 0, this_row.length);
|
||||
onInsertRow = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -220,6 +223,8 @@ public abstract class AbstractJdbc2ResultSet extends org.postgresql.jdbc1.Abstra
|
||||
final int rows_size = rows.size();
|
||||
if (rows_size > 0)
|
||||
current_row = rows_size;
|
||||
|
||||
onInsertRow = false;
|
||||
}
|
||||
|
||||
|
||||
@ -227,6 +232,8 @@ public abstract class AbstractJdbc2ResultSet extends org.postgresql.jdbc1.Abstra
|
||||
{
|
||||
if (rows.size() > 0)
|
||||
current_row = -1;
|
||||
|
||||
onInsertRow = false;
|
||||
}
|
||||
|
||||
|
||||
@ -235,12 +242,12 @@ public abstract class AbstractJdbc2ResultSet extends org.postgresql.jdbc1.Abstra
|
||||
if (rows.size() <= 0)
|
||||
return false;
|
||||
|
||||
onInsertRow = false;
|
||||
current_row = 0;
|
||||
this_row = (byte[][]) rows.elementAt(current_row);
|
||||
|
||||
rowBuffer = new byte[this_row.length][];
|
||||
System.arraycopy(this_row, 0, rowBuffer, 0, this_row.length);
|
||||
onInsertRow = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -483,6 +490,7 @@ public abstract class AbstractJdbc2ResultSet extends org.postgresql.jdbc1.Abstra
|
||||
|
||||
rowBuffer = new byte[this_row.length][];
|
||||
System.arraycopy(this_row, 0, rowBuffer, 0, this_row.length);
|
||||
onInsertRow = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -762,21 +770,39 @@ public abstract class AbstractJdbc2ResultSet extends org.postgresql.jdbc1.Abstra
|
||||
)
|
||||
throws SQLException
|
||||
{
|
||||
byte[] theData = null;
|
||||
if (x == null)
|
||||
{
|
||||
updateNull(columnIndex);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
x.read(theData, 0, length);
|
||||
InputStreamReader reader = new InputStreamReader(x, "ASCII");
|
||||
char data[] = new char[length];
|
||||
int numRead = 0;
|
||||
while (true)
|
||||
{
|
||||
int n = reader.read(data, numRead, length - numRead);
|
||||
if (n == -1)
|
||||
break;
|
||||
|
||||
numRead += n;
|
||||
|
||||
if (numRead == length)
|
||||
break;
|
||||
}
|
||||
updateString(columnIndex, new String(data, 0, numRead));
|
||||
}
|
||||
catch (NullPointerException ex )
|
||||
catch (UnsupportedEncodingException uee)
|
||||
{
|
||||
throw new PSQLException("postgresql.updateable.inputstream");
|
||||
throw new PSQLException("postgresql.unusual", PSQLState.UNEXPECTED_ERROR, uee);
|
||||
}
|
||||
catch (IOException ie)
|
||||
{
|
||||
throw new PSQLException("postgresql.updateable.ioerror", ie);
|
||||
}
|
||||
|
||||
updateValue(columnIndex, theData);
|
||||
}
|
||||
|
||||
|
||||
@ -794,21 +820,46 @@ public abstract class AbstractJdbc2ResultSet extends org.postgresql.jdbc1.Abstra
|
||||
)
|
||||
throws SQLException
|
||||
{
|
||||
byte[] theData = null;
|
||||
if (x == null)
|
||||
{
|
||||
updateNull(columnIndex);
|
||||
return;
|
||||
}
|
||||
|
||||
byte data[] = new byte[length];
|
||||
int numRead = 0;
|
||||
try
|
||||
{
|
||||
x.read(theData, 0, length);
|
||||
while (true)
|
||||
{
|
||||
int n = x.read(data, numRead, length - numRead);
|
||||
if (n == -1)
|
||||
break;
|
||||
|
||||
}
|
||||
catch ( NullPointerException ex )
|
||||
{
|
||||
throw new PSQLException("postgresql.updateable.inputstream");
|
||||
numRead += n;
|
||||
|
||||
if (numRead == length)
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (IOException ie)
|
||||
{
|
||||
throw new PSQLException("postgresql.updateable.ioerror", ie);
|
||||
}
|
||||
updateValue(columnIndex, theData);
|
||||
|
||||
if (numRead == length)
|
||||
{
|
||||
updateBytes(columnIndex, data);
|
||||
}
|
||||
else
|
||||
{
|
||||
// the stream contained less data than they said
|
||||
// perhaps this is an error?
|
||||
byte data2[] = new byte[numRead];
|
||||
System.arraycopy(data, 0, data2, 0, numRead);
|
||||
updateBytes(columnIndex, data2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -841,21 +892,33 @@ public abstract class AbstractJdbc2ResultSet extends org.postgresql.jdbc1.Abstra
|
||||
)
|
||||
throws SQLException
|
||||
{
|
||||
char[] theData = null;
|
||||
if (x == null)
|
||||
{
|
||||
updateNull(columnIndex);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
x.read(theData, 0, length);
|
||||
char data[] = new char[length];
|
||||
int numRead = 0;
|
||||
while (true)
|
||||
{
|
||||
int n = x.read(data, numRead, length - numRead);
|
||||
if (n == -1)
|
||||
break;
|
||||
|
||||
}
|
||||
catch (NullPointerException ex)
|
||||
{
|
||||
throw new PSQLException("postgresql.updateable.inputstream");
|
||||
numRead += n;
|
||||
|
||||
if (numRead == length)
|
||||
break;
|
||||
}
|
||||
updateString(columnIndex, new String(data, 0, numRead));
|
||||
}
|
||||
catch (IOException ie)
|
||||
{
|
||||
throw new PSQLException("postgresql.updateable.ioerror", ie);
|
||||
}
|
||||
updateValue(columnIndex, theData);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user