Skip to content
Snippets Groups Projects
Commit 45b5d792 authored by Peter Mount's avatar Peter Mount
Browse files

Thu Jan 18 12:24:00 GMT 2001 peter@retep.org.uk

        - These methods in org.postgresql.jdbc2.ResultSet are now implemented:
            getBigDecimal(int) ie: without a scale (why did this get missed?)
            getBlob(int)
            getCharacterStream(int)
            getConcurrency()
            getDate(int,Calendar)
            getFetchDirection()
            getFetchSize()
            getTime(int,Calendar)
            getTimestamp(int,Calendar)
            getType()
          NB: Where int represents the column name, the associated version
              taking a String were already implemented by calling the int
              version.
        - These methods no longer throw the not implemented but the new noupdate
          error. This is in preparation for the Updateable ResultSet support
          which will overide these methods by extending the existing class to
          implement that functionality, but needed to show something other than
          notimplemented:
            cancelRowUpdates()
            deleteRow()
        - Added new error message into errors.properties "postgresql.noupdate"
          This is used by jdbc2.ResultSet when an update method is called and
          the ResultSet is not updateable. A new method notUpdateable() has been
          added to that class to throw this exception, keeping the binary size
          down.
        - Added new error message into errors.properties "postgresql.psqlnotimp"
          This is used instead of unimplemented when it's a feature in the
          backend that is preventing this method from being implemented.
        - Removed getKeysetSize() as its not part of the ResultSet API

Thu Jan 18 09:46:00 GMT 2001 peter@retep.org.uk
        - Applied modified patch from Richard Bullington-McGuire
          <rbulling@microstate.com>. I had to modify it as some of the code
          patched now exists in different classes, and some of it actually
          patched obsolete code.

Wed Jan 17 10:19:00 GMT 2001 peter@retep.org.uk
        - Updated Implementation to include both ANT & JBuilder
        - Updated README to reflect the changes since 7.0
	- Created jdbc.jpr file which allows JBuilder to be used to edit the
          source. JBuilder _CAN_NOT_ be used to compile. You must use ANT for
          that. It's only to allow JBuilders syntax checking to improve the
          drivers source. Refer to Implementation for more details
