mirror of
https://github.com/postgres/postgres.git
synced 2025-07-18 17:42:25 +03:00
Some more including the patch to DatabaseMetaData backed out by Bruce.
Tue Feb 13 16:33:00 GMT 2001 peter@retep.org.uk - More TestCases implemented. Refined the test suite api's. - Removed need for SimpleDateFormat in ResultSet.getDate() improving performance. - Rewrote ResultSet.getTime() so that it uses JDK api's better. Tue Feb 13 10:25:00 GMT 2001 peter@retep.org.uk - Added MiscTest to hold reported problems from users. - Fixed PGMoney. - JBuilder4/JDBCExplorer now works with Money fields. Patched Field & ResultSet (lots of methods) for this one. Also changed cash/money to return type DOUBLE not DECIMAL. This broke JBuilder as zero scale BigDecimal's can't have decimal places! - When a Statement is reused, the previous ResultSet is now closed. - Removed deprecated call in ResultSet.getTime() Thu Feb 08 18:53:00 GMT 2001 peter@retep.org.uk - Changed a couple of settings in DatabaseMetaData where 7.1 now supports those features - Implemented the DatabaseMetaData TestCase. Wed Feb 07 18:06:00 GMT 2001 peter@retep.org.uk - Added comment to Connection.isClosed() explaining why we deviate from the JDBC2 specification. - Fixed bug where the Isolation Level is lost while in autocommit mode. - Fixed bug where several calls to getTransactionIsolationLevel() returned the first call's result.
This commit is contained in:
@ -17,7 +17,7 @@ import org.postgresql.largeobject.*;
|
||||
import org.postgresql.util.*;
|
||||
|
||||
/**
|
||||
* $Id: Connection.java,v 1.6 2001/01/31 08:26:02 peter Exp $
|
||||
* $Id: Connection.java,v 1.7 2001/02/13 16:39:02 peter Exp $
|
||||
*
|
||||
* A Connection represents a session with a specific database. Within the
|
||||
* context of a Connection, SQL statements are executed and results are
|
||||
@ -39,8 +39,16 @@ public class Connection extends org.postgresql.Connection implements java.sql.Co
|
||||
// This is a cache of the DatabaseMetaData instance for this connection
|
||||
protected DatabaseMetaData metadata;
|
||||
|
||||
/**
|
||||
* The current type mappings
|
||||
*/
|
||||
protected java.util.Map typemap;
|
||||
|
||||
/**
|
||||
* Cache of the current isolation level
|
||||
*/
|
||||
protected int isolationLevel = java.sql.Connection.TRANSACTION_READ_COMMITTED;
|
||||
|
||||
/**
|
||||
* SQL statements without parameters are normally executed using
|
||||
* Statement objects. If the same SQL statement is executed many
|
||||
@ -179,8 +187,10 @@ public class Connection extends org.postgresql.Connection implements java.sql.Co
|
||||
return;
|
||||
if (autoCommit)
|
||||
ExecSQL("end");
|
||||
else
|
||||
else {
|
||||
ExecSQL("begin");
|
||||
doIsolationLevel();
|
||||
}
|
||||
this.autoCommit = autoCommit;
|
||||
}
|
||||
|
||||
@ -213,6 +223,7 @@ public class Connection extends org.postgresql.Connection implements java.sql.Co
|
||||
ExecSQL("commit");
|
||||
autoCommit = true;
|
||||
ExecSQL("begin");
|
||||
doIsolationLevel();
|
||||
autoCommit = false;
|
||||
}
|
||||
|
||||
@ -231,6 +242,7 @@ public class Connection extends org.postgresql.Connection implements java.sql.Co
|
||||
ExecSQL("rollback");
|
||||
autoCommit = true;
|
||||
ExecSQL("begin");
|
||||
doIsolationLevel();
|
||||
autoCommit = false;
|
||||
}
|
||||
|
||||
@ -258,7 +270,18 @@ public class Connection extends org.postgresql.Connection implements java.sql.Co
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests to see if a Connection is closed
|
||||
* Tests to see if a Connection is closed.
|
||||
*
|
||||
* Peter Feb 7 2000: Now I've discovered that this doesn't actually obey the
|
||||
* specifications. Under JDBC2.1, this should only be valid _after_ close()
|
||||
* has been called. It's result is not guraranteed to be valid before, and
|
||||
* client code should not use it to see if a connection is open. The spec says
|
||||
* that the client should monitor the SQLExceptions thrown when their queries
|
||||
* fail because the connection is dead.
|
||||
*
|
||||
* I don't like this definition. As it doesn't hurt breaking it here, our
|
||||
* isClosed() implementation does test the connection, so for PostgreSQL, you
|
||||
* can rely on isClosed() returning a valid result.
|
||||
*
|
||||
* @return the status of the connection
|
||||
* @exception SQLException (why?)
|
||||
@ -370,10 +393,20 @@ public class Connection extends org.postgresql.Connection implements java.sql.Co
|
||||
* @see java.sql.DatabaseMetaData#supportsTransactionIsolationLevel
|
||||
*/
|
||||
public void setTransactionIsolation(int level) throws SQLException
|
||||
{
|
||||
isolationLevel = level;
|
||||
doIsolationLevel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method used by setTransactionIsolation(), commit(), rollback()
|
||||
* and setAutoCommit(). This sets the current isolation level.
|
||||
*/
|
||||
private void doIsolationLevel() throws SQLException
|
||||
{
|
||||
String q = "SET TRANSACTION ISOLATION LEVEL";
|
||||
|
||||
switch(level) {
|
||||
switch(isolationLevel) {
|
||||
|
||||
case java.sql.Connection.TRANSACTION_READ_COMMITTED:
|
||||
ExecSQL(q + " READ COMMITTED");
|
||||
@ -384,7 +417,7 @@ public class Connection extends org.postgresql.Connection implements java.sql.Co
|
||||
return;
|
||||
|
||||
default:
|
||||
throw new PSQLException("postgresql.con.isolevel",new Integer(level));
|
||||
throw new PSQLException("postgresql.con.isolevel",new Integer(isolationLevel));
|
||||
}
|
||||
}
|
||||
|
||||
@ -396,14 +429,17 @@ public class Connection extends org.postgresql.Connection implements java.sql.Co
|
||||
*/
|
||||
public int getTransactionIsolation() throws SQLException
|
||||
{
|
||||
clearWarnings();
|
||||
ExecSQL("show xactisolevel");
|
||||
|
||||
SQLWarning w = getWarnings();
|
||||
if (w != null) {
|
||||
if (w.getMessage().indexOf("READ COMMITTED") != -1) return java.sql.Connection.TRANSACTION_READ_COMMITTED; else
|
||||
if (w.getMessage().indexOf("READ UNCOMMITTED") != -1) return java.sql.Connection.TRANSACTION_READ_UNCOMMITTED; else
|
||||
if (w.getMessage().indexOf("REPEATABLE READ") != -1) return java.sql.Connection.TRANSACTION_REPEATABLE_READ; else
|
||||
if (w.getMessage().indexOf("SERIALIZABLE") != -1) return java.sql.Connection.TRANSACTION_SERIALIZABLE;
|
||||
String m = w.getMessage();
|
||||
clearWarnings();
|
||||
if (m.indexOf("READ COMMITTED") != -1) return java.sql.Connection.TRANSACTION_READ_COMMITTED; else
|
||||
if (m.indexOf("READ UNCOMMITTED") != -1) return java.sql.Connection.TRANSACTION_READ_UNCOMMITTED; else
|
||||
if (m.indexOf("REPEATABLE READ") != -1) return java.sql.Connection.TRANSACTION_REPEATABLE_READ; else
|
||||
if (m.indexOf("SERIALIZABLE") != -1) return java.sql.Connection.TRANSACTION_SERIALIZABLE;
|
||||
}
|
||||
return java.sql.Connection.TRANSACTION_READ_COMMITTED;
|
||||
}
|
||||
|
@ -736,7 +736,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
|
||||
*/
|
||||
public boolean supportsOuterJoins() throws SQLException
|
||||
{
|
||||
return false;
|
||||
return true; // yes 7.1 does
|
||||
}
|
||||
|
||||
/**
|
||||
@ -748,7 +748,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
|
||||
*/
|
||||
public boolean supportsFullOuterJoins() throws SQLException
|
||||
{
|
||||
return false;
|
||||
return true; // yes in 7.1
|
||||
}
|
||||
|
||||
/**
|
||||
@ -760,7 +760,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
|
||||
*/
|
||||
public boolean supportsLimitedOuterJoins() throws SQLException
|
||||
{
|
||||
return false;
|
||||
return true; // yes in 7.1
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1009,7 +1009,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
|
||||
*/
|
||||
public boolean supportsUnion() throws SQLException
|
||||
{
|
||||
return false;
|
||||
return true; // 7.0?
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1617,8 +1617,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
|
||||
* </ol>
|
||||
*
|
||||
* <p>The valid values for the types parameter are:
|
||||
* "TABLE", "INDEX", "LARGE OBJECT", "SEQUENCE", "SYSTEM TABLE" and
|
||||
* "SYSTEM INDEX"
|
||||
* "TABLE", "INDEX", "SEQUENCE", "SYSTEM TABLE" and "SYSTEM INDEX"
|
||||
*
|
||||
* @param catalog a catalog name; For org.postgresql, this is ignored, and
|
||||
* should be set to null
|
||||
@ -1722,9 +1721,8 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
|
||||
// IMPORTANT: the query must be enclosed in ( )
|
||||
private static final String getTableTypes[][] = {
|
||||
{"TABLE", "(relkind='r' and relhasrules='f' and relname !~ '^pg_' and relname !~ '^xinv')"},
|
||||
{"VIEW", "(relkind='v' and relname !~ '^pg_' and relname !~ '^xinv')"},
|
||||
{"INDEX", "(relkind='i' and relname !~ '^pg_' and relname !~ '^xinx')"},
|
||||
{"LARGE OBJECT", "(relkind='r' and relname ~ '^xinv')"},
|
||||
{"VIEW", "(relkind='v' and relname !~ '^pg_')"},
|
||||
{"INDEX", "(relkind='i' and relname !~ '^pg_')"},
|
||||
{"SEQUENCE", "(relkind='S' and relname !~ '^pg_')"},
|
||||
{"SYSTEM TABLE", "(relkind='r' and relname ~ '^pg_')"},
|
||||
{"SYSTEM INDEX", "(relkind='i' and relname ~ '^pg_')"}
|
||||
|
@ -356,6 +356,10 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
|
||||
StringBuffer strBuf = new StringBuffer("'");
|
||||
strBuf.append(df.format(x)).append('.').append(x.getNanos()/10000000).append("+00'");
|
||||
set(parameterIndex, strBuf.toString());
|
||||
|
||||
// The above works, but so does the following. I'm leaving the above in, but this seems
|
||||
// to be identical. Pays to read the docs ;-)
|
||||
//set(parameterIndex,"'"+x.toString()+"'");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -131,7 +131,10 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
|
||||
public void close() throws SQLException
|
||||
{
|
||||
//release resources held (memory for tuples)
|
||||
rows.setSize(0);
|
||||
if(rows!=null) {
|
||||
rows.setSize(0);
|
||||
rows=null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -157,16 +160,13 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
|
||||
*/
|
||||
public String getString(int columnIndex) throws SQLException
|
||||
{
|
||||
//byte[] bytes = getBytes(columnIndex);
|
||||
//
|
||||
//if (bytes == null)
|
||||
//return null;
|
||||
//return new String(bytes);
|
||||
if (columnIndex < 1 || columnIndex > fields.length)
|
||||
throw new PSQLException("postgresql.res.colrange");
|
||||
|
||||
wasNullFlag = (this_row[columnIndex - 1] == null);
|
||||
if(wasNullFlag)
|
||||
return null;
|
||||
|
||||
String encoding = connection.getEncoding();
|
||||
if (encoding == null)
|
||||
return new String(this_row[columnIndex - 1]);
|
||||
@ -230,7 +230,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
|
||||
*/
|
||||
public short getShort(int columnIndex) throws SQLException
|
||||
{
|
||||
String s = getString(columnIndex);
|
||||
String s = getFixedString(columnIndex);
|
||||
|
||||
if (s != null)
|
||||
{
|
||||
@ -253,7 +253,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
|
||||
*/
|
||||
public int getInt(int columnIndex) throws SQLException
|
||||
{
|
||||
String s = getString(columnIndex);
|
||||
String s = getFixedString(columnIndex);
|
||||
|
||||
if (s != null)
|
||||
{
|
||||
@ -276,7 +276,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
|
||||
*/
|
||||
public long getLong(int columnIndex) throws SQLException
|
||||
{
|
||||
String s = getString(columnIndex);
|
||||
String s = getFixedString(columnIndex);
|
||||
|
||||
if (s != null)
|
||||
{
|
||||
@ -299,7 +299,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
|
||||
*/
|
||||
public float getFloat(int columnIndex) throws SQLException
|
||||
{
|
||||
String s = getString(columnIndex);
|
||||
String s = getFixedString(columnIndex);
|
||||
|
||||
if (s != null)
|
||||
{
|
||||
@ -322,7 +322,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
|
||||
*/
|
||||
public double getDouble(int columnIndex) throws SQLException
|
||||
{
|
||||
String s = getString(columnIndex);
|
||||
String s = getFixedString(columnIndex);
|
||||
|
||||
if (s != null)
|
||||
{
|
||||
@ -348,14 +348,14 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
|
||||
*/
|
||||
public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException
|
||||
{
|
||||
String s = getString(columnIndex);
|
||||
String s = getFixedString(columnIndex);
|
||||
BigDecimal val;
|
||||
|
||||
if (s != null)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
val = new BigDecimal(s);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new PSQLException ("postgresql.res.badbigdec",s);
|
||||
@ -418,12 +418,8 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
|
||||
String s = getString(columnIndex);
|
||||
if(s==null)
|
||||
return null;
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
||||
try {
|
||||
return new java.sql.Date(df.parse(s).getTime());
|
||||
} catch (ParseException e) {
|
||||
throw new PSQLException("postgresql.res.baddate",new Integer(e.getErrorOffset()),s);
|
||||
}
|
||||
|
||||
return java.sql.Date.valueOf(s);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -438,21 +434,10 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
|
||||
{
|
||||
String s = getString(columnIndex);
|
||||
|
||||
if (s != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (s.length() != 5 && s.length() != 8)
|
||||
throw new NumberFormatException("Wrong Length!");
|
||||
int hr = Integer.parseInt(s.substring(0,2));
|
||||
int min = Integer.parseInt(s.substring(3,5));
|
||||
int sec = (s.length() == 5) ? 0 : Integer.parseInt(s.substring(6));
|
||||
return new Time(hr, min, sec);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new PSQLException ("postgresql.res.badtime",s);
|
||||
}
|
||||
}
|
||||
return null; // SQL NULL
|
||||
if(s==null)
|
||||
return null; // SQL NULL
|
||||
|
||||
return java.sql.Time.valueOf(s);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -945,11 +930,8 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
|
||||
|
||||
public java.math.BigDecimal getBigDecimal(int columnIndex) throws SQLException
|
||||
{
|
||||
try {
|
||||
return new BigDecimal(getDouble(columnIndex));
|
||||
} catch(NumberFormatException nfe) {
|
||||
throw new PSQLException("postgresql.res.badbigdec",nfe.toString());
|
||||
}
|
||||
// Now must call BigDecimal with a scale otherwise JBuilder barfs
|
||||
return getBigDecimal(columnIndex,0);
|
||||
}
|
||||
|
||||
public java.math.BigDecimal getBigDecimal(String columnName) throws SQLException
|
||||
|
@ -281,6 +281,15 @@ public class Statement extends org.postgresql.Statement implements java.sql.Stat
|
||||
if(escapeProcessing)
|
||||
sql=connection.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 = connection.ExecSQL(sql,this);
|
||||
|
||||
|
Reference in New Issue
Block a user