Commit 1e318736 authored by Barry Lind's avatar Barry Lind

Initial restructuring to add jdbc3 support. There was a significant amount

of duplicated code between the jdbc1 and jdbc2.  This checkin restructures
the code so that the duplication is removed so that the jdbc3 support
can be added without adding yet another copy of everything.  Also many
classes were renamed to avoid confusion with multiple different objects
having the same name.  The timestamp tests were also updated to add support
for testing timestamp without time zone in addition to timestamp with time zone

 Modified Files:
 	jdbc/Makefile jdbc/build.xml jdbc/example/ImageViewer.java
 	jdbc/example/basic.java jdbc/example/blobtest.java
 	jdbc/example/threadsafe.java
 	jdbc/org/postgresql/Driver.java.in
 	jdbc/org/postgresql/Field.java
 	jdbc/org/postgresql/core/QueryExecutor.java
 	jdbc/org/postgresql/fastpath/Fastpath.java
 	jdbc/org/postgresql/jdbc1/CallableStatement.java
 	jdbc/org/postgresql/jdbc1/DatabaseMetaData.java
 	jdbc/org/postgresql/jdbc1/PreparedStatement.java
 	jdbc/org/postgresql/jdbc2/Array.java
 	jdbc/org/postgresql/jdbc2/CallableStatement.java
 	jdbc/org/postgresql/jdbc2/DatabaseMetaData.java
 	jdbc/org/postgresql/jdbc2/PreparedStatement.java
 	jdbc/org/postgresql/jdbc2/UpdateableResultSet.java
 	jdbc/org/postgresql/largeobject/LargeObjectManager.java
 	jdbc/org/postgresql/largeobject/PGblob.java
 	jdbc/org/postgresql/largeobject/PGclob.java
 	jdbc/org/postgresql/test/jdbc2/BlobTest.java
 	jdbc/org/postgresql/test/jdbc2/ConnectionTest.java
 	jdbc/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java
 	jdbc/org/postgresql/test/jdbc2/TimestampTest.java
 	jdbc/org/postgresql/test/jdbc2/UpdateableResultTest.java
 	jdbc/org/postgresql/util/Serialize.java
 Added Files:
 	jdbc/org/postgresql/PGConnection.java
 	jdbc/org/postgresql/PGStatement.java
 	jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java
 	jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java
 	jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java
 	jdbc/org/postgresql/jdbc1/Jdbc1Connection.java
 	jdbc/org/postgresql/jdbc1/Jdbc1ResultSet.java
 	jdbc/org/postgresql/jdbc1/Jdbc1Statement.java
 	jdbc/org/postgresql/jdbc2/AbstractJdbc2Connection.java
 	jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
 	jdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java
 	jdbc/org/postgresql/jdbc2/Jdbc2Connection.java
 	jdbc/org/postgresql/jdbc2/Jdbc2ResultSet.java
 	jdbc/org/postgresql/jdbc2/Jdbc2Statement.java
 Removed Files:
 	jdbc/org/postgresql/Connection.java
 	jdbc/org/postgresql/ResultSet.java
 	jdbc/org/postgresql/Statement.java
 	jdbc/org/postgresql/jdbc1/Connection.java
 	jdbc/org/postgresql/jdbc1/ResultSet.java
 	jdbc/org/postgresql/jdbc1/Statement.java
 	jdbc/org/postgresql/jdbc2/Connection.java
 	jdbc/org/postgresql/jdbc2/ResultSet.java
 	jdbc/org/postgresql/jdbc2/Statement.java
