Back out Gunnar R|nning jdbc changes.

This commit is contained in:
Bruce Momjian 2000-10-09 16:48:19 +00:00
parent c4ccc6146b
commit a4e3943b3f
13 changed files with 84 additions and 412 deletions

View File

@ -10,7 +10,7 @@ import org.postgresql.largeobject.*;
import org.postgresql.util.*; import org.postgresql.util.*;
/** /**
* $Id: Connection.java,v 1.7 2000/10/08 19:37:54 momjian Exp $ * $Id: Connection.java,v 1.8 2000/10/09 16:48:16 momjian Exp $
* *
* This abstract class is used by org.postgresql.Driver to open either the JDBC1 or * This abstract class is used by org.postgresql.Driver to open either the JDBC1 or
* JDBC2 versions of the Connection class. * JDBC2 versions of the Connection class.
@ -81,11 +81,6 @@ public abstract class Connection
// The PID an cancellation key we get from the backend process // The PID an cancellation key we get from the backend process
public int pid; public int pid;
public int ckey; public int ckey;
// This receive_sbuf should be used by the different methods
// that call pg_stream.ReceiveString() in this Connection, so
// so we avoid uneccesary new allocations.
byte receive_sbuf[] = new byte[8192];
/** /**
* This is called by Class.forName() from within org.postgresql.Driver * This is called by Class.forName() from within org.postgresql.Driver
@ -169,9 +164,8 @@ public abstract class Connection
// The most common one to be thrown here is: // The most common one to be thrown here is:
// "User authentication failed" // "User authentication failed"
// //
String msg = pg_stream.ReceiveString(receive_sbuf, 4096, throw new SQLException(pg_stream.ReceiveString
getEncoding()); (4096, getEncoding()));
throw new SQLException(msg);
case 'R': case 'R':
// Get the type of request // Get the type of request
@ -242,7 +236,7 @@ public abstract class Connection
case 'E': case 'E':
case 'N': case 'N':
throw new SQLException(pg_stream.ReceiveString throw new SQLException(pg_stream.ReceiveString
(receive_sbuf, 4096, getEncoding())); (4096, getEncoding()));
default: default:
throw new PSQLException("postgresql.con.setup"); throw new PSQLException("postgresql.con.setup");
} }
@ -254,7 +248,7 @@ public abstract class Connection
break; break;
case 'E': case 'E':
case 'N': case 'N':
throw new SQLException(pg_stream.ReceiveString(receive_sbuf, 4096, getEncoding())); throw new SQLException(pg_stream.ReceiveString(4096));
default: default:
throw new PSQLException("postgresql.con.setup"); throw new PSQLException("postgresql.con.setup");
} }
@ -269,7 +263,7 @@ public abstract class Connection
// //
firstWarning = null; firstWarning = null;
ExecSQL(null, "set datestyle to 'ISO'"); ExecSQL("set datestyle to 'ISO'");
// Initialise object handling // Initialise object handling
initObjectTypes(); initObjectTypes();
@ -312,8 +306,7 @@ public abstract class Connection
//currentDateStyle=i+1; // this is the index of the format //currentDateStyle=i+1; // this is the index of the format
//} //}
} }
/** /**
* Send a query to the backend. Returns one of the ResultSet * Send a query to the backend. Returns one of the ResultSet
* objects. * objects.
@ -321,18 +314,15 @@ public abstract class Connection
* <B>Note:</B> there does not seem to be any method currently * <B>Note:</B> there does not seem to be any method currently
* in existance to return the update count. * in existance to return the update count.
* *
* @param stmt The statment object.
* @param sql the SQL statement to be executed * @param sql the SQL statement to be executed
* @return a ResultSet holding the results * @return a ResultSet holding the results
* @exception SQLException if a database error occurs * @exception SQLException if a database error occurs
*/ */
public java.sql.ResultSet ExecSQL(PGStatement stmt, public java.sql.ResultSet ExecSQL(String sql) throws SQLException
String sql) throws SQLException
{ {
// added Oct 7 1998 to give us thread safety. // added Oct 7 1998 to give us thread safety.
synchronized(pg_stream) { synchronized(pg_stream) {
pg_stream.setExecutingStatement(stmt);
Field[] fields = null; Field[] fields = null;
Vector tuples = new Vector(); Vector tuples = new Vector();
byte[] buf = null; byte[] buf = null;
@ -362,7 +352,8 @@ public abstract class Connection
try try
{ {
pg_stream.SendChar('Q'); pg_stream.SendChar('Q');
pg_stream.Send(sql.getBytes()); buf = sql.getBytes();
pg_stream.Send(buf);
pg_stream.SendChar(0); pg_stream.SendChar(0);
pg_stream.flush(); pg_stream.flush();
} catch (IOException e) { } catch (IOException e) {
@ -379,8 +370,7 @@ public abstract class Connection
{ {
case 'A': // Asynchronous Notify case 'A': // Asynchronous Notify
pid = pg_stream.ReceiveInteger(4); pid = pg_stream.ReceiveInteger(4);
msg = pg_stream.ReceiveString(receive_sbuf, 8192, msg = pg_stream.ReceiveString(8192);
getEncoding());
break; break;
case 'B': // Binary Data Transfer case 'B': // Binary Data Transfer
if (fields == null) if (fields == null)
@ -391,9 +381,7 @@ public abstract class Connection
tuples.addElement(tup); tuples.addElement(tup);
break; break;
case 'C': // Command Status case 'C': // Command Status
recv_status = recv_status = pg_stream.ReceiveString(8192);
pg_stream.ReceiveString(receive_sbuf, 8192,
getEncoding());
// Now handle the update count correctly. // Now handle the update count correctly.
if(recv_status.startsWith("INSERT") || recv_status.startsWith("UPDATE") || recv_status.startsWith("DELETE")) { if(recv_status.startsWith("INSERT") || recv_status.startsWith("UPDATE") || recv_status.startsWith("DELETE")) {
@ -435,8 +423,7 @@ public abstract class Connection
tuples.addElement(tup); tuples.addElement(tup);
break; break;
case 'E': // Error Message case 'E': // Error Message
msg = pg_stream.ReceiveString(receive_sbuf, 4096, msg = pg_stream.ReceiveString(4096);
getEncoding());
final_error = new SQLException(msg); final_error = new SQLException(msg);
hfr = true; hfr = true;
break; break;
@ -451,14 +438,10 @@ public abstract class Connection
hfr = true; hfr = true;
break; break;
case 'N': // Error Notification case 'N': // Error Notification
addWarning(pg_stream.ReceiveString(receive_sbuf, addWarning(pg_stream.ReceiveString(4096));
4096,
getEncoding()));
break; break;
case 'P': // Portal Name case 'P': // Portal Name
String pname = String pname = pg_stream.ReceiveString(8192);
pg_stream.ReceiveString(receive_sbuf, 8192,
getEncoding());
break; break;
case 'T': // MetaData Field Description case 'T': // MetaData Field Description
if (fields != null) if (fields != null)
@ -478,8 +461,6 @@ public abstract class Connection
} }
} }
/** /**
* Receive the field descriptions from the back end * Receive the field descriptions from the back end
* *
@ -493,8 +474,7 @@ public abstract class Connection
for (i = 0 ; i < nf ; ++i) for (i = 0 ; i < nf ; ++i)
{ {
String typname = pg_stream.ReceiveString(receive_sbuf, 8192, String typname = pg_stream.ReceiveString(8192);
getEncoding());
int typid = pg_stream.ReceiveIntegerR(4); int typid = pg_stream.ReceiveIntegerR(4);
int typlen = pg_stream.ReceiveIntegerR(2); int typlen = pg_stream.ReceiveIntegerR(2);
int typmod = pg_stream.ReceiveIntegerR(4); int typmod = pg_stream.ReceiveIntegerR(4);

View File

@ -76,9 +76,7 @@ public class Field
// it's not in the cache, so perform a query, and add the result to // it's not in the cache, so perform a query, and add the result to
// the cache // the cache
if(type_name==null) { if(type_name==null) {
ResultSet result = (org.postgresql.ResultSet) ResultSet result = (org.postgresql.ResultSet)conn.ExecSQL("select typname from pg_type where oid = " + oid);
conn.ExecSQL(null, "select typname from pg_type where oid = "
+ oid);
if (result.getColumnCount() != 1 || result.getTupleCount() != 1) if (result.getColumnCount() != 1 || result.getTupleCount() != 1)
throw new PSQLException("postgresql.unexpected"); throw new PSQLException("postgresql.unexpected");
result.next(); result.next();

View File

@ -1,86 +0,0 @@
package org.postgresql;
/**
* A simple and fast object pool implementation that can pool objects
* of any type. This implementation is not thread safe, it is up to the users
* of this class to assure thread safety.
*/
public class ObjectPool {
int cursize = 0;
int maxsize = 8;
Object arr[] = new Object[8];
/**
* Add object to the pool.
* @param o The object to add.
*/
public void add(Object o){
if(cursize >= maxsize){
Object newarr[] = new Object[maxsize*2];
System.arraycopy(arr, 0, newarr, 0, maxsize);
maxsize = maxsize * 2;
arr = newarr;
}
arr[cursize++] = o;
}
/**
* Remove an object from the pool. If the pool is empty
* ArrayIndexOutOfBoundsException will be thrown.
* @return Returns the removed object.
* @exception If the pool is empty
* ArrayIndexOutOfBoundsException will be thrown.
*/
public Object remove(){
Object o = arr[cursize-1];
// This have to be here, so we don't decrease the counter when
// cursize == 0;
cursize--;
return o;
}
/**
* Check if pool is empty.
* @return true if pool is empty, false otherwise.
*/
public boolean isEmpty(){
return cursize == 0;
}
/**
* Get the size of the pool.
* @return Returns the number of objects in the pool.
*/
public int size(){
return cursize;
}
/**
* Add all the objects from another pool to this pool.
* @pool The pool to add the objects from.
*/
public void addAll(ObjectPool pool){
int srcsize = pool.size();
if(srcsize == 0)
return;
int totalsize = srcsize + cursize;
if(totalsize > maxsize){
Object newarr[] = new Object[totalsize*2];
System.arraycopy(arr, 0, newarr, 0, cursize);
maxsize = maxsize = totalsize * 2;
arr = newarr;
}
System.arraycopy(pool.arr, 0, arr, cursize, srcsize);
cursize = totalsize;
}
/**
* Clear the elements from this pool.
* The method is lazy, so it just resets the index counter without
* removing references to pooled objects. This could possibly
* be an issue with garbage collection, depending on how the
* pool is used.
*/
public void clear(){
cursize = 0;
}
}

View File

@ -1,57 +0,0 @@
package org.postgresql;
import java.util.Hashtable;
/**
* Just a factory class for creating and reusing
* ObjectPool arrays of different sizes.
*/
public class ObjectPoolFactory {
private static Hashtable instances = new Hashtable();
ObjectPool pool = new ObjectPool();
int maxsize;
public static ObjectPoolFactory getInstance(int size){
Integer s = new Integer(size);
ObjectPoolFactory poolFactory = (ObjectPoolFactory) instances.get(s);
if(poolFactory == null){
synchronized(instances) {
poolFactory = (ObjectPoolFactory) instances.get(s);
if(poolFactory == null){
poolFactory = new ObjectPoolFactory(size);
instances.put(s, poolFactory);
}
}
}
return poolFactory;
}
private ObjectPoolFactory(int maxsize){
this.maxsize = maxsize;
}
public ObjectPool[] getObjectPoolArr(){
ObjectPool p[] = null;
synchronized(pool){
if(pool.size() > 0)
p = (ObjectPool []) pool.remove();
}
if(p == null) {
p = new ObjectPool[maxsize];
for(int i = 0; i < maxsize; i++){
p[i] = new ObjectPool();
}
}
return p;
}
public void releaseObjectPoolArr(ObjectPool p[]){
synchronized(pool){
pool.add(p);
for(int i = 0; i < maxsize; i++){
p[i].clear();
}
}
}
}

View File

@ -1,26 +0,0 @@
package org.postgresql;
import java.sql.Statement;
import java.sql.SQLException;
public abstract class PGStatement implements Statement {
public ObjectPool inusemap_dim1[];
public ObjectPool inusemap_dim2[];
protected Connection connection;
public PGStatement(Connection connection){
this.connection = connection;
inusemap_dim1 = connection.pg_stream.factory_dim1.getObjectPoolArr();
inusemap_dim2 = connection.pg_stream.factory_dim2.getObjectPoolArr();
}
public void deallocate(){
connection.pg_stream.deallocate(this);
}
public void close() throws SQLException {
deallocate();
connection.pg_stream.factory_dim1.releaseObjectPoolArr(inusemap_dim1);
connection.pg_stream.factory_dim2.releaseObjectPoolArr(inusemap_dim2);
}
}

View File

@ -22,10 +22,7 @@ public class PG_Stream
private Socket connection; private Socket connection;
private InputStream pg_input; private InputStream pg_input;
private BufferedOutputStream pg_output; private BufferedOutputStream pg_output;
public PGStatement executingStatement;
/** /**
* Constructor: Connect to the PostgreSQL back end and return * Constructor: Connect to the PostgreSQL back end and return
* a stream connection. * a stream connection.
@ -47,15 +44,6 @@ public class PG_Stream
pg_output = new BufferedOutputStream(connection.getOutputStream(), 8192); pg_output = new BufferedOutputStream(connection.getOutputStream(), 8192);
} }
/**
* Set the currently executing statement. This is used to bind cached byte
* arrays to a Statement, so the statement can return the to the global
* pool of unused byte arrays when they are no longer inuse.
*/
public void setExecutingStatement(PGStatement executingStatement){
this.executingStatement = executingStatement;
}
/** /**
* Sends a single character to the back end * Sends a single character to the back end
* *
@ -82,7 +70,7 @@ public class PG_Stream
*/ */
public void SendInteger(int val, int siz) throws IOException public void SendInteger(int val, int siz) throws IOException
{ {
byte[] buf = allocByteDim1(siz); byte[] buf = new byte[siz];
while (siz-- > 0) while (siz-- > 0)
{ {
@ -106,7 +94,7 @@ public class PG_Stream
*/ */
public void SendIntegerReverse(int val, int siz) throws IOException public void SendIntegerReverse(int val, int siz) throws IOException
{ {
byte[] buf = allocByteDim1(siz); byte[] buf = new byte[siz];
int p=0; int p=0;
while (siz-- > 0) while (siz-- > 0)
{ {
@ -248,52 +236,23 @@ public class PG_Stream
return n; return n;
} }
public String ReceiveString(int maxsize) throws SQLException {
/** return ReceiveString(maxsize, null);
* Receives a null-terminated string from the backend. Maximum of }
* maxsiz bytes - if we don't see a null, then we assume something
* has gone wrong.
*
* @param maxsiz maximum length of string
* @return string from back end
* @exception SQLException if an I/O error occurs
*/
public String ReceiveString(int maxsiz) throws SQLException
{
return ReceiveString(maxsiz, null);
}
/**
* Receives a null-terminated string from the backend. Maximum of
* maxsiz bytes - if we don't see a null, then we assume something
* has gone wrong.
*
* @param maxsiz maximum length of string
* @param encoding the charset encoding to use.
* @return string from back end
* @exception SQLException if an I/O error occurs
*/
public String ReceiveString(int maxsiz, String encoding) throws SQLException
{
byte[] rst = allocByteDim1(maxsiz);
return ReceiveString(rst, maxsiz, encoding);
}
/** /**
* Receives a null-terminated string from the backend. Maximum of * Receives a null-terminated string from the backend. Maximum of
* maxsiz bytes - if we don't see a null, then we assume something * maxsiz bytes - if we don't see a null, then we assume something
* has gone wrong. * has gone wrong.
* *
* @param rst byte array to read the String into. rst.length must
* equal to or greater than maxsize.
* @param maxsiz maximum length of string in bytes
* @param encoding the charset encoding to use. * @param encoding the charset encoding to use.
* @param maxsiz maximum length of string in bytes
* @return string from back end * @return string from back end
* @exception SQLException if an I/O error occurs * @exception SQLException if an I/O error occurs
*/ */
public String ReceiveString(byte rst[], int maxsiz, String encoding) public String ReceiveString(int maxsiz, String encoding) throws SQLException
throws SQLException
{ {
byte[] rst = new byte[maxsiz];
int s = 0; int s = 0;
try try
@ -303,10 +262,9 @@ public class PG_Stream
int c = pg_input.read(); int c = pg_input.read();
if (c < 0) if (c < 0)
throw new PSQLException("postgresql.stream.eof"); throw new PSQLException("postgresql.stream.eof");
else if (c == 0) { else if (c == 0)
rst[s] = 0; break;
break; else
} else
rst[s++] = (byte)c; rst[s++] = (byte)c;
} }
if (s >= maxsiz) if (s >= maxsiz)
@ -341,7 +299,7 @@ public class PG_Stream
{ {
int i, bim = (nf + 7)/8; int i, bim = (nf + 7)/8;
byte[] bitmask = Receive(bim); byte[] bitmask = Receive(bim);
byte[][] answer = allocByteDim2(nf); byte[][] answer = new byte[nf][0];
int whichbit = 0x80; int whichbit = 0x80;
int whichbyte = 0; int whichbyte = 0;
@ -379,7 +337,7 @@ public class PG_Stream
*/ */
private byte[] Receive(int siz) throws SQLException private byte[] Receive(int siz) throws SQLException
{ {
byte[] answer = allocByteDim1(siz); byte[] answer = new byte[siz];
Receive(answer,0,siz); Receive(answer,0,siz);
return answer; return answer;
} }
@ -437,95 +395,4 @@ public class PG_Stream
pg_input.close(); pg_input.close();
connection.close(); connection.close();
} }
/**
* Deallocate all resources that has been associated with any previous
* query.
*/
public void deallocate(PGStatement stmt){
for(int i = 0; i < maxsize_dim1; i++){
synchronized(notusemap_dim1[i]){
notusemap_dim1[i].addAll(stmt.inusemap_dim1[i]);
}
stmt.inusemap_dim1[i].clear();
}
for(int i = 0; i < maxsize_dim2; i++){
synchronized(notusemap_dim2[i]){
notusemap_dim2[i].addAll(stmt.inusemap_dim2[i]);
}
stmt.inusemap_dim2[i].clear();
}
}
public static final int maxsize_dim1 = 256;
public static ObjectPool notusemap_dim1[] = new ObjectPool[maxsize_dim1];
public static byte binit[][] = new byte[maxsize_dim1][0];
public static final int maxsize_dim2 = 32;
public static ObjectPool notusemap_dim2[] = new ObjectPool[maxsize_dim2];
public static ObjectPoolFactory factory_dim1;
public static ObjectPoolFactory factory_dim2;
static {
for(int i = 0; i < maxsize_dim1; i++){
binit[i] = new byte[i];
notusemap_dim1[i] = new ObjectPool();
}
for(int i = 0; i < maxsize_dim2; i++){
notusemap_dim2[i] = new ObjectPool();
}
factory_dim1 = ObjectPoolFactory.getInstance(maxsize_dim1);
factory_dim2 = ObjectPoolFactory.getInstance(maxsize_dim2);
}
public byte[] allocByteDim1(int size){
if(size >= maxsize_dim1 || executingStatement == null){
return new byte[size];
}
ObjectPool not_usel = notusemap_dim1[size];
ObjectPool in_usel = executingStatement.inusemap_dim1[size];
byte b[] = null;
synchronized(not_usel){
if(!not_usel.isEmpty()) {
Object o = not_usel.remove();
b = (byte[]) o;
} else {
b = new byte[size];
}
}
in_usel.add(b);
return b;
}
public byte[][] allocByteDim2(int size){
if(size >= maxsize_dim2 || executingStatement == null){
return new byte[size][0];
}
ObjectPool not_usel = notusemap_dim2[size];
ObjectPool in_usel = executingStatement.inusemap_dim2[size];
byte b[][] = null;
synchronized(not_usel){
if(!not_usel.isEmpty()) {
Object o = not_usel.remove();
b = (byte[][]) o;
} else
b = new byte[size][0];
in_usel.add(b);
}
return b;
}
} }

View File

@ -17,7 +17,7 @@ import org.postgresql.largeobject.*;
import org.postgresql.util.*; import org.postgresql.util.*;
/** /**
* $Id: Connection.java,v 1.3 2000/10/08 19:37:54 momjian Exp $ * $Id: Connection.java,v 1.4 2000/10/09 16:48:17 momjian Exp $
* *
* A Connection represents a session with a specific database. Within the * A Connection represents a session with a specific database. Within the
* context of a Connection, SQL statements are executed and results are * context of a Connection, SQL statements are executed and results are
@ -138,9 +138,9 @@ public class Connection extends org.postgresql.Connection implements java.sql.Co
if (this.autoCommit == autoCommit) if (this.autoCommit == autoCommit)
return; return;
if (autoCommit) if (autoCommit)
ExecSQL(null, "end"); ExecSQL("end");
else else
ExecSQL(null, "begin"); ExecSQL("begin");
this.autoCommit = autoCommit; this.autoCommit = autoCommit;
} }
@ -170,9 +170,9 @@ public class Connection extends org.postgresql.Connection implements java.sql.Co
{ {
if (autoCommit) if (autoCommit)
return; return;
ExecSQL(null, "commit"); ExecSQL("commit");
autoCommit = true; autoCommit = true;
ExecSQL(null, "begin"); ExecSQL("begin");
autoCommit = false; autoCommit = false;
} }
@ -188,9 +188,9 @@ public class Connection extends org.postgresql.Connection implements java.sql.Co
{ {
if (autoCommit) if (autoCommit)
return; return;
ExecSQL(null, "rollback"); ExecSQL("rollback");
autoCommit = true; autoCommit = true;
ExecSQL(null, "begin"); ExecSQL("begin");
autoCommit = false; autoCommit = false;
} }
@ -316,11 +316,11 @@ public class Connection extends org.postgresql.Connection implements java.sql.Co
switch(level) { switch(level) {
case java.sql.Connection.TRANSACTION_READ_COMMITTED: case java.sql.Connection.TRANSACTION_READ_COMMITTED:
ExecSQL(null, q + " READ COMMITTED"); ExecSQL(q + " READ COMMITTED");
return; return;
case java.sql.Connection.TRANSACTION_SERIALIZABLE: case java.sql.Connection.TRANSACTION_SERIALIZABLE:
ExecSQL(null, q + " SERIALIZABLE"); ExecSQL(q + " SERIALIZABLE");
return; return;
default: default:
@ -336,7 +336,7 @@ public class Connection extends org.postgresql.Connection implements java.sql.Co
*/ */
public int getTransactionIsolation() throws SQLException public int getTransactionIsolation() throws SQLException
{ {
ExecSQL(null, "show xactisolevel"); ExecSQL("show xactisolevel");
SQLWarning w = getWarnings(); SQLWarning w = getWarnings();
if (w != null) { if (w != null) {

View File

@ -1497,7 +1497,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
if(procedureNamePattern==null) if(procedureNamePattern==null)
procedureNamePattern="%"; procedureNamePattern="%";
r = connection.ExecSQL(null, "select proname, proretset from pg_proc where proname like '"+procedureNamePattern.toLowerCase()+"' order by proname"); r = connection.ExecSQL("select proname, proretset from pg_proc where proname like '"+procedureNamePattern.toLowerCase()+"' order by proname");
while (r.next()) while (r.next())
{ {
@ -1670,7 +1670,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
sql.append("'"); sql.append("'");
// Now run the query // Now run the query
r = connection.ExecSQL(null, sql.toString()); r = connection.ExecSQL(sql.toString());
byte remarks[]; byte remarks[];
@ -1679,7 +1679,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
byte[][] tuple = new byte[5][0]; byte[][] tuple = new byte[5][0];
// Fetch the description for the table (if any) // Fetch the description for the table (if any)
java.sql.ResultSet dr = connection.ExecSQL(null, "select description from pg_description where objoid="+r.getInt(2)); java.sql.ResultSet dr = connection.ExecSQL("select description from pg_description where objoid="+r.getInt(2));
if(((org.postgresql.ResultSet)dr).getTupleCount()==1) { if(((org.postgresql.ResultSet)dr).getTupleCount()==1) {
dr.next(); dr.next();
remarks = dr.getBytes(1); remarks = dr.getBytes(1);
@ -1893,7 +1893,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
// Now form the query // Now form the query
// Modified by Stefan Andreasen <stefan@linux.kapow.dk> // Modified by Stefan Andreasen <stefan@linux.kapow.dk>
r = connection.ExecSQL(null, "select a.oid,c.relname,a.attname,a.atttypid,a.attnum,a.attnotnull,a.attlen,a.atttypmod from pg_class c, pg_attribute a where a.attrelid=c.oid and c.relname like '"+tableNamePattern.toLowerCase()+"' and a.attname like '"+columnNamePattern.toLowerCase()+"' and a.attnum>0 order by c.relname,a.attnum"); r = connection.ExecSQL("select a.oid,c.relname,a.attname,a.atttypid,a.attnum,a.attnotnull,a.attlen,a.atttypmod from pg_class c, pg_attribute a where a.attrelid=c.oid and c.relname like '"+tableNamePattern.toLowerCase()+"' and a.attname like '"+columnNamePattern.toLowerCase()+"' and a.attnum>0 order by c.relname,a.attnum");
byte remarks[]; byte remarks[];
@ -1901,7 +1901,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
byte[][] tuple = new byte[18][0]; byte[][] tuple = new byte[18][0];
// Fetch the description for the table (if any) // Fetch the description for the table (if any)
java.sql.ResultSet dr = connection.ExecSQL(null, "select description from pg_description where objoid="+r.getInt(1)); java.sql.ResultSet dr = connection.ExecSQL("select description from pg_description where objoid="+r.getInt(1));
if(((org.postgresql.ResultSet)dr).getTupleCount()==1) { if(((org.postgresql.ResultSet)dr).getTupleCount()==1) {
dr.next(); dr.next();
tuple[11] = dr.getBytes(1); tuple[11] = dr.getBytes(1);
@ -1915,7 +1915,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
tuple[2] = r.getBytes(2); // Table name tuple[2] = r.getBytes(2); // Table name
tuple[3] = r.getBytes(3); // Column name tuple[3] = r.getBytes(3); // Column name
dr = connection.ExecSQL(null, "select typname from pg_type where oid = "+r.getString(4)); dr = connection.ExecSQL("select typname from pg_type where oid = "+r.getString(4));
dr.next(); dr.next();
String typname=dr.getString(1); String typname=dr.getString(1);
dr.close(); dr.close();
@ -2009,7 +2009,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
f[7] = new Field(connection,"IS_GRANTABLE",iVarcharOid,32); f[7] = new Field(connection,"IS_GRANTABLE",iVarcharOid,32);
// This is taken direct from the psql source // This is taken direct from the psql source
java.sql.ResultSet r = connection.ExecSQL(null, "SELECT relname, relacl FROM pg_class, pg_user WHERE ( relkind = 'r' OR relkind = 'i') and relname !~ '^pg_' and relname !~ '^xin[vx][0-9]+' and usesysid = relowner and relname like '"+table.toLowerCase()+"' ORDER BY relname"); java.sql.ResultSet r = connection.ExecSQL("SELECT relname, relacl FROM pg_class, pg_user WHERE ( relkind = 'r' OR relkind = 'i') and relname !~ '^pg_' and relname !~ '^xin[vx][0-9]+' and usesysid = relowner and relname like '"+table.toLowerCase()+"' ORDER BY relname");
while(r.next()) { while(r.next()) {
byte[][] tuple = new byte[8][0]; byte[][] tuple = new byte[8][0];
tuple[0] = tuple[1]= "".getBytes(); tuple[0] = tuple[1]= "".getBytes();
@ -2406,7 +2406,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
*/ */
public java.sql.ResultSet getTypeInfo() throws SQLException public java.sql.ResultSet getTypeInfo() throws SQLException
{ {
java.sql.ResultSet rs = connection.ExecSQL(null, "select typname from pg_type"); java.sql.ResultSet rs = connection.ExecSQL("select typname from pg_type");
if(rs!=null) { if(rs!=null) {
Field f[] = new Field[18]; Field f[] = new Field[18];
ResultSet r; // ResultSet for the SQL query that we need to do ResultSet r; // ResultSet for the SQL query that we need to do

View File

@ -6,7 +6,6 @@ package org.postgresql.jdbc1;
// org.postgresql.jdbc2 package. // org.postgresql.jdbc2 package.
import java.sql.*; import java.sql.*;
import org.postgresql.PGStatement;
import org.postgresql.util.PSQLException; import org.postgresql.util.PSQLException;
@ -23,8 +22,9 @@ import org.postgresql.util.PSQLException;
* @see java.sql.Statement * @see java.sql.Statement
* @see ResultSet * @see ResultSet
*/ */
public class Statement extends PGStatement implements java.sql.Statement public class Statement implements java.sql.Statement
{ {
Connection connection; // The connection who created us
java.sql.ResultSet result = null; // The current results java.sql.ResultSet result = null; // The current results
SQLWarning warnings = null; // The warnings chain. SQLWarning warnings = null; // The warnings chain.
int timeout = 0; // The timeout for a query (not used) int timeout = 0; // The timeout for a query (not used)
@ -38,7 +38,7 @@ public class Statement extends PGStatement implements java.sql.Statement
*/ */
public Statement (Connection c) public Statement (Connection c)
{ {
super(c); connection = c;
} }
/** /**
@ -89,8 +89,7 @@ public class Statement extends PGStatement implements java.sql.Statement
*/ */
public void close() throws SQLException public void close() throws SQLException
{ {
super.close(); result = null;
result = null;
} }
/** /**
@ -267,8 +266,7 @@ public class Statement extends PGStatement implements java.sql.Statement
*/ */
public boolean execute(String sql) throws SQLException public boolean execute(String sql) throws SQLException
{ {
deallocate(); result = connection.ExecSQL(sql);
result = connection.ExecSQL(this, sql);
return (result != null && ((org.postgresql.ResultSet)result).reallyResultSet()); return (result != null && ((org.postgresql.ResultSet)result).reallyResultSet());
} }

View File

@ -17,7 +17,7 @@ import org.postgresql.largeobject.*;
import org.postgresql.util.*; import org.postgresql.util.*;
/** /**
* $Id: Connection.java,v 1.3 2000/10/08 19:37:55 momjian Exp $ * $Id: Connection.java,v 1.4 2000/10/09 16:48:18 momjian Exp $
* *
* A Connection represents a session with a specific database. Within the * A Connection represents a session with a specific database. Within the
* context of a Connection, SQL statements are executed and results are * context of a Connection, SQL statements are executed and results are
@ -138,9 +138,9 @@ public class Connection extends org.postgresql.Connection implements java.sql.Co
if (this.autoCommit == autoCommit) if (this.autoCommit == autoCommit)
return; return;
if (autoCommit) if (autoCommit)
ExecSQL(null, "end"); ExecSQL("end");
else else
ExecSQL(null, "begin"); ExecSQL("begin");
this.autoCommit = autoCommit; this.autoCommit = autoCommit;
} }
@ -170,9 +170,9 @@ public class Connection extends org.postgresql.Connection implements java.sql.Co
{ {
if (autoCommit) if (autoCommit)
return; return;
ExecSQL(null, "commit"); ExecSQL("commit");
autoCommit = true; autoCommit = true;
ExecSQL(null, "begin"); ExecSQL("begin");
autoCommit = false; autoCommit = false;
} }
@ -188,9 +188,9 @@ public class Connection extends org.postgresql.Connection implements java.sql.Co
{ {
if (autoCommit) if (autoCommit)
return; return;
ExecSQL(null, "rollback"); ExecSQL("rollback");
autoCommit = true; autoCommit = true;
ExecSQL(null, "begin"); ExecSQL("begin");
autoCommit = false; autoCommit = false;
} }
@ -316,11 +316,11 @@ public class Connection extends org.postgresql.Connection implements java.sql.Co
switch(level) { switch(level) {
case java.sql.Connection.TRANSACTION_READ_COMMITTED: case java.sql.Connection.TRANSACTION_READ_COMMITTED:
ExecSQL(null, q + " READ COMMITTED"); ExecSQL(q + " READ COMMITTED");
return; return;
case java.sql.Connection.TRANSACTION_SERIALIZABLE: case java.sql.Connection.TRANSACTION_SERIALIZABLE:
ExecSQL(null, q + " SERIALIZABLE"); ExecSQL(q + " SERIALIZABLE");
return; return;
default: default:
@ -336,7 +336,7 @@ public class Connection extends org.postgresql.Connection implements java.sql.Co
*/ */
public int getTransactionIsolation() throws SQLException public int getTransactionIsolation() throws SQLException
{ {
ExecSQL(null, "show xactisolevel"); ExecSQL("show xactisolevel");
SQLWarning w = getWarnings(); SQLWarning w = getWarnings();
if (w != null) { if (w != null) {

View File

@ -1497,8 +1497,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
if(procedureNamePattern==null) if(procedureNamePattern==null)
procedureNamePattern="%"; procedureNamePattern="%";
r = connection.ExecSQL(null, r = connection.ExecSQL("select proname, proretset from pg_proc where proname like '"+procedureNamePattern.toLowerCase()+"' order by proname");
"select proname, proretset from pg_proc where proname like '"+procedureNamePattern.toLowerCase()+"' order by proname");
while (r.next()) while (r.next())
{ {
@ -1671,7 +1670,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
sql.append("'"); sql.append("'");
// Now run the query // Now run the query
r = connection.ExecSQL(null, sql.toString()); r = connection.ExecSQL(sql.toString());
byte remarks[]; byte remarks[];
@ -1680,7 +1679,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
byte[][] tuple = new byte[5][0]; byte[][] tuple = new byte[5][0];
// Fetch the description for the table (if any) // Fetch the description for the table (if any)
java.sql.ResultSet dr = connection.ExecSQL(null, "select description from pg_description where objoid="+r.getInt(2)); java.sql.ResultSet dr = connection.ExecSQL("select description from pg_description where objoid="+r.getInt(2));
if(((org.postgresql.ResultSet)dr).getTupleCount()==1) { if(((org.postgresql.ResultSet)dr).getTupleCount()==1) {
dr.next(); dr.next();
remarks = dr.getBytes(1); remarks = dr.getBytes(1);
@ -1894,7 +1893,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
// Now form the query // Now form the query
// Modified by Stefan Andreasen <stefan@linux.kapow.dk> // Modified by Stefan Andreasen <stefan@linux.kapow.dk>
r = connection.ExecSQL(null, "select a.oid,c.relname,a.attname,a.atttypid,a.attnum,a.attnotnull,a.attlen,a.atttypmod from pg_class c, pg_attribute a where a.attrelid=c.oid and c.relname like '"+tableNamePattern.toLowerCase()+"' and a.attname like '"+columnNamePattern.toLowerCase()+"' and a.attnum>0 order by c.relname,a.attnum"); r = connection.ExecSQL("select a.oid,c.relname,a.attname,a.atttypid,a.attnum,a.attnotnull,a.attlen,a.atttypmod from pg_class c, pg_attribute a where a.attrelid=c.oid and c.relname like '"+tableNamePattern.toLowerCase()+"' and a.attname like '"+columnNamePattern.toLowerCase()+"' and a.attnum>0 order by c.relname,a.attnum");
byte remarks[]; byte remarks[];
@ -1902,7 +1901,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
byte[][] tuple = new byte[18][0]; byte[][] tuple = new byte[18][0];
// Fetch the description for the table (if any) // Fetch the description for the table (if any)
java.sql.ResultSet dr = connection.ExecSQL(null, "select description from pg_description where objoid="+r.getInt(1)); java.sql.ResultSet dr = connection.ExecSQL("select description from pg_description where objoid="+r.getInt(1));
if(((org.postgresql.ResultSet)dr).getTupleCount()==1) { if(((org.postgresql.ResultSet)dr).getTupleCount()==1) {
dr.next(); dr.next();
tuple[11] = dr.getBytes(1); tuple[11] = dr.getBytes(1);
@ -1916,7 +1915,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
tuple[2] = r.getBytes(2); // Table name tuple[2] = r.getBytes(2); // Table name
tuple[3] = r.getBytes(3); // Column name tuple[3] = r.getBytes(3); // Column name
dr = connection.ExecSQL(null, "select typname from pg_type where oid = "+r.getString(4)); dr = connection.ExecSQL("select typname from pg_type where oid = "+r.getString(4));
dr.next(); dr.next();
String typname=dr.getString(1); String typname=dr.getString(1);
dr.close(); dr.close();
@ -2010,7 +2009,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
f[7] = new Field(connection,"IS_GRANTABLE",iVarcharOid,32); f[7] = new Field(connection,"IS_GRANTABLE",iVarcharOid,32);
// This is taken direct from the psql source // This is taken direct from the psql source
java.sql.ResultSet r = connection.ExecSQL(null, "SELECT relname, relacl FROM pg_class, pg_user WHERE ( relkind = 'r' OR relkind = 'i') and relname !~ '^pg_' and relname !~ '^xin[vx][0-9]+' and usesysid = relowner and relname like '"+table.toLowerCase()+"' ORDER BY relname"); java.sql.ResultSet r = connection.ExecSQL("SELECT relname, relacl FROM pg_class, pg_user WHERE ( relkind = 'r' OR relkind = 'i') and relname !~ '^pg_' and relname !~ '^xin[vx][0-9]+' and usesysid = relowner and relname like '"+table.toLowerCase()+"' ORDER BY relname");
while(r.next()) { while(r.next()) {
byte[][] tuple = new byte[8][0]; byte[][] tuple = new byte[8][0];
tuple[0] = tuple[1]= "".getBytes(); tuple[0] = tuple[1]= "".getBytes();
@ -2407,7 +2406,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
*/ */
public java.sql.ResultSet getTypeInfo() throws SQLException public java.sql.ResultSet getTypeInfo() throws SQLException
{ {
java.sql.ResultSet rs = connection.ExecSQL(null, "select typname from pg_type"); java.sql.ResultSet rs = connection.ExecSQL("select typname from pg_type");
if(rs!=null) { if(rs!=null) {
Field f[] = new Field[18]; Field f[] = new Field[18];
ResultSet r; // ResultSet for the SQL query that we need to do ResultSet r; // ResultSet for the SQL query that we need to do

View File

@ -8,7 +8,6 @@ package org.postgresql.jdbc2;
import java.sql.*; import java.sql.*;
import java.util.Vector; import java.util.Vector;
import org.postgresql.util.*; import org.postgresql.util.*;
import org.postgresql.PGStatement;
/** /**
* A Statement object is used for executing a static SQL statement and * A Statement object is used for executing a static SQL statement and
@ -23,8 +22,9 @@ import org.postgresql.PGStatement;
* @see java.sql.Statement * @see java.sql.Statement
* @see ResultSet * @see ResultSet
*/ */
public class Statement extends PGStatement implements java.sql.Statement public class Statement implements java.sql.Statement
{ {
Connection connection; // The connection who created us
java.sql.ResultSet result = null; // The current results java.sql.ResultSet result = null; // The current results
SQLWarning warnings = null; // The warnings chain. SQLWarning warnings = null; // The warnings chain.
int timeout = 0; // The timeout for a query (not used) int timeout = 0; // The timeout for a query (not used)
@ -39,7 +39,7 @@ public class Statement extends PGStatement implements java.sql.Statement
*/ */
public Statement (Connection c) public Statement (Connection c)
{ {
super(c); connection = c;
} }
/** /**
@ -90,8 +90,7 @@ public class Statement extends PGStatement implements java.sql.Statement
*/ */
public void close() throws SQLException public void close() throws SQLException
{ {
super.close(); result = null;
result = null;
} }
/** /**
@ -270,8 +269,8 @@ public class Statement extends PGStatement implements java.sql.Statement
{ {
if(escapeProcessing) if(escapeProcessing)
sql=connection.EscapeSQL(sql); sql=connection.EscapeSQL(sql);
deallocate();
result = connection.ExecSQL(this, sql); result = connection.ExecSQL(sql);
return (result != null && ((org.postgresql.ResultSet)result).reallyResultSet()); return (result != null && ((org.postgresql.ResultSet)result).reallyResultSet());
} }

View File

@ -50,7 +50,7 @@ public class Serialize
// Second check, the type must be a table // Second check, the type must be a table
boolean status = false; boolean status = false;
ResultSet rs = conn.ExecSQL(null, "select typname from pg_type,pg_class where typname=relname and typname='"+type+"'"); ResultSet rs = conn.ExecSQL("select typname from pg_type,pg_class where typname=relname and typname='"+type+"'");
if(rs!=null) { if(rs!=null) {
if(rs.next()) if(rs.next())
status=true; status=true;
@ -97,7 +97,7 @@ public class Serialize
sb.append(oid); sb.append(oid);
DriverManager.println("store: "+sb.toString()); DriverManager.println("store: "+sb.toString());
ResultSet rs = conn.ExecSQL(null, sb.toString()); ResultSet rs = conn.ExecSQL(sb.toString());
if(rs!=null) { if(rs!=null) {
if(rs.next()) { if(rs.next()) {
for(int i=0;i<f.length;i++) { for(int i=0;i<f.length;i++) {
@ -189,7 +189,7 @@ public class Serialize
} }
DriverManager.println("store: "+sb.toString()); DriverManager.println("store: "+sb.toString());
ResultSet rs = conn.ExecSQL(null, sb.toString()); ResultSet rs = conn.ExecSQL(sb.toString());
if(rs!=null) { if(rs!=null) {
rs.close(); rs.close();
} }
@ -236,7 +236,7 @@ public class Serialize
// See if the table exists // See if the table exists
String tableName = toPostgreSQL(c.getName()); String tableName = toPostgreSQL(c.getName());
ResultSet rs = con.ExecSQL(null, "select relname from pg_class where relname = '"+tableName+"'"); ResultSet rs = con.ExecSQL("select relname from pg_class where relname = '"+tableName+"'");
if(!rs.next()) { if(!rs.next()) {
DriverManager.println("found "+rs.getString(1)); DriverManager.println("found "+rs.getString(1));
// No entries returned, so the table doesn't exist // No entries returned, so the table doesn't exist
@ -277,7 +277,7 @@ public class Serialize
// Now create the table // Now create the table
DriverManager.println("Serialize.create:"+sb); DriverManager.println("Serialize.create:"+sb);
con.ExecSQL(null, sb.toString()); con.ExecSQL(sb.toString());
rs.close(); rs.close();
} else { } else {
DriverManager.println("Serialize.create: table "+tableName+" exists, skipping"); DriverManager.println("Serialize.create: table "+tableName+" exists, skipping");