1 package org.postgresql.jdbc1;
3 // IMPORTANT NOTE: This file implements the JDBC 1 version of the driver.
4 // If you make any modifications to this file, you must make sure that the
5 // changes are also made (if relevent) to the related JDBC 2 class in the
6 // org.postgresql.jdbc2 package.
10 import org.postgresql.Field;
13 * This class provides information about the database as a whole.
15 * <p>Many of the methods here return lists of information in ResultSets. You
16 * can use the normal ResultSet methods such as getString and getInt to
17 * retrieve the data from these ResultSets. If a given form of metadata is
18 * not available, these methods should throw a SQLException.
20 * <p>Some of these methods take arguments that are String patterns. These
21 * arguments all have names such as fooPattern. Within a pattern String,
22 * "%" means match any substring of 0 or more characters, and "_" means
23 * match any one character. Only metadata entries matching the search
24 * pattern are returned. if a search pattern argument is set to a null
25 * ref, it means that argument's criteria should be dropped from the
28 * <p>A SQLException will be throws if a driver does not support a meta
29 * data method. In the case of methods that return a ResultSet, either
30 * a ResultSet (which may be empty) is returned or a SQLException is
33 * @see java.sql.DatabaseMetaData
35 public class DatabaseMetaData implements java.sql.DatabaseMetaData
37 Connection connection; // The connection association
39 // These define various OID's. Hopefully they will stay constant.
40 static final int iVarcharOid = 1043; // OID for varchar
41 static final int iBoolOid = 16; // OID for bool
42 static final int iInt2Oid = 21; // OID for int2
43 static final int iInt4Oid = 23; // OID for int4
44 static final int VARHDRSZ = 4; // length for int4
46 // This is a default value for remarks
47 private static final byte defaultRemarks[]="no remarks".getBytes();
49 public DatabaseMetaData(Connection conn)
51 this.connection = conn;
55 * Can all the procedures returned by getProcedures be called
56 * by the current user?
59 * @exception SQLException if a database access error occurs
61 public boolean allProceduresAreCallable() throws SQLException
63 return true; // For now...
67 * Can all the tables returned by getTable be SELECTed by
71 * @exception SQLException if a database access error occurs
73 public boolean allTablesAreSelectable() throws SQLException
75 return true; // For now...
79 * What is the URL for this database?
81 * @return the url or null if it cannott be generated
82 * @exception SQLException if a database access error occurs
84 public String getURL() throws SQLException
86 return connection.getURL();
90 * What is our user name as known to the database?
92 * @return our database user name
93 * @exception SQLException if a database access error occurs
95 public String getUserName() throws SQLException
97 return connection.getUserName();
101 * Is the database in read-only mode?
104 * @exception SQLException if a database access error occurs
106 public boolean isReadOnly() throws SQLException
108 return connection.isReadOnly();
112 * Are NULL values sorted high?
115 * @exception SQLException if a database access error occurs
117 public boolean nullsAreSortedHigh() throws SQLException
123 * Are NULL values sorted low?
126 * @exception SQLException if a database access error occurs
128 public boolean nullsAreSortedLow() throws SQLException
134 * Are NULL values sorted at the start regardless of sort order?
137 * @exception SQLException if a database access error occurs
139 public boolean nullsAreSortedAtStart() throws SQLException
145 * Are NULL values sorted at the end regardless of sort order?
148 * @exception SQLException if a database access error occurs
150 public boolean nullsAreSortedAtEnd() throws SQLException
156 * What is the name of this database product - we hope that it is
157 * PostgreSQL, so we return that explicitly.
159 * @return the database product name
160 * @exception SQLException if a database access error occurs
162 public String getDatabaseProductName() throws SQLException
168 * What is the version of this database product.
170 * @return the database version
171 * @exception SQLException if a database access error occurs
173 public String getDatabaseProductVersion() throws SQLException
175 java.sql.ResultSet resultSet = connection.ExecSQL("select version()");
178 StringTokenizer versionParts = new StringTokenizer(resultSet.getString(1));
179 versionParts.nextToken(); /* "PostgreSQL" */
180 String versionNumber = versionParts.nextToken(); /* "X.Y.Z" */
182 return versionNumber;
186 * What is the name of this JDBC driver? If we don't know this
187 * we are doing something wrong!
189 * @return the JDBC driver name
190 * @exception SQLException why?
192 public String getDriverName() throws SQLException
194 return "PostgreSQL Native Driver";
198 * What is the version string of this JDBC driver? Again, this is
201 * @return the JDBC driver name.
202 * @exception SQLException why?
204 public String getDriverVersion() throws SQLException
206 return connection.this_driver.getVersion();
210 * What is this JDBC driver's major version number?
212 * @return the JDBC driver major version
214 public int getDriverMajorVersion()
216 return connection.this_driver.getMajorVersion();
220 * What is this JDBC driver's minor version number?
222 * @return the JDBC driver minor version
224 public int getDriverMinorVersion()
226 return connection.this_driver.getMinorVersion();
230 * Does the database store tables in a local file? No - it
231 * stores them in a file on the server.
234 * @exception SQLException if a database access error occurs
236 public boolean usesLocalFiles() throws SQLException
242 * Does the database use a file for each table? Well, not really,
243 * since it doesnt use local files.
246 * @exception SQLException if a database access error occurs
248 public boolean usesLocalFilePerTable() throws SQLException
254 * Does the database treat mixed case unquoted SQL identifiers
255 * as case sensitive and as a result store them in mixed case?
256 * A JDBC-Compliant driver will always return false.
258 * <p>Predicament - what do they mean by "SQL identifiers" - if it
259 * means the names of the tables and columns, then the answers
260 * given below are correct - otherwise I don't know.
263 * @exception SQLException if a database access error occurs
265 public boolean supportsMixedCaseIdentifiers() throws SQLException
271 * Does the database treat mixed case unquoted SQL identifiers as
272 * case insensitive and store them in upper case?
276 public boolean storesUpperCaseIdentifiers() throws SQLException
282 * Does the database treat mixed case unquoted SQL identifiers as
283 * case insensitive and store them in lower case?
287 public boolean storesLowerCaseIdentifiers() throws SQLException
293 * Does the database treat mixed case unquoted SQL identifiers as
294 * case insensitive and store them in mixed case?
298 public boolean storesMixedCaseIdentifiers() throws SQLException
304 * Does the database treat mixed case quoted SQL identifiers as
305 * case sensitive and as a result store them in mixed case? A
306 * JDBC compliant driver will always return true.
308 * <p>Predicament - what do they mean by "SQL identifiers" - if it
309 * means the names of the tables and columns, then the answers
310 * given below are correct - otherwise I don't know.
313 * @exception SQLException if a database access error occurs
315 public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException
321 * Does the database treat mixed case quoted SQL identifiers as
322 * case insensitive and store them in upper case?
326 public boolean storesUpperCaseQuotedIdentifiers() throws SQLException
332 * Does the database treat mixed case quoted SQL identifiers as case
333 * insensitive and store them in lower case?
337 public boolean storesLowerCaseQuotedIdentifiers() throws SQLException
343 * Does the database treat mixed case quoted SQL identifiers as case
344 * insensitive and store them in mixed case?
348 public boolean storesMixedCaseQuotedIdentifiers() throws SQLException
354 * What is the string used to quote SQL identifiers? This returns
355 * a space if identifier quoting isn't supported. A JDBC Compliant
356 * driver will always use a double quote character.
358 * <p>If an SQL identifier is a table name, column name, etc. then
359 * we do not support it.
361 * @return the quoting string
362 * @exception SQLException if a database access error occurs
364 public String getIdentifierQuoteString() throws SQLException
370 * Get a comma separated list of all a database's SQL keywords that
371 * are NOT also SQL92 keywords.
373 * <p>Within PostgreSQL, the keywords are found in
374 * src/backend/parser/keywords.c
376 * <p>For SQL Keywords, I took the list provided at
377 * <a href="http://web.dementia.org/~shadow/sql/sql3bnf.sep93.txt">
378 * http://web.dementia.org/~shadow/sql/sql3bnf.sep93.txt</a>
379 * which is for SQL3, not SQL-92, but it is close enough for
382 * @return a comma separated list of keywords we use
383 * @exception SQLException if a database access error occurs
385 public String getSQLKeywords() throws SQLException
387 return "abort,acl,add,aggregate,append,archive,arch_store,backward,binary,change,cluster,copy,database,delimiters,do,extend,explain,forward,heavy,index,inherits,isnull,light,listen,load,merge,nothing,notify,notnull,oids,purge,rename,replace,retrieve,returns,rule,recipe,setof,stdin,stdout,store,vacuum,verbose,version";
390 public String getNumericFunctions() throws SQLException
392 // XXX-Not Implemented
396 public String getStringFunctions() throws SQLException
398 // XXX-Not Implemented
402 public String getSystemFunctions() throws SQLException
404 // XXX-Not Implemented
408 public String getTimeDateFunctions() throws SQLException
410 // XXX-Not Implemented
415 * This is the string that can be used to escape '_' and '%' in
416 * a search string pattern style catalog search parameters
418 * @return the string used to escape wildcard characters
419 * @exception SQLException if a database access error occurs
421 public String getSearchStringEscape() throws SQLException
427 * Get all the "extra" characters that can bew used in unquoted
428 * identifier names (those beyond a-zA-Z0-9 and _)
430 * <p>From the file src/backend/parser/scan.l, an identifier is
431 * {letter}{letter_or_digit} which makes it just those listed
434 * @return a string containing the extra characters
435 * @exception SQLException if a database access error occurs
437 public String getExtraNameCharacters() throws SQLException
443 * Is "ALTER TABLE" with an add column supported?
444 * Yes for PostgreSQL 6.1
447 * @exception SQLException if a database access error occurs
449 public boolean supportsAlterTableWithAddColumn() throws SQLException
455 * Is "ALTER TABLE" with a drop column supported?
456 * Peter 10/10/2000 This was set to true, but 7.1devel doesn't support it!
459 * @exception SQLException if a database access error occurs
461 public boolean supportsAlterTableWithDropColumn() throws SQLException
467 * Is column aliasing supported?
469 * <p>If so, the SQL AS clause can be used to provide names for
470 * computed columns or to provide alias names for columns as
471 * required. A JDBC Compliant driver always returns true.
476 * select count(C) as C_COUNT from T group by C;
479 * should return a column named as C_COUNT instead of count(C)
482 * @exception SQLException if a database access error occurs
484 public boolean supportsColumnAliasing() throws SQLException
490 * Are concatenations between NULL and non-NULL values NULL? A
491 * JDBC Compliant driver always returns true
494 * @exception SQLException if a database access error occurs
496 public boolean nullPlusNonNullIsNull() throws SQLException
501 public boolean supportsConvert() throws SQLException
503 // XXX-Not Implemented
507 public boolean supportsConvert(int fromType, int toType) throws SQLException
509 // XXX-Not Implemented
513 public boolean supportsTableCorrelationNames() throws SQLException
515 // XXX-Not Implemented
519 public boolean supportsDifferentTableCorrelationNames() throws SQLException
521 // XXX-Not Implemented
526 * Are expressions in "ORCER BY" lists supported?
528 * <br>e.g. select * from t order by a + b;
531 * @exception SQLException if a database access error occurs
533 public boolean supportsExpressionsInOrderBy() throws SQLException
539 * Can an "ORDER BY" clause use columns not in the SELECT?
540 * I checked it, and you can't.
543 * @exception SQLException if a database access error occurs
545 public boolean supportsOrderByUnrelated() throws SQLException
551 * Is some form of "GROUP BY" clause supported?
552 * I checked it, and yes it is.
555 * @exception SQLException if a database access error occurs
557 public boolean supportsGroupBy() throws SQLException
563 * Can a "GROUP BY" clause use columns not in the SELECT?
564 * I checked it - it seems to allow it
567 * @exception SQLException if a database access error occurs
569 public boolean supportsGroupByUnrelated() throws SQLException
575 * Can a "GROUP BY" clause add columns not in the SELECT provided
576 * it specifies all the columns in the SELECT? Does anyone actually
577 * understand what they mean here?
580 * @exception SQLException if a database access error occurs
582 public boolean supportsGroupByBeyondSelect() throws SQLException
584 return true; // For now...
588 * Is the escape character in "LIKE" clauses supported? A
589 * JDBC compliant driver always returns true.
592 * @exception SQLException if a database access error occurs
594 public boolean supportsLikeEscapeClause() throws SQLException
600 * Are multiple ResultSets from a single execute supported?
601 * Well, I implemented it, but I dont think this is possible from
602 * the back ends point of view.
605 * @exception SQLException if a database access error occurs
607 public boolean supportsMultipleResultSets() throws SQLException
613 * Can we have multiple transactions open at once (on different
615 * I guess we can have, since Im relying on it.
618 * @exception SQLException if a database access error occurs
620 public boolean supportsMultipleTransactions() throws SQLException
626 * Can columns be defined as non-nullable. A JDBC Compliant driver
627 * always returns true.
629 * <p>This changed from false to true in v6.2 of the driver, as this
630 * support was added to the backend.
633 * @exception SQLException if a database access error occurs
635 public boolean supportsNonNullableColumns() throws SQLException
641 * Does this driver support the minimum ODBC SQL grammar. This
642 * grammar is defined at:
644 * <p><a href="http://www.microsoft.com/msdn/sdk/platforms/doc/odbc/src/intropr.htm">http://www.microsoft.com/msdn/sdk/platforms/doc/odbc/src/intropr.htm</a>
646 * <p>In Appendix C. From this description, we seem to support the
647 * ODBC minimal (Level 0) grammar.
650 * @exception SQLException if a database access error occurs
652 public boolean supportsMinimumSQLGrammar() throws SQLException
658 * Does this driver support the Core ODBC SQL grammar. We need
659 * SQL-92 conformance for this.
662 * @exception SQLException if a database access error occurs
664 public boolean supportsCoreSQLGrammar() throws SQLException
670 * Does this driver support the Extended (Level 2) ODBC SQL
671 * grammar. We don't conform to the Core (Level 1), so we can't
672 * conform to the Extended SQL Grammar.
675 * @exception SQLException if a database access error occurs
677 public boolean supportsExtendedSQLGrammar() throws SQLException
683 * Does this driver support the ANSI-92 entry level SQL grammar?
684 * All JDBC Compliant drivers must return true. I think we have
685 * to support outer joins for this to be true.
688 * @exception SQLException if a database access error occurs
690 public boolean supportsANSI92EntryLevelSQL() throws SQLException
696 * Does this driver support the ANSI-92 intermediate level SQL
697 * grammar? Anyone who does not support Entry level cannot support
698 * Intermediate level.
701 * @exception SQLException if a database access error occurs
703 public boolean supportsANSI92IntermediateSQL() throws SQLException
709 * Does this driver support the ANSI-92 full SQL grammar?
712 * @exception SQLException if a database access error occurs
714 public boolean supportsANSI92FullSQL() throws SQLException
720 * Is the SQL Integrity Enhancement Facility supported?
721 * I haven't seen this mentioned anywhere, so I guess not
724 * @exception SQLException if a database access error occurs
726 public boolean supportsIntegrityEnhancementFacility() throws SQLException
732 * Is some form of outer join supported? From my knowledge, nope.
735 * @exception SQLException if a database access error occurs
737 public boolean supportsOuterJoins() throws SQLException
743 * Are full nexted outer joins supported? Well, we dont support any
744 * form of outer join, so this is no as well
747 * @exception SQLException if a database access error occurs
749 public boolean supportsFullOuterJoins() throws SQLException
755 * Is there limited support for outer joins? (This will be true if
756 * supportFullOuterJoins is true)
759 * @exception SQLException if a database access error occurs
761 public boolean supportsLimitedOuterJoins() throws SQLException
767 * What is the database vendor's preferred term for "schema" - well,
768 * we do not provide support for schemas, so lets just use that
771 * @return the vendor term
772 * @exception SQLException if a database access error occurs
774 public String getSchemaTerm() throws SQLException
780 * What is the database vendor's preferred term for "procedure" -
781 * I kind of like "Procedure" myself.
783 * @return the vendor term
784 * @exception SQLException if a database access error occurs
786 public String getProcedureTerm() throws SQLException
792 * What is the database vendor's preferred term for "catalog"? -
793 * we dont have a preferred term, so just use Catalog
795 * @return the vendor term
796 * @exception SQLException if a database access error occurs
798 public String getCatalogTerm() throws SQLException
804 * Does a catalog appear at the start of a qualified table name?
805 * (Otherwise it appears at the end).
808 * @exception SQLException if a database access error occurs
810 public boolean isCatalogAtStart() throws SQLException
816 * What is the Catalog separator. Hmmm....well, I kind of like
817 * a period (so we get catalog.table definitions). - I don't think
818 * PostgreSQL supports catalogs anyhow, so it makes no difference.
820 * @return the catalog separator string
821 * @exception SQLException if a database access error occurs
823 public String getCatalogSeparator() throws SQLException
825 // PM Sep 29 97 - changed from "." as we don't support catalogs.
830 * Can a schema name be used in a data manipulation statement? Nope.
833 * @exception SQLException if a database access error occurs
835 public boolean supportsSchemasInDataManipulation() throws SQLException
841 * Can a schema name be used in a procedure call statement? Nope.
844 * @exception SQLException if a database access error occurs
846 public boolean supportsSchemasInProcedureCalls() throws SQLException
852 * Can a schema be used in a table definition statement? Nope.
855 * @exception SQLException if a database access error occurs
857 public boolean supportsSchemasInTableDefinitions() throws SQLException
863 * Can a schema name be used in an index definition statement?
866 * @exception SQLException if a database access error occurs
868 public boolean supportsSchemasInIndexDefinitions() throws SQLException
874 * Can a schema name be used in a privilege definition statement?
877 * @exception SQLException if a database access error occurs
879 public boolean supportsSchemasInPrivilegeDefinitions() throws SQLException
885 * Can a catalog name be used in a data manipulation statement?
888 * @exception SQLException if a database access error occurs
890 public boolean supportsCatalogsInDataManipulation() throws SQLException
896 * Can a catalog name be used in a procedure call statement?
899 * @exception SQLException if a database access error occurs
901 public boolean supportsCatalogsInProcedureCalls() throws SQLException
907 * Can a catalog name be used in a table definition statement?
910 * @exception SQLException if a database access error occurs
912 public boolean supportsCatalogsInTableDefinitions() throws SQLException
918 * Can a catalog name be used in an index definition?
921 * @exception SQLException if a database access error occurs
923 public boolean supportsCatalogsInIndexDefinitions() throws SQLException
929 * Can a catalog name be used in a privilege definition statement?
932 * @exception SQLException if a database access error occurs
934 public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException
940 * We support cursors for gets only it seems. I dont see a method
941 * to get a positioned delete.
944 * @exception SQLException if a database access error occurs
946 public boolean supportsPositionedDelete() throws SQLException
948 return false; // For now...
952 * Is positioned UPDATE supported?
955 * @exception SQLException if a database access error occurs
957 public boolean supportsPositionedUpdate() throws SQLException
959 return false; // For now...
962 public boolean supportsSelectForUpdate() throws SQLException
964 // XXX-Not Implemented
968 public boolean supportsStoredProcedures() throws SQLException
970 // XXX-Not Implemented
974 public boolean supportsSubqueriesInComparisons() throws SQLException
976 // XXX-Not Implemented
980 public boolean supportsSubqueriesInExists() throws SQLException
982 // XXX-Not Implemented
986 public boolean supportsSubqueriesInIns() throws SQLException
988 // XXX-Not Implemented
992 public boolean supportsSubqueriesInQuantifieds() throws SQLException
994 // XXX-Not Implemented
998 public boolean supportsCorrelatedSubqueries() throws SQLException
1000 // XXX-Not Implemented
1005 * Is SQL UNION supported? Nope.
1007 * @return true if so
1008 * @exception SQLException if a database access error occurs
1010 public boolean supportsUnion() throws SQLException
1016 * Is SQL UNION ALL supported? Nope.
1018 * @return true if so
1019 * @exception SQLException if a database access error occurs
1021 public boolean supportsUnionAll() throws SQLException
1027 * In PostgreSQL, Cursors are only open within transactions.
1029 * @return true if so
1030 * @exception SQLException if a database access error occurs
1032 public boolean supportsOpenCursorsAcrossCommit() throws SQLException
1038 * Do we support open cursors across multiple transactions?
1040 * @return true if so
1041 * @exception SQLException if a database access error occurs
1043 public boolean supportsOpenCursorsAcrossRollback() throws SQLException
1049 * Can statements remain open across commits? They may, but
1050 * this driver cannot guarentee that. In further reflection.
1051 * we are talking a Statement object jere, so the answer is
1052 * yes, since the Statement is only a vehicle to ExecSQL()
1054 * @return true if they always remain open; false otherwise
1055 * @exception SQLException if a database access error occurs
1057 public boolean supportsOpenStatementsAcrossCommit() throws SQLException
1063 * Can statements remain open across rollbacks? They may, but
1064 * this driver cannot guarentee that. In further contemplation,
1065 * we are talking a Statement object here, so the answer is yes,
1066 * since the Statement is only a vehicle to ExecSQL() in Connection
1068 * @return true if they always remain open; false otherwise
1069 * @exception SQLException if a database access error occurs
1071 public boolean supportsOpenStatementsAcrossRollback() throws SQLException
1077 * How many hex characters can you have in an inline binary literal
1079 * @return the max literal length
1080 * @exception SQLException if a database access error occurs
1082 public int getMaxBinaryLiteralLength() throws SQLException
1084 return 0; // For now...
1088 * What is the maximum length for a character literal
1089 * I suppose it is 8190 (8192 - 2 for the quotes)
1091 * @return the max literal length
1092 * @exception SQLException if a database access error occurs
1094 public int getMaxCharLiteralLength() throws SQLException
1100 * Whats the limit on column name length. The description of
1101 * pg_class would say '32' (length of pg_class.relname) - we
1102 * should probably do a query for this....but....
1104 * @return the maximum column name length
1105 * @exception SQLException if a database access error occurs
1107 public int getMaxColumnNameLength() throws SQLException
1113 * What is the maximum number of columns in a "GROUP BY" clause?
1115 * @return the max number of columns
1116 * @exception SQLException if a database access error occurs
1118 public int getMaxColumnsInGroupBy() throws SQLException
1120 return getMaxColumnsInTable();
1124 * What's the maximum number of columns allowed in an index?
1125 * 6.0 only allowed one column, but 6.1 introduced multi-column
1126 * indices, so, theoretically, its all of them.
1128 * @return max number of columns
1129 * @exception SQLException if a database access error occurs
1131 public int getMaxColumnsInIndex() throws SQLException
1133 return getMaxColumnsInTable();
1137 * What's the maximum number of columns in an "ORDER BY clause?
1138 * Theoretically, all of them!
1140 * @return the max columns
1141 * @exception SQLException if a database access error occurs
1143 public int getMaxColumnsInOrderBy() throws SQLException
1145 return getMaxColumnsInTable();
1149 * What is the maximum number of columns in a "SELECT" list?
1150 * Theoretically, all of them!
1152 * @return the max columns
1153 * @exception SQLException if a database access error occurs
1155 public int getMaxColumnsInSelect() throws SQLException
1157 return getMaxColumnsInTable();
1161 * What is the maximum number of columns in a table? From the
1162 * create_table(l) manual page...
1164 * <p>"The new class is created as a heap with no initial data. A
1165 * class can have no more than 1600 attributes (realistically,
1166 * this is limited by the fact that tuple sizes must be less than
1169 * @return the max columns
1170 * @exception SQLException if a database access error occurs
1172 public int getMaxColumnsInTable() throws SQLException
1178 * How many active connection can we have at a time to this
1179 * database? Well, since it depends on postmaster, which just
1180 * does a listen() followed by an accept() and fork(), its
1181 * basically very high. Unless the system runs out of processes,
1182 * it can be 65535 (the number of aux. ports on a TCP/IP system).
1183 * I will return 8192 since that is what even the largest system
1184 * can realistically handle,
1186 * @return the maximum number of connections
1187 * @exception SQLException if a database access error occurs
1189 public int getMaxConnections() throws SQLException
1195 * What is the maximum cursor name length (the same as all
1196 * the other F***** identifiers!)
1198 * @return max cursor name length in bytes
1199 * @exception SQLException if a database access error occurs
1201 public int getMaxCursorNameLength() throws SQLException
1207 * What is the maximum length of an index (in bytes)? Now, does
1208 * the spec. mean name of an index (in which case its 32, the
1209 * same as a table) or does it mean length of an index element
1210 * (in which case its 8192, the size of a row) or does it mean
1211 * the number of rows it can access (in which case it 2^32 -
1212 * a 4 byte OID number)? I think its the length of an index
1213 * element, personally, so Im setting it to 65535.
1215 * @return max index length in bytes
1216 * @exception SQLException if a database access error occurs
1218 public int getMaxIndexLength() throws SQLException
1223 public int getMaxSchemaNameLength() throws SQLException
1225 // XXX-Not Implemented
1230 * What is the maximum length of a procedure name?
1231 * (length of pg_proc.proname used) - again, I really
1232 * should do a query here to get it.
1234 * @return the max name length in bytes
1235 * @exception SQLException if a database access error occurs
1237 public int getMaxProcedureNameLength() throws SQLException
1242 public int getMaxCatalogNameLength() throws SQLException
1244 // XXX-Not Implemented
1249 * What is the maximum length of a single row? (not including
1250 * blobs). 65535 is defined in PostgreSQL.
1252 * @return max row size in bytes
1253 * @exception SQLException if a database access error occurs
1255 public int getMaxRowSize() throws SQLException
1261 * Did getMaxRowSize() include LONGVARCHAR and LONGVARBINARY
1262 * blobs? We don't handle blobs yet
1264 * @return true if so
1265 * @exception SQLException if a database access error occurs
1267 public boolean doesMaxRowSizeIncludeBlobs() throws SQLException
1273 * What is the maximum length of a SQL statement?
1275 * @return max length in bytes
1276 * @exception SQLException if a database access error occurs
1278 public int getMaxStatementLength() throws SQLException
1284 * How many active statements can we have open at one time to
1285 * this database? Basically, since each Statement downloads
1286 * the results as the query is executed, we can have many. However,
1287 * we can only really have one statement per connection going
1288 * at once (since they are executed serially) - so we return
1291 * @return the maximum
1292 * @exception SQLException if a database access error occurs
1294 public int getMaxStatements() throws SQLException
1300 * What is the maximum length of a table name? This was found
1301 * from pg_class.relname length
1303 * @return max name length in bytes
1304 * @exception SQLException if a database access error occurs
1306 public int getMaxTableNameLength() throws SQLException
1312 * What is the maximum number of tables that can be specified
1313 * in a SELECT? Theoretically, this is the same number as the
1314 * number of tables allowable. In practice tho, it is much smaller
1315 * since the number of tables is limited by the statement, we
1316 * return 1024 here - this is just a number I came up with (being
1317 * the number of tables roughly of three characters each that you
1318 * can fit inside a 65535 character buffer with comma separators).
1320 * @return the maximum
1321 * @exception SQLException if a database access error occurs
1323 public int getMaxTablesInSelect() throws SQLException
1329 * What is the maximum length of a user name? Well, we generally
1330 * use UNIX like user names in PostgreSQL, so I think this would
1331 * be 8. However, showing the schema for pg_user shows a length
1332 * for username of 32.
1334 * @return the max name length in bytes
1335 * @exception SQLException if a database access error occurs
1337 public int getMaxUserNameLength() throws SQLException
1344 * What is the database's default transaction isolation level? We
1345 * do not support this, so all transactions are SERIALIZABLE.
1347 * @return the default isolation level
1348 * @exception SQLException if a database access error occurs
1351 public int getDefaultTransactionIsolation() throws SQLException
1353 return Connection.TRANSACTION_READ_COMMITTED;
1357 * Are transactions supported? If not, commit and rollback are noops
1358 * and the isolation level is TRANSACTION_NONE. We do support
1361 * @return true if transactions are supported
1362 * @exception SQLException if a database access error occurs
1364 public boolean supportsTransactions() throws SQLException
1370 * Does the database support the given transaction isolation level?
1371 * We only support TRANSACTION_SERIALIZABLE and TRANSACTION_READ_COMMITTED
1373 * @param level the values are defined in java.sql.Connection
1374 * @return true if so
1375 * @exception SQLException if a database access error occurs
1378 public boolean supportsTransactionIsolationLevel(int level) throws SQLException
1380 if (level == Connection.TRANSACTION_SERIALIZABLE ||
1381 level == Connection.TRANSACTION_READ_COMMITTED)
1388 * Are both data definition and data manipulation transactions
1389 * supported? I checked it, and could not do a CREATE TABLE
1390 * within a transaction, so I am assuming that we don't
1392 * @return true if so
1393 * @exception SQLException if a database access error occurs
1395 public boolean supportsDataDefinitionAndDataManipulationTransactions() throws SQLException
1401 * Are only data manipulation statements withing a transaction
1404 * @return true if so
1405 * @exception SQLException if a database access error occurs
1407 public boolean supportsDataManipulationTransactionsOnly() throws SQLException
1413 * Does a data definition statement within a transaction force
1414 * the transaction to commit? I think this means something like:
1417 * CREATE TABLE T (A INT);
1418 * INSERT INTO T (A) VALUES (2);
1420 * UPDATE T SET A = A + 1;
1421 * CREATE TABLE X (A INT);
1422 * SELECT A FROM T INTO X;
1426 * does the CREATE TABLE call cause a commit? The answer is no.
1428 * @return true if so
1429 * @exception SQLException if a database access error occurs
1431 public boolean dataDefinitionCausesTransactionCommit() throws SQLException
1437 * Is a data definition statement within a transaction ignored?
1438 * It seems to be (from experiment in previous method)
1440 * @return true if so
1441 * @exception SQLException if a database access error occurs
1443 public boolean dataDefinitionIgnoredInTransactions() throws SQLException
1449 * Get a description of stored procedures available in a catalog
1451 * <p>Only procedure descriptions matching the schema and procedure
1452 * name criteria are returned. They are ordered by PROCEDURE_SCHEM
1453 * and PROCEDURE_NAME
1455 * <p>Each procedure description has the following columns:
1457 * <li><b>PROCEDURE_CAT</b> String => procedure catalog (may be null)
1458 * <li><b>PROCEDURE_SCHEM</b> String => procedure schema (may be null)
1459 * <li><b>PROCEDURE_NAME</b> String => procedure name
1460 * <li><b>Field 4</b> reserved (make it null)
1461 * <li><b>Field 5</b> reserved (make it null)
1462 * <li><b>Field 6</b> reserved (make it null)
1463 * <li><b>REMARKS</b> String => explanatory comment on the procedure
1464 * <li><b>PROCEDURE_TYPE</b> short => kind of procedure
1466 * <li> procedureResultUnknown - May return a result
1467 * <li> procedureNoResult - Does not return a result
1468 * <li> procedureReturnsResult - Returns a result
1472 * @param catalog - a catalog name; "" retrieves those without a
1473 * catalog; null means drop catalog name from criteria
1474 * @param schemaParrern - a schema name pattern; "" retrieves those
1475 * without a schema - we ignore this parameter
1476 * @param procedureNamePattern - a procedure name pattern
1477 * @return ResultSet - each row is a procedure description
1478 * @exception SQLException if a database access error occurs
1480 public java.sql.ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern) throws SQLException
1482 // the field descriptors for the new ResultSet
1483 Field f[] = new Field[8];
1484 java.sql.ResultSet r; // ResultSet for the SQL query that we need to do
1485 Vector v = new Vector(); // The new ResultSet tuple stuff
1487 byte remarks[] = defaultRemarks;
1489 f[0] = new Field(connection, "PROCEDURE_CAT", iVarcharOid, 32);
1490 f[1] = new Field(connection, "PROCEDURE_SCHEM", iVarcharOid, 32);
1491 f[2] = new Field(connection, "PROCEDURE_NAME", iVarcharOid, 32);
1492 f[3] = f[4] = f[5] = null; // reserved, must be null for now
1493 f[6] = new Field(connection, "REMARKS", iVarcharOid, 8192);
1494 f[7] = new Field(connection, "PROCEDURE_TYPE", iInt2Oid, 2);
1496 // If the pattern is null, then set it to the default
1497 if(procedureNamePattern==null)
1498 procedureNamePattern="%";
1500 r = connection.ExecSQL("select proname, proretset from pg_proc where proname like '"+procedureNamePattern.toLowerCase()+"' order by proname");
1504 byte[][] tuple = new byte[8][0];
1506 tuple[0] = null; // Catalog name
1507 tuple[1] = null; // Schema name
1508 tuple[2] = r.getBytes(1); // Procedure name
1509 tuple[3] = tuple[4] = tuple[5] = null; // Reserved
1510 tuple[6] = remarks; // Remarks
1512 if (r.getBoolean(2))
1513 tuple[7] = Integer.toString(java.sql.DatabaseMetaData.procedureReturnsResult).getBytes();
1515 tuple[7] = Integer.toString(java.sql.DatabaseMetaData.procedureNoResult).getBytes();
1517 v.addElement(tuple);
1519 return new ResultSet(connection, f, v, "OK", 1);
1523 * Get a description of a catalog's stored procedure parameters
1524 * and result columns.
1526 * <p>Only descriptions matching the schema, procedure and parameter
1527 * name criteria are returned. They are ordered by PROCEDURE_SCHEM
1528 * and PROCEDURE_NAME. Within this, the return value, if any, is
1529 * first. Next are the parameter descriptions in call order. The
1530 * column descriptions follow in column number order.
1532 * <p>Each row in the ResultSet is a parameter description or column
1533 * description with the following fields:
1535 * <li><b>PROCEDURE_CAT</b> String => procedure catalog (may be null)
1536 * <li><b>PROCEDURE_SCHE</b>M String => procedure schema (may be null)
1537 * <li><b>PROCEDURE_NAME</b> String => procedure name
1538 * <li><b>COLUMN_NAME</b> String => column/parameter name
1539 * <li><b>COLUMN_TYPE</b> Short => kind of column/parameter:
1540 * <ul><li>procedureColumnUnknown - nobody knows
1541 * <li>procedureColumnIn - IN parameter
1542 * <li>procedureColumnInOut - INOUT parameter
1543 * <li>procedureColumnOut - OUT parameter
1544 * <li>procedureColumnReturn - procedure return value
1545 * <li>procedureColumnResult - result column in ResultSet
1547 * <li><b>DATA_TYPE</b> short => SQL type from java.sql.Types
1548 * <li><b>TYPE_NAME</b> String => SQL type name
1549 * <li><b>PRECISION</b> int => precision
1550 * <li><b>LENGTH</b> int => length in bytes of data
1551 * <li><b>SCALE</b> short => scale
1552 * <li><b>RADIX</b> short => radix
1553 * <li><b>NULLABLE</b> short => can it contain NULL?
1554 * <ul><li>procedureNoNulls - does not allow NULL values
1555 * <li>procedureNullable - allows NULL values
1556 * <li>procedureNullableUnknown - nullability unknown
1557 * <li><b>REMARKS</b> String => comment describing parameter/column
1559 * @param catalog This is ignored in org.postgresql, advise this is set to null
1560 * @param schemaPattern This is ignored in org.postgresql, advise this is set to null
1561 * @param procedureNamePattern a procedure name pattern
1562 * @param columnNamePattern a column name pattern
1563 * @return each row is a stored procedure parameter or column description
1564 * @exception SQLException if a database-access error occurs
1565 * @see #getSearchStringEscape
1567 // Implementation note: This is required for Borland's JBuilder to work
1568 public java.sql.ResultSet getProcedureColumns(String catalog, String schemaPattern, String procedureNamePattern, String columnNamePattern) throws SQLException
1570 if(procedureNamePattern==null)
1571 procedureNamePattern="%";
1573 if(columnNamePattern==null)
1574 columnNamePattern="%";
1576 // for now, this returns an empty result set.
1577 Field f[] = new Field[13];
1578 ResultSet r; // ResultSet for the SQL query that we need to do
1579 Vector v = new Vector(); // The new ResultSet tuple stuff
1581 f[0] = new Field(connection, "PROCEDURE_CAT", iVarcharOid, 32);
1582 f[1] = new Field(connection, "PROCEDURE_SCHEM", iVarcharOid, 32);
1583 f[2] = new Field(connection, "PROCEDURE_NAME", iVarcharOid, 32);
1584 f[3] = new Field(connection, "COLUMN_NAME", iVarcharOid, 32);
1585 f[4] = new Field(connection, "COLUMN_TYPE", iInt2Oid, 2);
1586 f[5] = new Field(connection, "DATA_TYPE", iInt2Oid, 2);
1587 f[6] = new Field(connection, "TYPE_NAME", iVarcharOid, 32);
1588 f[7] = new Field(connection, "PRECISION", iInt4Oid, 4);
1589 f[8] = new Field(connection, "LENGTH", iInt4Oid, 4);
1590 f[9] = new Field(connection, "SCALE", iInt2Oid, 2);
1591 f[10] = new Field(connection, "RADIX", iInt2Oid, 2);
1592 f[11] = new Field(connection, "NULLABLE", iInt2Oid, 2);
1593 f[12] = new Field(connection, "REMARKS", iVarcharOid, 32);
1595 // add query loop here
1597 return new ResultSet(connection, f, v, "OK", 1);
1601 * Get a description of tables available in a catalog.
1603 * <p>Only table descriptions matching the catalog, schema, table
1604 * name and type criteria are returned. They are ordered by
1605 * TABLE_TYPE, TABLE_SCHEM and TABLE_NAME.
1607 * <p>Each table description has the following columns:
1610 * <li><b>TABLE_CAT</b> String => table catalog (may be null)
1611 * <li><b>TABLE_SCHEM</b> String => table schema (may be null)
1612 * <li><b>TABLE_NAME</b> String => table name
1613 * <li><b>TABLE_TYPE</b> String => table type. Typical types are "TABLE",
1614 * "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", "LOCAL
1615 * TEMPORARY", "ALIAS", "SYNONYM".
1616 * <li><b>REMARKS</b> String => explanatory comment on the table
1619 * <p>The valid values for the types parameter are:
1620 * "TABLE", "INDEX", "LARGE OBJECT", "SEQUENCE", "SYSTEM TABLE" and
1623 * @param catalog a catalog name; For org.postgresql, this is ignored, and
1624 * should be set to null
1625 * @param schemaPattern a schema name pattern; For org.postgresql, this is ignored, and
1626 * should be set to null
1627 * @param tableNamePattern a table name pattern. For all tables this should be "%"
1628 * @param types a list of table types to include; null returns
1630 * @return each row is a table description
1631 * @exception SQLException if a database-access error occurs.
1633 public java.sql.ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String types[]) throws SQLException
1635 // Handle default value for types
1637 types = defaultTableTypes;
1639 if(tableNamePattern==null)
1640 tableNamePattern="%";
1642 // the field descriptors for the new ResultSet
1643 Field f[] = new Field[5];
1644 java.sql.ResultSet r; // ResultSet for the SQL query that we need to do
1645 Vector v = new Vector(); // The new ResultSet tuple stuff
1647 f[0] = new Field(connection, "TABLE_CAT", iVarcharOid, 32);
1648 f[1] = new Field(connection, "TABLE_SCHEM", iVarcharOid, 32);
1649 f[2] = new Field(connection, "TABLE_NAME", iVarcharOid, 32);
1650 f[3] = new Field(connection, "TABLE_TYPE", iVarcharOid, 32);
1651 f[4] = new Field(connection, "REMARKS", iVarcharOid, 32);
1653 // Now form the query
1654 StringBuffer sql = new StringBuffer("select relname,oid,relkind from pg_class where (");
1655 boolean notFirst=false;
1656 for(int i=0;i<types.length;i++) {
1657 for(int j=0;j<getTableTypes.length;j++)
1658 if(getTableTypes[j][0].equals(types[i])) {
1661 sql.append(getTableTypes[j][1]);
1666 // Added by Stefan Andreasen <stefan@linux.kapow.dk>
1667 // Now take the pattern into account
1668 sql.append(") and relname like '");
1669 sql.append(tableNamePattern.toLowerCase());
1672 // Now run the query
1673 r = connection.ExecSQL(sql.toString());
1679 byte[][] tuple = new byte[5][0];
1681 // Fetch the description for the table (if any)
1682 java.sql.ResultSet dr = connection.ExecSQL("select description from pg_description where objoid="+r.getInt(2));
1683 if(((org.postgresql.ResultSet)dr).getTupleCount()==1) {
1685 remarks = dr.getBytes(1);
1687 remarks = defaultRemarks;
1691 switch (r.getBytes(3)[0]) {
1699 relKind = "SEQUENCE";
1705 tuple[0] = null; // Catalog name
1706 tuple[1] = null; // Schema name
1707 tuple[2] = r.getBytes(1); // Table name
1708 tuple[3] = relKind.getBytes(); // Table type
1709 tuple[4] = remarks; // Remarks
1710 v.addElement(tuple);
1713 return new ResultSet(connection, f, v, "OK", 1);
1716 // This array contains the valid values for the types argument
1719 // Each supported type consists of it's name, and the sql where
1720 // clause to retrieve that value.
1722 // IMPORTANT: the query must be enclosed in ( )
1723 private static final String getTableTypes[][] = {
1724 {"TABLE", "(relkind='r' and relhasrules='f' and relname !~ '^pg_' and relname !~ '^xinv')"},
1725 {"VIEW", "(relkind='v' and relname !~ '^pg_' and relname !~ '^xinv')"},
1726 {"INDEX", "(relkind='i' and relname !~ '^pg_' and relname !~ '^xinx')"},
1727 {"LARGE OBJECT", "(relkind='r' and relname ~ '^xinv')"},
1728 {"SEQUENCE", "(relkind='S' and relname !~ '^pg_')"},
1729 {"SYSTEM TABLE", "(relkind='r' and relname ~ '^pg_')"},
1730 {"SYSTEM INDEX", "(relkind='i' and relname ~ '^pg_')"}
1733 // These are the default tables, used when NULL is passed to getTables
1734 // The choice of these provide the same behaviour as psql's \d
1735 private static final String defaultTableTypes[] = {
1736 "TABLE","VIEW","INDEX","SEQUENCE"
1740 * Get the schema names available in this database. The results
1741 * are ordered by schema name.
1743 * <P>The schema column is:
1745 * <LI><B>TABLE_SCHEM</B> String => schema name
1748 * @return ResultSet each row has a single String column that is a
1751 public java.sql.ResultSet getSchemas() throws SQLException
1753 // We don't use schemas, so we simply return a single schema name "".
1755 Field f[] = new Field[1];
1756 Vector v = new Vector();
1757 byte[][] tuple = new byte[1][0];
1758 f[0] = new Field(connection,"TABLE_SCHEM",iVarcharOid,32);
1759 tuple[0] = "".getBytes();
1760 v.addElement(tuple);
1761 return new ResultSet(connection,f,v,"OK",1);
1765 * Get the catalog names available in this database. The results
1766 * are ordered by catalog name.
1768 * <P>The catalog column is:
1770 * <LI><B>TABLE_CAT</B> String => catalog name
1773 * @return ResultSet each row has a single String column that is a
1776 public java.sql.ResultSet getCatalogs() throws SQLException
1778 // We don't use catalogs, so we simply return a single catalog name "".
1779 Field f[] = new Field[1];
1780 Vector v = new Vector();
1781 byte[][] tuple = new byte[1][0];
1782 f[0] = new Field(connection,"TABLE_CAT",iVarcharOid,32);
1783 tuple[0] = "".getBytes();
1784 v.addElement(tuple);
1785 return new ResultSet(connection,f,v,"OK",1);
1789 * Get the table types available in this database. The results
1790 * are ordered by table type.
1792 * <P>The table type is:
1794 * <LI><B>TABLE_TYPE</B> String => table type. Typical types are "TABLE",
1795 * "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY",
1796 * "LOCAL TEMPORARY", "ALIAS", "SYNONYM".
1799 * @return ResultSet each row has a single String column that is a
1802 public java.sql.ResultSet getTableTypes() throws SQLException
1804 Field f[] = new Field[1];
1805 Vector v = new Vector();
1806 f[0] = new Field(connection,new String("TABLE_TYPE"),iVarcharOid,32);
1807 for(int i=0;i<getTableTypes.length;i++) {
1808 byte[][] tuple = new byte[1][0];
1809 tuple[0] = getTableTypes[i][0].getBytes();
1810 v.addElement(tuple);
1812 return new ResultSet(connection,f,v,"OK",1);
1816 * Get a description of table columns available in a catalog.
1818 * <P>Only column descriptions matching the catalog, schema, table
1819 * and column name criteria are returned. They are ordered by
1820 * TABLE_SCHEM, TABLE_NAME and ORDINAL_POSITION.
1822 * <P>Each column description has the following columns:
1824 * <LI><B>TABLE_CAT</B> String => table catalog (may be null)
1825 * <LI><B>TABLE_SCHEM</B> String => table schema (may be null)
1826 * <LI><B>TABLE_NAME</B> String => table name
1827 * <LI><B>COLUMN_NAME</B> String => column name
1828 * <LI><B>DATA_TYPE</B> short => SQL type from java.sql.Types
1829 * <LI><B>TYPE_NAME</B> String => Data source dependent type name
1830 * <LI><B>COLUMN_SIZE</B> int => column size. For char or date
1831 * types this is the maximum number of characters, for numeric or
1832 * decimal types this is precision.
1833 * <LI><B>BUFFER_LENGTH</B> is not used.
1834 * <LI><B>DECIMAL_DIGITS</B> int => the number of fractional digits
1835 * <LI><B>NUM_PREC_RADIX</B> int => Radix (typically either 10 or 2)
1836 * <LI><B>NULLABLE</B> int => is NULL allowed?
1838 * <LI> columnNoNulls - might not allow NULL values
1839 * <LI> columnNullable - definitely allows NULL values
1840 * <LI> columnNullableUnknown - nullability unknown
1842 * <LI><B>REMARKS</B> String => comment describing column (may be null)
1843 * <LI><B>COLUMN_DEF</B> String => default value (may be null)
1844 * <LI><B>SQL_DATA_TYPE</B> int => unused
1845 * <LI><B>SQL_DATETIME_SUB</B> int => unused
1846 * <LI><B>CHAR_OCTET_LENGTH</B> int => for char types the
1847 * maximum number of bytes in the column
1848 * <LI><B>ORDINAL_POSITION</B> int => index of column in table
1850 * <LI><B>IS_NULLABLE</B> String => "NO" means column definitely
1851 * does not allow NULL values; "YES" means the column might
1852 * allow NULL values. An empty string means nobody knows.
1855 * @param catalog a catalog name; "" retrieves those without a catalog
1856 * @param schemaPattern a schema name pattern; "" retrieves those
1858 * @param tableNamePattern a table name pattern
1859 * @param columnNamePattern a column name pattern
1860 * @return ResultSet each row is a column description
1861 * @see #getSearchStringEscape
1863 public java.sql.ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException
1865 // the field descriptors for the new ResultSet
1866 Field f[] = new Field[18];
1867 java.sql.ResultSet r; // ResultSet for the SQL query that we need to do
1868 Vector v = new Vector(); // The new ResultSet tuple stuff
1870 f[0] = new Field(connection, "TABLE_CAT", iVarcharOid, 32);
1871 f[1] = new Field(connection, "TABLE_SCHEM", iVarcharOid, 32);
1872 f[2] = new Field(connection, "TABLE_NAME", iVarcharOid, 32);
1873 f[3] = new Field(connection, "COLUMN_NAME", iVarcharOid, 32);
1874 f[4] = new Field(connection, "DATA_TYPE", iInt2Oid, 2);
1875 f[5] = new Field(connection, "TYPE_NAME", iVarcharOid, 32);
1876 f[6] = new Field(connection, "COLUMN_SIZE", iInt4Oid, 4);
1877 f[7] = new Field(connection, "BUFFER_LENGTH", iVarcharOid, 32);
1878 f[8] = new Field(connection, "DECIMAL_DIGITS", iInt4Oid, 4);
1879 f[9] = new Field(connection, "NUM_PREC_RADIX", iInt4Oid, 4);
1880 f[10] = new Field(connection, "NULLABLE", iInt4Oid, 4);
1881 f[11] = new Field(connection, "REMARKS", iVarcharOid, 32);
1882 f[12] = new Field(connection, "COLUMN_DEF", iVarcharOid, 32);
1883 f[13] = new Field(connection, "SQL_DATA_TYPE", iInt4Oid, 4);
1884 f[14] = new Field(connection, "SQL_DATETIME_SUB", iInt4Oid, 4);
1885 f[15] = new Field(connection, "CHAR_OCTET_LENGTH", iVarcharOid, 32);
1886 f[16] = new Field(connection, "ORDINAL_POSITION", iInt4Oid,4);
1887 f[17] = new Field(connection, "IS_NULLABLE", iVarcharOid, 32);
1889 // Added by Stefan Andreasen <stefan@linux.kapow.dk>
1890 // If the pattern are null then set them to %
1891 if (tableNamePattern == null) tableNamePattern="%";
1892 if (columnNamePattern == null) columnNamePattern="%";
1894 // Now form the query
1895 // Modified by Stefan Andreasen <stefan@linux.kapow.dk>
1896 r = connection.ExecSQL("select a.oid,c.relname,a.attname,a.atttypid,a.attnum,a.attnotnull,a.attlen,a.atttypmod from pg_class c, pg_attribute a where a.attrelid=c.oid and c.relname like '"+tableNamePattern.toLowerCase()+"' and a.attname like '"+columnNamePattern.toLowerCase()+"' and a.attnum>0 order by c.relname,a.attnum");
1901 byte[][] tuple = new byte[18][0];
1903 // Fetch the description for the table (if any)
1904 java.sql.ResultSet dr = connection.ExecSQL("select description from pg_description where objoid="+r.getInt(1));
1905 if(((org.postgresql.ResultSet)dr).getTupleCount()==1) {
1907 tuple[11] = dr.getBytes(1);
1909 tuple[11] = defaultRemarks;
1913 tuple[0] = "".getBytes(); // Catalog name
1914 tuple[1] = "".getBytes(); // Schema name
1915 tuple[2] = r.getBytes(2); // Table name
1916 tuple[3] = r.getBytes(3); // Column name
1918 dr = connection.ExecSQL("select typname from pg_type where oid = "+r.getString(4));
1920 String typname=dr.getString(1);
1922 tuple[4] = Integer.toString(Field.getSQLType(typname)).getBytes(); // Data type
1923 tuple[5] = typname.getBytes(); // Type name
1926 // Looking at the psql source,
1927 // I think the length of a varchar as specified when the table was created
1928 // should be extracted from atttypmod which contains this length + sizeof(int32)
1929 if (typname.equals("bpchar") || typname.equals("varchar")) {
1930 int atttypmod = r.getInt(8);
1931 tuple[6] = Integer.toString(atttypmod != -1 ? atttypmod - VARHDRSZ : 0).getBytes();
1933 tuple[6] = r.getBytes(7);
1935 tuple[7] = null; // Buffer length
1937 tuple[8] = "0".getBytes(); // Decimal Digits - how to get this?
1938 tuple[9] = "10".getBytes(); // Num Prec Radix - assume decimal
1940 // tuple[10] is below
1941 // tuple[11] is above
1943 tuple[12] = null; // column default
1945 tuple[13] = null; // sql data type (unused)
1946 tuple[14] = null; // sql datetime sub (unused)
1948 tuple[15] = tuple[6]; // char octet length
1950 tuple[16] = r.getBytes(5); // ordinal position
1952 String nullFlag = r.getString(6);
1953 tuple[10] = Integer.toString(nullFlag.equals("f")?java.sql.DatabaseMetaData.columnNullable:java.sql.DatabaseMetaData.columnNoNulls).getBytes(); // Nullable
1954 tuple[17] = (nullFlag.equals("f")?"YES":"NO").getBytes(); // is nullable
1956 v.addElement(tuple);
1959 return new ResultSet(connection, f, v, "OK", 1);
1963 * Get a description of the access rights for a table's columns.
1965 * <P>Only privileges matching the column name criteria are
1966 * returned. They are ordered by COLUMN_NAME and PRIVILEGE.
1968 * <P>Each privilige description has the following columns:
1970 * <LI><B>TABLE_CAT</B> String => table catalog (may be null)
1971 * <LI><B>TABLE_SCHEM</B> String => table schema (may be null)
1972 * <LI><B>TABLE_NAME</B> String => table name
1973 * <LI><B>COLUMN_NAME</B> String => column name
1974 * <LI><B>GRANTOR</B> => grantor of access (may be null)
1975 * <LI><B>GRANTEE</B> String => grantee of access
1976 * <LI><B>PRIVILEGE</B> String => name of access (SELECT,
1977 * INSERT, UPDATE, REFRENCES, ...)
1978 * <LI><B>IS_GRANTABLE</B> String => "YES" if grantee is permitted
1979 * to grant to others; "NO" if not; null if unknown
1982 * @param catalog a catalog name; "" retrieves those without a catalog
1983 * @param schema a schema name; "" retrieves those without a schema
1984 * @param table a table name
1985 * @param columnNamePattern a column name pattern
1986 * @return ResultSet each row is a column privilege description
1987 * @see #getSearchStringEscape
1989 public java.sql.ResultSet getColumnPrivileges(String catalog, String schema, String table, String columnNamePattern) throws SQLException
1991 Field f[] = new Field[8];
1992 Vector v = new Vector();
1997 if(columnNamePattern==null)
1998 columnNamePattern="%";
2000 columnNamePattern=columnNamePattern.toLowerCase();
2002 f[0] = new Field(connection,"TABLE_CAT",iVarcharOid,32);
2003 f[1] = new Field(connection,"TABLE_SCHEM",iVarcharOid,32);
2004 f[2] = new Field(connection,"TABLE_NAME",iVarcharOid,32);
2005 f[3] = new Field(connection,"COLUMN_NAME",iVarcharOid,32);
2006 f[4] = new Field(connection,"GRANTOR",iVarcharOid,32);
2007 f[5] = new Field(connection,"GRANTEE",iVarcharOid,32);
2008 f[6] = new Field(connection,"PRIVILEGE",iVarcharOid,32);
2009 f[7] = new Field(connection,"IS_GRANTABLE",iVarcharOid,32);
2011 // This is taken direct from the psql source
2012 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 '"+table.toLowerCase()+"' ORDER BY relname");
2014 byte[][] tuple = new byte[8][0];
2015 tuple[0] = tuple[1]= "".getBytes();
2016 DriverManager.println("relname=\""+r.getString(1)+"\" relacl=\""+r.getString(2)+"\"");
2018 // For now, don't add to the result as relacl needs to be processed.
2019 //v.addElement(tuple);
2022 return new ResultSet(connection,f,v,"OK",1);
2026 * Get a description of the access rights for each table available
2029 * <P>Only privileges matching the schema and table name
2030 * criteria are returned. They are ordered by TABLE_SCHEM,
2031 * TABLE_NAME, and PRIVILEGE.
2033 * <P>Each privilige description has the following columns:
2035 * <LI><B>TABLE_CAT</B> String => table catalog (may be null)
2036 * <LI><B>TABLE_SCHEM</B> String => table schema (may be null)
2037 * <LI><B>TABLE_NAME</B> String => table name
2038 * <LI><B>COLUMN_NAME</B> String => column name
2039 * <LI><B>GRANTOR</B> => grantor of access (may be null)
2040 * <LI><B>GRANTEE</B> String => grantee of access
2041 * <LI><B>PRIVILEGE</B> String => name of access (SELECT,
2042 * INSERT, UPDATE, REFRENCES, ...)
2043 * <LI><B>IS_GRANTABLE</B> String => "YES" if grantee is permitted
2044 * to grant to others; "NO" if not; null if unknown
2047 * @param catalog a catalog name; "" retrieves those without a catalog
2048 * @param schemaPattern a schema name pattern; "" retrieves those
2050 * @param tableNamePattern a table name pattern
2051 * @return ResultSet each row is a table privilege description
2052 * @see #getSearchStringEscape
2054 public java.sql.ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern) throws SQLException
2056 // XXX-Not Implemented
2061 * Get a description of a table's optimal set of columns that
2062 * uniquely identifies a row. They are ordered by SCOPE.
2064 * <P>Each column description has the following columns:
2066 * <LI><B>SCOPE</B> short => actual scope of result
2068 * <LI> bestRowTemporary - very temporary, while using row
2069 * <LI> bestRowTransaction - valid for remainder of current transaction
2070 * <LI> bestRowSession - valid for remainder of current session
2072 * <LI><B>COLUMN_NAME</B> String => column name
2073 * <LI><B>DATA_TYPE</B> short => SQL data type from java.sql.Types
2074 * <LI><B>TYPE_NAME</B> String => Data source dependent type name
2075 * <LI><B>COLUMN_SIZE</B> int => precision
2076 * <LI><B>BUFFER_LENGTH</B> int => not used
2077 * <LI><B>DECIMAL_DIGITS</B> short => scale
2078 * <LI><B>PSEUDO_COLUMN</B> short => is this a pseudo column
2079 * like an Oracle ROWID
2081 * <LI> bestRowUnknown - may or may not be pseudo column
2082 * <LI> bestRowNotPseudo - is NOT a pseudo column
2083 * <LI> bestRowPseudo - is a pseudo column
2087 * @param catalog a catalog name; "" retrieves those without a catalog
2088 * @param schema a schema name; "" retrieves those without a schema
2089 * @param table a table name
2090 * @param scope the scope of interest; use same values as SCOPE
2091 * @param nullable include columns that are nullable?
2092 * @return ResultSet each row is a column description
2094 // Implementation note: This is required for Borland's JBuilder to work
2095 public java.sql.ResultSet getBestRowIdentifier(String catalog, String schema, String table, int scope, boolean nullable) throws SQLException
2097 // for now, this returns an empty result set.
2098 Field f[] = new Field[8];
2099 ResultSet r; // ResultSet for the SQL query that we need to do
2100 Vector v = new Vector(); // The new ResultSet tuple stuff
2102 f[0] = new Field(connection, "SCOPE", iInt2Oid, 2);
2103 f[1] = new Field(connection, "COLUMN_NAME", iVarcharOid, 32);
2104 f[2] = new Field(connection, "DATA_TYPE", iInt2Oid, 2);
2105 f[3] = new Field(connection, "TYPE_NAME", iVarcharOid, 32);
2106 f[4] = new Field(connection, "COLUMN_SIZE", iInt4Oid, 4);
2107 f[5] = new Field(connection, "BUFFER_LENGTH", iInt4Oid, 4);
2108 f[6] = new Field(connection, "DECIMAL_DIGITS", iInt2Oid, 2);
2109 f[7] = new Field(connection, "PSEUDO_COLUMN", iInt2Oid, 2);
2111 return new ResultSet(connection, f, v, "OK", 1);
2115 * Get a description of a table's columns that are automatically
2116 * updated when any value in a row is updated. They are
2119 * <P>Each column description has the following columns:
2121 * <LI><B>SCOPE</B> short => is not used
2122 * <LI><B>COLUMN_NAME</B> String => column name
2123 * <LI><B>DATA_TYPE</B> short => SQL data type from java.sql.Types
2124 * <LI><B>TYPE_NAME</B> String => Data source dependent type name
2125 * <LI><B>COLUMN_SIZE</B> int => precision
2126 * <LI><B>BUFFER_LENGTH</B> int => length of column value in bytes
2127 * <LI><B>DECIMAL_DIGITS</B> short => scale
2128 * <LI><B>PSEUDO_COLUMN</B> short => is this a pseudo column
2129 * like an Oracle ROWID
2131 * <LI> versionColumnUnknown - may or may not be pseudo column
2132 * <LI> versionColumnNotPseudo - is NOT a pseudo column
2133 * <LI> versionColumnPseudo - is a pseudo column
2137 * @param catalog a catalog name; "" retrieves those without a catalog
2138 * @param schema a schema name; "" retrieves those without a schema
2139 * @param table a table name
2140 * @return ResultSet each row is a column description
2142 public java.sql.ResultSet getVersionColumns(String catalog, String schema, String table) throws SQLException
2144 // XXX-Not Implemented
2149 * Get a description of a table's primary key columns. They
2150 * are ordered by COLUMN_NAME.
2152 * <P>Each column description has the following columns:
2154 * <LI><B>TABLE_CAT</B> String => table catalog (may be null)
2155 * <LI><B>TABLE_SCHEM</B> String => table schema (may be null)
2156 * <LI><B>TABLE_NAME</B> String => table name
2157 * <LI><B>COLUMN_NAME</B> String => column name
2158 * <LI><B>KEY_SEQ</B> short => sequence number within primary key
2159 * <LI><B>PK_NAME</B> String => primary key name (may be null)
2162 * @param catalog a catalog name; "" retrieves those without a catalog
2163 * @param schema a schema name pattern; "" retrieves those
2165 * @param table a table name
2166 * @return ResultSet each row is a primary key column description
2168 public java.sql.ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException
2170 return connection.createStatement().executeQuery("SELECT " +
2171 "'' as TABLE_CAT," +
2172 "'' AS TABLE_SCHEM," +
2173 "bc.relname AS TABLE_NAME," +
2174 "a.attname AS COLUMN_NAME," +
2175 "a.attnum as KEY_SEQ,"+
2176 "ic.relname as PK_NAME " +
2177 " FROM pg_class bc, pg_class ic, pg_index i, pg_attribute a" +
2178 " WHERE bc.relkind = 'r' " + // -- not indices
2179 " and upper(bc.relname) = upper('"+table+"')" +
2180 " and i.indrelid = bc.oid" +
2181 " and i.indexrelid = ic.oid" +
2182 " and ic.oid = a.attrelid" +
2183 " and i.indisprimary='t' " +
2184 " ORDER BY table_name, pk_name, key_seq"
2189 * Get a description of the primary key columns that are
2190 * referenced by a table's foreign key columns (the primary keys
2191 * imported by a table). They are ordered by PKTABLE_CAT,
2192 * PKTABLE_SCHEM, PKTABLE_NAME, and KEY_SEQ.
2194 * <P>Each primary key column description has the following columns:
2196 * <LI><B>PKTABLE_CAT</B> String => primary key table catalog
2197 * being imported (may be null)
2198 * <LI><B>PKTABLE_SCHEM</B> String => primary key table schema
2199 * being imported (may be null)
2200 * <LI><B>PKTABLE_NAME</B> String => primary key table name
2202 * <LI><B>PKCOLUMN_NAME</B> String => primary key column name
2204 * <LI><B>FKTABLE_CAT</B> String => foreign key table catalog (may be null)
2205 * <LI><B>FKTABLE_SCHEM</B> String => foreign key table schema (may be null)
2206 * <LI><B>FKTABLE_NAME</B> String => foreign key table name
2207 * <LI><B>FKCOLUMN_NAME</B> String => foreign key column name
2208 * <LI><B>KEY_SEQ</B> short => sequence number within foreign key
2209 * <LI><B>UPDATE_RULE</B> short => What happens to
2210 * foreign key when primary is updated:
2212 * <LI> importedKeyCascade - change imported key to agree
2213 * with primary key update
2214 * <LI> importedKeyRestrict - do not allow update of primary
2215 * key if it has been imported
2216 * <LI> importedKeySetNull - change imported key to NULL if
2217 * its primary key has been updated
2219 * <LI><B>DELETE_RULE</B> short => What happens to
2220 * the foreign key when primary is deleted.
2222 * <LI> importedKeyCascade - delete rows that import a deleted key
2223 * <LI> importedKeyRestrict - do not allow delete of primary
2224 * key if it has been imported
2225 * <LI> importedKeySetNull - change imported key to NULL if
2226 * its primary key has been deleted
2228 * <LI><B>FK_NAME</B> String => foreign key name (may be null)
2229 * <LI><B>PK_NAME</B> String => primary key name (may be null)
2232 * @param catalog a catalog name; "" retrieves those without a catalog
2233 * @param schema a schema name pattern; "" retrieves those
2235 * @param table a table name
2236 * @return ResultSet each row is a primary key column description
2237 * @see #getExportedKeys
2239 public java.sql.ResultSet getImportedKeys(String catalog, String schema, String table) throws SQLException
2241 // XXX-Not Implemented
2246 * Get a description of a foreign key columns that reference a
2247 * table's primary key columns (the foreign keys exported by a
2248 * table). They are ordered by FKTABLE_CAT, FKTABLE_SCHEM,
2249 * FKTABLE_NAME, and KEY_SEQ.
2251 * <P>Each foreign key column description has the following columns:
2253 * <LI><B>PKTABLE_CAT</B> String => primary key table catalog (may be null)
2254 * <LI><B>PKTABLE_SCHEM</B> String => primary key table schema (may be null)
2255 * <LI><B>PKTABLE_NAME</B> String => primary key table name
2256 * <LI><B>PKCOLUMN_NAME</B> String => primary key column name
2257 * <LI><B>FKTABLE_CAT</B> String => foreign key table catalog (may be null)
2258 * being exported (may be null)
2259 * <LI><B>FKTABLE_SCHEM</B> String => foreign key table schema (may be null)
2260 * being exported (may be null)
2261 * <LI><B>FKTABLE_NAME</B> String => foreign key table name
2263 * <LI><B>FKCOLUMN_NAME</B> String => foreign key column name
2265 * <LI><B>KEY_SEQ</B> short => sequence number within foreign key
2266 * <LI><B>UPDATE_RULE</B> short => What happens to
2267 * foreign key when primary is updated:
2269 * <LI> importedKeyCascade - change imported key to agree
2270 * with primary key update
2271 * <LI> importedKeyRestrict - do not allow update of primary
2272 * key if it has been imported
2273 * <LI> importedKeySetNull - change imported key to NULL if
2274 * its primary key has been updated
2276 * <LI><B>DELETE_RULE</B> short => What happens to
2277 * the foreign key when primary is deleted.
2279 * <LI> importedKeyCascade - delete rows that import a deleted key
2280 * <LI> importedKeyRestrict - do not allow delete of primary
2281 * key if it has been imported
2282 * <LI> importedKeySetNull - change imported key to NULL if
2283 * its primary key has been deleted
2285 * <LI><B>FK_NAME</B> String => foreign key identifier (may be null)
2286 * <LI><B>PK_NAME</B> String => primary key identifier (may be null)
2289 * @param catalog a catalog name; "" retrieves those without a catalog
2290 * @param schema a schema name pattern; "" retrieves those
2292 * @param table a table name
2293 * @return ResultSet each row is a foreign key column description
2294 * @see #getImportedKeys
2296 public java.sql.ResultSet getExportedKeys(String catalog, String schema, String table) throws SQLException
2298 // XXX-Not Implemented
2303 * Get a description of the foreign key columns in the foreign key
2304 * table that reference the primary key columns of the primary key
2305 * table (describe how one table imports another's key.) This
2306 * should normally return a single foreign key/primary key pair
2307 * (most tables only import a foreign key from a table once.) They
2308 * are ordered by FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, and
2311 * <P>Each foreign key column description has the following columns:
2313 * <LI><B>PKTABLE_CAT</B> String => primary key table catalog (may be null)
2314 * <LI><B>PKTABLE_SCHEM</B> String => primary key table schema (may be null)
2315 * <LI><B>PKTABLE_NAME</B> String => primary key table name
2316 * <LI><B>PKCOLUMN_NAME</B> String => primary key column name
2317 * <LI><B>FKTABLE_CAT</B> String => foreign key table catalog (may be null)
2318 * being exported (may be null)
2319 * <LI><B>FKTABLE_SCHEM</B> String => foreign key table schema (may be null)
2320 * being exported (may be null)
2321 * <LI><B>FKTABLE_NAME</B> String => foreign key table name
2323 * <LI><B>FKCOLUMN_NAME</B> String => foreign key column name
2325 * <LI><B>KEY_SEQ</B> short => sequence number within foreign key
2326 * <LI><B>UPDATE_RULE</B> short => What happens to
2327 * foreign key when primary is updated:
2329 * <LI> importedKeyCascade - change imported key to agree
2330 * with primary key update
2331 * <LI> importedKeyRestrict - do not allow update of primary
2332 * key if it has been imported
2333 * <LI> importedKeySetNull - change imported key to NULL if
2334 * its primary key has been updated
2336 * <LI><B>DELETE_RULE</B> short => What happens to
2337 * the foreign key when primary is deleted.
2339 * <LI> importedKeyCascade - delete rows that import a deleted key
2340 * <LI> importedKeyRestrict - do not allow delete of primary
2341 * key if it has been imported
2342 * <LI> importedKeySetNull - change imported key to NULL if
2343 * its primary key has been deleted
2345 * <LI><B>FK_NAME</B> String => foreign key identifier (may be null)
2346 * <LI><B>PK_NAME</B> String => primary key identifier (may be null)
2349 * @param catalog a catalog name; "" retrieves those without a catalog
2350 * @param schema a schema name pattern; "" retrieves those
2352 * @param table a table name
2353 * @return ResultSet each row is a foreign key column description
2354 * @see #getImportedKeys
2356 public java.sql.ResultSet getCrossReference(String primaryCatalog, String primarySchema, String primaryTable, String foreignCatalog, String foreignSchema, String foreignTable) throws SQLException
2358 // XXX-Not Implemented
2363 * Get a description of all the standard SQL types supported by
2364 * this database. They are ordered by DATA_TYPE and then by how
2365 * closely the data type maps to the corresponding JDBC SQL type.
2367 * <P>Each type description has the following columns:
2369 * <LI><B>TYPE_NAME</B> String => Type name
2370 * <LI><B>DATA_TYPE</B> short => SQL data type from java.sql.Types
2371 * <LI><B>PRECISION</B> int => maximum precision
2372 * <LI><B>LITERAL_PREFIX</B> String => prefix used to quote a literal
2374 * <LI><B>LITERAL_SUFFIX</B> String => suffix used to quote a literal
2376 * <LI><B>CREATE_PARAMS</B> String => parameters used in creating
2377 * the type (may be null)
2378 * <LI><B>NULLABLE</B> short => can you use NULL for this type?
2380 * <LI> typeNoNulls - does not allow NULL values
2381 * <LI> typeNullable - allows NULL values
2382 * <LI> typeNullableUnknown - nullability unknown
2384 * <LI><B>CASE_SENSITIVE</B> boolean=> is it case sensitive?
2385 * <LI><B>SEARCHABLE</B> short => can you use "WHERE" based on this type:
2387 * <LI> typePredNone - No support
2388 * <LI> typePredChar - Only supported with WHERE .. LIKE
2389 * <LI> typePredBasic - Supported except for WHERE .. LIKE
2390 * <LI> typeSearchable - Supported for all WHERE ..
2392 * <LI><B>UNSIGNED_ATTRIBUTE</B> boolean => is it unsigned?
2393 * <LI><B>FIXED_PREC_SCALE</B> boolean => can it be a money value?
2394 * <LI><B>AUTO_INCREMENT</B> boolean => can it be used for an
2395 * auto-increment value?
2396 * <LI><B>LOCAL_TYPE_NAME</B> String => localized version of type name
2398 * <LI><B>MINIMUM_SCALE</B> short => minimum scale supported
2399 * <LI><B>MAXIMUM_SCALE</B> short => maximum scale supported
2400 * <LI><B>SQL_DATA_TYPE</B> int => unused
2401 * <LI><B>SQL_DATETIME_SUB</B> int => unused
2402 * <LI><B>NUM_PREC_RADIX</B> int => usually 2 or 10
2405 * @return ResultSet each row is a SQL type description
2407 public java.sql.ResultSet getTypeInfo() throws SQLException
2409 java.sql.ResultSet rs = connection.ExecSQL("select typname from pg_type");
2411 Field f[] = new Field[18];
2412 ResultSet r; // ResultSet for the SQL query that we need to do
2413 Vector v = new Vector(); // The new ResultSet tuple stuff
2415 f[0] = new Field(connection, "TYPE_NAME", iVarcharOid, 32);
2416 f[1] = new Field(connection, "DATA_TYPE", iInt2Oid, 2);
2417 f[2] = new Field(connection, "PRECISION", iInt4Oid, 4);
2418 f[3] = new Field(connection, "LITERAL_PREFIX", iVarcharOid, 32);
2419 f[4] = new Field(connection, "LITERAL_SUFFIX", iVarcharOid, 32);
2420 f[5] = new Field(connection, "CREATE_PARAMS", iVarcharOid, 32);
2421 f[6] = new Field(connection, "NULLABLE", iInt2Oid, 2);
2422 f[7] = new Field(connection, "CASE_SENSITIVE", iBoolOid, 1);
2423 f[8] = new Field(connection, "SEARCHABLE", iInt2Oid, 2);
2424 f[9] = new Field(connection, "UNSIGNED_ATTRIBUTE", iBoolOid, 1);
2425 f[10] = new Field(connection, "FIXED_PREC_SCALE", iBoolOid, 1);
2426 f[11] = new Field(connection, "AUTO_INCREMENT", iBoolOid, 1);
2427 f[12] = new Field(connection, "LOCAL_TYPE_NAME", iVarcharOid, 32);
2428 f[13] = new Field(connection, "MINIMUM_SCALE", iInt2Oid, 2);
2429 f[14] = new Field(connection, "MAXIMUM_SCALE", iInt2Oid, 2);
2430 f[15] = new Field(connection, "SQL_DATA_TYPE", iInt4Oid, 4);
2431 f[16] = new Field(connection, "SQL_DATETIME_SUB", iInt4Oid, 4);
2432 f[17] = new Field(connection, "NUM_PREC_RADIX", iInt4Oid, 4);
2434 // cache some results, this will keep memory useage down, and speed
2435 // things up a little.
2436 byte b9[] = "9".getBytes();
2437 byte b10[] = "10".getBytes();
2438 byte bf[] = "f".getBytes();
2439 byte bnn[] = Integer.toString(typeNoNulls).getBytes();
2440 byte bts[] = Integer.toString(typeSearchable).getBytes();
2443 byte[][] tuple = new byte[18][];
2444 String typname=rs.getString(1);
2445 tuple[0] = typname.getBytes();
2446 tuple[1] = Integer.toString(Field.getSQLType(typname)).getBytes();
2447 tuple[2] = b9; // for now
2448 tuple[6] = bnn; // for now
2449 tuple[7] = bf; // false for now - not case sensitive
2451 tuple[9] = bf; // false for now - it's signed
2452 tuple[10] = bf; // false for now - must handle money
2453 tuple[11] = bf; // false for now - handle autoincrement
2454 // 12 - LOCAL_TYPE_NAME is null
2456 // 15 & 16 are unused so we return null
2457 tuple[17] = b10; // everything is base 10
2458 v.addElement(tuple);
2461 return new ResultSet(connection, f, v, "OK", 1);
2468 * Get a description of a table's indices and statistics. They are
2469 * ordered by NON_UNIQUE, TYPE, INDEX_NAME, and ORDINAL_POSITION.
2471 * <P>Each index column description has the following columns:
2473 * <LI><B>TABLE_CAT</B> String => table catalog (may be null)
2474 * <LI><B>TABLE_SCHEM</B> String => table schema (may be null)
2475 * <LI><B>TABLE_NAME</B> String => table name
2476 * <LI><B>NON_UNIQUE</B> boolean => Can index values be non-unique?
2477 * false when TYPE is tableIndexStatistic
2478 * <LI><B>INDEX_QUALIFIER</B> String => index catalog (may be null);
2479 * null when TYPE is tableIndexStatistic
2480 * <LI><B>INDEX_NAME</B> String => index name; null when TYPE is
2481 * tableIndexStatistic
2482 * <LI><B>TYPE</B> short => index type:
2484 * <LI> tableIndexStatistic - this identifies table statistics that are
2485 * returned in conjuction with a table's index descriptions
2486 * <LI> tableIndexClustered - this is a clustered index
2487 * <LI> tableIndexHashed - this is a hashed index
2488 * <LI> tableIndexOther - this is some other style of index
2490 * <LI><B>ORDINAL_POSITION</B> short => column sequence number
2491 * within index; zero when TYPE is tableIndexStatistic
2492 * <LI><B>COLUMN_NAME</B> String => column name; null when TYPE is
2493 * tableIndexStatistic
2494 * <LI><B>ASC_OR_DESC</B> String => column sort sequence, "A" => ascending
2495 * "D" => descending, may be null if sort sequence is not supported;
2496 * null when TYPE is tableIndexStatistic
2497 * <LI><B>CARDINALITY</B> int => When TYPE is tableIndexStatisic then
2498 * this is the number of rows in the table; otherwise it is the
2499 * number of unique values in the index.
2500 * <LI><B>PAGES</B> int => When TYPE is tableIndexStatisic then
2501 * this is the number of pages used for the table, otherwise it
2502 * is the number of pages used for the current index.
2503 * <LI><B>FILTER_CONDITION</B> String => Filter condition, if any.
2507 * @param catalog a catalog name; "" retrieves those without a catalog
2508 * @param schema a schema name pattern; "" retrieves those without a schema
2509 * @param table a table name
2510 * @param unique when true, return only indices for unique values;
2511 * when false, return indices regardless of whether unique or not
2512 * @param approximate when true, result is allowed to reflect approximate
2513 * or out of data values; when false, results are requested to be
2515 * @return ResultSet each row is an index column description
2517 // Implementation note: This is required for Borland's JBuilder to work
2518 public java.sql.ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) throws SQLException
2520 // for now, this returns an empty result set.
2521 Field f[] = new Field[13];
2522 ResultSet r; // ResultSet for the SQL query that we need to do
2523 Vector v = new Vector(); // The new ResultSet tuple stuff
2525 f[0] = new Field(connection, "TABLE_CAT", iVarcharOid, 32);
2526 f[1] = new Field(connection, "TABLE_SCHEM", iVarcharOid, 32);
2527 f[2] = new Field(connection, "TABLE_NAME", iVarcharOid, 32);
2528 f[3] = new Field(connection, "NON_UNIQUE", iBoolOid, 1);
2529 f[4] = new Field(connection, "INDEX_QUALIFIER", iVarcharOid, 32);
2530 f[5] = new Field(connection, "INDEX_NAME", iVarcharOid, 32);
2531 f[6] = new Field(connection, "TYPE", iInt2Oid, 2);
2532 f[7] = new Field(connection, "ORDINAL_POSITION", iInt2Oid, 2);
2533 f[8] = new Field(connection, "COLUMN_NAME", iVarcharOid, 32);
2534 f[9] = new Field(connection, "ASC_OR_DESC", iVarcharOid, 32);
2535 f[10] = new Field(connection, "CARDINALITY", iInt4Oid, 4);
2536 f[11] = new Field(connection, "PAGES", iInt4Oid, 4);
2537 f[12] = new Field(connection, "FILTER_CONDITION", iVarcharOid, 32);
2539 return new ResultSet(connection, f, v, "OK", 1);