import org.postgresql.core.*;
/*
- * $Id: Connection.java,v 1.36 2001/11/19 22:33:37 momjian Exp $
+ * $Id: Connection.java,v 1.37 2001/11/19 23:16:45 momjian Exp $
*
* This abstract class is used by org.postgresql.Driver to open either the JDBC1 or
* JDBC2 versions of the Connection class.
this_url = url;
PG_DATABASE = database;
PG_USER = info.getProperty("user");
- PG_PASSWORD = info.getProperty("password","");
+ PG_PASSWORD = info.getProperty("password", "");
PG_PORT = port;
PG_HOST = host;
PG_STATUS = CONNECTION_BAD;
int beresp = pg_stream.ReceiveChar();
switch (beresp)
{
- case 'E':
- // An error occured, so pass the error message to the
- // user.
- //
- // The most common one to be thrown here is:
- // "User authentication failed"
- //
- throw new SQLException(pg_stream.ReceiveString(encoding));
-
- case 'R':
- // Get the type of request
- areq = pg_stream.ReceiveIntegerR(4);
-
- // Get the crypt password salt if there is one
- if (areq == AUTH_REQ_CRYPT)
- {
- byte[] rst = new byte[2];
- rst[0] = (byte)pg_stream.ReceiveChar();
- rst[1] = (byte)pg_stream.ReceiveChar();
- salt = new String(rst, 0, 2);
- DriverManager.println("Crypt salt=" + salt);
- }
-
- // Or get the md5 password salt if there is one
- if (areq == AUTH_REQ_MD5)
- {
- byte[] rst = new byte[4];
- rst[0] = (byte)pg_stream.ReceiveChar();
- rst[1] = (byte)pg_stream.ReceiveChar();
- rst[2] = (byte)pg_stream.ReceiveChar();
- rst[3] = (byte)pg_stream.ReceiveChar();
- salt = new String(rst, 0, 4);
- DriverManager.println("MD5 salt=" + salt);
- }
-
- // now send the auth packet
- switch (areq)
- {
- case AUTH_REQ_OK:
- break;
-
- case AUTH_REQ_KRB4:
- DriverManager.println("postgresql: KRB4");
- throw new PSQLException("postgresql.con.kerb4");
-
- case AUTH_REQ_KRB5:
- DriverManager.println("postgresql: KRB5");
- throw new PSQLException("postgresql.con.kerb5");
-
- case AUTH_REQ_PASSWORD:
- DriverManager.println("postgresql: PASSWORD");
- pg_stream.SendInteger(5 + PG_PASSWORD.length(), 4);
- pg_stream.Send(PG_PASSWORD.getBytes());
- pg_stream.SendInteger(0, 1);
- pg_stream.flush();
- break;
-
- case AUTH_REQ_CRYPT:
- DriverManager.println("postgresql: CRYPT");
- String crypted = UnixCrypt.crypt(salt, PG_PASSWORD);
- pg_stream.SendInteger(5 + crypted.length(), 4);
- pg_stream.Send(crypted.getBytes());
- pg_stream.SendInteger(0, 1);
- pg_stream.flush();
- break;
-
- case AUTH_REQ_MD5:
- DriverManager.println("postgresql: MD5");
- byte[] digest = MD5Digest.encode(PG_USER, PG_PASSWORD, salt);
- pg_stream.SendInteger(5 + digest.length, 4);
- pg_stream.Send(digest);
- pg_stream.SendInteger(0, 1);
- pg_stream.flush();
+ case 'E':
+ // An error occured, so pass the error message to the
+ // user.
+ //
+ // The most common one to be thrown here is:
+ // "User authentication failed"
+ //
+ throw new SQLException(pg_stream.ReceiveString(encoding));
+
+ case 'R':
+ // Get the type of request
+ areq = pg_stream.ReceiveIntegerR(4);
+
+ // Get the crypt password salt if there is one
+ if (areq == AUTH_REQ_CRYPT)
+ {
+ byte[] rst = new byte[2];
+ rst[0] = (byte)pg_stream.ReceiveChar();
+ rst[1] = (byte)pg_stream.ReceiveChar();
+ salt = new String(rst, 0, 2);
+ DriverManager.println("Crypt salt=" + salt);
+ }
+
+ // Or get the md5 password salt if there is one
+ if (areq == AUTH_REQ_MD5)
+ {
+ byte[] rst = new byte[4];
+ rst[0] = (byte)pg_stream.ReceiveChar();
+ rst[1] = (byte)pg_stream.ReceiveChar();
+ rst[2] = (byte)pg_stream.ReceiveChar();
+ rst[3] = (byte)pg_stream.ReceiveChar();
+ salt = new String(rst, 0, 4);
+ DriverManager.println("MD5 salt=" + salt);
+ }
+
+ // now send the auth packet
+ switch (areq)
+ {
+ case AUTH_REQ_OK:
+ break;
+
+ case AUTH_REQ_KRB4:
+ DriverManager.println("postgresql: KRB4");
+ throw new PSQLException("postgresql.con.kerb4");
+
+ case AUTH_REQ_KRB5:
+ DriverManager.println("postgresql: KRB5");
+ throw new PSQLException("postgresql.con.kerb5");
+
+ case AUTH_REQ_PASSWORD:
+ DriverManager.println("postgresql: PASSWORD");
+ pg_stream.SendInteger(5 + PG_PASSWORD.length(), 4);
+ pg_stream.Send(PG_PASSWORD.getBytes());
+ pg_stream.SendInteger(0, 1);
+ pg_stream.flush();
+ break;
+
+ case AUTH_REQ_CRYPT:
+ DriverManager.println("postgresql: CRYPT");
+ String crypted = UnixCrypt.crypt(salt, PG_PASSWORD);
+ pg_stream.SendInteger(5 + crypted.length(), 4);
+ pg_stream.Send(crypted.getBytes());
+ pg_stream.SendInteger(0, 1);
+ pg_stream.flush();
+ break;
+
+ case AUTH_REQ_MD5:
+ DriverManager.println("postgresql: MD5");
+ byte[] digest = MD5Digest.encode(PG_USER, PG_PASSWORD, salt);
+ pg_stream.SendInteger(5 + digest.length, 4);
+ pg_stream.Send(digest);
+ pg_stream.SendInteger(0, 1);
+ pg_stream.flush();
+ break;
+
+ default:
+ throw new PSQLException("postgresql.con.auth", new Integer(areq));
+ }
break;
default:
- throw new PSQLException("postgresql.con.auth", new Integer(areq));
- }
- break;
-
- default:
- throw new PSQLException("postgresql.con.authfail");
+ throw new PSQLException("postgresql.con.authfail");
}
}
while (areq != AUTH_REQ_OK);
int beresp = pg_stream.ReceiveChar();
switch (beresp)
{
- case 'K':
- pid = pg_stream.ReceiveInteger(4);
- ckey = pg_stream.ReceiveInteger(4);
- break;
- case 'E':
- case 'N':
- throw new SQLException(pg_stream.ReceiveString(encoding));
- default:
- throw new PSQLException("postgresql.con.setup");
+ case 'K':
+ pid = pg_stream.ReceiveInteger(4);
+ ckey = pg_stream.ReceiveInteger(4);
+ break;
+ case 'E':
+ case 'N':
+ throw new SQLException(pg_stream.ReceiveString(encoding));
+ default:
+ throw new PSQLException("postgresql.con.setup");
}
// Expect ReadyForQuery packet
beresp = pg_stream.ReceiveChar();
switch (beresp)
{
- case 'Z':
- break;
- case 'E':
- case 'N':
- throw new SQLException(pg_stream.ReceiveString(encoding));
- default:
- throw new PSQLException("postgresql.con.setup");
+ case 'Z':
+ break;
+ case 'E':
+ case 'N':
+ throw new SQLException(pg_stream.ReceiveString(encoding));
+ default:
+ throw new PSQLException("postgresql.con.setup");
}
firstWarning = null;
isolationLevelSQL = "SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL ";
switch (isolationLevel)
{
- case java.sql.Connection.TRANSACTION_READ_COMMITTED:
- isolationLevelSQL += "READ COMMITTED";
- break;
- case java.sql.Connection.TRANSACTION_SERIALIZABLE:
- isolationLevelSQL += "SERIALIZABLE";
- break;
- default:
- throw new PSQLException("postgresql.con.isolevel",
- new Integer(isolationLevel));
+ case java.sql.Connection.TRANSACTION_READ_COMMITTED:
+ isolationLevelSQL += "READ COMMITTED";
+ break;
+ case java.sql.Connection.TRANSACTION_SERIALIZABLE:
+ isolationLevelSQL += "SERIALIZABLE";
+ break;
+ default:
+ throw new PSQLException("postgresql.con.isolevel",
+ new Integer(isolationLevel));
}
}
ExecSQL(isolationLevelSQL);
switch (isolationLevel)
{
- case java.sql.Connection.TRANSACTION_READ_COMMITTED:
- sb.append(" READ COMMITTED");
- break;
+ case java.sql.Connection.TRANSACTION_READ_COMMITTED:
+ sb.append(" READ COMMITTED");
+ break;
- case java.sql.Connection.TRANSACTION_SERIALIZABLE:
- sb.append(" SERIALIZABLE");
- break;
+ case java.sql.Connection.TRANSACTION_SERIALIZABLE:
+ sb.append(" SERIALIZABLE");
+ break;
- default:
- throw new PSQLException("postgresql.con.isolevel", new Integer(isolationLevel));
+ default:
+ throw new PSQLException("postgresql.con.isolevel", new Integer(isolationLevel));
}
return sb.toString();
}
}
return pgType;
}
-
}
/*
* This class provides information about the database as a whole.
*
- * $Id: DatabaseMetaData.java,v 1.39 2001/11/19 22:33:38 momjian Exp $
+ * $Id: DatabaseMetaData.java,v 1.40 2001/11/19 23:16:45 momjian Exp $
*
*
Many of the methods here return lists of information in ResultSets. You
* can use the normal ResultSet methods such as getString and getInt to
String relKind;
switch (r.getBytes(3)[0])
{
- case (byte) 'r':
- relKind = "TABLE";
- break;
- case (byte) 'i':
- relKind = "INDEX";
- break;
- case (byte) 'S':
- relKind = "SEQUENCE";
- break;
- case (byte) 'v':
- relKind = "VIEW";
- break;
- default:
- relKind = null;
+ case (byte) 'r':
+ relKind = "TABLE";
+ break;
+ case (byte) 'i':
+ relKind = "INDEX";
+ break;
+ case (byte) 'S':
+ relKind = "SEQUENCE";
+ break;
+ case (byte) 'v':
+ relKind = "VIEW";
+ break;
+ default:
+ relKind = null;
}
tuple[0] = null; // Catalog name
tuple[7] = null; // Buffer length
// Decimal digits = scale
- // From the source (see e.g. backend/utils/adt/numeric.c,
+ // From the source (see e.g. backend/utils/adt/numeric.c,
// function numeric()) the scale and precision can be calculated
// from the typmod value.
- if (typname.equals("numeric") || typname.equals("decimal"))
- {
- int attypmod = r.getInt(8);
- tuple[8] =
- Integer.toString((attypmod - VARHDRSZ) & 0xffff).getBytes();
+ if (typname.equals("numeric") || typname.equals("decimal"))
+ {
+ int attypmod = r.getInt(8);
+ tuple[8] =
+ Integer.toString((attypmod - VARHDRSZ) & 0xffff).getBytes();
}
else
- tuple[8] = "0".getBytes();
+ tuple[8] = "0".getBytes();
tuple[9] = "10".getBytes(); // Num Prec Radix - assume decimal
tuple[10] = Integer.toString(nullFlag.equals("f") ?
"a.attnum as KEY_SEQ," +
"ic.relname as PK_NAME " +
" FROM pg_class bc, pg_class ic, pg_index i, pg_attribute a" +
- " WHERE bc.relkind = 'r' " + // -- not indices
+ " WHERE bc.relkind = 'r' " + // -- not indices
" and upper(bc.relname) = upper('" + table + "')" +
" and i.indrelid = bc.oid" +
" and i.indexrelid = ic.oid" +
private java.sql.ResultSet getImportedExportedKeys(String catalog, String schema, String primaryTable, String foreignTable) throws SQLException
{
- Field f[]=new Field[14];
-
- f[0]=new Field(connection, "PKTABLE_CAT", iVarcharOid, 32);
- f[1]=new Field(connection, "PKTABLE_SCHEM", iVarcharOid, 32);
- f[2]=new Field(connection, "PKTABLE_NAME", iVarcharOid, 32);
- f[3]=new Field(connection, "PKCOLUMN_NAME", iVarcharOid, 32);
- f[4]=new Field(connection, "FKTABLE_CAT", iVarcharOid, 32);
- f[5]=new Field(connection, "FKTABLE_SCHEM", iVarcharOid, 32);
- f[6]=new Field(connection, "FKTABLE_NAME", iVarcharOid, 32);
- f[7]=new Field(connection, "FKCOLUMN_NAME", iVarcharOid, 32);
- f[8]=new Field(connection, "KEY_SEQ", iInt2Oid, 2);
- f[9]=new Field(connection, "UPDATE_RULE", iInt2Oid, 2);
- f[10]=new Field(connection, "DELETE_RULE", iInt2Oid, 2);
- f[11]=new Field(connection, "FK_NAME", iVarcharOid, 32);
- f[12]=new Field(connection, "PK_NAME", iVarcharOid, 32);
- f[13]=new Field(connection, "DEFERRABILITY", iInt2Oid, 2);
+ Field f[] = new Field[14];
+
+ f[0] = new Field(connection, "PKTABLE_CAT", iVarcharOid, 32);
+ f[1] = new Field(connection, "PKTABLE_SCHEM", iVarcharOid, 32);
+ f[2] = new Field(connection, "PKTABLE_NAME", iVarcharOid, 32);
+ f[3] = new Field(connection, "PKCOLUMN_NAME", iVarcharOid, 32);
+ f[4] = new Field(connection, "FKTABLE_CAT", iVarcharOid, 32);
+ f[5] = new Field(connection, "FKTABLE_SCHEM", iVarcharOid, 32);
+ f[6] = new Field(connection, "FKTABLE_NAME", iVarcharOid, 32);
+ f[7] = new Field(connection, "FKCOLUMN_NAME", iVarcharOid, 32);
+ f[8] = new Field(connection, "KEY_SEQ", iInt2Oid, 2);
+ f[9] = new Field(connection, "UPDATE_RULE", iInt2Oid, 2);
+ f[10] = new Field(connection, "DELETE_RULE", iInt2Oid, 2);
+ f[11] = new Field(connection, "FK_NAME", iVarcharOid, 32);
+ f[12] = new Field(connection, "PK_NAME", iVarcharOid, 32);
+ f[13] = new Field(connection, "DEFERRABILITY", iInt2Oid, 2);
java.sql.ResultSet rs = connection.ExecSQL("SELECT c.relname,c2.relname,"
- + "t.tgconstrname,ic.relname,"
- + "t.tgdeferrable,t.tginitdeferred,"
- + "t.tgnargs,t.tgargs,p.proname "
- + "FROM pg_trigger t,pg_class c,pg_class c2,"
- + "pg_class ic,pg_proc p, pg_index i "
- + "WHERE t.tgrelid=c.oid AND t.tgconstrrelid=c2.oid "
- + "AND t.tgfoid=p.oid AND tgisconstraint "
- + ((primaryTable!=null) ? "AND c2.relname='"+primaryTable+"' " : "")
- + ((foreignTable!=null) ? "AND c.relname='"+foreignTable+"' " : "")
- + "AND i.indrelid=c.oid "
- + "AND i.indexrelid=ic.oid AND i.indisprimary "
- + "ORDER BY c.relname,c2.relname"
- );
+ + "t.tgconstrname,ic.relname,"
+ + "t.tgdeferrable,t.tginitdeferred,"
+ + "t.tgnargs,t.tgargs,p.proname "
+ + "FROM pg_trigger t,pg_class c,pg_class c2,"
+ + "pg_class ic,pg_proc p, pg_index i "
+ + "WHERE t.tgrelid=c.oid AND t.tgconstrrelid=c2.oid "
+ + "AND t.tgfoid=p.oid AND tgisconstraint "
+ + ((primaryTable != null) ? "AND c2.relname='" + primaryTable + "' " : "")
+ + ((foreignTable != null) ? "AND c.relname='" + foreignTable + "' " : "")
+ + "AND i.indrelid=c.oid "
+ + "AND i.indexrelid=ic.oid AND i.indisprimary "
+ + "ORDER BY c.relname,c2.relname"
+ );
Vector tuples = new Vector();
- short seq=0;
- if (rs.next()) {
- boolean hasMore;
- do {
- byte tuple[][]=new byte[14][0];
- for (int k = 0;k < 14;k++)
- tuple[k] = null;
-
- String fKeyName=rs.getString(3);
- boolean foundRule=false;
- do {
- String proname=rs.getString(9);
- if (proname!=null && proname.startsWith("RI_FKey_")) {
- int col=-1;
- if (proname.endsWith("_upd")) col=9; // UPDATE_RULE
- else if (proname.endsWith("_del")) col=10; // DELETE_RULE
- if (col>-1) {
- String rule=proname.substring(8, proname.length()-4);
- int action=importedKeyNoAction;
- if ("cascade".equals(rule)) action=importedKeyCascade;
- else if ("setnull".equals(rule)) action=importedKeySetNull;
- else if ("setdefault".equals(rule)) action=importedKeySetDefault;
- tuple[col]=Integer.toString(action).getBytes();
- foundRule=true;
+ short seq = 0;
+ if (rs.next())
+ {
+ boolean hasMore;
+ do
+ {
+ byte tuple[][] = new byte[14][0];
+ for (int k = 0;k < 14;k++)
+ tuple[k] = null;
+
+ String fKeyName = rs.getString(3);
+ boolean foundRule = false;
+ do
+ {
+ String proname = rs.getString(9);
+ if (proname != null && proname.startsWith("RI_FKey_"))
+ {
+ int col = -1;
+ if (proname.endsWith("_upd"))
+ col = 9; // UPDATE_RULE
+ else if (proname.endsWith("_del"))
+ col = 10; // DELETE_RULE
+ if (col > -1)
+ {
+ String rule = proname.substring(8, proname.length() - 4);
+ int action = importedKeyNoAction;
+ if ("cascade".equals(rule))
+ action = importedKeyCascade;
+ else if ("setnull".equals(rule))
+ action = importedKeySetNull;
+ else if ("setdefault".equals(rule))
+ action = importedKeySetDefault;
+ tuple[col] = Integer.toString(action).getBytes();
+ foundRule = true;
+ }
}
}
- } while ((hasMore=rs.next()) && fKeyName.equals(rs.getString(3)));
-
- if (foundRule) {
- tuple[2]=rs.getBytes(2); //PKTABLE_NAME
- tuple[6]=rs.getBytes(1); //FKTABLE_NAME
-
- // Parse the tgargs data
- StringBuffer fkeyColumns=new StringBuffer();
- StringBuffer pkeyColumns=new StringBuffer();
- int numColumns=(rs.getInt(7) >> 1) - 2;
- String s=rs.getString(8);
- int pos=s.lastIndexOf("\\000");
- for(int c=0;c
- if (pos>-1) {
- int pos2=s.lastIndexOf("\\000", pos-1);
- if (pos2>-1) {
- if (fkeyColumns.length()>0) fkeyColumns.insert(0, ',');
- fkeyColumns.insert(0, s.substring(pos2+4, pos)); //FKCOLUMN_NAME
- pos=s.lastIndexOf("\\000", pos2-1);
- if (pos>-1) {
- if (pkeyColumns.length()>0) pkeyColumns.insert(0, ',');
- pkeyColumns.insert(0, s.substring(pos+4, pos2)); //PKCOLUMN_NAME
+ while ((hasMore = rs.next()) && fKeyName.equals(rs.getString(3)));
+
+ if (foundRule)
+ {
+ tuple[2] = rs.getBytes(2); //PKTABLE_NAME
+ tuple[6] = rs.getBytes(1); //FKTABLE_NAME
+
+ // Parse the tgargs data
+ StringBuffer fkeyColumns = new StringBuffer();
+ StringBuffer pkeyColumns = new StringBuffer();
+ int numColumns = (rs.getInt(7) >> 1) - 2;
+ String s = rs.getString(8);
+ int pos = s.lastIndexOf("\\000");
+ for (int c = 0;c < numColumns;c++)
+ {
+ if (pos > -1)
+ {
+ int pos2 = s.lastIndexOf("\\000", pos - 1);
+ if (pos2 > -1)
+ {
+ if (fkeyColumns.length() > 0)
+ fkeyColumns.insert(0, ',');
+ fkeyColumns.insert(0, s.substring(pos2 + 4, pos)); //FKCOLUMN_NAME
+ pos = s.lastIndexOf("\\000", pos2 - 1);
+ if (pos > -1)
+ {
+ if (pkeyColumns.length() > 0)
+ pkeyColumns.insert(0, ',');
+ pkeyColumns.insert(0, s.substring(pos + 4, pos2)); //PKCOLUMN_NAME
+ }
+ }
+ }
}
- }
+ tuple[7] = fkeyColumns.toString().getBytes(); //FKCOLUMN_NAME
+ tuple[3] = pkeyColumns.toString().getBytes(); //PKCOLUMN_NAME
+
+ tuple[8] = Integer.toString(seq++).getBytes(); //KEY_SEQ
+ tuple[11] = fKeyName.getBytes(); //FK_NAME
+ tuple[12] = rs.getBytes(4); //PK_NAME
+
+ // DEFERRABILITY
+ int deferrability = importedKeyNotDeferrable;
+ boolean deferrable = rs.getBoolean(5);
+ boolean initiallyDeferred = rs.getBoolean(6);
+ if (deferrable)
+ {
+ if (initiallyDeferred)
+ deferrability = importedKeyInitiallyDeferred;
+ else
+ deferrability = importedKeyInitiallyImmediate;
+ }
+ tuple[13] = Integer.toString(deferrability).getBytes();
+
+ tuples.addElement(tuple);
}
}
- tuple[7]=fkeyColumns.toString().getBytes(); //FKCOLUMN_NAME
- tuple[3]=pkeyColumns.toString().getBytes(); //PKCOLUMN_NAME
-
- tuple[8]=Integer.toString(seq++).getBytes(); //KEY_SEQ
- tuple[11]=fKeyName.getBytes(); //FK_NAME
- tuple[12]=rs.getBytes(4); //PK_NAME
-
- // DEFERRABILITY
- int deferrability=importedKeyNotDeferrable;
- boolean deferrable=rs.getBoolean(5);
- boolean initiallyDeferred=rs.getBoolean(6);
- if (deferrable) {
- if (initiallyDeferred)
- deferrability=importedKeyInitiallyDeferred;
- else
- deferrability=importedKeyInitiallyImmediate;
- }
- tuple[13]=Integer.toString(deferrability).getBytes();
-
- tuples.addElement(tuple);
- }
- } while (hasMore);
- }
+ while (hasMore);
+ }
- return new ResultSet(connection, f, tuples, "OK", 1);
+ return new ResultSet(connection, f, tuples, "OK", 1);
}
/*
*/
public java.sql.ResultSet getExportedKeys(String catalog, String schema, String table) throws SQLException
{
- return getImportedExportedKeys(catalog, schema, table, null);
+ return getImportedExportedKeys(catalog, schema, table, null);
}
/*
*/
public java.sql.ResultSet getCrossReference(String primaryCatalog, String primarySchema, String primaryTable, String foreignCatalog, String foreignSchema, String foreignTable) throws SQLException
{
- return getImportedExportedKeys(primaryCatalog, primarySchema, primaryTable, foreignTable);
+ return getImportedExportedKeys(primaryCatalog, primarySchema, primaryTable, foreignTable);
}
/*
}
switch (targetSqlType)
{
- case Types.TINYINT:
- case Types.SMALLINT:
- case Types.INTEGER:
- case Types.BIGINT:
- case Types.REAL:
- case Types.FLOAT:
- case Types.DOUBLE:
- case Types.DECIMAL:
- case Types.NUMERIC:
- if (x instanceof Boolean)
- set(parameterIndex, ((Boolean)x).booleanValue() ? "1" : "0");
- else
- set(parameterIndex, x.toString());
- break;
- case Types.CHAR:
- case Types.VARCHAR:
- case Types.LONGVARCHAR:
- setString(parameterIndex, x.toString());
- break;
- case Types.DATE:
- setDate(parameterIndex, (java.sql.Date)x);
- break;
- case Types.TIME:
- setTime(parameterIndex, (Time)x);
- break;
- case Types.TIMESTAMP:
- setTimestamp(parameterIndex, (Timestamp)x);
- break;
- case Types.BIT:
- if (x instanceof Boolean)
- {
- set(parameterIndex, ((Boolean)x).booleanValue() ? "TRUE" : "FALSE");
- }
- else
- {
+ case Types.TINYINT:
+ case Types.SMALLINT:
+ case Types.INTEGER:
+ case Types.BIGINT:
+ case Types.REAL:
+ case Types.FLOAT:
+ case Types.DOUBLE:
+ case Types.DECIMAL:
+ case Types.NUMERIC:
+ if (x instanceof Boolean)
+ set(parameterIndex, ((Boolean)x).booleanValue() ? "1" : "0");
+ else
+ set(parameterIndex, x.toString());
+ break;
+ case Types.CHAR:
+ case Types.VARCHAR:
+ case Types.LONGVARCHAR:
+ setString(parameterIndex, x.toString());
+ break;
+ case Types.DATE:
+ setDate(parameterIndex, (java.sql.Date)x);
+ break;
+ case Types.TIME:
+ setTime(parameterIndex, (Time)x);
+ break;
+ case Types.TIMESTAMP:
+ setTimestamp(parameterIndex, (Timestamp)x);
+ break;
+ case Types.BIT:
+ if (x instanceof Boolean)
+ {
+ set(parameterIndex, ((Boolean)x).booleanValue() ? "TRUE" : "FALSE");
+ }
+ else
+ {
+ throw new PSQLException("postgresql.prep.type");
+ }
+ break;
+ case Types.BINARY:
+ case Types.VARBINARY:
+ setObject(parameterIndex, x);
+ break;
+ case Types.OTHER:
+ setString(parameterIndex, ((PGobject)x).getValue());
+ break;
+ default:
throw new PSQLException("postgresql.prep.type");
- }
- break;
- case Types.BINARY:
- case Types.VARBINARY:
- setObject(parameterIndex, x);
- break;
- case Types.OTHER:
- setString(parameterIndex, ((PGobject)x).getValue());
- break;
- default:
- throw new PSQLException("postgresql.prep.type");
}
}
wasNullFlag = (this_row[columnIndex - 1] == null);
if (!wasNullFlag)
{
- if (binaryCursor)
- {
- //If the data is already binary then just return it
- return this_row[columnIndex - 1];
- }
- else if (connection.haveMinimumCompatibleVersion("7.2"))
- {
- //Version 7.2 supports the bytea datatype for byte arrays
- if (fields[columnIndex - 1].getPGType().equals("bytea"))
+ if (binaryCursor)
{
- return PGbytea.toBytes(getString(columnIndex));
+ //If the data is already binary then just return it
+ return this_row[columnIndex - 1];
}
- else
- {
- return this_row[columnIndex - 1];
- }
- }
- else
- {
- //Version 7.1 and earlier supports LargeObjects for byte arrays
- // Handle OID's as BLOBS
- if ( fields[columnIndex - 1].getOID() == 26)
+ else if (connection.haveMinimumCompatibleVersion("7.2"))
{
- LargeObjectManager lom = connection.getLargeObjectAPI();
- LargeObject lob = lom.open(getInt(columnIndex));
- byte buf[] = lob.read(lob.size());
- lob.close();
- return buf;
+ //Version 7.2 supports the bytea datatype for byte arrays
+ if (fields[columnIndex - 1].getPGType().equals("bytea"))
+ {
+ return PGbytea.toBytes(getString(columnIndex));
+ }
+ else
+ {
+ return this_row[columnIndex - 1];
+ }
}
else
{
- return this_row[columnIndex - 1];
+ //Version 7.1 and earlier supports LargeObjects for byte arrays
+ // Handle OID's as BLOBS
+ if ( fields[columnIndex - 1].getOID() == 26)
+ {
+ LargeObjectManager lom = connection.getLargeObjectAPI();
+ LargeObject lob = lom.open(getInt(columnIndex));
+ byte buf[] = lob.read(lob.size());
+ lob.close();
+ return buf;
+ }
+ else
+ {
+ return this_row[columnIndex - 1];
+ }
}
- }
}
return null;
}
return null;
// length == 10: SQL Date
// length > 10: SQL Timestamp, assumes PGDATESTYLE=ISO
- try {
- return java.sql.Date.valueOf((s.length() == 10) ? s : s.substring(0,10));
- } catch (NumberFormatException e) {
- throw new PSQLException("postgresql.res.baddate", s);
+ try
+ {
+ return java.sql.Date.valueOf((s.length() == 10) ? s : s.substring(0, 10));
+ }
+ catch (NumberFormatException e)
+ {
+ throw new PSQLException("postgresql.res.baddate", s);
}
}
switch (field.getSQLType())
{
- case Types.BIT:
- return new Boolean(getBoolean(columnIndex));
- case Types.SMALLINT:
- return new Integer(getInt(columnIndex));
- case Types.INTEGER:
- return new Integer(getInt(columnIndex));
- case Types.BIGINT:
- return new Long(getLong(columnIndex));
- case Types.NUMERIC:
- return getBigDecimal(columnIndex, ((field.getMod() - 4) & 0xffff));
- case Types.REAL:
- return new Float(getFloat(columnIndex));
- case Types.DOUBLE:
- return new Double(getDouble(columnIndex));
- case Types.CHAR:
- case Types.VARCHAR:
- return getString(columnIndex);
- case Types.DATE:
- return getDate(columnIndex);
- case Types.TIME:
- return getTime(columnIndex);
- case Types.TIMESTAMP:
- return getTimestamp(columnIndex);
- case Types.BINARY:
- case Types.VARBINARY:
- return getBytes(columnIndex);
- default:
- String type = field.getPGType();
- // if the backend doesn't know the type then coerce to String
- if (type.equals("unknown"))
- {
+ case Types.BIT:
+ return new Boolean(getBoolean(columnIndex));
+ case Types.SMALLINT:
+ return new Integer(getInt(columnIndex));
+ case Types.INTEGER:
+ return new Integer(getInt(columnIndex));
+ case Types.BIGINT:
+ return new Long(getLong(columnIndex));
+ case Types.NUMERIC:
+ return getBigDecimal(columnIndex, ((field.getMod() - 4) & 0xffff));
+ case Types.REAL:
+ return new Float(getFloat(columnIndex));
+ case Types.DOUBLE:
+ return new Double(getDouble(columnIndex));
+ case Types.CHAR:
+ case Types.VARCHAR:
return getString(columnIndex);
- }
- else
- {
- return connection.getObject(field.getPGType(), getString(columnIndex));
- }
+ case Types.DATE:
+ return getDate(columnIndex);
+ case Types.TIME:
+ return getTime(columnIndex);
+ case Types.TIMESTAMP:
+ return getTimestamp(columnIndex);
+ case Types.BINARY:
+ case Types.VARBINARY:
+ return getBytes(columnIndex);
+ default:
+ String type = field.getPGType();
+ // if the backend doesn't know the type then coerce to String
+ if (type.equals("unknown"))
+ {
+ return getString(columnIndex);
+ }
+ else
+ {
+ return connection.getObject(field.getPGType(), getString(columnIndex));
+ }
}
}
switch (sql_type)
{
- case Types.SMALLINT:
- case Types.INTEGER:
- case Types.FLOAT:
- case Types.REAL:
- case Types.DOUBLE:
- case Types.DATE:
- case Types.TIME:
- case Types.TIMESTAMP:
- return false;
- default:
- return true;
+ case Types.SMALLINT:
+ case Types.INTEGER:
+ case Types.FLOAT:
+ case Types.REAL:
+ case Types.DOUBLE:
+ case Types.DATE:
+ case Types.TIME:
+ case Types.TIMESTAMP:
+ return false;
+ default:
+ return true;
}
}
// for further expansion.
switch (sql_type)
{
- case Types.OTHER:
- return true;
- default:
- return true;
+ case Types.OTHER:
+ return true;
+ default:
+ return true;
}
}
switch (sql_type)
{
- case Types.SMALLINT:
- case Types.INTEGER:
- case Types.FLOAT:
- case Types.REAL:
- case Types.DOUBLE:
- return true;
- case Types.DATE:
- case Types.TIME:
- case Types.TIMESTAMP:
- return false; // I don't know about these?
- default:
- return false;
+ case Types.SMALLINT:
+ case Types.INTEGER:
+ case Types.FLOAT:
+ case Types.REAL:
+ case Types.DOUBLE:
+ return true;
+ case Types.DATE:
+ case Types.TIME:
+ case Types.TIMESTAMP:
+ return false; // I don't know about these?
+ default:
+ return false;
}
}
switch (sql_type)
{
- case Types.SMALLINT:
- return 5;
- case Types.INTEGER:
- return 10;
- case Types.REAL:
- return 8;
- case Types.FLOAT:
- return 16;
- case Types.DOUBLE:
- return 16;
- case Types.VARCHAR:
- return 0;
- case Types.NUMERIC:
- Field f = getField(column);
- if (f != null)
- return ((0xFFFF0000)&f.getMod()) >> 16;
- else
+ case Types.SMALLINT:
+ return 5;
+ case Types.INTEGER:
+ return 10;
+ case Types.REAL:
+ return 8;
+ case Types.FLOAT:
+ return 16;
+ case Types.DOUBLE:
+ return 16;
+ case Types.VARCHAR:
+ return 0;
+ case Types.NUMERIC:
+ Field f = getField(column);
+ if (f != null)
+ return ((0xFFFF0000)&f.getMod()) >> 16;
+ else
+ return 0;
+ default:
return 0;
- default:
- return 0;
}
}
switch (sql_type)
{
- case Types.SMALLINT:
- return 0;
- case Types.INTEGER:
- return 0;
- case Types.REAL:
- return 8;
- case Types.FLOAT:
- return 16;
- case Types.DOUBLE:
- return 16;
- case Types.VARCHAR:
- return 0;
- case Types.NUMERIC:
- Field f = getField(column);
- if (f != null)
- return (((0x0000FFFF)&f.getMod()) - 4);
- else
+ case Types.SMALLINT:
+ return 0;
+ case Types.INTEGER:
+ return 0;
+ case Types.REAL:
+ return 8;
+ case Types.FLOAT:
+ return 16;
+ case Types.DOUBLE:
+ return 16;
+ case Types.VARCHAR:
+ return 0;
+ case Types.NUMERIC:
+ Field f = getField(column);
+ if (f != null)
+ return (((0x0000FFFF)&f.getMod()) - 4);
+ else
+ return 0;
+ default:
return 0;
- default:
- return 0;
}
}
int i = 0;
switch ( getBaseType() )
{
- case Types.BIT:
- retVal = new boolean[ count ];
- for ( ; count > 0; count-- )
- ((boolean[])retVal)[i++] = ResultSet.toBoolean( arrayContents[(int)index++] );
- break;
- case Types.SMALLINT:
- case Types.INTEGER:
- retVal = new int[ count ];
- for ( ; count > 0; count-- )
- ((int[])retVal)[i++] = ResultSet.toInt( arrayContents[(int)index++] );
- break;
- case Types.BIGINT:
- retVal = new long[ count ];
- for ( ; count > 0; count-- )
- ((long[])retVal)[i++] = ResultSet.toLong( arrayContents[(int)index++] );
- break;
- case Types.NUMERIC:
- retVal = new BigDecimal[ count ];
- for ( ; count > 0; count-- )
- ((BigDecimal[])retVal)[i] = ResultSet.toBigDecimal( arrayContents[(int)index++], 0 );
- break;
- case Types.REAL:
- retVal = new float[ count ];
- for ( ; count > 0; count-- )
- ((float[])retVal)[i++] = ResultSet.toFloat( arrayContents[(int)index++] );
- break;
- case Types.DOUBLE:
- retVal = new double[ count ];
- for ( ; count > 0; count-- )
- ((double[])retVal)[i++] = ResultSet.toDouble( arrayContents[(int)index++] );
- break;
- case Types.CHAR:
- case Types.VARCHAR:
- retVal = new String[ count ];
- for ( ; count > 0; count-- )
- ((String[])retVal)[i++] = arrayContents[(int)index++];
- break;
- case Types.DATE:
- retVal = new java.sql.Date[ count ];
- for ( ; count > 0; count-- )
- ((java.sql.Date[])retVal)[i++] = ResultSet.toDate( arrayContents[(int)index++] );
- break;
- case Types.TIME:
- retVal = new java.sql.Time[ count ];
- for ( ; count > 0; count-- )
- ((java.sql.Time[])retVal)[i++] = ResultSet.toTime( arrayContents[(int)index++] );
- break;
- case Types.TIMESTAMP:
- retVal = new Timestamp[ count ];
- StringBuffer sbuf = null;
- for ( ; count > 0; count-- )
- ((java.sql.Timestamp[])retVal)[i++] = ResultSet.toTimestamp( arrayContents[(int)index], rs );
- break;
+ case Types.BIT:
+ retVal = new boolean[ count ];
+ for ( ; count > 0; count-- )
+ ((boolean[])retVal)[i++] = ResultSet.toBoolean( arrayContents[(int)index++] );
+ break;
+ case Types.SMALLINT:
+ case Types.INTEGER:
+ retVal = new int[ count ];
+ for ( ; count > 0; count-- )
+ ((int[])retVal)[i++] = ResultSet.toInt( arrayContents[(int)index++] );
+ break;
+ case Types.BIGINT:
+ retVal = new long[ count ];
+ for ( ; count > 0; count-- )
+ ((long[])retVal)[i++] = ResultSet.toLong( arrayContents[(int)index++] );
+ break;
+ case Types.NUMERIC:
+ retVal = new BigDecimal[ count ];
+ for ( ; count > 0; count-- )
+ ((BigDecimal[])retVal)[i] = ResultSet.toBigDecimal( arrayContents[(int)index++], 0 );
+ break;
+ case Types.REAL:
+ retVal = new float[ count ];
+ for ( ; count > 0; count-- )
+ ((float[])retVal)[i++] = ResultSet.toFloat( arrayContents[(int)index++] );
+ break;
+ case Types.DOUBLE:
+ retVal = new double[ count ];
+ for ( ; count > 0; count-- )
+ ((double[])retVal)[i++] = ResultSet.toDouble( arrayContents[(int)index++] );
+ break;
+ case Types.CHAR:
+ case Types.VARCHAR:
+ retVal = new String[ count ];
+ for ( ; count > 0; count-- )
+ ((String[])retVal)[i++] = arrayContents[(int)index++];
+ break;
+ case Types.DATE:
+ retVal = new java.sql.Date[ count ];
+ for ( ; count > 0; count-- )
+ ((java.sql.Date[])retVal)[i++] = ResultSet.toDate( arrayContents[(int)index++] );
+ break;
+ case Types.TIME:
+ retVal = new java.sql.Time[ count ];
+ for ( ; count > 0; count-- )
+ ((java.sql.Time[])retVal)[i++] = ResultSet.toTime( arrayContents[(int)index++] );
+ break;
+ case Types.TIMESTAMP:
+ retVal = new Timestamp[ count ];
+ StringBuffer sbuf = null;
+ for ( ; count > 0; count-- )
+ ((java.sql.Timestamp[])retVal)[i++] = ResultSet.toTimestamp( arrayContents[(int)index], rs );
+ break;
- // Other datatypes not currently supported. If you are really using other types ask
- // yourself if an array of non-trivial data types is really good database design.
- default:
- throw org.postgresql.Driver.notImplemented();
+ // Other datatypes not currently supported. If you are really using other types ask
+ // yourself if an array of non-trivial data types is really good database design.
+ default:
+ throw org.postgresql.Driver.notImplemented();
}
return retVal;
}
fields[0] = new Field(conn, "INDEX", conn.getOID("int2"), 2);
switch ( getBaseType() )
{
- case Types.BIT:
- boolean[] booleanArray = (boolean[]) array;
- fields[1] = new Field(conn, "VALUE", conn.getOID("bool"), 1);
- for ( int i = 0; i < booleanArray.length; i++ )
- {
- byte[][] tuple = new byte[2][0];
- tuple[0] = conn.getEncoding().encode( Integer.toString((int)index + i) ); // Index
- tuple[1] = conn.getEncoding().encode( (booleanArray[i] ? "YES" : "NO") ); // Value
- rows.addElement(tuple);
- }
- case Types.SMALLINT:
- fields[1] = new Field(conn, "VALUE", conn.getOID("int2"), 2);
- case Types.INTEGER:
- int[] intArray = (int[]) array;
- if ( fields[1] == null )
- fields[1] = new Field(conn, "VALUE", conn.getOID("int4"), 4);
- for ( int i = 0; i < intArray.length; i++ )
- {
- byte[][] tuple = new byte[2][0];
- tuple[0] = conn.getEncoding().encode( Integer.toString((int)index + i) ); // Index
- tuple[1] = conn.getEncoding().encode( Integer.toString(intArray[i]) ); // Value
- rows.addElement(tuple);
- }
- break;
- case Types.BIGINT:
- long[] longArray = (long[]) array;
- fields[1] = new Field(conn, "VALUE", conn.getOID("int8"), 8);
- for ( int i = 0; i < longArray.length; i++ )
- {
- byte[][] tuple = new byte[2][0];
- tuple[0] = conn.getEncoding().encode( Integer.toString((int)index + i) ); // Index
- tuple[1] = conn.getEncoding().encode( Long.toString(longArray[i]) ); // Value
- rows.addElement(tuple);
- }
- break;
- case Types.NUMERIC:
- BigDecimal[] bdArray = (BigDecimal[]) array;
- fields[1] = new Field(conn, "VALUE", conn.getOID("numeric"), -1);
- for ( int i = 0; i < bdArray.length; i++ )
- {
- byte[][] tuple = new byte[2][0];
- tuple[0] = conn.getEncoding().encode( Integer.toString((int)index + i) ); // Index
- tuple[1] = conn.getEncoding().encode( bdArray[i].toString() ); // Value
- rows.addElement(tuple);
- }
- break;
- case Types.REAL:
- float[] floatArray = (float[]) array;
- fields[1] = new Field(conn, "VALUE", conn.getOID("float4"), 4);
- for ( int i = 0; i < floatArray.length; i++ )
- {
- byte[][] tuple = new byte[2][0];
- tuple[0] = conn.getEncoding().encode( Integer.toString((int)index + i) ); // Index
- tuple[1] = conn.getEncoding().encode( Float.toString(floatArray[i]) ); // Value
- rows.addElement(tuple);
- }
- break;
- case Types.DOUBLE:
- double[] doubleArray = (double[]) array;
- fields[1] = new Field(conn, "VALUE", conn.getOID("float8"), 8);
- for ( int i = 0; i < doubleArray.length; i++ )
- {
- byte[][] tuple = new byte[2][0];
- tuple[0] = conn.getEncoding().encode( Integer.toString((int)index + i) ); // Index
- tuple[1] = conn.getEncoding().encode( Double.toString(doubleArray[i]) ); // Value
- rows.addElement(tuple);
- }
- break;
- case Types.CHAR:
- fields[1] = new Field(conn, "VALUE", conn.getOID("char"), 1);
- case Types.VARCHAR:
- String[] strArray = (String[]) array;
- if ( fields[1] == null )
- fields[1] = new Field(conn, "VALUE", conn.getOID("varchar"), -1);
- for ( int i = 0; i < strArray.length; i++ )
- {
- byte[][] tuple = new byte[2][0];
- tuple[0] = conn.getEncoding().encode( Integer.toString((int)index + i) ); // Index
- tuple[1] = conn.getEncoding().encode( strArray[i] ); // Value
- rows.addElement(tuple);
- }
- break;
- case Types.DATE:
- java.sql.Date[] dateArray = (java.sql.Date[]) array;
- fields[1] = new Field(conn, "VALUE", conn.getOID("date"), 4);
- for ( int i = 0; i < dateArray.length; i++ )
- {
- byte[][] tuple = new byte[2][0];
- tuple[0] = conn.getEncoding().encode( Integer.toString((int)index + i) ); // Index
- tuple[1] = conn.getEncoding().encode( dateArray[i].toString() ); // Value
- rows.addElement(tuple);
- }
- break;
- case Types.TIME:
- java.sql.Time[] timeArray = (java.sql.Time[]) array;
- fields[1] = new Field(conn, "VALUE", conn.getOID("time"), 8);
- for ( int i = 0; i < timeArray.length; i++ )
- {
- byte[][] tuple = new byte[2][0];
- tuple[0] = conn.getEncoding().encode( Integer.toString((int)index + i) ); // Index
- tuple[1] = conn.getEncoding().encode( timeArray[i].toString() ); // Value
- rows.addElement(tuple);
- }
- break;
- case Types.TIMESTAMP:
- java.sql.Timestamp[] timestampArray = (java.sql.Timestamp[]) array;
- fields[1] = new Field(conn, "VALUE", conn.getOID("timestamp"), 8);
- for ( int i = 0; i < timestampArray.length; i++ )
- {
- byte[][] tuple = new byte[2][0];
- tuple[0] = conn.getEncoding().encode( Integer.toString((int)index + i) ); // Index
- tuple[1] = conn.getEncoding().encode( timestampArray[i].toString() ); // Value
- rows.addElement(tuple);
- }
- break;
+ case Types.BIT:
+ boolean[] booleanArray = (boolean[]) array;
+ fields[1] = new Field(conn, "VALUE", conn.getOID("bool"), 1);
+ for ( int i = 0; i < booleanArray.length; i++ )
+ {
+ byte[][] tuple = new byte[2][0];
+ tuple[0] = conn.getEncoding().encode( Integer.toString((int)index + i) ); // Index
+ tuple[1] = conn.getEncoding().encode( (booleanArray[i] ? "YES" : "NO") ); // Value
+ rows.addElement(tuple);
+ }
+ case Types.SMALLINT:
+ fields[1] = new Field(conn, "VALUE", conn.getOID("int2"), 2);
+ case Types.INTEGER:
+ int[] intArray = (int[]) array;
+ if ( fields[1] == null )
+ fields[1] = new Field(conn, "VALUE", conn.getOID("int4"), 4);
+ for ( int i = 0; i < intArray.length; i++ )
+ {
+ byte[][] tuple = new byte[2][0];
+ tuple[0] = conn.getEncoding().encode( Integer.toString((int)index + i) ); // Index
+ tuple[1] = conn.getEncoding().encode( Integer.toString(intArray[i]) ); // Value
+ rows.addElement(tuple);
+ }
+ break;
+ case Types.BIGINT:
+ long[] longArray = (long[]) array;
+ fields[1] = new Field(conn, "VALUE", conn.getOID("int8"), 8);
+ for ( int i = 0; i < longArray.length; i++ )
+ {
+ byte[][] tuple = new byte[2][0];
+ tuple[0] = conn.getEncoding().encode( Integer.toString((int)index + i) ); // Index
+ tuple[1] = conn.getEncoding().encode( Long.toString(longArray[i]) ); // Value
+ rows.addElement(tuple);
+ }
+ break;
+ case Types.NUMERIC:
+ BigDecimal[] bdArray = (BigDecimal[]) array;
+ fields[1] = new Field(conn, "VALUE", conn.getOID("numeric"), -1);
+ for ( int i = 0; i < bdArray.length; i++ )
+ {
+ byte[][] tuple = new byte[2][0];
+ tuple[0] = conn.getEncoding().encode( Integer.toString((int)index + i) ); // Index
+ tuple[1] = conn.getEncoding().encode( bdArray[i].toString() ); // Value
+ rows.addElement(tuple);
+ }
+ break;
+ case Types.REAL:
+ float[] floatArray = (float[]) array;
+ fields[1] = new Field(conn, "VALUE", conn.getOID("float4"), 4);
+ for ( int i = 0; i < floatArray.length; i++ )
+ {
+ byte[][] tuple = new byte[2][0];
+ tuple[0] = conn.getEncoding().encode( Integer.toString((int)index + i) ); // Index
+ tuple[1] = conn.getEncoding().encode( Float.toString(floatArray[i]) ); // Value
+ rows.addElement(tuple);
+ }
+ break;
+ case Types.DOUBLE:
+ double[] doubleArray = (double[]) array;
+ fields[1] = new Field(conn, "VALUE", conn.getOID("float8"), 8);
+ for ( int i = 0; i < doubleArray.length; i++ )
+ {
+ byte[][] tuple = new byte[2][0];
+ tuple[0] = conn.getEncoding().encode( Integer.toString((int)index + i) ); // Index
+ tuple[1] = conn.getEncoding().encode( Double.toString(doubleArray[i]) ); // Value
+ rows.addElement(tuple);
+ }
+ break;
+ case Types.CHAR:
+ fields[1] = new Field(conn, "VALUE", conn.getOID("char"), 1);
+ case Types.VARCHAR:
+ String[] strArray = (String[]) array;
+ if ( fields[1] == null )
+ fields[1] = new Field(conn, "VALUE", conn.getOID("varchar"), -1);
+ for ( int i = 0; i < strArray.length; i++ )
+ {
+ byte[][] tuple = new byte[2][0];
+ tuple[0] = conn.getEncoding().encode( Integer.toString((int)index + i) ); // Index
+ tuple[1] = conn.getEncoding().encode( strArray[i] ); // Value
+ rows.addElement(tuple);
+ }
+ break;
+ case Types.DATE:
+ java.sql.Date[] dateArray = (java.sql.Date[]) array;
+ fields[1] = new Field(conn, "VALUE", conn.getOID("date"), 4);
+ for ( int i = 0; i < dateArray.length; i++ )
+ {
+ byte[][] tuple = new byte[2][0];
+ tuple[0] = conn.getEncoding().encode( Integer.toString((int)index + i) ); // Index
+ tuple[1] = conn.getEncoding().encode( dateArray[i].toString() ); // Value
+ rows.addElement(tuple);
+ }
+ break;
+ case Types.TIME:
+ java.sql.Time[] timeArray = (java.sql.Time[]) array;
+ fields[1] = new Field(conn, "VALUE", conn.getOID("time"), 8);
+ for ( int i = 0; i < timeArray.length; i++ )
+ {
+ byte[][] tuple = new byte[2][0];
+ tuple[0] = conn.getEncoding().encode( Integer.toString((int)index + i) ); // Index
+ tuple[1] = conn.getEncoding().encode( timeArray[i].toString() ); // Value
+ rows.addElement(tuple);
+ }
+ break;
+ case Types.TIMESTAMP:
+ java.sql.Timestamp[] timestampArray = (java.sql.Timestamp[]) array;
+ fields[1] = new Field(conn, "VALUE", conn.getOID("timestamp"), 8);
+ for ( int i = 0; i < timestampArray.length; i++ )
+ {
+ byte[][] tuple = new byte[2][0];
+ tuple[0] = conn.getEncoding().encode( Integer.toString((int)index + i) ); // Index
+ tuple[1] = conn.getEncoding().encode( timestampArray[i].toString() ); // Value
+ rows.addElement(tuple);
+ }
+ break;
- // Other datatypes not currently supported. If you are really using other types ask
- // yourself if an array of non-trivial data types is really good database design.
- default:
- throw org.postgresql.Driver.notImplemented();
+ // Other datatypes not currently supported. If you are really using other types ask
+ // yourself if an array of non-trivial data types is really good database design.
+ default:
+ throw org.postgresql.Driver.notImplemented();
}
return new ResultSet((org.postgresql.jdbc2.Connection)conn, fields, rows, "OK", 1 );
}
/*
* This class provides information about the database as a whole.
*
- * $Id: DatabaseMetaData.java,v 1.46 2001/11/19 22:33:39 momjian Exp $
+ * $Id: DatabaseMetaData.java,v 1.47 2001/11/19 23:16:46 momjian Exp $
*
*
Many of the methods here return lists of information in ResultSets. You
* can use the normal ResultSet methods such as getString and getInt to
public String getURL() throws SQLException
{
String url = connection.getURL();
- Driver.debug("getURL "+url);
+ Driver.debug("getURL " + url);
return url;
}
public String getUserName() throws SQLException
{
String userName = connection.getUserName();
- Driver.debug("getUserName "+ userName);
+ Driver.debug("getUserName " + userName);
return userName;
}
public boolean isReadOnly() throws SQLException
{
boolean isReadOnly = connection.isReadOnly();
- Driver.debug("isReadOnly " +isReadOnly);
+ Driver.debug("isReadOnly " + isReadOnly);
return isReadOnly;
}
public boolean nullsAreSortedAtEnd() throws SQLException
{
boolean nullsAreSortedAtEnd = ! connection.haveMinimumServerVersion("7.2");
- Driver.debug("nullsAreSortedAtEnd "+nullsAreSortedAtEnd);
+ Driver.debug("nullsAreSortedAtEnd " + nullsAreSortedAtEnd);
return nullsAreSortedAtEnd;
}
}
/*
- * What is the version string of this JDBC driver? Again, this is
+ * What is the version string of this JDBC driver? Again, this is
* static.
*
* @return the JDBC driver name.
public String getDriverVersion() throws SQLException
{
String driverVersion = connection.this_driver.getVersion();
- Driver.debug("getDriverVersion "+driverVersion);
+ Driver.debug("getDriverVersion " + driverVersion);
return driverVersion;
}
public int getDriverMajorVersion()
{
int majorVersion = connection.this_driver.getMajorVersion();
- Driver.debug("getMajorVersion " +majorVersion);
+ Driver.debug("getMajorVersion " + majorVersion);
return majorVersion;
}
public int getDriverMinorVersion()
{
int minorVersion = connection.this_driver.getMinorVersion();
- Driver.debug("getMinorVersion " +minorVersion);
+ Driver.debug("getMinorVersion " + minorVersion);
return minorVersion;
}
/*
- * Does the database store tables in a local file? No - it
+ * Does the database store tables in a local file? No - it
* stores them in a file on the server.
*
* @return true if so
*/
public boolean storesUpperCaseIdentifiers() throws SQLException
{
- Driver.debug("storesUpperCaseIdentifiers "+false);
+ Driver.debug("storesUpperCaseIdentifiers " + false);
return false;
}
public boolean supportsGroupByUnrelated() throws SQLException
{
boolean supportsGroupByUnrelated = connection.haveMinimumServerVersion("6.4");
- Driver.debug("supportsGroupByUnrelated "+ supportsGroupByUnrelated);
+ Driver.debug("supportsGroupByUnrelated " + supportsGroupByUnrelated);
return supportsGroupByUnrelated;
}
/*
* Can a "GROUP BY" clause add columns not in the SELECT provided
- * it specifies all the columns in the SELECT? Does anyone actually
+ * it specifies all the columns in the SELECT? Does anyone actually
* understand what they mean here?
*
* (I think this is a subset of the previous function. -- petere)
}
/*
- * Can columns be defined as non-nullable. A JDBC Compliant driver
+ * Can columns be defined as non-nullable. A JDBC Compliant driver
* always returns true.
*
*
This changed from false to true in v6.2 of the driver, as this
*/
public boolean supportsMinimumSQLGrammar() throws SQLException
{
- Driver.debug("supportsMinimumSQLGrammar TRUE");
- return true;
+ Driver.debug("supportsMinimumSQLGrammar TRUE");
+ return true;
}
/*
- * Does this driver support the Core ODBC SQL grammar. We need
+ * Does this driver support the Core ODBC SQL grammar. We need
* SQL-92 conformance for this.
*
* @return true if so
}
/*
- * Can a schema name be used in a data manipulation statement? Nope.
+ * Can a schema name be used in a data manipulation statement? Nope.
*
* @return true if so
* @exception SQLException if a database access error occurs
String relKind;
switch (r.getBytes(3)[0])
{
- case (byte) 'r':
- relKind = "TABLE";
- break;
- case (byte) 'i':
- relKind = "INDEX";
- break;
- case (byte) 'S':
- relKind = "SEQUENCE";
- break;
- case (byte) 'v':
- relKind = "VIEW";
- break;
- default:
- relKind = null;
+ case (byte) 'r':
+ relKind = "TABLE";
+ break;
+ case (byte) 'i':
+ relKind = "INDEX";
+ break;
+ case (byte) 'S':
+ relKind = "SEQUENCE";
+ break;
+ case (byte) 'v':
+ relKind = "VIEW";
+ break;
+ default:
+ relKind = null;
}
tuple[0] = null; // Catalog name
Vector v = new Vector();
if (tableNamePattern == null)
- tableNamePattern = "%";
+ tableNamePattern = "%";
- f[0] = new Field(connection,"TABLE_CAT",iVarcharOid,32);
- f[1] = new Field(connection,"TABLE_SCHEM",iVarcharOid,32);
- f[2] = new Field(connection,"TABLE_NAME",iVarcharOid,32);
- f[3] = new Field(connection,"COLUMN_NAME",iVarcharOid,32);
- f[4] = new Field(connection,"GRANTOR",iVarcharOid,32);
- f[5] = new Field(connection,"GRANTEE",iVarcharOid,32);
- f[6] = new Field(connection,"PRIVILEGE",iVarcharOid,32);
- f[7] = new Field(connection,"IS_GRANTABLE",iVarcharOid,32);
+ f[0] = new Field(connection, "TABLE_CAT", iVarcharOid, 32);
+ f[1] = new Field(connection, "TABLE_SCHEM", iVarcharOid, 32);
+ f[2] = new Field(connection, "TABLE_NAME", iVarcharOid, 32);
+ f[3] = new Field(connection, "COLUMN_NAME", iVarcharOid, 32);
+ f[4] = new Field(connection, "GRANTOR", iVarcharOid, 32);
+ f[5] = new Field(connection, "GRANTEE", iVarcharOid, 32);
+ f[6] = new Field(connection, "PRIVILEGE", iVarcharOid, 32);
+ f[7] = new Field(connection, "IS_GRANTABLE", iVarcharOid, 32);
// This is taken direct from the psql source
- 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 '"+tableNamePattern.toLowerCase()+"' ORDER BY relname");
- while (r.next()) {
- byte[][] tuple = new byte[8][0];
- tuple[0] = tuple[1]= "".getBytes();
- DriverManager.println("relname=\""+r.getString(1)+"\" relacl=\""+r.getString(2)+"\"");
-
- // For now, don't add to the result as relacl needs to be processed.
- //v.addElement(tuple);
+ 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 '" + tableNamePattern.toLowerCase() + "' ORDER BY relname");
+ while (r.next())
+ {
+ byte[][] tuple = new byte[8][0];
+ tuple[0] = tuple[1] = "".getBytes();
+ DriverManager.println("relname=\"" + r.getString(1) + "\" relacl=\"" + r.getString(2) + "\"");
+
+ // For now, don't add to the result as relacl needs to be processed.
+ //v.addElement(tuple);
}
- return new ResultSet(connection,f,v,"OK",1);
+ return new ResultSet(connection, f, v, "OK", 1);
}
/*
"a.attnum as KEY_SEQ," +
"ic.relname as PK_NAME " +
" FROM pg_class bc, pg_class ic, pg_index i, pg_attribute a" +
- " WHERE bc.relkind = 'r' " + // -- not indices
+ " WHERE bc.relkind = 'r' " + // -- not indices
" and upper(bc.relname) = upper('" + table + "')" +
" and i.indrelid = bc.oid" +
" and i.indexrelid = ic.oid" +
private java.sql.ResultSet getImportedExportedKeys(String catalog, String schema, String primaryTable, String foreignTable) throws SQLException
{
- Field f[]=new Field[14];
-
- f[0]=new Field(connection, "PKTABLE_CAT", iVarcharOid, 32);
- f[1]=new Field(connection, "PKTABLE_SCHEM", iVarcharOid, 32);
- f[2]=new Field(connection, "PKTABLE_NAME", iVarcharOid, 32);
- f[3]=new Field(connection, "PKCOLUMN_NAME", iVarcharOid, 32);
- f[4]=new Field(connection, "FKTABLE_CAT", iVarcharOid, 32);
- f[5]=new Field(connection, "FKTABLE_SCHEM", iVarcharOid, 32);
- f[6]=new Field(connection, "FKTABLE_NAME", iVarcharOid, 32);
- f[7]=new Field(connection, "FKCOLUMN_NAME", iVarcharOid, 32);
- f[8]=new Field(connection, "KEY_SEQ", iInt2Oid, 2);
- f[9]=new Field(connection, "UPDATE_RULE", iInt2Oid, 2);
- f[10]=new Field(connection, "DELETE_RULE", iInt2Oid, 2);
- f[11]=new Field(connection, "FK_NAME", iVarcharOid, 32);
- f[12]=new Field(connection, "PK_NAME", iVarcharOid, 32);
- f[13]=new Field(connection, "DEFERRABILITY", iInt2Oid, 2);
+ Field f[] = new Field[14];
+
+ f[0] = new Field(connection, "PKTABLE_CAT", iVarcharOid, 32);
+ f[1] = new Field(connection, "PKTABLE_SCHEM", iVarcharOid, 32);
+ f[2] = new Field(connection, "PKTABLE_NAME", iVarcharOid, 32);
+ f[3] = new Field(connection, "PKCOLUMN_NAME", iVarcharOid, 32);
+ f[4] = new Field(connection, "FKTABLE_CAT", iVarcharOid, 32);
+ f[5] = new Field(connection, "FKTABLE_SCHEM", iVarcharOid, 32);
+ f[6] = new Field(connection, "FKTABLE_NAME", iVarcharOid, 32);
+ f[7] = new Field(connection, "FKCOLUMN_NAME", iVarcharOid, 32);
+ f[8] = new Field(connection, "KEY_SEQ", iInt2Oid, 2);
+ f[9] = new Field(connection, "UPDATE_RULE", iInt2Oid, 2);
+ f[10] = new Field(connection, "DELETE_RULE", iInt2Oid, 2);
+ f[11] = new Field(connection, "FK_NAME", iVarcharOid, 32);
+ f[12] = new Field(connection, "PK_NAME", iVarcharOid, 32);
+ f[13] = new Field(connection, "DEFERRABILITY", iInt2Oid, 2);
java.sql.ResultSet rs = connection.ExecSQL("SELECT c.relname,c2.relname,"
- + "t.tgconstrname,ic.relname,"
- + "t.tgdeferrable,t.tginitdeferred,"
- + "t.tgnargs,t.tgargs,p.proname "
- + "FROM pg_trigger t,pg_class c,pg_class c2,"
- + "pg_class ic,pg_proc p, pg_index i "
- + "WHERE t.tgrelid=c.oid AND t.tgconstrrelid=c2.oid "
- + "AND t.tgfoid=p.oid AND tgisconstraint "
- + ((primaryTable!=null) ? "AND c2.relname='"+primaryTable+"' " : "")
- + ((foreignTable!=null) ? "AND c.relname='"+foreignTable+"' " : "")
- + "AND i.indrelid=c.oid "
- + "AND i.indexrelid=ic.oid AND i.indisprimary "
- + "ORDER BY c.relname,c2.relname"
- );
+ + "t.tgconstrname,ic.relname,"
+ + "t.tgdeferrable,t.tginitdeferred,"
+ + "t.tgnargs,t.tgargs,p.proname "
+ + "FROM pg_trigger t,pg_class c,pg_class c2,"
+ + "pg_class ic,pg_proc p, pg_index i "
+ + "WHERE t.tgrelid=c.oid AND t.tgconstrrelid=c2.oid "
+ + "AND t.tgfoid=p.oid AND tgisconstraint "
+ + ((primaryTable != null) ? "AND c2.relname='" + primaryTable + "' " : "")
+ + ((foreignTable != null) ? "AND c.relname='" + foreignTable + "' " : "")
+ + "AND i.indrelid=c.oid "
+ + "AND i.indexrelid=ic.oid AND i.indisprimary "
+ + "ORDER BY c.relname,c2.relname"
+ );
Vector tuples = new Vector();
- short seq=0;
- if (rs.next()) {
- boolean hasMore;
- do {
- byte tuple[][]=new byte[14][0];
- for (int k = 0;k < 14;k++)
- tuple[k] = null;
-
- String fKeyName=rs.getString(3);
- boolean foundRule=false;
- do {
- String proname=rs.getString(9);
- if (proname!=null && proname.startsWith("RI_FKey_")) {
- int col=-1;
- if (proname.endsWith("_upd")) col=9; // UPDATE_RULE
- else if (proname.endsWith("_del")) col=10; // DELETE_RULE
- if (col>-1) {
- String rule=proname.substring(8, proname.length()-4);
- int action=importedKeyNoAction;
- if ("cascade".equals(rule)) action=importedKeyCascade;
- else if ("setnull".equals(rule)) action=importedKeySetNull;
- else if ("setdefault".equals(rule)) action=importedKeySetDefault;
- tuple[col]=Integer.toString(action).getBytes();
- foundRule=true;
- }
- }
- } while ((hasMore=rs.next()) && fKeyName.equals(rs.getString(3)));
-
- if (foundRule) {
- tuple[2]=rs.getBytes(2); //PKTABLE_NAME
- tuple[6]=rs.getBytes(1); //FKTABLE_NAME
-
- // Parse the tgargs data
- StringBuffer fkeyColumns=new StringBuffer();
- StringBuffer pkeyColumns=new StringBuffer();
- int numColumns=(rs.getInt(7) >> 1) - 2;
- String s=rs.getString(8);
- int pos=s.lastIndexOf("\\000");
- for(int c=0;c
- if (pos>-1) {
- int pos2=s.lastIndexOf("\\000", pos-1);
- if (pos2>-1) {
- if (fkeyColumns.length()>0) fkeyColumns.insert(0, ',');
- fkeyColumns.insert(0, s.substring(pos2+4, pos)); //FKCOLUMN_NAME
- pos=s.lastIndexOf("\\000", pos2-1);
- if (pos>-1) {
- if (pkeyColumns.length()>0) pkeyColumns.insert(0, ',');
- pkeyColumns.insert(0, s.substring(pos+4, pos2)); //PKCOLUMN_NAME
+ short seq = 0;
+ if (rs.next())
+ {
+ boolean hasMore;
+ do
+ {
+ byte tuple[][] = new byte[14][0];
+ for (int k = 0;k < 14;k++)
+ tuple[k] = null;
+
+ String fKeyName = rs.getString(3);
+ boolean foundRule = false;
+ do
+ {
+ String proname = rs.getString(9);
+ if (proname != null && proname.startsWith("RI_FKey_"))
+ {
+ int col = -1;
+ if (proname.endsWith("_upd"))
+ col = 9; // UPDATE_RULE
+ else if (proname.endsWith("_del"))
+ col = 10; // DELETE_RULE
+ if (col > -1)
+ {
+ String rule = proname.substring(8, proname.length() - 4);
+ int action = importedKeyNoAction;
+ if ("cascade".equals(rule))
+ action = importedKeyCascade;
+ else if ("setnull".equals(rule))
+ action = importedKeySetNull;
+ else if ("setdefault".equals(rule))
+ action = importedKeySetDefault;
+ tuple[col] = Integer.toString(action).getBytes();
+ foundRule = true;
+ }
}
}
- }
- }
- tuple[7]=fkeyColumns.toString().getBytes(); //FKCOLUMN_NAME
- tuple[3]=pkeyColumns.toString().getBytes(); //PKCOLUMN_NAME
-
- tuple[8]=Integer.toString(seq++).getBytes(); //KEY_SEQ
- tuple[11]=fKeyName.getBytes(); //FK_NAME
- tuple[12]=rs.getBytes(4); //PK_NAME
-
- // DEFERRABILITY
- int deferrability=importedKeyNotDeferrable;
- boolean deferrable=rs.getBoolean(5);
- boolean initiallyDeferred=rs.getBoolean(6);
- if (deferrable) {
- if (initiallyDeferred)
- deferrability=importedKeyInitiallyDeferred;
- else
- deferrability=importedKeyInitiallyImmediate;
- }
- tuple[13]=Integer.toString(deferrability).getBytes();
+ while ((hasMore = rs.next()) && fKeyName.equals(rs.getString(3)));
+
+ if (foundRule)
+ {
+ tuple[2] = rs.getBytes(2); //PKTABLE_NAME
+ tuple[6] = rs.getBytes(1); //FKTABLE_NAME
+
+ // Parse the tgargs data
+ StringBuffer fkeyColumns = new StringBuffer();
+ StringBuffer pkeyColumns = new StringBuffer();
+ int numColumns = (rs.getInt(7) >> 1) - 2;
+ String s = rs.getString(8);
+ int pos = s.lastIndexOf("\\000");
+ for (int c = 0;c < numColumns;c++)
+ {
+ if (pos > -1)
+ {
+ int pos2 = s.lastIndexOf("\\000", pos - 1);
+ if (pos2 > -1)
+ {
+ if (fkeyColumns.length() > 0)
+ fkeyColumns.insert(0, ',');
+ fkeyColumns.insert(0, s.substring(pos2 + 4, pos)); //FKCOLUMN_NAME
+ pos = s.lastIndexOf("\\000", pos2 - 1);
+ if (pos > -1)
+ {
+ if (pkeyColumns.length() > 0)
+ pkeyColumns.insert(0, ',');
+ pkeyColumns.insert(0, s.substring(pos + 4, pos2)); //PKCOLUMN_NAME
+ }
+ }
+ }
+ }
+ tuple[7] = fkeyColumns.toString().getBytes(); //FKCOLUMN_NAME
+ tuple[3] = pkeyColumns.toString().getBytes(); //PKCOLUMN_NAME
+
+ tuple[8] = Integer.toString(seq++).getBytes(); //KEY_SEQ
+ tuple[11] = fKeyName.getBytes(); //FK_NAME
+ tuple[12] = rs.getBytes(4); //PK_NAME
+
+ // DEFERRABILITY
+ int deferrability = importedKeyNotDeferrable;
+ boolean deferrable = rs.getBoolean(5);
+ boolean initiallyDeferred = rs.getBoolean(6);
+ if (deferrable)
+ {
+ if (initiallyDeferred)
+ deferrability = importedKeyInitiallyDeferred;
+ else
+ deferrability = importedKeyInitiallyImmediate;
+ }
+ tuple[13] = Integer.toString(deferrability).getBytes();
- tuples.addElement(tuple);
+ tuples.addElement(tuple);
+ }
}
- } while (hasMore);
+ while (hasMore);
}
return new ResultSet(connection, f, tuples, "OK", 1);
*/
public java.sql.ResultSet getImportedKeys(String catalog, String schema, String table) throws SQLException
{
- return getImportedExportedKeys(catalog, schema, null, table);
+ return getImportedExportedKeys(catalog, schema, null, table);
}
/*
*/
public java.sql.ResultSet getExportedKeys(String catalog, String schema, String table) throws SQLException
{
- return getImportedExportedKeys(catalog, schema, table, null);
+ return getImportedExportedKeys(catalog, schema, table, null);
}
/*
*/
public java.sql.ResultSet getCrossReference(String primaryCatalog, String primarySchema, String primaryTable, String foreignCatalog, String foreignSchema, String foreignTable) throws SQLException
{
- return getImportedExportedKeys(primaryCatalog, primarySchema, primaryTable, foreignTable);
+ return getImportedExportedKeys(primaryCatalog, primarySchema, primaryTable, foreignTable);
}
/*
}
switch (targetSqlType)
{
- case Types.TINYINT:
- case Types.SMALLINT:
- case Types.INTEGER:
- case Types.BIGINT:
- case Types.REAL:
- case Types.FLOAT:
- case Types.DOUBLE:
- case Types.DECIMAL:
- case Types.NUMERIC:
- if (x instanceof Boolean)
- set(parameterIndex, ((Boolean)x).booleanValue() ? "1" : "0");
- else
- set(parameterIndex, x.toString());
- break;
- case Types.CHAR:
- case Types.VARCHAR:
- case Types.LONGVARCHAR:
- setString(parameterIndex, x.toString());
- break;
- case Types.DATE:
- setDate(parameterIndex, (java.sql.Date)x);
- break;
- case Types.TIME:
- setTime(parameterIndex, (Time)x);
- break;
- case Types.TIMESTAMP:
- setTimestamp(parameterIndex, (Timestamp)x);
- break;
- case Types.BIT:
- if (x instanceof Boolean)
- {
- set(parameterIndex, ((Boolean)x).booleanValue() ? "TRUE" : "FALSE");
- }
- else
- {
+ case Types.TINYINT:
+ case Types.SMALLINT:
+ case Types.INTEGER:
+ case Types.BIGINT:
+ case Types.REAL:
+ case Types.FLOAT:
+ case Types.DOUBLE:
+ case Types.DECIMAL:
+ case Types.NUMERIC:
+ if (x instanceof Boolean)
+ set(parameterIndex, ((Boolean)x).booleanValue() ? "1" : "0");
+ else
+ set(parameterIndex, x.toString());
+ break;
+ case Types.CHAR:
+ case Types.VARCHAR:
+ case Types.LONGVARCHAR:
+ setString(parameterIndex, x.toString());
+ break;
+ case Types.DATE:
+ setDate(parameterIndex, (java.sql.Date)x);
+ break;
+ case Types.TIME:
+ setTime(parameterIndex, (Time)x);
+ break;
+ case Types.TIMESTAMP:
+ setTimestamp(parameterIndex, (Timestamp)x);
+ break;
+ case Types.BIT:
+ if (x instanceof Boolean)
+ {
+ set(parameterIndex, ((Boolean)x).booleanValue() ? "TRUE" : "FALSE");
+ }
+ else
+ {
+ throw new PSQLException("postgresql.prep.type");
+ }
+ break;
+ case Types.BINARY:
+ case Types.VARBINARY:
+ setObject(parameterIndex, x);
+ break;
+ case Types.OTHER:
+ setString(parameterIndex, ((PGobject)x).getValue());
+ break;
+ default:
throw new PSQLException("postgresql.prep.type");
- }
- break;
- case Types.BINARY:
- case Types.VARBINARY:
- setObject(parameterIndex, x);
- break;
- case Types.OTHER:
- setString(parameterIndex, ((PGobject)x).getValue());
- break;
- default:
- throw new PSQLException("postgresql.prep.type");
}
}
wasNullFlag = (this_row[columnIndex - 1] == null);
if (!wasNullFlag)
{
- if (binaryCursor)
- {
- //If the data is already binary then just return it
- return this_row[columnIndex - 1];
- }
- else if (connection.haveMinimumCompatibleVersion("7.2"))
- {
- //Version 7.2 supports the bytea datatype for byte arrays
- if (fields[columnIndex - 1].getPGType().equals("bytea"))
+ if (binaryCursor)
{
- return PGbytea.toBytes(getString(columnIndex));
+ //If the data is already binary then just return it
+ return this_row[columnIndex - 1];
}
- else
+ else if (connection.haveMinimumCompatibleVersion("7.2"))
{
- return this_row[columnIndex - 1];
- }
- }
- else
- {
- //Version 7.1 and earlier supports LargeObjects for byte arrays
- // Handle OID's as BLOBS
- if ( fields[columnIndex - 1].getOID() == 26)
- {
- LargeObjectManager lom = connection.getLargeObjectAPI();
- LargeObject lob = lom.open(getInt(columnIndex));
- byte buf[] = lob.read(lob.size());
- lob.close();
- return buf;
+ //Version 7.2 supports the bytea datatype for byte arrays
+ if (fields[columnIndex - 1].getPGType().equals("bytea"))
+ {
+ return PGbytea.toBytes(getString(columnIndex));
+ }
+ else
+ {
+ return this_row[columnIndex - 1];
+ }
}
else
{
- return this_row[columnIndex - 1];
+ //Version 7.1 and earlier supports LargeObjects for byte arrays
+ // Handle OID's as BLOBS
+ if ( fields[columnIndex - 1].getOID() == 26)
+ {
+ LargeObjectManager lom = connection.getLargeObjectAPI();
+ LargeObject lob = lom.open(getInt(columnIndex));
+ byte buf[] = lob.read(lob.size());
+ lob.close();
+ return buf;
+ }
+ else
+ {
+ return this_row[columnIndex - 1];
+ }
}
- }
}
return null;
}
switch (field.getSQLType())
{
- case Types.BIT:
- return new Boolean(getBoolean(columnIndex));
- case Types.SMALLINT:
- return new Integer(getInt(columnIndex));
- case Types.INTEGER:
- return new Integer(getInt(columnIndex));
- case Types.BIGINT:
- return new Long(getLong(columnIndex));
- case Types.NUMERIC:
- return getBigDecimal
- (columnIndex, (field.getMod() == -1) ? -1 : ((field.getMod() - 4) & 0xffff));
- case Types.REAL:
- return new Float(getFloat(columnIndex));
- case Types.DOUBLE:
- return new Double(getDouble(columnIndex));
- case Types.CHAR:
- case Types.VARCHAR:
- return getString(columnIndex);
- case Types.DATE:
- return getDate(columnIndex);
- case Types.TIME:
- return getTime(columnIndex);
- case Types.TIMESTAMP:
- return getTimestamp(columnIndex);
- case Types.BINARY:
- case Types.VARBINARY:
- return getBytes(columnIndex);
- default:
- String type = field.getPGType();
- // if the backend doesn't know the type then coerce to String
- if (type.equals("unknown"))
- {
+ case Types.BIT:
+ return new Boolean(getBoolean(columnIndex));
+ case Types.SMALLINT:
+ return new Integer(getInt(columnIndex));
+ case Types.INTEGER:
+ return new Integer(getInt(columnIndex));
+ case Types.BIGINT:
+ return new Long(getLong(columnIndex));
+ case Types.NUMERIC:
+ return getBigDecimal
+ (columnIndex, (field.getMod() == -1) ? -1 : ((field.getMod() - 4) & 0xffff));
+ case Types.REAL:
+ return new Float(getFloat(columnIndex));
+ case Types.DOUBLE:
+ return new Double(getDouble(columnIndex));
+ case Types.CHAR:
+ case Types.VARCHAR:
return getString(columnIndex);
- }
- else
- {
- return connection.getObject(field.getPGType(), getString(columnIndex));
- }
+ case Types.DATE:
+ return getDate(columnIndex);
+ case Types.TIME:
+ return getTime(columnIndex);
+ case Types.TIMESTAMP:
+ return getTimestamp(columnIndex);
+ case Types.BINARY:
+ case Types.VARBINARY:
+ return getBytes(columnIndex);
+ default:
+ String type = field.getPGType();
+ // if the backend doesn't know the type then coerce to String
+ if (type.equals("unknown"))
+ {
+ return getString(columnIndex);
+ }
+ else
+ {
+ return connection.getObject(field.getPGType(), getString(columnIndex));
+ }
}
}
if (current_row < 0 || current_row >= rows_size)
return 0;
-
+
return current_row + 1;
}
return null;
// length == 10: SQL Date
// length > 10: SQL Timestamp, assumes PGDATESTYLE=ISO
- try {
- return java.sql.Date.valueOf((s.length() == 10) ? s : s.substring(0,10));
- } catch (NumberFormatException e) {
- throw new PSQLException("postgresql.res.baddate", s);
+ try
+ {
+ return java.sql.Date.valueOf((s.length() == 10) ? s : s.substring(0, 10));
+ }
+ catch (NumberFormatException e)
+ {
+ throw new PSQLException("postgresql.res.baddate", s);
}
}
return null; // SQL NULL
// length == 8: SQL Time
// length > 8: SQL Timestamp
- try {
- return java.sql.Time.valueOf((s.length() == 8) ? s : s.substring(11,19));
- } catch (NumberFormatException e) {
- throw new PSQLException("postgresql.res.badtime",s);
+ try
+ {
+ return java.sql.Time.valueOf((s.length() == 8) ? s : s.substring(11, 19));
+ }
+ catch (NumberFormatException e)
+ {
+ throw new PSQLException("postgresql.res.badtime", s);
}
}
char sub = resultSet.sbuf.charAt(resultSet.sbuf.length() - 3);
if (sub == '+' || sub == '-')
{
- //we have found timezone info of format +/-HH
+ //we have found timezone info of format +/-HH
resultSet.sbuf.setLength(resultSet.sbuf.length() - 3);
if (subsecond)
{
resultSet.sbuf.append("GMT").append(s.substring(s.length() - 3)).append(":00");
}
- } else if (sub == ':') {
- //we may have found timezone info of format +/-HH:MM, or there is no
- //timezone info at all and this is the : preceding the seconds
- char sub2 = resultSet.sbuf.charAt(resultSet.sbuf.length()-5);
- if (sub2 == '+' || sub2 == '-')
+ }
+ else if (sub == ':')
+ {
+ //we may have found timezone info of format +/-HH:MM, or there is no
+ //timezone info at all and this is the : preceding the seconds
+ char sub2 = resultSet.sbuf.charAt(resultSet.sbuf.length() - 5);
+ if (sub2 == '+' || sub2 == '-')
{
- //we have found timezone info of format +/-HH:MM
- resultSet.sbuf.setLength(resultSet.sbuf.length()-5);
- if (subsecond)
+ //we have found timezone info of format +/-HH:MM
+ resultSet.sbuf.setLength(resultSet.sbuf.length() - 5);
+ if (subsecond)
{
- resultSet.sbuf.append('0').append("GMT").append(s.substring(s.length()-5));
- } else {
- resultSet.sbuf.append("GMT").append(s.substring(s.length()-5));
+ resultSet.sbuf.append('0').append("GMT").append(s.substring(s.length() - 5));
}
- } else if (subsecond) {
- resultSet.sbuf.append('0');
+ else
+ {
+ resultSet.sbuf.append("GMT").append(s.substring(s.length() - 5));
+ }
+ }
+ else if (subsecond)
+ {
+ resultSet.sbuf.append('0');
}
}
else if (subsecond)
switch (sql_type)
{
- case Types.SMALLINT:
- case Types.INTEGER:
- case Types.FLOAT:
- case Types.REAL:
- case Types.DOUBLE:
- case Types.DATE:
- case Types.TIME:
- case Types.TIMESTAMP:
- return false;
- default:
- return true;
+ case Types.SMALLINT:
+ case Types.INTEGER:
+ case Types.FLOAT:
+ case Types.REAL:
+ case Types.DOUBLE:
+ case Types.DATE:
+ case Types.TIME:
+ case Types.TIMESTAMP:
+ return false;
+ default:
+ return true;
}
}
// for further expansion.
switch (sql_type)
{
- case Types.OTHER:
- return true;
- default:
- return true;
+ case Types.OTHER:
+ return true;
+ default:
+ return true;
}
}
switch (sql_type)
{
- case Types.SMALLINT:
- case Types.INTEGER:
- case Types.FLOAT:
- case Types.REAL:
- case Types.DOUBLE:
- return true;
- case Types.DATE:
- case Types.TIME:
- case Types.TIMESTAMP:
- return false; // I don't know about these?
- default:
- return false;
+ case Types.SMALLINT:
+ case Types.INTEGER:
+ case Types.FLOAT:
+ case Types.REAL:
+ case Types.DOUBLE:
+ return true;
+ case Types.DATE:
+ case Types.TIME:
+ case Types.TIMESTAMP:
+ return false; // I don't know about these?
+ default:
+ return false;
}
}
switch (sql_type)
{
- case Types.SMALLINT:
- return 5;
- case Types.INTEGER:
- return 10;
- case Types.REAL:
- return 8;
- case Types.FLOAT:
- return 16;
- case Types.DOUBLE:
- return 16;
- case Types.VARCHAR:
- return 0;
- case Types.NUMERIC:
- Field f = getField(column);
- if (f != null)
- return ((0xFFFF0000)&f.getMod()) >> 16;
- else
+ case Types.SMALLINT:
+ return 5;
+ case Types.INTEGER:
+ return 10;
+ case Types.REAL:
+ return 8;
+ case Types.FLOAT:
+ return 16;
+ case Types.DOUBLE:
+ return 16;
+ case Types.VARCHAR:
+ return 0;
+ case Types.NUMERIC:
+ Field f = getField(column);
+ if (f != null)
+ return ((0xFFFF0000)&f.getMod()) >> 16;
+ else
+ return 0;
+ default:
return 0;
- default:
- return 0;
}
}
switch (sql_type)
{
- case Types.SMALLINT:
- return 0;
- case Types.INTEGER:
- return 0;
- case Types.REAL:
- return 8;
- case Types.FLOAT:
- return 16;
- case Types.DOUBLE:
- return 16;
- case Types.VARCHAR:
- return 0;
- case Types.NUMERIC:
- Field f = getField(column);
- if (f != null)
- return (((0x0000FFFF)&f.getMod()) - 4);
- else
+ case Types.SMALLINT:
+ return 0;
+ case Types.INTEGER:
+ return 0;
+ case Types.REAL:
+ return 8;
+ case Types.FLOAT:
+ return 16;
+ case Types.DOUBLE:
+ return 16;
+ case Types.VARCHAR:
+ return 0;
+ case Types.NUMERIC:
+ Field f = getField(column);
+ if (f != null)
+ return (((0x0000FFFF)&f.getMod()) - 4);
+ else
+ return 0;
+ default:
return 0;
- default:
- return 0;
}
}
import org.postgresql.largeobject.*;
/*
- * $Id: BlobTest.java,v 1.4 2001/11/19 22:33:39 momjian Exp $
+ * $Id: BlobTest.java,v 1.5 2001/11/19 23:16:46 momjian Exp $
*
* Some simple tests based on problems reported by users. Hopefully these will
* help prevent previous problems from re-occuring ;-)
switch (method)
{
- case LOOP:
- buf = new byte[2048];
- t = 0;
- while ((s = fis.read(buf, 0, buf.length)) > 0)
- {
- t += s;
- blob.write(buf, 0, s);
- }
- break;
-
- case NATIVE_STREAM:
- os = blob.getOutputStream();
- s = fis.read();
- while (s > -1)
- {
- os.write(s);
+ case LOOP:
+ buf = new byte[2048];
+ t = 0;
+ while ((s = fis.read(buf, 0, buf.length)) > 0)
+ {
+ t += s;
+ blob.write(buf, 0, s);
+ }
+ break;
+
+ case NATIVE_STREAM:
+ os = blob.getOutputStream();
s = fis.read();
- }
- os.close();
- break;
-
- case JDBC_STREAM:
- File f = new File(file);
- PreparedStatement ps = con.prepareStatement(JDBC2Tests.insertSQL("testblob", "?"));
- ps.setBinaryStream(1, fis, (int) f.length());
- ps.execute();
- break;
-
- default:
- assertTrue("Unknown method in uploadFile", false);
+ while (s > -1)
+ {
+ os.write(s);
+ s = fis.read();
+ }
+ os.close();
+ break;
+
+ case JDBC_STREAM:
+ File f = new File(file);
+ PreparedStatement ps = con.prepareStatement(JDBC2Tests.insertSQL("testblob", "?"));
+ ps.setBinaryStream(1, fis, (int) f.length());
+ ps.execute();
+ break;
+
+ default:
+ assertTrue("Unknown method in uploadFile", false);
}
blob.close();
{
con = JDBC2Tests.openDB();
Statement stmt = con.createStatement();
-
+
JDBC2Tests.createTable(con, "testrs", "id integer");
stmt.executeUpdate("INSERT INTO testrs VALUES (1)");
{
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM testrs");
-
- assertTrue(rs.absolute(-1));
+
+ assertTrue(rs.absolute( -1));
assertEquals(6, rs.getRow());
assertTrue(rs.absolute(1));
assertEquals(1, rs.getRow());
- assertTrue(!rs.absolute(-10));
+ assertTrue(!rs.absolute( -10));
assertEquals(0, rs.getRow());
- assertTrue(rs.next());
- assertEquals(1, rs.getRow());
+ assertTrue(rs.next());
+ assertEquals(1, rs.getRow());
assertTrue(!rs.absolute(10));
assertEquals(0, rs.getRow());
assertTrue(rs.previous());
assertEquals(6, rs.getRow());
-
+
stmt.close();
}
}
// Don't forget the last token ;-)
+
if (s < string.length())
tokens.addElement(string.substring(s));
*
* Copyright 1999 (C) Exoffice Technologies Inc. All Rights Reserved.
*
-* $Id: XADataSourceImpl.java,v 1.3 2001/11/19 22:33:39 momjian Exp $
+* $Id: XADataSourceImpl.java,v 1.4 2001/11/19 23:16:46 momjian Exp $
*/
// Look for all connections inside a transaction that
// should have timed out by now.
+
timeout = System.currentTimeMillis();
enum = _txConnections.elements();
while ( enum.hasMoreElements() )
for FILE
do
- astyle --style=java -b -p -j < "$FILE" >/tmp/$$ 2>/tmp/$$a
+ astyle --style=java -b -p -j -S < "$FILE" >/tmp/$$ 2>/tmp/$$a
if [ "$?" -ne 0 -o -s /tmp/$$a ]
then echo "$FILE"
cat /tmp/$$a