mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-11-21 03:13:05 +08:00
Back out Gunnar R|nning jdbc changes.
This commit is contained in:
parent
c4ccc6146b
commit
a4e3943b3f
@ -10,7 +10,7 @@ import org.postgresql.largeobject.*;
|
||||
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
|
||||
* 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
|
||||
public int pid;
|
||||
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
|
||||
@ -169,9 +164,8 @@ public abstract class Connection
|
||||
// The most common one to be thrown here is:
|
||||
// "User authentication failed"
|
||||
//
|
||||
String msg = pg_stream.ReceiveString(receive_sbuf, 4096,
|
||||
getEncoding());
|
||||
throw new SQLException(msg);
|
||||
throw new SQLException(pg_stream.ReceiveString
|
||||
(4096, getEncoding()));
|
||||
|
||||
case 'R':
|
||||
// Get the type of request
|
||||
@ -242,7 +236,7 @@ public abstract class Connection
|
||||
case 'E':
|
||||
case 'N':
|
||||
throw new SQLException(pg_stream.ReceiveString
|
||||
(receive_sbuf, 4096, getEncoding()));
|
||||
(4096, getEncoding()));
|
||||
default:
|
||||
throw new PSQLException("postgresql.con.setup");
|
||||
}
|
||||
@ -254,7 +248,7 @@ public abstract class Connection
|
||||
break;
|
||||
case 'E':
|
||||
case 'N':
|
||||
throw new SQLException(pg_stream.ReceiveString(receive_sbuf, 4096, getEncoding()));
|
||||
throw new SQLException(pg_stream.ReceiveString(4096));
|
||||
default:
|
||||
throw new PSQLException("postgresql.con.setup");
|
||||
}
|
||||
@ -269,7 +263,7 @@ public abstract class Connection
|
||||
//
|
||||
firstWarning = null;
|
||||
|
||||
ExecSQL(null, "set datestyle to 'ISO'");
|
||||
ExecSQL("set datestyle to 'ISO'");
|
||||
|
||||
// Initialise object handling
|
||||
initObjectTypes();
|
||||
@ -312,8 +306,7 @@ public abstract class Connection
|
||||
//currentDateStyle=i+1; // this is the index of the format
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Send a query to the backend. Returns one of the ResultSet
|
||||
* objects.
|
||||
@ -321,18 +314,15 @@ public abstract class Connection
|
||||
* <B>Note:</B> there does not seem to be any method currently
|
||||
* in existance to return the update count.
|
||||
*
|
||||
* @param stmt The statment object.
|
||||
* @param sql the SQL statement to be executed
|
||||
* @return a ResultSet holding the results
|
||||
* @exception SQLException if a database error occurs
|
||||
*/
|
||||
public java.sql.ResultSet ExecSQL(PGStatement stmt,
|
||||
String sql) throws SQLException
|
||||
public java.sql.ResultSet ExecSQL(String sql) throws SQLException
|
||||
{
|
||||
// added Oct 7 1998 to give us thread safety.
|
||||
synchronized(pg_stream) {
|
||||
pg_stream.setExecutingStatement(stmt);
|
||||
|
||||
|
||||
Field[] fields = null;
|
||||
Vector tuples = new Vector();
|
||||
byte[] buf = null;
|
||||
@ -362,7 +352,8 @@ public abstract class Connection
|
||||
try
|
||||
{
|
||||
pg_stream.SendChar('Q');
|
||||
pg_stream.Send(sql.getBytes());
|
||||
buf = sql.getBytes();
|
||||
pg_stream.Send(buf);
|
||||
pg_stream.SendChar(0);
|
||||
pg_stream.flush();
|
||||
} catch (IOException e) {
|
||||
@ -379,8 +370,7 @@ public abstract class Connection
|
||||
{
|
||||
case 'A': // Asynchronous Notify
|
||||
pid = pg_stream.ReceiveInteger(4);
|
||||
msg = pg_stream.ReceiveString(receive_sbuf, 8192,
|
||||
getEncoding());
|
||||
msg = pg_stream.ReceiveString(8192);
|
||||
break;
|
||||
case 'B': // Binary Data Transfer
|
||||
if (fields == null)
|
||||
@ -391,9 +381,7 @@ public abstract class Connection
|
||||
tuples.addElement(tup);
|
||||
break;
|
||||
case 'C': // Command Status
|
||||
recv_status =
|
||||
pg_stream.ReceiveString(receive_sbuf, 8192,
|
||||
getEncoding());
|
||||
recv_status = pg_stream.ReceiveString(8192);
|
||||
|
||||
// Now handle the update count correctly.
|
||||
if(recv_status.startsWith("INSERT") || recv_status.startsWith("UPDATE") || recv_status.startsWith("DELETE")) {
|
||||
@ -435,8 +423,7 @@ public abstract class Connection
|
||||
tuples.addElement(tup);
|
||||
break;
|
||||
case 'E': // Error Message
|
||||
msg = pg_stream.ReceiveString(receive_sbuf, 4096,
|
||||
getEncoding());
|
||||
msg = pg_stream.ReceiveString(4096);
|
||||
final_error = new SQLException(msg);
|
||||
hfr = true;
|
||||
break;
|
||||
@ -451,14 +438,10 @@ public abstract class Connection
|
||||
hfr = true;
|
||||
break;
|
||||
case 'N': // Error Notification
|
||||
addWarning(pg_stream.ReceiveString(receive_sbuf,
|
||||
4096,
|
||||
getEncoding()));
|
||||
addWarning(pg_stream.ReceiveString(4096));
|
||||
break;
|
||||
case 'P': // Portal Name
|
||||
String pname =
|
||||
pg_stream.ReceiveString(receive_sbuf, 8192,
|
||||
getEncoding());
|
||||
String pname = pg_stream.ReceiveString(8192);
|
||||
break;
|
||||
case 'T': // MetaData Field Description
|
||||
if (fields != null)
|
||||
@ -478,8 +461,6 @@ public abstract class Connection
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Receive the field descriptions from the back end
|
||||
*
|
||||
@ -493,8 +474,7 @@ public abstract class Connection
|
||||
|
||||
for (i = 0 ; i < nf ; ++i)
|
||||
{
|
||||
String typname = pg_stream.ReceiveString(receive_sbuf, 8192,
|
||||
getEncoding());
|
||||
String typname = pg_stream.ReceiveString(8192);
|
||||
int typid = pg_stream.ReceiveIntegerR(4);
|
||||
int typlen = pg_stream.ReceiveIntegerR(2);
|
||||
int typmod = pg_stream.ReceiveIntegerR(4);
|
||||
|
@ -76,9 +76,7 @@ public class Field
|
||||
// it's not in the cache, so perform a query, and add the result to
|
||||
// the cache
|
||||
if(type_name==null) {
|
||||
ResultSet result = (org.postgresql.ResultSet)
|
||||
conn.ExecSQL(null, "select typname from pg_type where oid = "
|
||||
+ oid);
|
||||
ResultSet result = (org.postgresql.ResultSet)conn.ExecSQL("select typname from pg_type where oid = " + oid);
|
||||
if (result.getColumnCount() != 1 || result.getTupleCount() != 1)
|
||||
throw new PSQLException("postgresql.unexpected");
|
||||
result.next();
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -22,10 +22,7 @@ public class PG_Stream
|
||||
private Socket connection;
|
||||
private InputStream pg_input;
|
||||
private BufferedOutputStream pg_output;
|
||||
|
||||
public PGStatement executingStatement;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructor: Connect to the PostgreSQL back end and return
|
||||
* a stream connection.
|
||||
@ -47,15 +44,6 @@ public class PG_Stream
|
||||
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
|
||||
*
|
||||
@ -82,7 +70,7 @@ public class PG_Stream
|
||||
*/
|
||||
public void SendInteger(int val, int siz) throws IOException
|
||||
{
|
||||
byte[] buf = allocByteDim1(siz);
|
||||
byte[] buf = new byte[siz];
|
||||
|
||||
while (siz-- > 0)
|
||||
{
|
||||
@ -106,7 +94,7 @@ public class PG_Stream
|
||||
*/
|
||||
public void SendIntegerReverse(int val, int siz) throws IOException
|
||||
{
|
||||
byte[] buf = allocByteDim1(siz);
|
||||
byte[] buf = new byte[siz];
|
||||
int p=0;
|
||||
while (siz-- > 0)
|
||||
{
|
||||
@ -248,52 +236,23 @@ public class PG_Stream
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
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 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 maxsiz maximum length of string in bytes
|
||||
* @return string from back end
|
||||
* @exception SQLException if an I/O error occurs
|
||||
*/
|
||||
public String ReceiveString(byte rst[], int maxsiz, String encoding)
|
||||
throws SQLException
|
||||
public String ReceiveString(int maxsiz, String encoding) throws SQLException
|
||||
{
|
||||
byte[] rst = new byte[maxsiz];
|
||||
int s = 0;
|
||||
|
||||
try
|
||||
@ -303,10 +262,9 @@ public class PG_Stream
|
||||
int c = pg_input.read();
|
||||
if (c < 0)
|
||||
throw new PSQLException("postgresql.stream.eof");
|
||||
else if (c == 0) {
|
||||
rst[s] = 0;
|
||||
break;
|
||||
} else
|
||||
else if (c == 0)
|
||||
break;
|
||||
else
|
||||
rst[s++] = (byte)c;
|
||||
}
|
||||
if (s >= maxsiz)
|
||||
@ -341,7 +299,7 @@ public class PG_Stream
|
||||
{
|
||||
int i, bim = (nf + 7)/8;
|
||||
byte[] bitmask = Receive(bim);
|
||||
byte[][] answer = allocByteDim2(nf);
|
||||
byte[][] answer = new byte[nf][0];
|
||||
|
||||
int whichbit = 0x80;
|
||||
int whichbyte = 0;
|
||||
@ -379,7 +337,7 @@ public class PG_Stream
|
||||
*/
|
||||
private byte[] Receive(int siz) throws SQLException
|
||||
{
|
||||
byte[] answer = allocByteDim1(siz);
|
||||
byte[] answer = new byte[siz];
|
||||
Receive(answer,0,siz);
|
||||
return answer;
|
||||
}
|
||||
@ -437,95 +395,4 @@ public class PG_Stream
|
||||
pg_input.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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -17,7 +17,7 @@ import org.postgresql.largeobject.*;
|
||||
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
|
||||
* 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)
|
||||
return;
|
||||
if (autoCommit)
|
||||
ExecSQL(null, "end");
|
||||
ExecSQL("end");
|
||||
else
|
||||
ExecSQL(null, "begin");
|
||||
ExecSQL("begin");
|
||||
this.autoCommit = autoCommit;
|
||||
}
|
||||
|
||||
@ -170,9 +170,9 @@ public class Connection extends org.postgresql.Connection implements java.sql.Co
|
||||
{
|
||||
if (autoCommit)
|
||||
return;
|
||||
ExecSQL(null, "commit");
|
||||
ExecSQL("commit");
|
||||
autoCommit = true;
|
||||
ExecSQL(null, "begin");
|
||||
ExecSQL("begin");
|
||||
autoCommit = false;
|
||||
}
|
||||
|
||||
@ -188,9 +188,9 @@ public class Connection extends org.postgresql.Connection implements java.sql.Co
|
||||
{
|
||||
if (autoCommit)
|
||||
return;
|
||||
ExecSQL(null, "rollback");
|
||||
ExecSQL("rollback");
|
||||
autoCommit = true;
|
||||
ExecSQL(null, "begin");
|
||||
ExecSQL("begin");
|
||||
autoCommit = false;
|
||||
}
|
||||
|
||||
@ -316,11 +316,11 @@ public class Connection extends org.postgresql.Connection implements java.sql.Co
|
||||
switch(level) {
|
||||
|
||||
case java.sql.Connection.TRANSACTION_READ_COMMITTED:
|
||||
ExecSQL(null, q + " READ COMMITTED");
|
||||
ExecSQL(q + " READ COMMITTED");
|
||||
return;
|
||||
|
||||
case java.sql.Connection.TRANSACTION_SERIALIZABLE:
|
||||
ExecSQL(null, q + " SERIALIZABLE");
|
||||
ExecSQL(q + " SERIALIZABLE");
|
||||
return;
|
||||
|
||||
default:
|
||||
@ -336,7 +336,7 @@ public class Connection extends org.postgresql.Connection implements java.sql.Co
|
||||
*/
|
||||
public int getTransactionIsolation() throws SQLException
|
||||
{
|
||||
ExecSQL(null, "show xactisolevel");
|
||||
ExecSQL("show xactisolevel");
|
||||
|
||||
SQLWarning w = getWarnings();
|
||||
if (w != null) {
|
||||
|
@ -1497,7 +1497,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
|
||||
if(procedureNamePattern==null)
|
||||
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())
|
||||
{
|
||||
@ -1670,7 +1670,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
|
||||
sql.append("'");
|
||||
|
||||
// Now run the query
|
||||
r = connection.ExecSQL(null, sql.toString());
|
||||
r = connection.ExecSQL(sql.toString());
|
||||
|
||||
byte remarks[];
|
||||
|
||||
@ -1679,7 +1679,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
|
||||
byte[][] tuple = new byte[5][0];
|
||||
|
||||
// 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) {
|
||||
dr.next();
|
||||
remarks = dr.getBytes(1);
|
||||
@ -1893,7 +1893,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
|
||||
|
||||
// Now form the query
|
||||
// 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[];
|
||||
|
||||
@ -1901,7 +1901,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
|
||||
byte[][] tuple = new byte[18][0];
|
||||
|
||||
// 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) {
|
||||
dr.next();
|
||||
tuple[11] = dr.getBytes(1);
|
||||
@ -1915,7 +1915,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
|
||||
tuple[2] = r.getBytes(2); // Table 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();
|
||||
String typname=dr.getString(1);
|
||||
dr.close();
|
||||
@ -2009,7 +2009,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
|
||||
f[7] = new Field(connection,"IS_GRANTABLE",iVarcharOid,32);
|
||||
|
||||
// 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()) {
|
||||
byte[][] tuple = new byte[8][0];
|
||||
tuple[0] = tuple[1]= "".getBytes();
|
||||
@ -2406,7 +2406,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
|
||||
*/
|
||||
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) {
|
||||
Field f[] = new Field[18];
|
||||
ResultSet r; // ResultSet for the SQL query that we need to do
|
||||
|
@ -6,7 +6,6 @@ package org.postgresql.jdbc1;
|
||||
// org.postgresql.jdbc2 package.
|
||||
|
||||
import java.sql.*;
|
||||
import org.postgresql.PGStatement;
|
||||
|
||||
import org.postgresql.util.PSQLException;
|
||||
|
||||
@ -23,8 +22,9 @@ import org.postgresql.util.PSQLException;
|
||||
* @see java.sql.Statement
|
||||
* @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
|
||||
SQLWarning warnings = null; // The warnings chain.
|
||||
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)
|
||||
{
|
||||
super(c);
|
||||
connection = c;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -89,8 +89,7 @@ public class Statement extends PGStatement implements java.sql.Statement
|
||||
*/
|
||||
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
|
||||
{
|
||||
deallocate();
|
||||
result = connection.ExecSQL(this, sql);
|
||||
result = connection.ExecSQL(sql);
|
||||
return (result != null && ((org.postgresql.ResultSet)result).reallyResultSet());
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ import org.postgresql.largeobject.*;
|
||||
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
|
||||
* 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)
|
||||
return;
|
||||
if (autoCommit)
|
||||
ExecSQL(null, "end");
|
||||
ExecSQL("end");
|
||||
else
|
||||
ExecSQL(null, "begin");
|
||||
ExecSQL("begin");
|
||||
this.autoCommit = autoCommit;
|
||||
}
|
||||
|
||||
@ -170,9 +170,9 @@ public class Connection extends org.postgresql.Connection implements java.sql.Co
|
||||
{
|
||||
if (autoCommit)
|
||||
return;
|
||||
ExecSQL(null, "commit");
|
||||
ExecSQL("commit");
|
||||
autoCommit = true;
|
||||
ExecSQL(null, "begin");
|
||||
ExecSQL("begin");
|
||||
autoCommit = false;
|
||||
}
|
||||
|
||||
@ -188,9 +188,9 @@ public class Connection extends org.postgresql.Connection implements java.sql.Co
|
||||
{
|
||||
if (autoCommit)
|
||||
return;
|
||||
ExecSQL(null, "rollback");
|
||||
ExecSQL("rollback");
|
||||
autoCommit = true;
|
||||
ExecSQL(null, "begin");
|
||||
ExecSQL("begin");
|
||||
autoCommit = false;
|
||||
}
|
||||
|
||||
@ -316,11 +316,11 @@ public class Connection extends org.postgresql.Connection implements java.sql.Co
|
||||
switch(level) {
|
||||
|
||||
case java.sql.Connection.TRANSACTION_READ_COMMITTED:
|
||||
ExecSQL(null, q + " READ COMMITTED");
|
||||
ExecSQL(q + " READ COMMITTED");
|
||||
return;
|
||||
|
||||
case java.sql.Connection.TRANSACTION_SERIALIZABLE:
|
||||
ExecSQL(null, q + " SERIALIZABLE");
|
||||
ExecSQL(q + " SERIALIZABLE");
|
||||
return;
|
||||
|
||||
default:
|
||||
@ -336,7 +336,7 @@ public class Connection extends org.postgresql.Connection implements java.sql.Co
|
||||
*/
|
||||
public int getTransactionIsolation() throws SQLException
|
||||
{
|
||||
ExecSQL(null, "show xactisolevel");
|
||||
ExecSQL("show xactisolevel");
|
||||
|
||||
SQLWarning w = getWarnings();
|
||||
if (w != null) {
|
||||
|
@ -1497,8 +1497,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
|
||||
if(procedureNamePattern==null)
|
||||
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())
|
||||
{
|
||||
@ -1671,7 +1670,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
|
||||
sql.append("'");
|
||||
|
||||
// Now run the query
|
||||
r = connection.ExecSQL(null, sql.toString());
|
||||
r = connection.ExecSQL(sql.toString());
|
||||
|
||||
byte remarks[];
|
||||
|
||||
@ -1680,7 +1679,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
|
||||
byte[][] tuple = new byte[5][0];
|
||||
|
||||
// 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) {
|
||||
dr.next();
|
||||
remarks = dr.getBytes(1);
|
||||
@ -1894,7 +1893,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
|
||||
|
||||
// Now form the query
|
||||
// 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[];
|
||||
|
||||
@ -1902,7 +1901,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
|
||||
byte[][] tuple = new byte[18][0];
|
||||
|
||||
// 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) {
|
||||
dr.next();
|
||||
tuple[11] = dr.getBytes(1);
|
||||
@ -1916,7 +1915,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
|
||||
tuple[2] = r.getBytes(2); // Table 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();
|
||||
String typname=dr.getString(1);
|
||||
dr.close();
|
||||
@ -2010,7 +2009,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
|
||||
f[7] = new Field(connection,"IS_GRANTABLE",iVarcharOid,32);
|
||||
|
||||
// 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()) {
|
||||
byte[][] tuple = new byte[8][0];
|
||||
tuple[0] = tuple[1]= "".getBytes();
|
||||
@ -2407,7 +2406,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
|
||||
*/
|
||||
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) {
|
||||
Field f[] = new Field[18];
|
||||
ResultSet r; // ResultSet for the SQL query that we need to do
|
||||
|
@ -8,7 +8,6 @@ package org.postgresql.jdbc2;
|
||||
import java.sql.*;
|
||||
import java.util.Vector;
|
||||
import org.postgresql.util.*;
|
||||
import org.postgresql.PGStatement;
|
||||
|
||||
/**
|
||||
* 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 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
|
||||
SQLWarning warnings = null; // The warnings chain.
|
||||
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)
|
||||
{
|
||||
super(c);
|
||||
connection = c;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,8 +90,7 @@ public class Statement extends PGStatement implements java.sql.Statement
|
||||
*/
|
||||
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)
|
||||
sql=connection.EscapeSQL(sql);
|
||||
deallocate();
|
||||
result = connection.ExecSQL(this, sql);
|
||||
|
||||
result = connection.ExecSQL(sql);
|
||||
return (result != null && ((org.postgresql.ResultSet)result).reallyResultSet());
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ public class Serialize
|
||||
|
||||
// Second check, the type must be a table
|
||||
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.next())
|
||||
status=true;
|
||||
@ -97,7 +97,7 @@ public class Serialize
|
||||
sb.append(oid);
|
||||
|
||||
DriverManager.println("store: "+sb.toString());
|
||||
ResultSet rs = conn.ExecSQL(null, sb.toString());
|
||||
ResultSet rs = conn.ExecSQL(sb.toString());
|
||||
if(rs!=null) {
|
||||
if(rs.next()) {
|
||||
for(int i=0;i<f.length;i++) {
|
||||
@ -189,7 +189,7 @@ public class Serialize
|
||||
}
|
||||
|
||||
DriverManager.println("store: "+sb.toString());
|
||||
ResultSet rs = conn.ExecSQL(null, sb.toString());
|
||||
ResultSet rs = conn.ExecSQL(sb.toString());
|
||||
if(rs!=null) {
|
||||
rs.close();
|
||||
}
|
||||
@ -236,7 +236,7 @@ public class Serialize
|
||||
// See if the table exists
|
||||
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()) {
|
||||
DriverManager.println("found "+rs.getString(1));
|
||||
// No entries returned, so the table doesn't exist
|
||||
@ -277,7 +277,7 @@ public class Serialize
|
||||
|
||||
// Now create the table
|
||||
DriverManager.println("Serialize.create:"+sb);
|
||||
con.ExecSQL(null, sb.toString());
|
||||
con.ExecSQL(sb.toString());
|
||||
rs.close();
|
||||
} else {
|
||||
DriverManager.println("Serialize.create: table "+tableName+" exists, skipping");
|
||||
|
Loading…
Reference in New Issue
Block a user