diff --git a/src/interfaces/jdbc/example/ImageViewer.java b/src/interfaces/jdbc/example/ImageViewer.java index 9540bfa67ed..f61a8870e7b 100644 --- a/src/interfaces/jdbc/example/ImageViewer.java +++ b/src/interfaces/jdbc/example/ImageViewer.java @@ -291,7 +291,6 @@ public class ImageViewer implements ItemListener public void run() { - // Now the real import stuff if (name != null && dir != null) { diff --git a/src/interfaces/jdbc/example/Unicode.java b/src/interfaces/jdbc/example/Unicode.java index 0d84c719a50..2312742235b 100644 --- a/src/interfaces/jdbc/example/Unicode.java +++ b/src/interfaces/jdbc/example/Unicode.java @@ -214,21 +214,21 @@ public class Unicode { switch (mode) { - case CREATE: - log("Exception creating database", sqle); - break; - case INSERT: - log("Exception inserting block " + blockNum, sqle); - break; - case SELECT: - log("Exception selecting block " + blockNum, sqle); - break; - case LIKE: - log("Exception doing LIKE on block " + blockNum, sqle); - break; - default: - log("Exception", sqle); - break; + case CREATE: + log("Exception creating database", sqle); + break; + case INSERT: + log("Exception inserting block " + blockNum, sqle); + break; + case SELECT: + log("Exception selecting block " + blockNum, sqle); + break; + case LIKE: + log("Exception doing LIKE on block " + blockNum, sqle); + break; + default: + log("Exception", sqle); + break; } } catch (ClassNotFoundException cnfe) diff --git a/src/interfaces/jdbc/example/basic.java b/src/interfaces/jdbc/example/basic.java index 61b35abc459..f01cb9cb8c5 100644 --- a/src/interfaces/jdbc/example/basic.java +++ b/src/interfaces/jdbc/example/basic.java @@ -6,7 +6,7 @@ import java.text.*; /* * - * $Id: basic.java,v 1.9 2001/11/19 22:43:13 momjian Exp $ + * $Id: basic.java,v 1.10 2001/11/19 23:16:44 momjian Exp $ * * This example tests the basic components of the JDBC driver, and shows * how even the simplest of queries can be implemented. @@ -137,6 +137,7 @@ public class basic // Now run the query again, showing a more efficient way of getting the // result if you don't know what column number a value is in + System.out.println("performing another query"); rs = st.executeQuery("select * from basic where b>1"); if (rs != null) @@ -163,6 +164,7 @@ public class basic // Now test maxrows by setting it to 3 rows + st.setMaxRows(3); System.out.println("performing a query limited to " + st.getMaxRows()); rs = st.executeQuery("select a, b from basic"); diff --git a/src/interfaces/jdbc/example/blobtest.java b/src/interfaces/jdbc/example/blobtest.java index bfa0cc42959..271026250dd 100644 --- a/src/interfaces/jdbc/example/blobtest.java +++ b/src/interfaces/jdbc/example/blobtest.java @@ -61,7 +61,6 @@ public class blobtest System.out.println("Now closing the connection"); s.close(); db.close(); - } /* @@ -171,7 +170,6 @@ public class blobtest lobj.unlink(oid); } - //======================================================================= // This tests the Blob interface of the JDBC 2.0 specification public void jdbc2api(int oid) throws SQLException, IOException { @@ -218,8 +216,6 @@ public class blobtest db.setAutoCommit(false); } - //======================================================================= - public static void instructions() { System.err.println("java example.blobtest jdbc-url user password [debug]"); diff --git a/src/interfaces/jdbc/example/corba/StockClient.java b/src/interfaces/jdbc/example/corba/StockClient.java index 3ccb28c7fd8..519bf49f97d 100644 --- a/src/interfaces/jdbc/example/corba/StockClient.java +++ b/src/interfaces/jdbc/example/corba/StockClient.java @@ -9,7 +9,7 @@ import org.omg.CosNaming.*; * * It has no GUI, just a text frontend to keep it simple. * - * $Id: StockClient.java,v 1.3 2001/11/19 22:43:13 momjian Exp $ + * $Id: StockClient.java,v 1.4 2001/11/19 23:16:45 momjian Exp $ */ public class StockClient { @@ -116,29 +116,29 @@ public class StockClient int i = getMenu("Main", 5); switch (i) { - case 0: - run = false; - break; + case 0: + run = false; + break; - case 1: - displayItem(); - break; + case 1: + displayItem(); + break; - case 2: - bookOut(); - break; + case 2: + bookOut(); + break; - case 3: - bookIn(); - break; + case 3: + bookIn(); + break; - case 4: - order(0); - break; + case 4: + order(0); + break; - case 5: - displayAll(); - break; + case 5: + displayAll(); + break; } } } diff --git a/src/interfaces/jdbc/example/datestyle.java b/src/interfaces/jdbc/example/datestyle.java index 6e503552b70..4cf40159ca1 100644 --- a/src/interfaces/jdbc/example/datestyle.java +++ b/src/interfaces/jdbc/example/datestyle.java @@ -9,7 +9,6 @@ import java.text.*; * * To use this example, you need a database to be in existence. This example * will create a table called datestyle. - * */ public class datestyle @@ -105,7 +104,6 @@ public class datestyle ps.setDate(1, standard); ps.executeUpdate(); ps.close(); - } /* diff --git a/src/interfaces/jdbc/example/metadata.java b/src/interfaces/jdbc/example/metadata.java index 6cd2802456c..468af6b9598 100644 --- a/src/interfaces/jdbc/example/metadata.java +++ b/src/interfaces/jdbc/example/metadata.java @@ -218,7 +218,6 @@ public class metadata { if (line.startsWith("\\d")) { - if (line.startsWith("\\d ")) { // Display details about a table diff --git a/src/interfaces/jdbc/example/psql.java b/src/interfaces/jdbc/example/psql.java index 697198ce3a6..a5af214d574 100644 --- a/src/interfaces/jdbc/example/psql.java +++ b/src/interfaces/jdbc/example/psql.java @@ -50,7 +50,7 @@ public class psql // Now the main loop. int tt = 0, lineno = 1; while (tt != StreamTokenizer.TT_EOF && ! done) - { // done added by CWJ to permit \q command + { System.out.print("[" + lineno + "] "); System.out.flush(); @@ -72,7 +72,6 @@ public class psql System.out.println("Now closing the connection"); st.close(); db.close(); - } /* diff --git a/src/interfaces/jdbc/example/threadsafe.java b/src/interfaces/jdbc/example/threadsafe.java index ceb1ef8f6f5..cca7be75bee 100644 --- a/src/interfaces/jdbc/example/threadsafe.java +++ b/src/interfaces/jdbc/example/threadsafe.java @@ -53,7 +53,6 @@ public class threadsafe System.out.println("Now closing the connection"); st.close(); db.close(); - } /* @@ -108,7 +107,6 @@ public class threadsafe System.out.println("Waiting for threads to run"); while (thread1.isAlive() || thread2.isAlive() || thread3.isAlive()) thread0.yield(); - } finally { diff --git a/src/interfaces/jdbc/org/postgresql/Connection.java b/src/interfaces/jdbc/org/postgresql/Connection.java index 239e4dc7d24..93bfa677811 100644 --- a/src/interfaces/jdbc/org/postgresql/Connection.java +++ b/src/interfaces/jdbc/org/postgresql/Connection.java @@ -11,7 +11,7 @@ import org.postgresql.util.*; 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. @@ -115,7 +115,7 @@ public abstract class Connection 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; @@ -168,88 +168,88 @@ public abstract class Connection 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 '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); + 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); - } + // 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); - } + // 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"); + // now send the auth packet + switch (areq) + { + case AUTH_REQ_OK: + break; - case AUTH_REQ_KRB5: - DriverManager.println("postgresql: KRB5"); - throw new PSQLException("postgresql.con.kerb5"); + case AUTH_REQ_KRB4: + DriverManager.println("postgresql: KRB4"); + throw new PSQLException("postgresql.con.kerb4"); - 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_KRB5: + DriverManager.println("postgresql: KRB5"); + throw new PSQLException("postgresql.con.kerb5"); - 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_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_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 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); @@ -265,28 +265,28 @@ public abstract class Connection 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; @@ -958,15 +958,15 @@ public abstract class Connection 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); @@ -993,16 +993,16 @@ public abstract class Connection 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(); } @@ -1166,6 +1166,5 @@ public abstract class Connection } return pgType; } - } diff --git a/src/interfaces/jdbc/org/postgresql/PG_Stream.java b/src/interfaces/jdbc/org/postgresql/PG_Stream.java index 488edecdf02..9a85df8a256 100644 --- a/src/interfaces/jdbc/org/postgresql/PG_Stream.java +++ b/src/interfaces/jdbc/org/postgresql/PG_Stream.java @@ -10,7 +10,7 @@ import org.postgresql.core.*; import org.postgresql.util.*; /* - * $Id: PG_Stream.java,v 1.15 2001/11/19 22:33:37 momjian Exp $ + * $Id: PG_Stream.java,v 1.16 2001/11/19 23:16:45 momjian Exp $ * * This class is used by Connection & PGlobj for communicating with the * backend. @@ -371,5 +371,4 @@ public class PG_Stream pg_input.close(); connection.close(); } - } diff --git a/src/interfaces/jdbc/org/postgresql/PostgresqlDataSource.java b/src/interfaces/jdbc/org/postgresql/PostgresqlDataSource.java index 65c110be21b..3b37f790cf5 100644 --- a/src/interfaces/jdbc/org/postgresql/PostgresqlDataSource.java +++ b/src/interfaces/jdbc/org/postgresql/PostgresqlDataSource.java @@ -40,7 +40,7 @@ * * Copyright 1999 (C) Exoffice Technologies Inc. All Rights Reserved. * -* $Id: PostgresqlDataSource.java,v 1.4 2001/11/19 22:33:37 momjian Exp $ +* $Id: PostgresqlDataSource.java,v 1.5 2001/11/19 23:16:45 momjian Exp $ */ @@ -133,38 +133,32 @@ public class PostgresqlDataSource */ private int _loginTimeout; - /* * Holds the user's account name. */ private String _user; - /* * Holds the database password. */ private String _password; - /* * Holds the name of the particular database on the server. */ private String _databaseName; - /* * Description of this datasource. */ private String _description = "PostgreSQL DataSource"; - /* * Holds the database server name. If null, this is * assumed to be the localhost. */ private String _serverName; - /* * Holds the port number where a server is listening. * The default value will open a connection with an @@ -172,7 +166,6 @@ public class PostgresqlDataSource */ private int _portNumber = DEFAULT_PORT; - /* * The default port number. Since we open the connection * without specifying the port if it's the default one, @@ -180,7 +173,6 @@ public class PostgresqlDataSource */ private static final int DEFAULT_PORT = 0; - /* * Holds the log writer to which all messages should be * printed. The default writer is obtained from the driver @@ -189,7 +181,6 @@ public class PostgresqlDataSource */ private transient PrintWriter _logWriter; - /* * Each datasource maintains it's own driver, in case of * driver-specific setup (e.g. pools, log writer). @@ -197,9 +188,6 @@ public class PostgresqlDataSource // FIXME // private transient postgresql.Driver _driver; private transient org.postgresql.Driver _driver; - //--------- - - public PostgresqlDataSource() { @@ -233,12 +221,10 @@ public class PostgresqlDataSource // FIXME // _driver = new postgresql.Driver(); _driver = new org.postgresql.Driver(); - //----------- //FIXME // _driver.setLogWriter( _logWriter ); // Method seems to be unavailable. Just commented it out. - //---------- } catch ( SQLException except ) { @@ -282,7 +268,6 @@ public class PostgresqlDataSource // if ( ! ( conn instanceof postgresql.jdbc2.Connection ) ) { if ( ! ( conn instanceof org.postgresql.jdbc2.Connection ) ) { - //-------- if ( _logWriter != null ) _logWriter.println( "DataSource: JDBC 1 connections not supported" ); throw new PSQLException( "postgresql.ds.onlyjdbc2" ); @@ -317,7 +302,6 @@ public class PostgresqlDataSource // FIXME // _driver.setLogWriter( writer ); // Method seems to be unavailable. Commented it out. - //---------- _logWriter = writer; } } @@ -617,7 +601,5 @@ public class PostgresqlDataSource else return null; } - - } diff --git a/src/interfaces/jdbc/org/postgresql/Statement.java b/src/interfaces/jdbc/org/postgresql/Statement.java index 80e5bf79a8e..95fd62d9f81 100644 --- a/src/interfaces/jdbc/org/postgresql/Statement.java +++ b/src/interfaces/jdbc/org/postgresql/Statement.java @@ -269,50 +269,50 @@ public abstract class Statement char c = sql.charAt(i); switch (state) { - case IN_SQLCODE: - if (c == '\'') // start of a string? - state = IN_STRING; - else if (c == '{') // start of an escape code? - if (i + 1 < len) - { - char next = sql.charAt(i + 1); - if (next == 'd') + case IN_SQLCODE: + if (c == '\'') // start of a string? + state = IN_STRING; + else if (c == '{') // start of an escape code? + if (i + 1 < len) { - state = ESC_TIMEDATE; - i++; - break; + char next = sql.charAt(i + 1); + if (next == 'd') + { + state = ESC_TIMEDATE; + i++; + break; + } + else if (next == 't') + { + state = ESC_TIMEDATE; + i += (i + 2 < len && sql.charAt(i + 2) == 's') ? 2 : 1; + break; + } } - else if (next == 't') - { - state = ESC_TIMEDATE; - i += (i + 2 < len && sql.charAt(i + 2) == 's') ? 2 : 1; - break; - } - } - newsql.append(c); - break; - - case IN_STRING: - if (c == '\'') // end of string? - state = IN_SQLCODE; - else if (c == '\\') // a backslash? - state = BACKSLASH; - - newsql.append(c); - break; - - case BACKSLASH: - state = IN_STRING; - - newsql.append(c); - break; - - case ESC_TIMEDATE: - if (c == '}') - state = IN_SQLCODE; // end of escape code. - else newsql.append(c); - break; + break; + + case IN_STRING: + if (c == '\'') // end of string? + state = IN_SQLCODE; + else if (c == '\\') // a backslash? + state = BACKSLASH; + + newsql.append(c); + break; + + case BACKSLASH: + state = IN_STRING; + + newsql.append(c); + break; + + case ESC_TIMEDATE: + if (c == '}') + state = IN_SQLCODE; // end of escape code. + else + newsql.append(c); + break; } // end switch } diff --git a/src/interfaces/jdbc/org/postgresql/core/BytePoolDim1.java b/src/interfaces/jdbc/org/postgresql/core/BytePoolDim1.java index bc2d6425940..1badf4f0724 100644 --- a/src/interfaces/jdbc/org/postgresql/core/BytePoolDim1.java +++ b/src/interfaces/jdbc/org/postgresql/core/BytePoolDim1.java @@ -6,7 +6,6 @@ package org.postgresql.core; */ public class BytePoolDim1 { - /* * The maximum size of the array we manage. */ @@ -47,26 +46,26 @@ public class BytePoolDim1 // for now until the bug can be removed return new byte[size]; /* - // Don't pool if >maxsize - if (size > maxsize){ - return new byte[size]; - } + // Don't pool if >maxsize + if (size > maxsize){ + return new byte[size]; + } - ObjectPool not_usel = notusemap[size]; - ObjectPool in_usel = inusemap[size]; - byte b[] = null; + ObjectPool not_usel = notusemap[size]; + ObjectPool in_usel = inusemap[size]; + byte b[] = null; - // Fetch from the unused pool if available otherwise allocate a new - // now array - if (!not_usel.isEmpty()) { - Object o = not_usel.remove(); - b = (byte[]) o; - } else - b = new byte[size]; - in_usel.add(b); + // Fetch from the unused pool if available otherwise allocate a new + // now array + if (!not_usel.isEmpty()) { + Object o = not_usel.remove(); + b = (byte[]) o; + } else + b = new byte[size]; + in_usel.add(b); - return b; - */ + return b; + */ } /* diff --git a/src/interfaces/jdbc/org/postgresql/core/BytePoolDim2.java b/src/interfaces/jdbc/org/postgresql/core/BytePoolDim2.java index be115b841d0..df55b30d04f 100644 --- a/src/interfaces/jdbc/org/postgresql/core/BytePoolDim2.java +++ b/src/interfaces/jdbc/org/postgresql/core/BytePoolDim2.java @@ -20,22 +20,22 @@ public class BytePoolDim2 // For now until the bug can be removed return new byte[size][0]; /* - if (size > maxsize){ - return new byte[size][0]; - } - ObjectPool not_usel = notusemap[size]; - ObjectPool in_usel = inusemap[size]; + if (size > maxsize){ + return new byte[size][0]; + } + ObjectPool not_usel = notusemap[size]; + ObjectPool in_usel = inusemap[size]; - byte b[][] = null; + byte b[][] = null; - if (!not_usel.isEmpty()) { - Object o = not_usel.remove(); - b = (byte[][]) o; - } else - b = new byte[size][0]; - in_usel.add(b); - return b; - */ + if (!not_usel.isEmpty()) { + Object o = not_usel.remove(); + b = (byte[][]) o; + } else + b = new byte[size][0]; + in_usel.add(b); + return b; + */ } public void release(byte[][] b) diff --git a/src/interfaces/jdbc/org/postgresql/core/QueryExecutor.java b/src/interfaces/jdbc/org/postgresql/core/QueryExecutor.java index c066001554d..7e85dcd583b 100644 --- a/src/interfaces/jdbc/org/postgresql/core/QueryExecutor.java +++ b/src/interfaces/jdbc/org/postgresql/core/QueryExecutor.java @@ -13,7 +13,7 @@ import org.postgresql.util.PSQLException; *
The lifetime of a QueryExecutor object is from sending the query * until the response has been received from the backend. * - * $Id: QueryExecutor.java,v 1.4 2001/11/19 22:33:37 momjian Exp $ + * $Id: QueryExecutor.java,v 1.5 2001/11/19 23:16:45 momjian Exp $ */ public class QueryExecutor @@ -69,53 +69,53 @@ public class QueryExecutor switch (c) { - case 'A': // Asynchronous Notify - int pid = pg_stream.ReceiveInteger(4); - String msg = pg_stream.ReceiveString(connection.getEncoding()); - break; - case 'B': // Binary Data Transfer - receiveTuple(true); - break; - case 'C': // Command Status - receiveCommandStatus(); + case 'A': // Asynchronous Notify + int pid = pg_stream.ReceiveInteger(4); + String msg = pg_stream.ReceiveString(connection.getEncoding()); + break; + case 'B': // Binary Data Transfer + receiveTuple(true); + break; + case 'C': // Command Status + receiveCommandStatus(); - if (fields != null) - hfr = true; - else - { - sendQuery(" "); - fqp++; - } - break; - case 'D': // Text Data Transfer - receiveTuple(false); - break; - case 'E': // Error Message - throw new SQLException(pg_stream.ReceiveString(connection.getEncoding())); - case 'I': // Empty Query - int t = pg_stream.ReceiveChar(); - if (t != 0) - throw new PSQLException("postgresql.con.garbled"); + if (fields != null) + hfr = true; + else + { + sendQuery(" "); + fqp++; + } + break; + case 'D': // Text Data Transfer + receiveTuple(false); + break; + case 'E': // Error Message + throw new SQLException(pg_stream.ReceiveString(connection.getEncoding())); + case 'I': // Empty Query + int t = pg_stream.ReceiveChar(); + if (t != 0) + throw new PSQLException("postgresql.con.garbled"); - if (fqp > 0) - fqp--; - if (fqp == 0) - hfr = true; - break; - case 'N': // Error Notification - connection.addWarning(pg_stream.ReceiveString(connection.getEncoding())); - break; - case 'P': // Portal Name - String pname = pg_stream.ReceiveString(connection.getEncoding()); - break; - case 'T': // MetaData Field Description - receiveFields(); - break; - case 'Z': // backend ready for query, ignore for now :-) - break; - default: - throw new PSQLException("postgresql.con.type", - new Character((char) c)); + if (fqp > 0) + fqp--; + if (fqp == 0) + hfr = true; + break; + case 'N': // Error Notification + connection.addWarning(pg_stream.ReceiveString(connection.getEncoding())); + break; + case 'P': // Portal Name + String pname = pg_stream.ReceiveString(connection.getEncoding()); + break; + case 'T': // MetaData Field Description + receiveFields(); + break; + case 'Z': // backend ready for query, ignore for now :-) + break; + default: + throw new PSQLException("postgresql.con.type", + new Character((char) c)); } } return connection.getResultSet(connection, statement, fields, tuples, status, update_count, insert_oid, binaryCursor); @@ -162,7 +162,6 @@ public class QueryExecutor */ private void receiveCommandStatus() throws SQLException { - status = pg_stream.ReceiveString(connection.getEncoding()); try diff --git a/src/interfaces/jdbc/org/postgresql/fastpath/Fastpath.java b/src/interfaces/jdbc/org/postgresql/fastpath/Fastpath.java index 5f38d2f8dc9..5c7850147f2 100644 --- a/src/interfaces/jdbc/org/postgresql/fastpath/Fastpath.java +++ b/src/interfaces/jdbc/org/postgresql/fastpath/Fastpath.java @@ -61,7 +61,6 @@ public class Fastpath // added Oct 7 1998 to give us thread safety synchronized (stream) { - // send the function call try { @@ -105,52 +104,52 @@ public class Fastpath //DriverManager.println("ReceiveChar() = "+in+" '"+((char)in)+"'"); switch (in) { - case 'V': - break; + case 'V': + break; - //------------------------------ - // Function returned properly - // - case 'G': - int sz = stream.ReceiveIntegerR(4); - //DriverManager.println("G: size="+sz); //debug + //------------------------------ + // Function returned properly + // + case 'G': + int sz = stream.ReceiveIntegerR(4); + //DriverManager.println("G: size="+sz); //debug - // Return an Integer if - if (resulttype) - result = new Integer(stream.ReceiveIntegerR(sz)); - else - { - byte buf[] = new byte[sz]; - stream.Receive(buf, 0, sz); - result = buf; - } - break; + // Return an Integer if + if (resulttype) + result = new Integer(stream.ReceiveIntegerR(sz)); + else + { + byte buf[] = new byte[sz]; + stream.Receive(buf, 0, sz); + result = buf; + } + break; - //------------------------------ - // Error message returned - case 'E': - throw new PSQLException("postgresql.fp.error", stream.ReceiveString(conn.getEncoding())); + //------------------------------ + // Error message returned + case 'E': + throw new PSQLException("postgresql.fp.error", stream.ReceiveString(conn.getEncoding())); - //------------------------------ - // Notice from backend - case 'N': - conn.addWarning(stream.ReceiveString(conn.getEncoding())); - break; + //------------------------------ + // Notice from backend + case 'N': + conn.addWarning(stream.ReceiveString(conn.getEncoding())); + break; - //------------------------------ - // End of results - // - // Here we simply return res, which would contain the result - // processed earlier. If no result, this already contains null - case '0': - //DriverManager.println("returning "+result); - return result; + //------------------------------ + // End of results + // + // Here we simply return res, which would contain the result + // processed earlier. If no result, this already contains null + case '0': + //DriverManager.println("returning "+result); + return result; - case 'Z': - break; + case 'Z': + break; - default: - throw new PSQLException("postgresql.fp.protocol", new Character((char)in)); + default: + throw new PSQLException("postgresql.fp.protocol", new Character((char)in)); } } } diff --git a/src/interfaces/jdbc/org/postgresql/geometric/PGpath.java b/src/interfaces/jdbc/org/postgresql/geometric/PGpath.java index a260ab928f5..60a4c924883 100644 --- a/src/interfaces/jdbc/org/postgresql/geometric/PGpath.java +++ b/src/interfaces/jdbc/org/postgresql/geometric/PGpath.java @@ -148,5 +148,4 @@ public class PGpath extends PGobject implements Serializable, Cloneable { open = true; } - } diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/DatabaseMetaData.java b/src/interfaces/jdbc/org/postgresql/jdbc1/DatabaseMetaData.java index 0bcb39ca652..cf9a46b4f12 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc1/DatabaseMetaData.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc1/DatabaseMetaData.java @@ -13,7 +13,7 @@ import org.postgresql.util.PSQLException; /* * 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
@@ -1731,20 +1731,20 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
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
@@ -2012,17 +2012,17 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
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") ?
@@ -2262,7 +2262,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
"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" +
@@ -2274,115 +2274,135 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
private java.sql.ResultSet getImportedExportedKeys(String catalog, String schema, String primaryTable, String foreignTable) throws SQLException
{
- Field f[]=new Field[14];
+ 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);
+ 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;
+ 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;
+ 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)));
+ 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
+ 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 Many of the methods here return lists of information in ResultSets. You
* can use the normal ResultSet methods such as getString and getInt to
@@ -88,7 +88,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
public String getURL() throws SQLException
{
String url = connection.getURL();
- Driver.debug("getURL "+url);
+ Driver.debug("getURL " + url);
return url;
}
@@ -101,7 +101,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
public String getUserName() throws SQLException
{
String userName = connection.getUserName();
- Driver.debug("getUserName "+ userName);
+ Driver.debug("getUserName " + userName);
return userName;
}
@@ -114,7 +114,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
public boolean isReadOnly() throws SQLException
{
boolean isReadOnly = connection.isReadOnly();
- Driver.debug("isReadOnly " +isReadOnly);
+ Driver.debug("isReadOnly " + isReadOnly);
return isReadOnly;
}
@@ -164,7 +164,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
public boolean nullsAreSortedAtEnd() throws SQLException
{
boolean nullsAreSortedAtEnd = ! connection.haveMinimumServerVersion("7.2");
- Driver.debug("nullsAreSortedAtEnd "+nullsAreSortedAtEnd);
+ Driver.debug("nullsAreSortedAtEnd " + nullsAreSortedAtEnd);
return nullsAreSortedAtEnd;
}
@@ -209,7 +209,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
}
/*
- * 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.
@@ -218,7 +218,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
public String getDriverVersion() throws SQLException
{
String driverVersion = connection.this_driver.getVersion();
- Driver.debug("getDriverVersion "+driverVersion);
+ Driver.debug("getDriverVersion " + driverVersion);
return driverVersion;
}
@@ -230,7 +230,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
public int getDriverMajorVersion()
{
int majorVersion = connection.this_driver.getMajorVersion();
- Driver.debug("getMajorVersion " +majorVersion);
+ Driver.debug("getMajorVersion " + majorVersion);
return majorVersion;
}
@@ -242,12 +242,12 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
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
@@ -298,7 +298,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
*/
public boolean storesUpperCaseIdentifiers() throws SQLException
{
- Driver.debug("storesUpperCaseIdentifiers "+false);
+ Driver.debug("storesUpperCaseIdentifiers " + false);
return false;
}
@@ -622,13 +622,13 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
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)
@@ -686,7 +686,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
}
/*
- * 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
@@ -715,12 +715,12 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
*/
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
@@ -910,7 +910,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
}
/*
- * 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
@@ -1831,20 +1831,20 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
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
@@ -2243,29 +2243,30 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
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)+"\"");
+ 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);
+ // 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);
}
/*
@@ -2389,7 +2390,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
"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" +
@@ -2401,112 +2402,132 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
private java.sql.ResultSet getImportedExportedKeys(String catalog, String schema, String primaryTable, String foreignTable) throws SQLException
{
- Field f[]=new Field[14];
+ 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);
+ 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;
+ 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