parent e9c013f4
......@@ -4,7 +4,7 @@
#
# Copyright (c) 2001, PostgreSQL Global Development Group
#
# $Header: /cvsroot/pgsql/src/interfaces/jdbc/Attic/Makefile,v 1.34 2002/03/05 17:55:23 momjian Exp $
# $Header: /cvsroot/pgsql/src/interfaces/jdbc/Attic/Makefile,v 1.35 2002/07/23 03:59:54 barry Exp $
#
#-------------------------------------------------------------------------
......@@ -38,5 +38,5 @@ uninstall:
clean distclean maintainer-clean:
$(ANT) -buildfile $(srcdir)/build.xml clean
check:
check: all
$(ANT) -buildfile $(srcdir)/build.xml test
......@@ -6,7 +6,7 @@
This file now requires Ant 1.4.1. 2002-04-18
$Header: /cvsroot/pgsql/src/interfaces/jdbc/Attic/build.xml,v 1.24 2002/06/27 04:38:01 barry Exp $
$Header: /cvsroot/pgsql/src/interfaces/jdbc/Attic/build.xml,v 1.25 2002/07/23 03:59:54 barry Exp $
-->
......@@ -29,7 +29,7 @@
in the CLASSPATH (ie JDK1.2 or later), and then enterprise if the
javax.sql.DataSource class is present.
Important: This must have the following order: jdbc1, jdbc2, enterprise
Important: This must have the following order: jdbc1, jdbc2, jdbc3
-->
<target name="check_versions">
<condition property="jdbc1">
......@@ -39,22 +39,12 @@
<or>
<equals arg1="${ant.java.version}" arg2="1.2"/>
<equals arg1="${ant.java.version}" arg2="1.3"/>
<equals arg1="${ant.java.version}" arg2="1.4"/>
</or>
</condition>
<condition property="jdbc3">
<equals arg1="${ant.java.version}" arg2="1.4"/>
</condition>
<condition property="datasource">
<and>
<or>
<equals arg1="${ant.java.version}" arg2="1.2"/>
<equals arg1="${ant.java.version}" arg2="1.3"/>
<equals arg1="${ant.java.version}" arg2="1.4"/>
</or>
<available classname="javax.sql.DataSource"/>
</and>
</condition>
<available property="datasource" classname="javax.sql.DataSource"/>
<available property="junit" classname="junit.framework.Test" />
</target>
......@@ -97,16 +87,17 @@
<exclude name="${package}/jdbc1/**" unless="jdbc1"/>
<exclude name="${package}/jdbc2/**" unless="jdbc2"/>
<exclude name="${package}/jdbc3/**" unless="jdbc3"/>
<exclude name="${package}/largeobject/PGblob.java" unless="jdbc2" />
<exclude name="${package}/largeobject/PGclob.java" unless="jdbc2" />
<exclude name="${package}/largeobject/PGblob.java" if="jdbc1" />
<exclude name="${package}/largeobject/PGclob.java" if="jdbc1" />
<exclude name="${package}/PostgresqlDataSource.java" unless="datasource" />
<exclude name="${package}/xa/**" unless="datasource" />
<exclude name="${package}/test/**" unless="junit" />
<exclude name="${package}/test/jdbc2/**" unless="jdbc2" />
<exclude name="${package}/test/JDBC2Tests.java" unless="jdbc2" />
<exclude name="${package}/test/jdbc2/**" if="jdbc1" />
<exclude name="${package}/test/JDBC2Tests.java" if="jdbc1" />
</javac>
</target>
......@@ -121,10 +112,10 @@
<equals arg1="${jdbc1}" arg2="true"/>
</condition>
<condition property="edition" value="JDBC2">
<or>
<equals arg1="${jdbc2}" arg2="true"/>
<equals arg1="${jdbc3}" arg2="true"/> <!-- fake it for now -->
</or>
</condition>
<condition property="edition" value="JDBC3">
<equals arg1="${jdbc3}" arg2="true"/>
</condition>
<condition property="edition" value="JDBC2 Enterprise">
<and>
......@@ -134,8 +125,8 @@
</condition>
<!-- determine the connection class -->
<property name="connectclass" value="org.postgresql.jdbc1.Connection" />
<available property="connectclass" value="org.postgresql.jdbc2.Connection" classname="java.lang.ThreadLocal" />
<property name="connectclass" value="org.postgresql.jdbc1.Jdbc1Connection" />
<available property="connectclass" value="org.postgresql.jdbc2.Jdbc2Connection" classname="java.lang.ThreadLocal" />
<!-- Some defaults -->
<filter token="MAJORVERSION" value="${major}" />
......@@ -173,13 +164,13 @@
<javac srcdir="${srcdir}" destdir="${builddir}" debug="${debug}">
<include name="example/**" />
<exclude name="example/corba/**"/>
<exclude name="example/blobtest.java" unless="jdk1.2+"/>
<exclude name="example/blobtest.java" if="jdbc1"/>
</javac>
</target>
<!-- Builds the corba example -->
<target name="corba" if="jdk1.2+">
<target name="corba" if="jdbc2">
<exec dir="${srcdir}/example/corba" executable="idl2java">
<arg value="stock.idl" />
</exec>
......@@ -230,8 +221,8 @@
<target name="test" depends="jar" if="junit">
<javac srcdir="${srcdir}" destdir="${builddir}" debug="${debug}">
<include name="${package}/test/jdbc2/**" if="jdk1.2+" />
<include name="${package}/test/java2ee/**" if="jdk1.2e+" />
<include name="${package}/test/jdbc2/**" if="jdbc2" />
<include name="${package}/test/jdbc2/**" if="jdbc3" />
</javac>
<java fork="yes" classname="junit.${junit.ui}.TestRunner" taskname="junit" failonerror="true">
......
......@@ -205,7 +205,7 @@ public class ImageViewer implements ItemListener
stat = db.createStatement();
// Also, get the LargeObjectManager for this connection
lom = ((org.postgresql.Connection)db).getLargeObjectAPI();
lom = ((org.postgresql.PGConnection)db).getLargeObjectAPI();
// Now refresh the image selection list
refreshList();
......@@ -299,7 +299,7 @@ public class ImageViewer implements ItemListener
try
{
// fetch the large object manager
LargeObjectManager lom = ((org.postgresql.Connection)db).getLargeObjectAPI();
LargeObjectManager lom = ((org.postgresql.PGConnection)db).getLargeObjectAPI();
db.setAutoCommit(false);
......
......@@ -6,7 +6,7 @@ import java.text.*;
/*
*
* $Id: basic.java,v 1.11 2001/11/25 23:26:56 barry Exp $
* $Id: basic.java,v 1.12 2002/07/23 03:59:54 barry Exp $
*
* This example tests the basic components of the JDBC driver, and shows
* how even the simplest of queries can be implemented.
......@@ -87,9 +87,8 @@ public class basic
st.executeUpdate("insert into basic values (3,1)");
// This shows how to get the oid of a just inserted row
// updated for 7.1
st.executeUpdate("insert into basic values (4,1)");
long insertedOID = ((org.postgresql.Statement)st).getLastOID();
long insertedOID = ((org.postgresql.PGStatement)st).getLastOID();
System.out.println("Inserted row with oid " + insertedOID);
// Now change the value of b from 1 to 8
......
......@@ -76,7 +76,7 @@ public class blobtest
// objects, however the unique methods available to postgresql makes
// things a little easier.
System.out.println("Gaining access to large object api");
lobj = ((org.postgresql.Connection)db).getLargeObjectAPI();
lobj = ((org.postgresql.PGConnection)db).getLargeObjectAPI();
int oid = ownapi_test1();
ownapi_test2(oid);
......
......@@ -301,7 +301,7 @@ public class threadsafe
//st = c.createStatement();
// create a blob
lom = ((org.postgresql.Connection)c).getLargeObjectAPI();
lom = ((org.postgresql.PGConnection)c).getLargeObjectAPI();
oid = lom.create();
System.out.println("Thread 3 has created a blob of oid " + oid);
}
......
......@@ -116,7 +116,7 @@ public class Driver implements java.sql.Driver
{
if (Driver.logDebug) Driver.debug("connect " + url);
org.postgresql.Connection con = (org.postgresql.Connection)(Class.forName("@JDBCCONNECTCLASS@").newInstance());
@JDBCCONNECTCLASS@ con = (@JDBCCONNECTCLASS@)(Class.forName("@JDBCCONNECTCLASS@").newInstance());
con.openConnection (host(), port(), props, database(), url, this);
return (java.sql.Connection)con;
}
......
......@@ -17,7 +17,7 @@ public class Field
private int mod; // type modifier of this field
private String name; // Name of this field
private Connection conn; // Connection Instantation
private org.postgresql.PGConnection conn; // Connection Instantation
/*
......@@ -28,7 +28,7 @@ public class Field
* @param oid the OID of the field
* @param len the length of the field
*/
public Field(Connection conn, String name, int oid, int length, int mod)
public Field(org.postgresql.PGConnection conn, String name, int oid, int length, int mod)
{
this.conn = conn;
this.name = name;
......@@ -45,7 +45,7 @@ public class Field
* @param oid the OID of the field
* @param len the length of the field
*/
public Field(Connection conn, String name, int oid, int length)
public Field(org.postgresql.PGConnection conn, String name, int oid, int length)
{
this(conn, name, oid, length, 0);
}
......
package org.postgresql;
import java.sql.*;
import java.util.Properties;
import java.util.Vector;
import org.postgresql.core.Encoding;
import org.postgresql.fastpath.Fastpath;
import org.postgresql.largeobject.LargeObjectManager;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/Attic/PGConnection.java,v 1.1 2002/07/23 03:59:55 barry Exp $
* This interface defines PostgreSQL extentions to the java.sql.Connection interface.
* Any java.sql.Connection object returned by the driver will also implement this
* interface
*/
public interface PGConnection
{
/*
* Get the character encoding to use for this connection.
*/
public Encoding getEncoding() throws SQLException;
/*
* This method returns the java.sql.Types type for a postgres datatype name
*/
public int getSQLType(String pgTypeName) throws SQLException;
/*
* This returns the java.sql.Types type for a postgres datatype OID
*/
public int getSQLType(int oid) throws SQLException;
/*
* This returns the postgres datatype name from the
* postgres datatype OID
*/
public String getPGType(int oid) throws SQLException;
/*
* This returns the postgres datatype OID from the
* postgres datatype name
*/
public int getPGType(String typeName) throws SQLException;
/*
* This returns the LargeObject API for the current connection.
*/
public LargeObjectManager getLargeObjectAPI() throws SQLException;
/*
* This returns the Fastpath API for the current connection.
*/
public Fastpath getFastpathAPI() throws SQLException;
/*
* This method is used internally to return an object based around
* org.postgresql's more unique data types.
*
* <p>It uses an internal Hashtable to get the handling class. If the
* type is not supported, then an instance of org.postgresql.util.PGobject
* is returned.
*
* You can use the getValue() or setValue() methods to handle the returned
* object. Custom objects can have their own methods.
*
* @return PGobject for this type, and set to value
* @exception SQLException if value is not correct for this type
* @see org.postgresql.util.Serialize
*/
public Object getObject(String type, String value) throws SQLException;
}
package org.postgresql;
import java.sql.*;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/Attic/PGStatement.java,v 1.3 2002/07/23 03:59:55 barry Exp $
* This interface defines PostgreSQL extentions to the java.sql.Statement interface.
* Any java.sql.Statement object returned by the driver will also implement this
* interface
*/
public interface PGStatement
{
/*
* Returns the Last inserted/updated oid.
* @return OID of last insert
* @since 7.3
*/
public long getLastOID() throws SQLException;
}
package org.postgresql;
import java.lang.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
import java.sql.*;
import org.postgresql.largeobject.*;
import org.postgresql.util.*;
/*
* This class implements the common internal methods used by both JDBC 1 and
* JDBC 2 specifications.
*/
public abstract class ResultSet
{
protected Vector rows; // The results
protected Field fields[]; // The field descriptions
protected String status; // Status of the result
protected boolean binaryCursor = false; // is the data binary or Strings
protected int updateCount; // How many rows did we get back?
protected long insertOID; // The oid of an inserted row
protected int current_row; // Our pointer to where we are at
protected byte[][] this_row; // the current row result
protected Connection connection; // the connection which we returned from
protected SQLWarning warnings = null; // The warning chain
protected boolean wasNullFlag = false; // the flag for wasNull()
// We can chain multiple resultSets together - this points to
// next resultSet in the chain.
protected ResultSet next = null;
/*
* Create a new ResultSet - Note that we create ResultSets to
* represent the results of everything.
*
* @param fields an array of Field objects (basically, the
* ResultSet MetaData)
* @param tuples Vector of the actual data
* @param status the status string returned from the back end
* @param updateCount the number of rows affected by the operation
* @param cursor the positioned update/delete cursor name
*/
public ResultSet(Connection conn, Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor)
{
this.connection = conn;
this.fields = fields;
this.rows = tuples;
this.status = status;
this.updateCount = updateCount;
this.insertOID = insertOID;
this.this_row = null;
this.current_row = -1;
this.binaryCursor = binaryCursor;
}
/*
* Create a new ResultSet - Note that we create ResultSets to
* represent the results of everything.
*
* @param fields an array of Field objects (basically, the
* ResultSet MetaData)
* @param tuples Vector of the actual data
* @param status the status string returned from the back end
* @param updateCount the number of rows affected by the operation
* @param cursor the positioned update/delete cursor name
*/
public ResultSet(Connection conn, Field[] fields, Vector tuples, String status, int updateCount)
{
this(conn, fields, tuples, status, updateCount, 0, false);
}
/*
* We at times need to know if the resultSet we are working
* with is the result of an UPDATE, DELETE or INSERT (in which
* case, we only have a row count), or of a SELECT operation
* (in which case, we have multiple fields) - this routine
* tells us.
*
* @return true if we have tuples available
*/
public boolean reallyResultSet()
{
return (fields != null);
}
/*
* Since ResultSets can be chained, we need some method of
* finding the next one in the chain. The method getNext()
* returns the next one in the chain.
*
* @return the next ResultSet, or null if there are none
*/
public java.sql.ResultSet getNext()
{
return (java.sql.ResultSet)next;
}
/*
* This following method allows us to add a ResultSet object
* to the end of the current chain.
*
* @param r the resultset to add to the end of the chain.
*/
public void append(ResultSet r)
{
if (next == null)
next = r;
else
next.append(r);
}
/*
* If we are just a place holder for results, we still need
* to get an updateCount. This method returns it.
*
* @return the updateCount
*/
public int getResultCount()
{
return updateCount;
}
/*
* We also need to provide a couple of auxiliary functions for
* the implementation of the ResultMetaData functions. In
* particular, we need to know the number of rows and the
* number of columns. Rows are also known as Tuples
*
* @return the number of rows
*/
public int getTupleCount()
{
return rows.size();
}
/*
* getColumnCount returns the number of columns
*
* @return the number of columns
*/
public int getColumnCount()
{
return fields.length;
}
/*
* Returns the status message from the backend.<p>
* It is used internally by the driver.
*
* @return the status string from the backend
*/
public String getStatusString()
{
return status;
}
/*
* returns the OID of a field.<p>
* It is used internally by the driver.
*
* @param field field id
* @return the oid of that field's type
*/
public int getColumnOID(int field)
{
return fields[field -1].getOID();
}
/*
* returns the OID of the last inserted row. Deprecated in 7.2 because
* range for OID values is greater than java signed int.
* @deprecated Replaced by getLastOID() in 7.2
*/
public int getInsertedOID()
{
return (int) getLastOID();
}
/*
* returns the OID of the last inserted row
* @since 7.2
*/
public long getLastOID()
{
return insertOID;
}
/*
* This is part of the JDBC API, but is required by org.postgresql.Field
*/
public abstract void close() throws SQLException;
public abstract boolean next() throws SQLException;
public abstract String getString(int i) throws SQLException;
/*
* This is used to fix get*() methods on Money fields. It should only be
* used by those methods!
*
* It converts ($##.##) to -##.## and $##.## to ##.##
*/
public String getFixedString(int col) throws SQLException
{
String s = getString(col);
// Handle SQL Null
wasNullFlag = (this_row[col - 1] == null);
if (wasNullFlag)
return null;
// Handle Money
if (s.charAt(0) == '(')
{
s = "-" + org.postgresql.util.PGtokenizer.removePara(s).substring(1);
}
if (s.charAt(0) == '$')
{
s = s.substring(1);
}
return s;
}
/**
* The first warning reported by calls on this ResultSet is
* returned. Subsequent ResultSet warnings will be chained
* to this SQLWarning.
*
* <p>The warning chain is automatically cleared each time a new
* row is read.
*
* <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.
*
* @return the first SQLWarning or null;
* @exception SQLException if a database access error occurs.
*/
public SQLWarning getWarnings() throws SQLException
{
return warnings;
}
/**
* Add a warning chain to the current warning chain
* @param warnings warnings to add
*/
public void addWarnings(SQLWarning warnings) {
if ( this.warnings != null )
this.warnings.setNextWarning(warnings);
else
this.warnings = warnings;
}
protected void checkResultSet( int column ) throws SQLException
{
if ( this_row == null ) throw new PSQLException("postgresql.res.nextrequired");
if ( column < 1 || column > fields.length ) throw new PSQLException("postgresql.res.colrange" );
}
}
......@@ -13,7 +13,7 @@ import org.postgresql.util.PSQLException;
* <p>The lifetime of a QueryExecutor object is from sending the query
* until the response has been received from the backend.
*
* $Id: QueryExecutor.java,v 1.12 2002/03/26 05:52:49 barry Exp $
* $Id: QueryExecutor.java,v 1.13 2002/07/23 03:59:55 barry Exp $
*/
public class QueryExecutor
......@@ -22,18 +22,18 @@ public class QueryExecutor
private final String sql;
private final java.sql.Statement statement;
private final PG_Stream pg_stream;
private final org.postgresql.Connection connection;
private final org.postgresql.jdbc1.AbstractJdbc1Connection connection;
public QueryExecutor(String sql,
java.sql.Statement statement,
PG_Stream pg_stream,
org.postgresql.Connection connection)
java.sql.Connection connection)
throws SQLException
{
this.sql = sql;
this.statement = statement;
this.pg_stream = pg_stream;
this.connection = connection;
this.connection = (org.postgresql.jdbc1.AbstractJdbc1Connection)connection;
if (statement != null)
maxRows = statement.getMaxRows();
......@@ -122,7 +122,7 @@ public class QueryExecutor
if ( errorMessage != null )
throw new SQLException( errorMessage.toString() );
return connection.getResultSet(connection, statement, fields, tuples, status, update_count, insert_oid, binaryCursor);
return connection.getResultSet(statement, fields, tuples, status, update_count, insert_oid, binaryCursor);
}
}
......
......@@ -28,7 +28,7 @@ public class Fastpath
// to a connection).
protected Hashtable func = new Hashtable();
protected org.postgresql.Connection conn; // our connection
protected org.postgresql.PGConnection conn; // our connection
protected org.postgresql.PG_Stream stream; // the network stream
/*
......@@ -41,7 +41,7 @@ public class Fastpath
* @param conn org.postgresql.Connection to attach to
* @param stream The network stream to the backend
*/
public Fastpath(org.postgresql.Connection conn, org.postgresql.PG_Stream stream)
public Fastpath(org.postgresql.PGConnection conn, org.postgresql.PG_Stream stream)
{
this.conn = conn;
this.stream = stream;
......@@ -113,7 +113,7 @@ public class Fastpath
//------------------------------
// Notice from backend
case 'N':
conn.addWarning(stream.ReceiveString(conn.getEncoding()));
((org.postgresql.jdbc1.AbstractJdbc1Connection)conn).addWarning(stream.ReceiveString(conn.getEncoding()));
break;
case 'V':
......
package org.postgresql;
package org.postgresql.jdbc1;
import java.sql.*;
import org.postgresql.util.PSQLException;
/*
* This class defines methods implemented by the two subclasses
* org.postgresql.jdbc1.Statement and org.postgresql.jdbc2.Statement that are
* unique to PostgreSQL's JDBC driver.
*
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.1 2002/07/23 03:59:55 barry Exp $
* This class defines methods of the jdbc1 specification. This class is
* extended by org.postgresql.jdbc2.AbstractJdbc2Statement which adds the jdbc2
* methods. The real Statement class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Statement
*/
public abstract class Statement
public abstract class AbstractJdbc1Statement implements org.postgresql.PGStatement
{
// The connection who created us
protected AbstractJdbc1Connection connection;
/** The warnings chain. */
protected SQLWarning warnings = null;
/** The current results */
protected java.sql.ResultSet result = null;
/** Maximum number of rows to return, 0 = unlimited */
protected int maxrows = 0;
......@@ -27,14 +25,146 @@ public abstract class Statement
protected boolean escapeProcessing = true;
/** The current results */
protected java.sql.ResultSet result = null;
// Static variables for parsing SQL when escapeProcessing is true.
private static final short IN_SQLCODE = 0;
private static final short IN_STRING = 1;
private static final short BACKSLASH = 2;
private static final short ESC_TIMEDATE = 3;
public Statement()
{}
/*
* Execute a SQL statement that retruns a single ResultSet
*
* @param sql typically a static SQL SELECT statement
* @return a ResulSet that contains the data produced by the query
* @exception SQLException if a database access error occurs
*/
public java.sql.ResultSet executeQuery(String sql) throws SQLException
{
this.execute(sql);
while (result != null && !((AbstractJdbc1ResultSet)result).reallyResultSet())
result = ((AbstractJdbc1ResultSet)result).getNext();
if (result == null)
throw new PSQLException("postgresql.stat.noresult");
return result;
}
/*
* Execute a SQL INSERT, UPDATE or DELETE statement. In addition
* SQL statements that return nothing such as SQL DDL statements
* can be executed
*
* @param sql a SQL statement
* @return either a row count, or 0 for SQL commands
* @exception SQLException if a database access error occurs
*/
public int executeUpdate(String sql) throws SQLException
{
this.execute(sql);
if (((AbstractJdbc1ResultSet)result).reallyResultSet())
throw new PSQLException("postgresql.stat.result");
return this.getUpdateCount();
}
/*
* Execute a SQL statement that may return multiple results. We
* don't have to worry about this since we do not support multiple
* ResultSets. You can use getResultSet or getUpdateCount to
* retrieve the result.
*
* @param sql any SQL statement
* @return true if the next result is a ResulSet, false if it is
* an update count or there are no more results
* @exception SQLException if a database access error occurs
*/
public boolean execute(String sql) throws SQLException
{
if (escapeProcessing)
sql = escapeSQL(sql);
// New in 7.1, if we have a previous resultset then force it to close
// This brings us nearer to compliance, and helps memory management.
// Internal stuff will call ExecSQL directly, bypassing this.
if (result != null)
{
java.sql.ResultSet rs = getResultSet();
if (rs != null)
rs.close();
}
// New in 7.1, pass Statement so that ExecSQL can customise to it
result = ((AbstractJdbc1Connection)connection).ExecSQL(sql, (java.sql.Statement)this);
return (result != null && ((AbstractJdbc1ResultSet)result).reallyResultSet());
}
/*
* setCursorName defines the SQL cursor name that will be used by
* subsequent execute methods. This name can then be used in SQL
* positioned update/delete statements to identify the current row
* in the ResultSet generated by this statement. If a database
* doesn't support positioned update/delete, this method is a
* no-op.
*
* <p><B>Note:</B> By definition, positioned update/delete execution
* must be done by a different Statement than the one which
* generated the ResultSet being used for positioning. Also, cursor
* names must be unique within a Connection.
*
* <p>We throw an additional constriction. There can only be one
* cursor active at any one time.
*
* @param name the new cursor name
* @exception SQLException if a database access error occurs
*/
public void setCursorName(String name) throws SQLException
{
((AbstractJdbc1Connection)connection).setCursorName(name);
}
/*
* getUpdateCount returns the current result as an update count,
* if the result is a ResultSet or there are no more results, -1
* is returned. It should only be called once per result.
*
* @return the current result as an update count.
* @exception SQLException if a database access error occurs
*/
public int getUpdateCount() throws SQLException
{
if (result == null)
return -1;
if (((AbstractJdbc1ResultSet)result).reallyResultSet())
return -1;
return ((AbstractJdbc1ResultSet)result).getResultCount();
}
/*
* getMoreResults moves to a Statement's next result. If it returns
* true, this result is a ResulSet.
*
* @return true if the next ResultSet is valid
* @exception SQLException if a database access error occurs
*/
public boolean getMoreResults() throws SQLException
{
result = ((AbstractJdbc1ResultSet)result).getNext();
return (result != null && ((AbstractJdbc1ResultSet)result).reallyResultSet());
}
/*
* Returns the status message from the current Result.<p>
......@@ -46,7 +176,7 @@ public abstract class Statement
{
if (result == null)
return null;
return ((org.postgresql.ResultSet) result).getStatusString();
return ((AbstractJdbc1ResultSet)result).getStatusString();
}
/*
......@@ -194,30 +324,6 @@ public abstract class Statement
throw new PSQLException("postgresql.unimplemented");
}
/*
* Returns the Last inserted/updated oid. Deprecated in 7.2 because
* range of OID values is greater than a java signed int.
* @deprecated Replaced by getLastOID in 7.2
*/
public int getInsertedOID() throws SQLException
{
if (result == null)
return 0;
return (int)((org.postgresql.ResultSet) result).getLastOID();
}
/*
* Returns the Last inserted/updated oid.
* @return OID of last insert
* @since 7.2
*/
public long getLastOID() throws SQLException
{
if (result == null)
return 0;
return ((org.postgresql.ResultSet) result).getLastOID();
}
/*
* getResultSet returns the current result as a ResultSet. It
* should only be called once per result.
......@@ -227,7 +333,7 @@ public abstract class Statement
*/
public java.sql.ResultSet getResultSet() throws SQLException
{
if (result != null && ((org.postgresql.ResultSet) result).reallyResultSet())
if (result != null && ((AbstractJdbc1ResultSet) result).reallyResultSet())
return result;
return null;
}
......@@ -328,4 +434,38 @@ public abstract class Statement
return newsql.toString();
}
/*
*
* The following methods are postgres extensions and are defined
* in the interface org.postgresql.Statement
*
*/
/*
* Returns the Last inserted/updated oid. Deprecated in 7.2 because
* range of OID values is greater than a java signed int.
* @deprecated Replaced by getLastOID in 7.2
*/
public int getInsertedOID() throws SQLException
{
if (result == null)
return 0;
return (int)((AbstractJdbc1ResultSet)result).getLastOID();
}
/*
* Returns the Last inserted/updated oid.
* @return OID of last insert
* @since 7.2
*/
public long getLastOID() throws SQLException
{
if (result == null)
return 0;
return ((AbstractJdbc1ResultSet)result).getLastOID();
}
}
......@@ -44,7 +44,7 @@ public class CallableStatement extends PreparedStatement implements java.sql.Cal
/*
* @exception SQLException on failure
*/
CallableStatement(Connection c, String q) throws SQLException
CallableStatement(Jdbc1Connection c, String q) throws SQLException
{
super(c, q);
}
......
package org.postgresql.jdbc1;
// IMPORTANT NOTE: This file implements the JDBC 1 version of the driver.
// If you make any modifications to this file, you must make sure that the
// changes are also made (if relevent) to the related JDBC 2 class in the
// org.postgresql.jdbc2 package.
import java.io.*;
import java.lang.*;
import java.lang.reflect.*;
import java.net.*;
import java.util.*;
import java.sql.*;
import org.postgresql.Field;
import org.postgresql.fastpath.*;
import org.postgresql.largeobject.*;
import org.postgresql.util.*;
/*
* $Id: Connection.java,v 1.15 2002/01/15 06:55:13 barry Exp $
*
* A Connection represents a session with a specific database. Within the
* context of a Connection, SQL statements are executed and results are
* returned.
*
* <P>A Connection's database is able to provide information describing
* its tables, its supported SQL grammar, its stored procedures, the
* capabilities of this connection, etc. This information is obtained
* with the getMetaData method.
*
* <p><B>Note:</B> By default, the Connection automatically commits changes
* after executing each statement. If auto-commit has been disabled, an
* explicit commit must be done or database changes will not be saved.
*
* @see java.sql.Connection
*/
public class Connection extends org.postgresql.Connection implements java.sql.Connection
{
// This is a cache of the DatabaseMetaData instance for this connection
protected DatabaseMetaData metadata;
/*
* SQL statements without parameters are normally executed using
* Statement objects. If the same SQL statement is executed many
* times, it is more efficient to use a PreparedStatement
*
* @return a new Statement object
* @exception SQLException passed through from the constructor
*/
public java.sql.Statement createStatement() throws SQLException
{
return new Statement(this);
}
/*
* A SQL statement with or without IN parameters can be pre-compiled
* and stored in a PreparedStatement object. This object can then
* be used to efficiently execute this statement multiple times.
*
* <B>Note:</B> This method is optimized for handling parametric
* SQL statements that benefit from precompilation if the drivers
* supports precompilation. PostgreSQL does not support precompilation.
* In this case, the statement is not sent to the database until the
* PreparedStatement is executed. This has no direct effect on users;
* however it does affect which method throws certain SQLExceptions
*
* @param sql a SQL statement that may contain one or more '?' IN
* parameter placeholders
* @return a new PreparedStatement object containing the pre-compiled
* statement.
* @exception SQLException if a database access error occurs.
*/
public java.sql.PreparedStatement prepareStatement(String sql) throws SQLException
{
return new PreparedStatement(this, sql);
}
/*
* A SQL stored procedure call statement is handled by creating a
* CallableStatement for it. The CallableStatement provides methods
* for setting up its IN and OUT parameters and methods for executing
* it.
*
* <B>Note:</B> This method is optimised for handling stored procedure
* call statements. Some drivers may send the call statement to the
* database when the prepareCall is done; others may wait until the
* CallableStatement is executed. This has no direct effect on users;
* however, it does affect which method throws certain SQLExceptions
*
* @param sql a SQL statement that may contain one or more '?' parameter
* placeholders. Typically this statement is a JDBC function call
* escape string.
* @return a new CallableStatement object containing the pre-compiled
* SQL statement
* @exception SQLException if a database access error occurs
*/
public java.sql.CallableStatement prepareCall(String sql) throws SQLException
{
throw new PSQLException("postgresql.con.call");
// return new CallableStatement(this, sql);
}
/*
* Tests to see if a Connection is closed
*
* @return the status of the connection
* @exception SQLException (why?)
*/
public boolean isClosed() throws SQLException
{
return (pg_stream == null);
}
/*
* A connection's database is able to provide information describing
* its tables, its supported SQL grammar, its stored procedures, the
* capabilities of this connection, etc. This information is made
* available through a DatabaseMetaData object.
*
* @return a DatabaseMetaData object for this connection
* @exception SQLException if a database access error occurs
*/
public java.sql.DatabaseMetaData getMetaData() throws SQLException
{
if (metadata == null)
metadata = new DatabaseMetaData(this);
return metadata;
}
/*
* This overides the method in org.postgresql.Connection and returns a
* ResultSet.
*/
public java.sql.ResultSet getResultSet(org.postgresql.Connection conn, java.sql.Statement stat, Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException
{
// in jdbc1 stat is ignored.
return new org.postgresql.jdbc1.ResultSet((org.postgresql.jdbc1.Connection)conn, fields, tuples, status, updateCount, insertOID, binaryCursor);
}
/* An implementation of the abstract method in the parent class.
* This implemetation uses the jdbc1Types array to support the jdbc1
* datatypes. Basically jdbc1 and jdbc2 are the same, except that
* jdbc2 adds the Array types.
*/
public int getSQLType(String pgTypeName)
{
int sqlType = Types.OTHER; // default value
for (int i = 0;i < jdbc1Types.length;i++)
{
if (pgTypeName.equals(jdbc1Types[i]))
{
sqlType = jdbc1Typei[i];
break;
}
}
return sqlType;
}
/*
* This table holds the org.postgresql names for the types supported.
* Any types that map to Types.OTHER (eg POINT) don't go into this table.
* They default automatically to Types.OTHER
*
* Note: This must be in the same order as below.
*
* Tip: keep these grouped together by the Types. value
*/
private static final String jdbc1Types[] = {
"int2",
"int4", "oid",
"int8",
"cash", "money",
"numeric",
"float4",
"float8",
"bpchar", "char", "char2", "char4", "char8", "char16",
"varchar", "text", "name", "filename",
"bytea",
"bool",
"date",
"time",
"abstime", "timestamp", "timestamptz"
};
/*
* This table holds the JDBC type for each entry above.
*
* Note: This must be in the same order as above
*
* Tip: keep these grouped together by the Types. value
*/
private static final int jdbc1Typei[] = {
Types.SMALLINT,
Types.INTEGER, Types.INTEGER,
Types.BIGINT,
Types.DOUBLE, Types.DOUBLE,
Types.NUMERIC,
Types.REAL,
Types.DOUBLE,
Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR,
Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
Types.BINARY,
Types.BIT,
Types.DATE,
Types.TIME,
Types.TIMESTAMP, Types.TIMESTAMP, Types.TIMESTAMP
};
}
// ***********************************************************************
......@@ -13,7 +13,7 @@ import org.postgresql.util.PSQLException;
/*
* This class provides information about the database as a whole.
*
* $Id: DatabaseMetaData.java,v 1.47 2002/06/20 16:00:44 momjian Exp $
* $Id: DatabaseMetaData.java,v 1.48 2002/07/23 03:59:55 barry Exp $
*
* <p>Many of the methods here return lists of information in ResultSets. You
* can use the normal ResultSet methods such as getString and getInt to
......@@ -37,7 +37,7 @@ import org.postgresql.util.PSQLException;
*/
public class DatabaseMetaData implements java.sql.DatabaseMetaData
{
Connection connection; // The connection association
Jdbc1Connection connection; // The connection association
// These define various OID's. Hopefully they will stay constant.
static final int iVarcharOid = 1043; // OID for varchar
......@@ -46,7 +46,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
static final int iInt4Oid = 23; // OID for int4
static final int VARHDRSZ = 4; // length for int4
public DatabaseMetaData(Connection conn)
public DatabaseMetaData(Jdbc1Connection conn)
{
this.connection = conn;
}
......@@ -196,7 +196,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
*/
public String getDriverVersion() throws SQLException
{
return connection.this_driver.getVersion();
return connection.getDriver().getVersion();
}
/*
......@@ -206,7 +206,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
*/
public int getDriverMajorVersion()
{
return connection.this_driver.getMajorVersion();
return connection.getDriver().getMajorVersion();
}
/*
......@@ -216,7 +216,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
*/
public int getDriverMinorVersion()
{
return connection.this_driver.getMinorVersion();
return connection.getDriver().getMinorVersion();
}
/*
......@@ -1549,7 +1549,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
v.addElement(tuple);
}
return new ResultSet(connection, f, v, "OK", 1);
return new Jdbc1ResultSet(connection, f, v, "OK", 1);
}
/*
......@@ -1627,7 +1627,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
// add query loop here
return new ResultSet(connection, f, v, "OK", 1);
return new Jdbc1ResultSet(connection, f, v, "OK", 1);
}
/*
......@@ -1721,7 +1721,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
byte remarks[] = null;
if (((org.postgresql.ResultSet)dr).getTupleCount() == 1)
if (((AbstractJdbc1ResultSet)dr).getTupleCount() == 1)
{
dr.next();
remarks = dr.getBytes(1);
......@@ -1762,7 +1762,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
v.addElement(tuple);
}
r.close();
return new ResultSet(connection, f, v, "OK", 1);
return new Jdbc1ResultSet(connection, f, v, "OK", 1);
}
// This array contains the valid values for the types argument
......@@ -1809,7 +1809,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
f[0] = new Field(connection, "TABLE_SCHEM", iVarcharOid, 32);
tuple[0] = "".getBytes();
v.addElement(tuple);
return new ResultSet(connection, f, v, "OK", 1);
return new Jdbc1ResultSet(connection, f, v, "OK", 1);
}
/*
......@@ -1854,7 +1854,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
tuple[0] = getTableTypes[i][0].getBytes();
v.addElement(tuple);
}
return new ResultSet(connection, f, v, "OK", 1);
return new Jdbc1ResultSet(connection, f, v, "OK", 1);
}
/*
......@@ -2050,7 +2050,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
}
r.close();
return new ResultSet(connection, f, v, "OK", 1);
return new Jdbc1ResultSet(connection, f, v, "OK", 1);
}
/*
......@@ -2113,7 +2113,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
//v.addElement(tuple);
}
return new ResultSet(connection, f, v, "OK", 1);
return new Jdbc1ResultSet(connection, f, v, "OK", 1);
}
/*
......@@ -2203,7 +2203,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
f[6] = new Field(connection, "DECIMAL_DIGITS", iInt2Oid, 2);
f[7] = new Field(connection, "PSEUDO_COLUMN", iInt2Oid, 2);
return new ResultSet(connection, f, v, "OK", 1);
return new Jdbc1ResultSet(connection, f, v, "OK", 1);
}
/*
......@@ -2413,7 +2413,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
while (hasMore);
}
return new ResultSet(connection, f, tuples, "OK", 1);
return new Jdbc1ResultSet(connection, f, tuples, "OK", 1);
}
/*
......@@ -2692,7 +2692,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
v.addElement(tuple);
}
rs.close();
return new ResultSet(connection, f, v, "OK", 1);
return new Jdbc1ResultSet(connection, f, v, "OK", 1);
}
throw new PSQLException("postgresql.metadata.unavailable");
......@@ -2832,7 +2832,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
}
}
return new ResultSet(connection, f, v, "OK", 1);
return new Jdbc1ResultSet(connection, f, v, "OK", 1);
}
}
package org.postgresql.jdbc1;
import java.util.Vector;
import java.sql.*;
import org.postgresql.Field;
import org.postgresql.util.PSQLException;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/Jdbc1Connection.java,v 1.1 2002/07/23 03:59:55 barry Exp $
* This class implements the java.sql.Connection interface for JDBC1.
* However most of the implementation is really done in
* org.postgresql.jdbc1.AbstractJdbc1Connection
*/
public class Jdbc1Connection extends org.postgresql.jdbc1.AbstractJdbc1Connection implements java.sql.Connection
{
public java.sql.Statement createStatement() throws SQLException
{
return new org.postgresql.jdbc1.Jdbc1Statement(this);
}
public java.sql.PreparedStatement prepareStatement(String sql) throws SQLException
{
return new org.postgresql.jdbc1.PreparedStatement(this, sql);
}
//BJL TODO - merge callable statement logic from jdbc2 to jdbc1
public java.sql.CallableStatement prepareCall(String sql) throws SQLException
{
throw new PSQLException("postgresql.con.call");
}
public java.sql.DatabaseMetaData getMetaData() throws SQLException
{
if (metadata == null)
metadata = new org.postgresql.jdbc1.DatabaseMetaData(this);
return metadata;
}
public java.sql.ResultSet getResultSet(java.sql.Statement stat, Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException
{
return new Jdbc1ResultSet(this, fields, tuples, status, updateCount, insertOID, binaryCursor);
}
}
package org.postgresql.jdbc1;
import java.sql.*;
import java.util.Vector;
import org.postgresql.Field;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/Jdbc1ResultSet.java,v 1.1 2002/07/23 03:59:55 barry Exp $
* This class implements the java.sql.ResultSet interface for JDBC1.
* However most of the implementation is really done in
* org.postgresql.jdbc1.AbstractJdbc1ResultSet
*/
public class Jdbc1ResultSet extends org.postgresql.jdbc1.AbstractJdbc1ResultSet implements java.sql.ResultSet
{
public Jdbc1ResultSet(Jdbc1Connection conn, Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor)
{
super(conn, fields, tuples, status, updateCount, insertOID, binaryCursor);
}
public Jdbc1ResultSet(Jdbc1Connection conn, Field[] fields, Vector tuples, String status, int updateCount)
{
super(conn, fields, tuples, status, updateCount, 0, false);
}
public java.sql.ResultSetMetaData getMetaData() throws SQLException
{
return new ResultSetMetaData(rows, fields);
}
}
package org.postgresql.jdbc1;
import java.sql.*;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/Jdbc1Statement.java,v 1.1 2002/07/23 03:59:55 barry Exp $
* This class implements the java.sql.Statement interface for JDBC1.
* However most of the implementation is really done in
* org.postgresql.jdbc1.AbstractJdbc1Statement
*/
public class Jdbc1Statement extends org.postgresql.jdbc1.AbstractJdbc1Statement implements java.sql.Statement
{
public Jdbc1Statement (Jdbc1Connection c)
{
connection = c;
}
}
......@@ -29,12 +29,12 @@ import org.postgresql.util.*;
* @see ResultSet
* @see java.sql.PreparedStatement
*/
public class PreparedStatement extends Statement implements java.sql.PreparedStatement
public class PreparedStatement extends Jdbc1Statement implements java.sql.PreparedStatement
{
String sql;
String[] templateStrings;
String[] inStrings;
Connection connection;
Jdbc1Connection connection;
// Some performance caches
private StringBuffer sbuf = new StringBuffer();
......@@ -49,7 +49,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
* @param sql the SQL statement with ? for IN markers
* @exception SQLException if something bad occurs
*/
public PreparedStatement(Connection connection, String sql) throws SQLException
public PreparedStatement(Jdbc1Connection connection, String sql) throws SQLException
{
super(connection);
......
package org.postgresql.jdbc1;
// IMPORTANT NOTE: This file implements the JDBC 1 version of the driver.
// If you make any modifications to this file, you must make sure that the
// changes are also made (if relevent) to the related JDBC 2 class in the
// org.postgresql.jdbc2 package.
import java.sql.*;
import org.postgresql.util.PSQLException;
/*
* A Statement object is used for executing a static SQL statement and
* obtaining the results produced by it.
*
* <p>Only one ResultSet per Statement can be open at any point in time.
* Therefore, if the reading of one ResultSet is interleaved with the
* reading of another, each must have been generated by different
* Statements. All statement execute methods implicitly close a
* statement's current ResultSet if an open one exists.
*
* @see java.sql.Statement
* @see ResultSet
*/
public class Statement extends org.postgresql.Statement implements java.sql.Statement
{
private Connection connection; // The connection who created us
/*
* Constructor for a Statement. It simply sets the connection
* that created us.
*
* @param c the Connection instantation that creates us
*/
public Statement (Connection c)
{
connection = c;
}
/*
* Execute a SQL statement that retruns a single ResultSet
*
* @param sql typically a static SQL SELECT statement
* @return a ResulSet that contains the data produced by the query
* @exception SQLException if a database access error occurs
*/
public java.sql.ResultSet executeQuery(String sql) throws SQLException
{
this.execute(sql);
while (result != null && !((org.postgresql.ResultSet)result).reallyResultSet())
result = ((org.postgresql.ResultSet)result).getNext();
if (result == null)
throw new PSQLException("postgresql.stat.noresult");
return result;
}
/*
* Execute a SQL INSERT, UPDATE or DELETE statement. In addition
* SQL statements that return nothing such as SQL DDL statements
* can be executed
*
* @param sql a SQL statement
* @return either a row count, or 0 for SQL commands
* @exception SQLException if a database access error occurs
*/
public int executeUpdate(String sql) throws SQLException
{
this.execute(sql);
return this.getUpdateCount();
}
/*
* setCursorName defines the SQL cursor name that will be used by
* subsequent execute methods. This name can then be used in SQL
* positioned update/delete statements to identify the current row
* in the ResultSet generated by this statement. If a database
* doesn't support positioned update/delete, this method is a
* no-op.
*
* <p><B>Note:</B> By definition, positioned update/delete execution
* must be done by a different Statement than the one which
* generated the ResultSet being used for positioning. Also, cursor
* names must be unique within a Connection.
*
* <p>We throw an additional constriction. There can only be one
* cursor active at any one time.
*
* @param name the new cursor name
* @exception SQLException if a database access error occurs
*/
public void setCursorName(String name) throws SQLException
{
connection.setCursorName(name);
}
/*
* Execute a SQL statement that may return multiple results. We
* don't have to worry about this since we do not support multiple
* ResultSets. You can use getResultSet or getUpdateCount to
* retrieve the result.
*
* @param sql any SQL statement
* @return true if the next result is a ResulSet, false if it is
* an update count or there are no more results
* @exception SQLException if a database access error occurs
*/
public boolean execute(String sql) throws SQLException
{
if (escapeProcessing)
sql = escapeSQL(sql);
result = connection.ExecSQL(sql);
return (result != null && ((org.postgresql.ResultSet)result).reallyResultSet());
}
/*
* getUpdateCount returns the current result as an update count,
* if the result is a ResultSet or there are no more results, -1
* is returned. It should only be called once per result.
*
* @return the current result as an update count.
* @exception SQLException if a database access error occurs
*/
public int getUpdateCount() throws SQLException
{
if (result == null)
return -1;
if (((org.postgresql.ResultSet)result).reallyResultSet())
return -1;
return ((org.postgresql.ResultSet)result).getResultCount();
}
/*
* getMoreResults moves to a Statement's next result. If it returns
* true, this result is a ResulSet.
*
* @return true if the next ResultSet is valid
* @exception SQLException if a database access error occurs
*/
public boolean getMoreResults() throws SQLException
{
result = ((org.postgresql.ResultSet)result).getNext();
return (result != null && ((org.postgresql.ResultSet)result).reallyResultSet());
}
}
......@@ -45,7 +45,7 @@ public class CallableStatement extends org.postgresql.jdbc2.PreparedStatement im
/*
* @exception SQLException on failure
*/
public CallableStatement(Connection c, String q) throws SQLException
public CallableStatement(Jdbc2Connection c, String q) throws SQLException
{
super(c, q); // don't parse yet..
}
......
......@@ -15,7 +15,7 @@ import org.postgresql.util.PSQLException;
/*
* This class provides information about the database as a whole.
*
* $Id: DatabaseMetaData.java,v 1.58 2002/07/12 13:07:48 davec Exp $
* $Id: DatabaseMetaData.java,v 1.59 2002/07/23 03:59:55 barry Exp $
*
* <p>Many of the methods here return lists of information in ResultSets. You
* can use the normal ResultSet methods such as getString and getInt to
......@@ -39,7 +39,7 @@ import org.postgresql.util.PSQLException;
*/
public class DatabaseMetaData implements java.sql.DatabaseMetaData
{
Connection connection; // The connection association
Jdbc2Connection connection; // The connection association
// These define various OID's. Hopefully they will stay constant.
static final int iVarcharOid = 1043; // OID for varchar
......@@ -48,7 +48,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
static final int iInt4Oid = 23; // OID for int4
static final int VARHDRSZ = 4; // length for int4
public DatabaseMetaData(Connection conn)
public DatabaseMetaData(Jdbc2Connection conn)
{
this.connection = conn;
}
......@@ -1653,7 +1653,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
v.addElement(tuple);
}
return new ResultSet(connection, f, v, "OK", 1);
return new Jdbc2ResultSet(connection, f, v, "OK", 1);
}
/*
......@@ -1731,7 +1731,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
// add query loop here
return new ResultSet(connection, f, v, "OK", 1);
return new Jdbc2ResultSet(connection, f, v, "OK", 1);
}
/*
......@@ -1825,7 +1825,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
byte remarks[] = null;
if (((org.postgresql.ResultSet)dr).getTupleCount() == 1)
if (((AbstractJdbc2ResultSet)dr).getTupleCount() == 1)
{
dr.next();
remarks = dr.getBytes(1);
......@@ -1866,7 +1866,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
v.addElement(tuple);
}
r.close();
return new ResultSet(connection, f, v, "OK", 1);
return new Jdbc2ResultSet(connection, f, v, "OK", 1);
}
// This array contains the valid values for the types argument
......@@ -1913,7 +1913,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
f[0] = new Field(connection, "TABLE_SCHEM", iVarcharOid, 32);
tuple[0] = "".getBytes();
v.addElement(tuple);
return new ResultSet(connection, f, v, "OK", 1);
return new Jdbc2ResultSet(connection, f, v, "OK", 1);
}
/*
......@@ -1958,7 +1958,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
tuple[0] = getTableTypes[i][0].getBytes();
v.addElement(tuple);
}
return new ResultSet(connection, f, v, "OK", 1);
return new Jdbc2ResultSet(connection, f, v, "OK", 1);
}
/*
......@@ -2154,7 +2154,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
}
r.close();
return new ResultSet(connection, f, v, "OK", 1);
return new Jdbc2ResultSet(connection, f, v, "OK", 1);
}
/*
......@@ -2218,7 +2218,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
//v.addElement(tuple);
}
return new ResultSet(connection, f, v, "OK", 1);
return new Jdbc2ResultSet(connection, f, v, "OK", 1);
}
/*
......@@ -2281,7 +2281,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
//v.addElement(tuple);
}
return new ResultSet(connection, f, v, "OK", 1);
return new Jdbc2ResultSet(connection, f, v, "OK", 1);
}
/*
......@@ -2337,7 +2337,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
f[6] = new Field(connection, "DECIMAL_DIGITS", iInt2Oid, 2);
f[7] = new Field(connection, "PSEUDO_COLUMN", iInt2Oid, 2);
return new ResultSet(connection, f, v, "OK", 1);
return new Jdbc2ResultSet(connection, f, v, "OK", 1);
}
/*
......@@ -2680,7 +2680,7 @@ WHERE
tuples.addElement(tuple);
}
return new ResultSet(connection, f, tuples, "OK", 1);
return new Jdbc2ResultSet(connection, f, tuples, "OK", 1);
}
/*
......@@ -2959,7 +2959,7 @@ WHERE
v.addElement(tuple);
}
rs.close();
return new ResultSet(connection, f, v, "OK", 1);
return new Jdbc2ResultSet(connection, f, v, "OK", 1);
}
throw new PSQLException("postgresql.metadata.unavailable");
......@@ -3097,7 +3097,7 @@ WHERE
}
}
return new ResultSet(connection, f, v, "OK", 1);
return new Jdbc2ResultSet(connection, f, v, "OK", 1);
}
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment