aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/jdbc/postgresql/ResultSet.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces/jdbc/postgresql/ResultSet.java')
-rw-r--r--src/interfaces/jdbc/postgresql/ResultSet.java94
1 files changed, 58 insertions, 36 deletions
diff --git a/src/interfaces/jdbc/postgresql/ResultSet.java b/src/interfaces/jdbc/postgresql/ResultSet.java
index 017b0ad2927..f8eea22595e 100644
--- a/src/interfaces/jdbc/postgresql/ResultSet.java
+++ b/src/interfaces/jdbc/postgresql/ResultSet.java
@@ -6,31 +6,32 @@ import java.math.*;
import java.text.*;
import java.util.*;
import java.sql.*;
-import postgresql.*;
+import postgresql.largeobject.*;
+import postgresql.util.*;
/**
* A ResultSet provides access to a table of data generated by executing a
* Statement. The table rows are retrieved in sequence. Within a row its
* column values can be accessed in any order.
*
- * A ResultSet maintains a cursor pointing to its current row of data.
+ * <P>A ResultSet maintains a cursor pointing to its current row of data.
* Initially the cursor is positioned before the first row. The 'next'
* method moves the cursor to the next row.
*
- * The getXXX methods retrieve column values for the current row. You can
+ * <P>The getXXX methods retrieve column values for the current row. You can
* retrieve values either using the index number of the column, or by using
* the name of the column. In general using the column index will be more
* efficient. Columns are numbered from 1.
*
- * For maximum portability, ResultSet columns within each row should be read
+ * <P>For maximum portability, ResultSet columns within each row should be read
* in left-to-right order and each column should be read only once.
*
- * For the getXXX methods, the JDBC driver attempts to convert the underlying
- * data to the specified Java type and returns a suitable Java value. See the
- * JDBC specification for allowable mappings from SQL types to Java types with
- * the ResultSet getXXX methods.
+ *<P> For the getXXX methods, the JDBC driver attempts to convert the
+ * underlying data to the specified Java type and returns a suitable Java
+ * value. See the JDBC specification for allowable mappings from SQL types
+ * to Java types with the ResultSet getXXX methods.
*
- * Column names used as input to getXXX methods are case insenstive. When
+ * <P>Column names used as input to getXXX methods are case insenstive. When
* performing a getXXX using a column name, if several columns have the same
* name, then the value of the first matching column will be returned. The
* column name option is designed to be used when column names are used in the
@@ -39,11 +40,11 @@ import postgresql.*;
* the programmer to guarentee that they actually refer to the intended
* columns.
*
- * A ResultSet is automatically closed by the Statement that generated it
+ * <P>A ResultSet is automatically closed by the Statement that generated it
* when that Statement is closed, re-executed, or is used to retrieve the
* next result from a sequence of multiple results.
*
- * The number, types and properties of a ResultSet's columns are provided by
+ * <P>The number, types and properties of a ResultSet's columns are provided by
* the ResultSetMetaData object returned by the getMetaData method.
*
* @see ResultSetMetaData
@@ -92,7 +93,7 @@ public class ResultSet implements java.sql.ResultSet
* the first call to next makes the first row the current row;
* the second call makes the second row the current row, etc.
*
- * If an input stream from the previous row is open, it is
+ * <p>If an input stream from the previous row is open, it is
* implicitly closed. The ResultSet's warning chain is cleared
* when a new row is read
*
@@ -114,7 +115,7 @@ public class ResultSet implements java.sql.ResultSet
* when it is automatically closed. The close method provides this
* immediate release.
*
- * <B>Note:</B> A ResultSet is automatically closed by the Statement
+ * <p><B>Note:</B> A ResultSet is automatically closed by the Statement
* the Statement that generated it when that Statement is closed,
* re-executed, or is used to retrieve the next result from a sequence
* of multiple results. A ResultSet is also automatically closed
@@ -150,11 +151,17 @@ public class ResultSet implements java.sql.ResultSet
*/
public String getString(int columnIndex) throws SQLException
{
- byte[] bytes = getBytes(columnIndex);
-
- if (bytes == null)
+ //byte[] bytes = getBytes(columnIndex);
+ //
+ //if (bytes == null)
+ //return null;
+ //return new String(bytes);
+ if (columnIndex < 1 || columnIndex > fields.length)
+ throw new SQLException("Column Index out of range");
+ wasNullFlag = (this_row[columnIndex - 1] == null);
+ if(wasNullFlag)
return null;
- return new String(bytes);
+ return new String(this_row[columnIndex - 1]);
}
/**
@@ -347,8 +354,14 @@ public class ResultSet implements java.sql.ResultSet
}
/**
- * Get the value of a column in the current row as a Java byte array
- * The bytes represent the raw values returned by the driver.
+ * Get the value of a column in the current row as a Java byte array.
+ *
+ * <p>In normal use, the bytes represent the raw values returned by the
+ * backend. However, if the column is an OID, then it is assumed to
+ * refer to a Large Object, and that object is returned as a byte array.
+ *
+ * <p><b>Be warned</b> If the large object is huge, then you may run out
+ * of memory.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @return the column value; if the value is SQL NULL, the result
@@ -360,6 +373,17 @@ public class ResultSet implements java.sql.ResultSet
if (columnIndex < 1 || columnIndex > fields.length)
throw new SQLException("Column Index out of range");
wasNullFlag = (this_row[columnIndex - 1] == null);
+
+ // Handle OID's as BLOBS
+ if(!wasNullFlag)
+ if( fields[columnIndex - 1].getOID() == 26) {
+ LargeObjectManager lom = connection.getLargeObjectAPI();
+ LargeObject lob = lom.open(getInt(columnIndex));
+ byte buf[] = lob.read(lob.size());
+ lob.close();
+ return buf;
+ }
+
return this_row[columnIndex - 1];
}
@@ -374,7 +398,7 @@ public class ResultSet implements java.sql.ResultSet
public java.sql.Date getDate(int columnIndex) throws SQLException
{
String s = getString(columnIndex);
- SimpleDateFormat df = new SimpleDateFormat(connection.europeanDates?"dd-MM-yyyy":"MM-dd-yyyy");
+ SimpleDateFormat df = new SimpleDateFormat(connection.getDateStyle());
try {
return new java.sql.Date(df.parse(s).getTime());
} catch (ParseException e) {
@@ -449,13 +473,13 @@ public class ResultSet implements java.sql.ResultSet
* The JDBC driver will do any necessary conversion from the
* database format into ASCII.
*
- * <B>Note:</B> All the data in the returned stream must be read
+ * <p><B>Note:</B> All the data in the returned stream must be read
* prior to getting the value of any other column. The next call
* to a get method implicitly closes the stream. Also, a stream
* may return 0 for available() whether there is data available
* or not.
*
- * We implement an ASCII stream as a Binary stream - we should really
+ *<p> We implement an ASCII stream as a Binary stream - we should really
* do the data conversion, but I cannot be bothered to implement this
* right now.
*
@@ -494,8 +518,8 @@ public class ResultSet implements java.sql.ResultSet
*
* @param columnIndex the first column is 1, the second is 2...
* @return a Java InputStream that delivers the database column value
- * as a stream of two byte Unicode characters. If the value is
- * SQL NULL, then the result is null
+ * as a stream of bytes. If the value is SQL NULL, then the result
+ * is null
* @exception SQLException if a database access error occurs
* @see getAsciiStream
* @see getUnicodeStream
@@ -603,10 +627,10 @@ public class ResultSet implements java.sql.ResultSet
* returned. Subsequent ResultSet warnings will be chained
* to this SQLWarning.
*
- * The warning chain is automatically cleared each time a new
+ * <p>The warning chain is automatically cleared each time a new
* row is read.
*
- * <B>Note:</B> This warning chain only covers warnings caused by
+ * <p><B>Note:</B> This warning chain only covers warnings caused by
* ResultSet methods. Any warnings caused by statement methods
* (such as reading OUT parameters) will be chained on the
* Statement object.
@@ -633,16 +657,16 @@ public class ResultSet implements java.sql.ResultSet
/**
* Get the name of the SQL cursor used by this ResultSet
*
- * In SQL, a result table is retrieved though a cursor that is
+ * <p>In SQL, a result table is retrieved though a cursor that is
* named. The current row of a result can be updated or deleted
* using a positioned update/delete statement that references
* the cursor name.
*
- * JDBC supports this SQL feature by providing the name of the
+ * <p>JDBC supports this SQL feature by providing the name of the
* SQL cursor used by a ResultSet. The current row of a ResulSet
* is also the current row of this SQL cursor.
*
- * <B>Note:</B> If positioned update is not supported, a SQLException
+ * <p><B>Note:</B> If positioned update is not supported, a SQLException
* is thrown.
*
* @return the ResultSet's SQL cursor name.
@@ -668,12 +692,12 @@ public class ResultSet implements java.sql.ResultSet
/**
* Get the value of a column in the current row as a Java object
*
- * This method will return the value of the given column as a
+ * <p>This method will return the value of the given column as a
* Java object. The type of the Java object will be the default
* Java Object type corresponding to the column's SQL type, following
* the mapping specified in the JDBC specification.
*
- * This method may also be used to read database specific abstract
+ * <p>This method may also be used to read database specific abstract
* data types.
*
* @param columnIndex the first column is 1, the second is 2...
@@ -714,19 +738,19 @@ public class ResultSet implements java.sql.ResultSet
case Types.TIMESTAMP:
return getTimestamp(columnIndex);
default:
- return new PG_Object(field.getTypeName(), getString(columnIndex));
+ return connection.getObject(field.getTypeName(), getString(columnIndex));
}
}
/**
* Get the value of a column in the current row as a Java object
*
- * This method will return the value of the given column as a
+ *<p> This method will return the value of the given column as a
* Java object. The type of the Java object will be the default
* Java Object type corresponding to the column's SQL type, following
* the mapping specified in the JDBC specification.
*
- * This method may also be used to read database specific abstract
+ * <p>This method may also be used to read database specific abstract
* data types.
*
* @param columnName is the SQL name of the column
@@ -816,8 +840,6 @@ public class ResultSet implements java.sql.ResultSet
* particular, we need to know the number of rows and the
* number of columns. Rows are also known as Tuples
*
- * getTupleCount returns the number of rows
- *
* @return the number of rows
*/
public int getTupleCount()