parent 89ac6439
No related branches found
No related tags found
No related merge requests found
package org.postgresql.core;
/**
* 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 SimpleObjectPool implements ObjectPool
{
// This was originally in PG_Stream but moved out to fix the major problem
// where more than one query (usually all the time) overwrote the results
// of another query.
int cursize = 0;
int maxsize = 16;
Object arr[] = new Object[maxsize];
/**
* Adds an object to the pool
* @param o 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;
}
/**
* Removes the top object from the pool
* @return Object from the top.
*/
public Object remove(){
return arr[--cursize];
}
/**
* Removes the given object from the pool
* @param o Object to remove
*/
public void remove(Object o) {
int p=0;
while(p<cursize && !arr[p].equals(o))
p++;
if(arr[p].equals(o)) {
// This should be ok as there should be no overlap conflict
System.arraycopy(arr,p+1,arr,p,cursize-p);
cursize--;
}
}
/**
* @return true if the pool is empty
*/
public boolean isEmpty(){
return cursize == 0;
}
/**
* @return the number of objects in the pool
*/
public int size(){
return cursize;
}
/**
* Adds all objects in one pool to this one
* @param pool The pool to take the objects from
*/
public void addAll(ObjectPool p){
SimpleObjectPool pool = (SimpleObjectPool)p;
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;
}
/**
* Clears the pool of all objects
*/
public void clear(){
cursize = 0;
}
}
......@@ -35,6 +35,8 @@ postgresql.geo.point:Conversion of point failed - {0}
postgresql.jvm.version:The postgresql.jar file does not contain the correct JDBC classes for this JVM. Try rebuilding. If that fails, try forcing the version supplying it to the command line using the argument -Djava.version=1.1 or -Djava.version=1.2\nException thrown was {0}
postgresql.lo.init:failed to initialise LargeObject API
postgresql.money:conversion of money failed - {0}.
postgresql.noupdate:This ResultSet is not updateable
postgresql.psqlnotimp:The backend currently does not support this feature.
postgresql.prep.is:InputStream as parameter not supported
postgresql.prep.param:No value specified for parameter {0}.
postgresql.prep.range:Parameter index out of range.
......
......@@ -266,6 +266,8 @@ public class Statement implements java.sql.Statement
*/
public boolean execute(String sql) throws SQLException
{
if(escapeProcessing)
sql=connection.EscapeSQL(sql);
result = connection.ExecSQL(sql);
return (result != null && ((org.postgresql.ResultSet)result).reallyResultSet());
}
......
......@@ -888,12 +888,14 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
public void cancelRowUpdates() throws SQLException
{
throw org.postgresql.Driver.notImplemented();
// only sub-classes implement CONCUR_UPDATEABLE
notUpdateable();
}
public void deleteRow() throws SQLException
{
throw org.postgresql.Driver.notImplemented();
// only sub-classes implement CONCUR_UPDATEABLE
notUpdateable();
}
public boolean first() throws SQLException
......@@ -917,7 +919,11 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
public java.math.BigDecimal getBigDecimal(int columnIndex) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
try {
return new BigDecimal(getDouble(columnIndex));
} catch(NumberFormatException nfe) {
throw new PSQLException("postgresql.res.badbigdec",nfe.toString());
}
}
public java.math.BigDecimal getBigDecimal(String columnName) throws SQLException
......@@ -942,7 +948,15 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
public java.io.Reader getCharacterStream(int i) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
// New in 7.1
try {
String encoding = connection.getEncoding();
if(encoding==null)
return new InputStreamReader(getBinaryStream(i));
return new InputStreamReader(getBinaryStream(i),encoding);
} catch (UnsupportedEncodingException unse) {
throw new PSQLException("postgresql.res.encoding", unse);
}
}
public Clob getClob(String columnName) throws SQLException
......@@ -957,22 +971,34 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
public int getConcurrency() throws SQLException
{
throw org.postgresql.Driver.notImplemented();
// New in 7.1 - The standard ResultSet class will now return
// CONCUR_READ_ONLY. A sub-class will overide this if the query was
// updateable.
return CONCUR_READ_ONLY;
}
public java.sql.Date getDate(int i,java.util.Calendar cal) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
// new in 7.1: If I read the specs, this should use cal only if we don't
// store the timezone, and if we do, then act just like getDate()?
// for now...
return getDate(i);
}
public Time getTime(int i,java.util.Calendar cal) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
// new in 7.1: If I read the specs, this should use cal only if we don't
// store the timezone, and if we do, then act just like getTime()?
// for now...
return getTime(i);
}
public Timestamp getTimestamp(int i,java.util.Calendar cal) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
// new in 7.1: If I read the specs, this should use cal only if we don't
// store the timezone, and if we do, then act just like getDate()?
// for now...
return getTimestamp(i);
}
public java.sql.Date getDate(String c,java.util.Calendar cal) throws SQLException
......@@ -992,17 +1018,16 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
public int getFetchDirection() throws SQLException
{
throw org.postgresql.Driver.notImplemented();
// new in 7.1: PostgreSQL normally sends rows first->last
return FETCH_FORWARD;
}
public int getFetchSize() throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
public int getKeysetSize() throws SQLException
{
throw org.postgresql.Driver.notImplemented();
// new in 7.1: In this implementation we return the entire result set, so
// here return the number of rows we have. Sub-classes can return a proper
// value
return rows.size();
}
public Object getObject(String columnName,java.util.Map map) throws SQLException
......@@ -1010,9 +1035,23 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
return getObject(findColumn(columnName),map);
}
/**
* This checks against map for the type of column i, and if found returns
* an object based on that mapping. The class must implement the SQLData
* interface.
*/
public Object getObject(int i,java.util.Map map) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
/* In preparation
SQLInput s = new PSQLInput(this,i);
String t = getTypeName(i);
SQLData o = (SQLData) map.get(t);
// If the type is not in the map, then pass to the existing code
if(o==null)
return getObject(i);
o.readSQL(s,t);
return o;
*/throw org.postgresql.Driver.notImplemented();
}
public Ref getRef(String columnName) throws SQLException
......@@ -1022,7 +1061,8 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
public Ref getRef(int i) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
// new in 7.1: The backend doesn't yet have SQL3 REF types
throw new PSQLException("postgresql.psqlnotimp");
}
public int getRow() throws SQLException
......@@ -1033,12 +1073,15 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
// This one needs some thought, as not all ResultSets come from a statement
public java.sql.Statement getStatement() throws SQLException
{
throw org.postgresql.Driver.notImplemented();
return statement;
}
public int getType() throws SQLException
{
throw org.postgresql.Driver.notImplemented();
// New in 7.1. This implementation allows scrolling but is not able to
// see any changes. Sub-classes may overide this to return a more
// meaningful result.
return TYPE_SCROLL_INSENSITIVE;
}
public void insertRow() throws SQLException
......@@ -1352,5 +1395,20 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
updateTimestamp(findColumn(columnName),x);
}
// helper method. Throws an SQLException when an update is not possible
public void notUpdateable() throws SQLException
{
throw new PSQLException("postgresql.noupdate");
}
/**
* This is called by Statement to register itself with this statement.
* It's used currently by getStatement() but may also with the new core
* package.
*/
public void setStatement(org.postgresql.Statement statement) {
this.statement=statement;
}
}
......@@ -83,7 +83,7 @@ public class PSQLException extends SQLException
}
// Expand any arguments
if(args!=null)
if(args!=null && message != null)
message = MessageFormat.format(message,args);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment