1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-21 16:02:15 +03:00

Some more updates...

Fri Feb 17 15:11:00 GMT 2001 peter@retep.org.uk
        - Reduced the object overhead in PreparedStatement by reusing the same
          StringBuffer object throughout. Similarly SimpleDateStamp's are alse
          reused in a thread save manner.
        - Implemented in PreparedStatement: setNull(), setDate/Time/Timestamp
          using Calendar, setBlob(), setCharacterStream()
        - Clob's are now implemented in ResultSet & PreparedStatement!
        - Implemented a lot of DatabaseMetaData & ResultSetMetaData methods.
          We have about 18 unimplemented methods left in JDBC2 at the current
          time.
This commit is contained in:
Peter Mount
2001-02-16 16:45:01 +00:00
parent 016f0eed24
commit cdbd27cb23
7 changed files with 348 additions and 124 deletions

View File

@ -61,6 +61,11 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
{
protected org.postgresql.jdbc2.Statement statement;
/**
* StringBuffer used by getTimestamp
*/
private StringBuffer sbuf;
/**
* Create a new ResultSet - Note that we create ResultSets to
* represent the results of everything.
@ -467,43 +472,53 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
//and java expects three digits if fractional seconds are present instead of two for postgres
//so this code strips off timezone info and adds on the GMT+/-...
//as well as adds a third digit for partial seconds if necessary
StringBuffer strBuf = new StringBuffer(s);
char sub = strBuf.charAt(strBuf.length()-3);
if (sub == '+' || sub == '-') {
strBuf.setLength(strBuf.length()-3);
if (subsecond) {
strBuf = strBuf.append('0').append("GMT").append(s.substring(s.length()-3, s.length())).append(":00");
} else {
strBuf = strBuf.append("GMT").append(s.substring(s.length()-3, s.length())).append(":00");
synchronized(this) {
// We must be synchronized here incase more theads access the ResultSet
// bad practice but possible. Anyhow this is to protect sbuf and
// SimpleDateFormat objects
// First time?
if(sbuf==null)
sbuf = new StringBuffer();
sbuf.setLength(0);
sbuf.append(s);
char sub = sbuf.charAt(sbuf.length()-3);
if (sub == '+' || sub == '-') {
sbuf.setLength(sbuf.length()-3);
if (subsecond) {
sbuf.append('0').append("GMT").append(s.substring(s.length()-3)).append(":00");
} else {
sbuf.append("GMT").append(s.substring(s.length()-3)).append(":00");
}
} else if (subsecond) {
sbuf.append('0');
}
} else if (subsecond) {
strBuf = strBuf.append('0');
}
s = strBuf.toString();
// could optimize this a tad to remove too many object creations...
SimpleDateFormat df = null;
SimpleDateFormat df = null;
if (s.length()>23 && subsecond) {
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSzzzzzzzzz");
} else if (s.length()>23 && !subsecond) {
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:sszzzzzzzzz");
} else if (s.length()>10 && subsecond) {
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
} else if (s.length()>10 && !subsecond) {
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
} else {
df = new SimpleDateFormat("yyyy-MM-dd");
}
if (s.length()>23 && subsecond) {
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSzzzzzzzzz");
} else if (s.length()>23 && !subsecond) {
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:sszzzzzzzzz");
} else if (s.length()>10 && subsecond) {
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
} else if (s.length()>10 && !subsecond) {
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
} else {
df = new SimpleDateFormat("yyyy-MM-dd");
}
try {
return new Timestamp(df.parse(s).getTime());
} catch(ParseException e) {
throw new PSQLException("postgresql.res.badtimestamp",new Integer(e.getErrorOffset()),s);
try {
return new Timestamp(df.parse(sbuf.toString()).getTime());
} catch(ParseException e) {
throw new PSQLException("postgresql.res.badtimestamp",new Integer(e.getErrorOffset()),s);
}
}
}
/**
* A column value can be retrieved as a stream of ASCII characters
* and then read in chunks from the stream. This method is
@ -967,14 +982,20 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
}
}
/**
* New in 7.1
*/
public Clob getClob(String columnName) throws SQLException
{
return getClob(findColumn(columnName));
}
/**
* New in 7.1
*/
public Clob getClob(int i) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
return new org.postgresql.largeobject.PGclob(connection,getInt(i));
}
public int getConcurrency() throws SQLException
@ -1192,11 +1213,6 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
throw org.postgresql.Driver.notImplemented();
}
//public void setKeysetSize(int keys) throws SQLException
//{
//throw org.postgresql.Driver.notImplemented();
//}
public void updateAsciiStream(int columnIndex,
java.io.InputStream x,
int length