KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > jdbc > JdbcDatabaseMetaData


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.jdbc;
6
7 import java.sql.*;
8
9 import org.h2.engine.Constants;
10 import org.h2.message.Message;
11 import org.h2.message.Trace;
12 import org.h2.message.TraceObject;
13 import org.h2.util.StringUtils;
14
15 /**
16  * Represents the meta data for a database.
17  */

18 public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaData {
19
20     private JdbcConnection conn;
21
22     /**
23      * Returns the major version of this driver.
24      *
25      * @return the major version number
26      */

27     public int getDriverMajorVersion() {
28         debugCodeCall("getDriverMajorVersion");
29         return Constants.VERSION_MAJOR;
30     }
31
32     /**
33      * Returns the minor version of this driver.
34      *
35      * @return the minor version number
36      */

37     public int getDriverMinorVersion() {
38         debugCodeCall("getDriverMinorVersion");
39         return Constants.VERSION_MINOR;
40     }
41
42     /**
43      * Gets the database product name.
44      *
45      * @return the product name
46      */

47     public String JavaDoc getDatabaseProductName() {
48         debugCodeCall("getDatabaseProductName");
49         return Constants.PRODUCT_NAME;
50     }
51
52     /**
53      * Gets the product version of the database.
54      *
55      * @return the product version
56      */

57     public String JavaDoc getDatabaseProductVersion() {
58         debugCodeCall("getDatabaseProductVersion");
59         return Constants.getVersion();
60     }
61
62     /**
63      * Gets the name of the JDBC driver.
64      *
65      * @return the driver name
66      */

67     public String JavaDoc getDriverName() {
68         debugCodeCall("getDriverName");
69         return Constants.DRIVER_NAME;
70     }
71
72     /**
73      * Gets the version number of the driver in the format
74      * [MajorVersion].[MinorVersion].
75      *
76      * @return the version number
77      */

78     public String JavaDoc getDriverVersion() {
79         debugCodeCall("getDriverVersion");
80         return Constants.getVersion();
81     }
82
83     /**
84      * Gets the list of tables in the database.
85      * The result set is sorted by TABLE_TYPE, TABLE_SCHEM, and TABLE_NAME.
86      *
87      * <ul>
88      * <li>1 TABLE_CAT (String) table catalog
89      * <li>2 TABLE_SCHEM (String) table schema
90      * <li>3 TABLE_NAME (String) table name
91      * <li>4 TABLE_TYPE (String) table type
92      * <li>5 REMARKS (String) comment
93      *
94      * <li>6 SQL (String) the create table statement or NULL for systems tables
95      * </ul>
96      *
97      * @param catalog null (to get all objects) or the catalog name
98      * @param schemaPattern null (to get all objects) or a schema name (uppercase for unquoted names)
99      * @param tableNamePattern null (to get all objects) or a table name (uppercase for unquoted names)
100      * @param types null or a list of table types
101      * @return the list of columns
102      * @throws SQLException if the connection is closed
103      */

104     public ResultSet getTables(String JavaDoc catalog, String JavaDoc schemaPattern, String JavaDoc tableNamePattern, String JavaDoc[] types) throws SQLException {
105         try {
106             if(debug()) {
107                 debugCode("getTables("
108                         +quote(catalog)+", "
109                         +quote(schemaPattern)+", "
110                         +quote(tableNamePattern)+", "
111                         +quoteArray(types)+");");
112             }
113             checkClosed();
114             String JavaDoc tableType;
115             if (types != null && types.length>0) {
116                 StringBuffer JavaDoc buff = new StringBuffer JavaDoc("TABLE_TYPE IN(");
117                 for (int i = 0; i < types.length; i++) {
118                     if (i>0) {
119                         buff.append(", ");
120                     }
121                     buff.append("?");
122                 }
123                 buff.append(")");
124                 tableType = buff.toString();
125             } else {
126                 tableType = "TRUE";
127             }
128             PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
129                     + "TABLE_CATALOG TABLE_CAT, "
130                     + "TABLE_SCHEMA TABLE_SCHEM, "
131                     + "TABLE_NAME, "
132                     + "TABLE_TYPE, "
133                     + "REMARKS, "
134                     + "SQL "
135                     + "FROM INFORMATION_SCHEMA.TABLES "
136                     + "WHERE TABLE_CATALOG LIKE ? "
137                     + "AND TABLE_SCHEMA LIKE ? "
138                     + "AND TABLE_NAME LIKE ? "
139                     + "AND (" + tableType + ") "
140                     + "ORDER BY TABLE_TYPE, TABLE_SCHEMA, TABLE_NAME");
141             prep.setString(1, getCatalogPattern(catalog));
142             prep.setString(2, getSchemaPattern(schemaPattern));
143             prep.setString(3, getPattern(tableNamePattern));
144             for (int i = 0; types != null && i < types.length; i++) {
145                 prep.setString(4 + i, types[i]);
146             }
147             return prep.executeQuery();
148         } catch(Throwable JavaDoc e) {
149             throw logAndConvert(e);
150         }
151     }
152
153     /**
154      * Gets the list of columns.
155      * The result set is sorted by TABLE_SCHEM, TABLE_NAME, and ORDINAL_POSITION.
156      *
157      * <ul>
158      * <li>1 TABLE_CAT (String) table catalog
159      * <li>2 TABLE_SCHEM (String) table schema
160      * <li>3 TABLE_NAME (String) table name
161      * <li>4 COLUMN_NAME (String) column name
162      * <li>5 DATA_TYPE (short) data type (see java.sql.Types)
163      * <li>6 TYPE_NAME (String) data type name ("INTEGER", "VARCHAR",...)
164      * <li>7 COLUMN_SIZE (int) precision
165      * <li>8 BUFFER_LENGTH (int) unused
166      * <li>9 DECIMAL_DIGITS (int) scale (0 for INTEGER and VARCHAR)
167      * <li>10 NUM_PREC_RADIX (int) radix (always 10)
168      * <li>11 NULLABLE (int) nullable or not. columnNoNulls or columnNullable
169      * <li>12 REMARKS (String) comment (always empty)
170      * <li>13 COLUMN_DEF (String) default value
171      * <li>14 SQL_DATA_TYPE (int) unused
172      * <li>15 SQL_DATETIME_SUB (int) unused
173      * <li>16 CHAR_OCTET_LENGTH (int) unused
174      * <li>17 ORDINAL_POSITION (int) the column index (1,2,...)
175      * <li>18 IS_NULLABLE (String) "NO" or "YES"
176      * </ul>
177      *
178      * @param catalog null (to get all objects) or the catalog name
179      * @param schemaPattern null (to get all objects) or a schema name (uppercase for unquoted names)
180      * @param tableNamePattern null (to get all objects) or a table name (uppercase for unquoted names)
181      * @param columnNamePattern null (to get all objects) or a column name (uppercase for unquoted names)
182      * @return the list of columns
183      * @throws SQLException if the connection is closed
184      */

185     public ResultSet getColumns(String JavaDoc catalog, String JavaDoc schemaPattern,
186             String JavaDoc tableNamePattern, String JavaDoc columnNamePattern)
187             throws SQLException {
188         try {
189             if(debug()) {
190                 debugCode("getColumns("
191                         +quote(catalog)+", "
192                         +quote(schemaPattern)+", "
193                         +quote(tableNamePattern)+", "
194                         +quote(columnNamePattern)+");");
195             }
196             checkClosed();
197             PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
198                     + "TABLE_CATALOG TABLE_CAT, "
199                     + "TABLE_SCHEMA TABLE_SCHEM, "
200                     + "TABLE_NAME, "
201                     + "COLUMN_NAME, "
202                     + "DATA_TYPE, "
203                     + "TYPE_NAME, "
204                     + "CHARACTER_MAXIMUM_LENGTH COLUMN_SIZE, "
205                     + "CHARACTER_MAXIMUM_LENGTH BUFFER_LENGTH, "
206                     + "NUMERIC_SCALE DECIMAL_DIGITS, "
207                     + "NUMERIC_PRECISION_RADIX NUM_PREC_RADIX, "
208                     + "NULLABLE, "
209                     + "REMARKS, "
210                     + "COLUMN_DEFAULT COLUMN_DEF, "
211                     + "DATA_TYPE SQL_DATA_TYPE, "
212                     + "ZERO() SQL_DATETIME_SUB, "
213                     + "CHARACTER_OCTET_LENGTH CHAR_OCTET_LENGTH, "
214                     + "ORDINAL_POSITION, "
215                     + "IS_NULLABLE IS_NULLABLE "
216                     + "FROM INFORMATION_SCHEMA.COLUMNS "
217                     + "WHERE TABLE_CATALOG LIKE ? "
218                     + "AND TABLE_SCHEMA LIKE ? "
219                     + "AND TABLE_NAME LIKE ? "
220                     + "AND COLUMN_NAME LIKE ? "
221                     + "ORDER BY TABLE_SCHEM, TABLE_NAME, ORDINAL_POSITION");
222             prep.setString(1, getCatalogPattern(catalog));
223             prep.setString(2, getSchemaPattern(schemaPattern));
224             prep.setString(3, getPattern(tableNamePattern));
225             prep.setString(4, getPattern(columnNamePattern));
226             return prep.executeQuery();
227         } catch(Throwable JavaDoc e) {
228             throw logAndConvert(e);
229         }
230     }
231
232     /**
233      * Gets the list of indexes for this database.
234      * The primary key index (if there is one) is also listed, with the name PRIMARY_KEY.
235      * The result set is sorted by NON_UNIQUE ('false' first), TYPE, TABLE_SCHEM, INDEX_NAME, and ORDINAL_POSITION.
236      *
237      * <ul>
238      * <li>1 TABLE_CAT (String) table catalog
239      * <li>2 TABLE_SCHEM (String) table schema
240      * <li>3 TABLE_NAME (String) table name
241      * <li>4 NON_UNIQUE (boolean) 'false' for unique, 'true' for non-unique
242      * <li>5 INDEX_QUALIFIER (String) index catalog
243      * <li>6 INDEX_NAME (String) index name
244      * <li>7 TYPE (short) the index type (always tableIndexOther)
245      * <li>8 ORDINAL_POSITION (short) column index (1, 2, ...)
246      * <li>9 COLUMN_NAME (String) column name
247      * <li>10 ASC_OR_DESC (String) ascending or descending (always 'A')
248      * <li>11 CARDINALITY (int) numbers of unique values
249      * <li>12 PAGES (int) number of pages use (always 0)
250      * <li>13 FILTER_CONDITION (String) filter condition (always empty)
251      * </ul>
252      *
253      * @param catalog null (to get all objects) or the catalog name
254      * @param schema schema name (must be specified)
255      * @param tableName table name (must be specified)
256      * @param unique only unique indexes
257      * @param approximate is ignored
258      * @return the list of indexes and columns
259      * @throws SQLException if the connection is closed
260      */

261     public ResultSet getIndexInfo(String JavaDoc catalog, String JavaDoc schema, String JavaDoc tableName, boolean unique, boolean approximate)
262             throws SQLException {
263         try {
264             if(debug()) {
265                 debugCode("getIndexInfo("
266                         +quote(catalog)+", "
267                         +quote(schema)+", "
268                         +quote(tableName)+", "
269                         +unique+", "
270                         +approximate+");");
271             }
272             String JavaDoc uniqueCondition;
273             if(unique) {
274                 uniqueCondition = "NON_UNIQUE=FALSE";
275             } else {
276                 uniqueCondition = "TRUE";
277             }
278             checkClosed();
279             PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
280                     + "TABLE_CATALOG TABLE_CAT, "
281                     + "TABLE_SCHEMA TABLE_SCHEM, "
282                     + "TABLE_NAME, "
283                     + "NON_UNIQUE, "
284                     + "TABLE_CATALOG INDEX_QUALIFIER, "
285                     + "INDEX_NAME, "
286                     + "INDEX_TYPE TYPE, "
287                     + "ORDINAL_POSITION, "
288                     + "COLUMN_NAME, "
289                     + "ASC_OR_DESC, "
290                     + "CARDINALITY, " // TODO meta data for number of unique values in an index
291
+ "PAGES, "
292                     + "FILTER_CONDITION "
293                     + "FROM INFORMATION_SCHEMA.INDEXES "
294                     + "WHERE TABLE_CATALOG LIKE ? "
295                     + "AND TABLE_SCHEMA LIKE ? "
296                     + "AND (" + uniqueCondition + ") "
297                     + "AND TABLE_NAME = ? "
298                     + "ORDER BY NON_UNIQUE, TYPE, TABLE_SCHEM, INDEX_NAME, ORDINAL_POSITION");
299             prep.setString(1, getCatalogPattern(catalog));
300             prep.setString(2, getSchemaPattern(schema));
301             prep.setString(3, tableName);
302             return prep.executeQuery();
303         } catch(Throwable JavaDoc e) {
304             throw logAndConvert(e);
305         }
306     }
307
308     /**
309      * Gets the primary key columns for a table.
310      * The result set is sorted by TABLE_SCHEM, and COLUMN_NAME (and not by KEY_SEQ).
311      *
312      * <ul>
313      * <li>1 TABLE_CAT (String) table catalog
314      * <li>2 TABLE_SCHEM (String) table schema
315      * <li>3 TABLE_NAME (String) table name
316      * <li>4 COLUMN_NAME (String) column name
317      * <li>5 KEY_SEQ (short) the column index of this column (1,2,...)
318      * <li>6 PK_NAME (String) always 'PRIMARY_KEY'
319      * </ul>
320      *
321      * @param catalog null (to get all objects) or the catalog name
322      * @param schema schema name (must be specified)
323      * @param tableName table name (must be specified)
324      * @return the list of primary key columns
325      * @throws SQLException if the connection is closed
326      */

327     public ResultSet getPrimaryKeys(String JavaDoc catalog, String JavaDoc schema, String JavaDoc tableName) throws SQLException {
328         try {
329             if(debug()) {
330                 debugCode("getPrimaryKeys("
331                         +quote(catalog)+", "
332                         +quote(schema)+", "
333                         +quote(tableName)+");");
334             }
335             checkClosed();
336             PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
337                     + "TABLE_CATALOG TABLE_CAT, "
338                     + "TABLE_SCHEMA TABLE_SCHEM, "
339                     + "TABLE_NAME, "
340                     + "COLUMN_NAME, "
341                     + "ORDINAL_POSITION KEY_SEQ, "
342                     + "INDEX_NAME PK_NAME "
343                     + "FROM INFORMATION_SCHEMA.INDEXES "
344                     + "WHERE TABLE_CATALOG LIKE ? "
345                     + "AND TABLE_SCHEMA LIKE ? "
346                     + "AND TABLE_NAME = ? "
347                     + "AND PRIMARY_KEY = TRUE "
348                     + "ORDER BY COLUMN_NAME");
349             prep.setString(1, getCatalogPattern(catalog));
350             prep.setString(2, getSchemaPattern(schema));
351             prep.setString(3, tableName);
352             return prep.executeQuery();
353         } catch(Throwable JavaDoc e) {
354             throw logAndConvert(e);
355         }
356     }
357
358     /**
359      * Checks if all procedures callable.
360      *
361      * @return true
362      */

363     public boolean allProceduresAreCallable() {
364         debugCodeCall("allProceduresAreCallable");
365         return true;
366     }
367
368     /**
369      * Checks if it possible to query all tables returned by getTables.
370      *
371      * @return true
372      */

373     public boolean allTablesAreSelectable() {
374         debugCodeCall("allTablesAreSelectable");
375         return true;
376     }
377
378     /**
379      * Returns the database URL for this connection.
380      *
381      * @return the url
382      */

383     public String JavaDoc getURL() throws SQLException {
384         try {
385             debugCodeCall("getURL");
386             return conn.getURL();
387         } catch(Throwable JavaDoc e) {
388             throw logAndConvert(e);
389         }
390     }
391
392     /**
393      * Returns the user name as passed to DriverManager.getConnection(url, user, password).
394      *
395      * @return the user name
396      */

397     public String JavaDoc getUserName() throws SQLException {
398         try {
399             debugCodeCall("getUserName");
400             return conn.getUser();
401         } catch(Throwable JavaDoc e) {
402             throw logAndConvert(e);
403         }
404     }
405
406     /**
407      * Returns the same as Connection.isReadOnly().
408      *
409      * @return if read only optimization is switched on
410      */

411     public boolean isReadOnly() throws SQLException {
412         try {
413             debugCodeCall("isReadOnly");
414             return conn.isReadOnly();
415         } catch(Throwable JavaDoc e) {
416             throw logAndConvert(e);
417         }
418     }
419
420     /**
421      * Checks is NULL values are sorted high (bigger than any non-null values).
422      *
423      * @return true or false
424      */

425     public boolean nullsAreSortedHigh() {
426         debugCodeCall("nullsAreSortedHigh");
427         return Constants.NULL_SORT_DEFAULT == Constants.NULL_SORT_HIGH;
428     }
429
430     /**
431      * Checks is NULL values are sorted low (smaller than any non-null values).
432      *
433      * @return true or false
434      */

435     public boolean nullsAreSortedLow() {
436         debugCodeCall("nullsAreSortedLow");
437         return Constants.NULL_SORT_DEFAULT == Constants.NULL_SORT_LOW;
438     }
439
440     /**
441      * Checks is NULL values are sorted at the beginning (no matter if ASC or DESC is used).
442      *
443      * @return true or false
444      */

445     public boolean nullsAreSortedAtStart() {
446         debugCodeCall("nullsAreSortedAtStart");
447         return Constants.NULL_SORT_DEFAULT == Constants.NULL_SORT_START;
448     }
449
450     /**
451      * Checks is NULL values are sorted at the end (no matter if ASC or DESC is used).
452      *
453      * @return true or false
454      */

455     public boolean nullsAreSortedAtEnd() {
456         debugCodeCall("nullsAreSortedAtEnd");
457         return Constants.NULL_SORT_DEFAULT == Constants.NULL_SORT_END;
458     }
459
460     /**
461      * Returns the connection that created this object.
462      *
463      * @return the connection
464      */

465     public Connection getConnection() {
466         debugCodeCall("getConnection");
467         return conn;
468     }
469
470     /**
471      * Gets the list of procedures.
472      * The result set is sorted by PROCEDURE_SCHEM, and PROCEDURE_NAME.
473      *
474      * <ul>
475      * <li>1 PROCEDURE_CAT (String) catalog
476      * <li>2 PROCEDURE_SCHEM (String) schema
477      * <li>3 PROCEDURE_NAME (String) name
478      * <li>4 NUM_INPUT_PARAMS (int) for future use, always 0
479      * <li>5 NUM_OUTPUT_PARAMS (int) for future use, always 0
480      * <li>6 NUM_RESULT_SETS (int) for future use, always 0
481      * <li>7 REMARKS (String) description
482      * <li>8 PROCEDURE_TYPE (short) if this procedure returns a result
483      * (procedureNoResult or procedureReturnsResult)
484      * </ul>
485      *
486      * @return an empty result set
487      * @throws SQLException if the connection is closed
488      */

489     public ResultSet getProcedures(String JavaDoc catalog, String JavaDoc schemaPattern,
490             String JavaDoc procedureNamePattern) throws SQLException {
491         try {
492             if(debug()) {
493                 debugCode("getProcedures("
494                         +quote(catalog)+", "
495                         +quote(schemaPattern)+", "
496                         +quote(procedureNamePattern)+");");
497             }
498             checkClosed();
499             PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
500                     + "ALIAS_CATALOG PROCEDURE_CAT, "
501                     + "ALIAS_SCHEMA PROCEDURE_SCHEM, "
502                     + "ALIAS_NAME PROCEDURE_NAME, "
503                     + "ZERO() NUM_INPUT_PARAMS, "
504                     + "ZERO() NUM_OUTPUT_PARAMS, "
505                     + "ZERO() NUM_RESULT_SETS, "
506                     + "REMARKS, "
507                     + "RETURNS_RESULT PROCEDURE_TYPE "
508                     + "FROM INFORMATION_SCHEMA.FUNCTION_ALIASES "
509                     + "WHERE ALIAS_CATALOG LIKE ? "
510                     + "AND ALIAS_SCHEMA LIKE ? "
511                     + "AND ALIAS_NAME LIKE ? "
512                     + "ORDER BY PROCEDURE_SCHEM, PROCEDURE_NAME");
513             prep.setString(1, getCatalogPattern(catalog));
514             prep.setString(2, getSchemaPattern(schemaPattern));
515             prep.setString(3, getPattern(procedureNamePattern));
516             return prep.executeQuery();
517         } catch(Throwable JavaDoc e) {
518             throw logAndConvert(e);
519         }
520     }
521
522     /**
523      * Gets the list of procedure columns.
524      *
525      * <ul>
526      * <li>1 PROCEDURE_CAT (String) catalog
527      * <li>2 PROCEDURE_SCHEM (String) schema
528      * <li>3 PROCEDURE_NAME (String) name
529      * <li>4 COLUMN_NAME (String) column name
530      * <li>5 COLUMN_TYPE (short) column type
531      * <li>6 DATA_TYPE (short) sql type
532      * <li>7 TYPE_NAME (String) type name
533      * <li>8 PRECISION (int) precision
534      * <li>9 LENGTH (int) length
535      * <li>10 SCALE (short) scale
536      * <li>11 RADIX (int) always 10
537      * <li>12 NULLABLE (short) nullable
538      * <li>13 REMARKS (String) description
539      * </ul>
540      *
541      * @throws SQLException if the connection is closed
542      */

543     public ResultSet getProcedureColumns(String JavaDoc catalog, String JavaDoc schemaPattern,
544             String JavaDoc procedureNamePattern, String JavaDoc columnNamePattern)
545             throws SQLException {
546         try {
547             if(debug()) {
548                 debugCode("getProcedureColumns("
549                         +quote(catalog)+", "
550                         +quote(schemaPattern)+", "
551                         +quote(procedureNamePattern)+", "
552                         +quote(columnNamePattern)+");");
553             }
554             checkClosed();
555             PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
556                     + "ALIAS_CATALOG PROCEDURE_CAT, "
557                     + "ALIAS_SCHEMA PROCEDURE_SCHEM, "
558                     + "ALIAS_NAME PROCEDURE_NAME, "
559                     + "COLUMN_NAME, "
560                     + "COLUMN_TYPE, "
561                     + "DATA_TYPE, "
562                     + "TYPE_NAME, "
563                     + "PRECISION, "
564                     + "PRECISION LENGTH, "
565                     + "SCALE, "
566                     + "RADIX, "
567                     + "NULLABLE, "
568                     + "REMARKS "
569                     + "FROM INFORMATION_SCHEMA.FUNCTION_COLUMNS "
570                     + "WHERE ALIAS_CATALOG LIKE ? "
571                     + "AND ALIAS_SCHEMA LIKE ? "
572                     + "AND ALIAS_NAME LIKE ? "
573                     + "AND COLUMN_NAME LIKE ?");
574             prep.setString(1, getCatalogPattern(catalog));
575             prep.setString(2, getSchemaPattern(schemaPattern));
576             prep.setString(3, getPattern(procedureNamePattern));
577             prep.setString(4, getPattern(columnNamePattern));
578             return prep.executeQuery();
579         } catch(Throwable JavaDoc e) {
580             throw logAndConvert(e);
581         }
582     }
583
584     /**
585      * Gets the list of schemas.
586      * The result set is sorted by TABLE_SCHEM.
587      *
588      * <ul>
589      * <li>1 TABLE_SCHEM (String) schema name
590      * <li>2 TABLE_CATALOG (String) catalog name
591      * <li>3 IS_DEFAULT (boolean) if this is the default schema
592      * </ul>
593      *
594      * @return the schema list
595      * @throws SQLException if the connection is closed
596      */

597     public ResultSet getSchemas() throws SQLException {
598         try {
599             debugCodeCall("getSchemas");
600             checkClosed();
601             PreparedStatement prep = conn
602                     .prepareAutoCloseStatement("SELECT "
603                             + "SCHEMA_NAME TABLE_SCHEM, "
604                             + "CATALOG_NAME TABLE_CATALOG, "
605                             +" IS_DEFAULT "
606                             + "FROM INFORMATION_SCHEMA.SCHEMATA "
607                             + "ORDER BY SCHEMA_NAME");
608             return prep.executeQuery();
609         } catch(Throwable JavaDoc e) {
610             throw logAndConvert(e);
611         }
612     }
613
614     /**
615      * Gets the list of catalogs.
616      * The result set is sorted by TABLE_CAT.
617      *
618      * <ul>
619      * <li>1 TABLE_CAT (String) catalog name
620      * </ul>
621      *
622      * @return the catalog list
623      * @throws SQLException if the connection is closed
624      */

625     public ResultSet getCatalogs() throws SQLException {
626         try {
627             debugCodeCall("getCatalogs");
628             checkClosed();
629             PreparedStatement prep = conn.prepareAutoCloseStatement(
630                     "SELECT CATALOG_NAME TABLE_CAT "
631                     + "FROM INFORMATION_SCHEMA.CATALOGS");
632             return prep.executeQuery();
633         } catch(Throwable JavaDoc e) {
634             throw logAndConvert(e);
635         }
636     }
637
638     /**
639      * Gets the list of table types. This call returns a result set with three
640      * records: "SYSTEM TABLE", "TABLE", "and "VIEW".
641      * The result set is sorted by TABLE_TYPE.
642      *
643      * <ul>
644      * <li>1 TABLE_TYPE (String) table type
645      * </ul>
646      *
647      * @return the table types
648      * @throws SQLException if the connection is closed
649      */

650     public ResultSet getTableTypes() throws SQLException {
651         try {
652             debugCodeCall("getTableTypes");
653             checkClosed();
654             PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
655                     + "TYPE TABLE_TYPE "
656                     + "FROM INFORMATION_SCHEMA.TABLE_TYPES "
657                     + "ORDER BY TABLE_TYPE");
658             return prep.executeQuery();
659         } catch(Throwable JavaDoc e) {
660             throw logAndConvert(e);
661         }
662     }
663
664     /**
665      * Gets the list of column privileges.
666      * The result set is sorted by COLUMN_NAME and PRIVILEGE
667      *
668      * <ul>
669      * <li>1 TABLE_CAT (String) table catalog
670      * <li>2 TABLE_SCHEM (String) table schema
671      * <li>3 TABLE_NAME (String) table name
672      * <li>4 COLUMN_NAME (String) column name
673      * <li>5 GRANTOR (String) grantor of access
674      * <li>6 GRANTEE (String) grantee of access
675      * <li>7 PRIVILEGE (String) SELECT, INSERT, UPDATE, DELETE or REFERENCES (only one per row)
676      * <li>8 IS_GRANTABLE (String) YES means the grantee can grant access to others
677      * </ul>
678      *
679      * @param catalog null (to get all objects) or the catalog name
680      * @param schema null (to get all objects) or a schema name (uppercase for unquoted names)
681      * @param table a table name (uppercase for unquoted names)
682      * @param columnNamePattern null (to get all objects) or a column name (uppercase for unquoted names)
683      * @return the list of privileges
684      * @throws SQLException if the connection is closed
685      */

686     public ResultSet getColumnPrivileges(String JavaDoc catalog, String JavaDoc schema,
687             String JavaDoc table, String JavaDoc columnNamePattern) throws SQLException {
688         try {
689             if(debug()) {
690                 debugCode("getColumnPrivileges("
691                         +quote(catalog)+", "
692                         +quote(schema)+", "
693                         +quote(table)+", "
694                         +quote(columnNamePattern)+");");
695             }
696             checkClosed();
697             PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
698                     + "TABLE_CATALOG TABLE_CAT, "
699                     + "TABLE_SCHEMA TABLE_SCHEM, "
700                     + "TABLE_NAME, "
701                     + "COLUMN_NAME, "
702                     + "GRANTOR, "
703                     + "GRANTEE, "
704                     + "PRIVILEGE_TYPE PRIVILEGE, "
705                     + "IS_GRANTABLE "
706                     + "FROM INFORMATION_SCHEMA.COLUMN_PRIVILEGES "
707                     + "WHERE TABLE_CATALOG LIKE ? "
708                     + "AND TABLE_SCHEMA LIKE ? "
709                     + "AND TABLE_NAME = ? "
710                     + "AND COLUMN_NAME LIKE ? "
711                     + "ORDER BY COLUMN_NAME, PRIVILEGE");
712             prep.setString(1, getCatalogPattern(catalog));
713             prep.setString(2, getSchemaPattern(schema));
714             prep.setString(3, table);
715             prep.setString(4, getPattern(columnNamePattern));
716             return prep.executeQuery();
717         } catch(Throwable JavaDoc e) {
718             throw logAndConvert(e);
719         }
720     }
721
722     /**
723      * Gets the list of table privileges.
724      * The result set is sorted by TABLE_SCHEM, TABLE_NAME, and PRIVILEGE.
725      *
726      * <ul>
727      * <li>1 TABLE_CAT (String) table catalog
728      * <li>2 TABLE_SCHEM (String) table schema
729      * <li>3 TABLE_NAME (String) table name
730      * <li>4 GRANTOR (String) grantor of access
731      * <li>5 GRANTEE (String) grantee of access
732      * <li>6 PRIVILEGE (String) SELECT, INSERT, UPDATE, DELETE or REFERENCES (only one per row)
733      * <li>7 IS_GRANTABLE (String) YES means the grantee can grant access to others
734      * </ul>
735      *
736      * @param catalog null (to get all objects) or the catalog name
737      * @param schemaPattern null (to get all objects) or a schema name (uppercase for unquoted names)
738      * @param tableNamePattern null (to get all objects) or a table name (uppercase for unquoted names)
739      * @return the list of privileges
740      * @throws SQLException if the connection is closed
741      */

742     public ResultSet getTablePrivileges(String JavaDoc catalog, String JavaDoc schemaPattern, String JavaDoc tableNamePattern) throws SQLException {
743         try {
744             if(debug()) {
745                 debugCode("getTablePrivileges("
746                         +quote(catalog)+", "
747                         +quote(schemaPattern)+", "
748                         +quote(tableNamePattern)+");");
749             }
750             checkClosed();
751             PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
752                     + "TABLE_CATALOG TABLE_CAT, "
753                     + "TABLE_SCHEMA TABLE_SCHEM, "
754                     + "TABLE_NAME, "
755                     + "GRANTOR, "
756                     + "GRANTEE, "
757                     + "PRIVILEGE_TYPE PRIVILEGE, "
758                     + "IS_GRANTABLE "
759                     + "FROM INFORMATION_SCHEMA.TABLE_PRIVILEGES "
760                     + "WHERE TABLE_CATALOG LIKE ? "
761                     + "AND TABLE_SCHEMA LIKE ? "
762                     + "AND TABLE_NAME LIKE ? "
763                     + "ORDER BY TABLE_SCHEM, TABLE_NAME, PRIVILEGE");
764             prep.setString(1, getCatalogPattern(catalog));
765             prep.setString(2, getSchemaPattern(schemaPattern));
766             prep.setString(3, getPattern(tableNamePattern));
767             return prep.executeQuery();
768         } catch(Throwable JavaDoc e) {
769             throw logAndConvert(e);
770         }
771     }
772
773     /**
774      * Gets the list of columns that best identifier a row in a table.
775      * The list is ordered by SCOPE.
776      *
777      * <ul>
778      * <li>1 SCOPE (short) scope of result (always bestRowSession)
779      * <li>2 COLUMN_NAME (String) column name
780      * <li>3 DATA_TYPE (short) SQL data type, see also java.sql.Types
781      * <li>4 TYPE_NAME (String) type name
782      * <li>5 COLUMN_SIZE (int) precision
783      * <li>6 BUFFER_LENGTH (int) unused
784      * <li>7 DECIMAL_DIGITS (short) scale
785      * <li>8 PSEUDO_COLUMN (short) (always bestRowNotPseudo)
786      * </ul>
787      *
788      * @param catalog null (to get all objects) or the catalog name
789      * @param schema schema name (must be specified)
790      * @param tableName table name (must be specified)
791      * @param scope ignored
792      * @param nullable ignored
793      * @return the primary key index
794      * @throws SQLException if the connection is closed
795      */

796     public ResultSet getBestRowIdentifier(String JavaDoc catalog, String JavaDoc schema,
797             String JavaDoc tableName, int scope, boolean nullable) throws SQLException {
798         try {
799             if(debug()) {
800                 debugCode("getBestRowIdentifier("
801                         +quote(catalog)+", "
802                         +quote(schema)+", "
803                         +quote(tableName)+", "
804                         +scope+", "+nullable+");");
805             }
806             checkClosed();
807             PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
808                     + "CAST(? AS SMALLINT) SCOPE, "
809                     + "C.COLUMN_NAME, "
810                     + "C.DATA_TYPE, "
811                     + "C.TYPE_NAME, "
812                     + "C.CHARACTER_MAXIMUM_LENGTH COLUMN_SIZE, "
813                     + "C.CHARACTER_MAXIMUM_LENGTH BUFFER_LENGTH, "
814                     + "CAST(C.NUMERIC_SCALE AS SMALLINT) DECIMAL_DIGITS, "
815                     + "CAST(? AS SMALLINT) PSEUDO_COLUMN "
816                     + "FROM INFORMATION_SCHEMA.INDEXES I, "
817                     +" INFORMATION_SCHEMA.COLUMNS C "
818                     + "WHERE C.TABLE_NAME = I.TABLE_NAME "
819                     + "AND C.COLUMN_NAME = I.COLUMN_NAME "
820                     + "AND C.TABLE_CATALOG LIKE ? "
821                     + "AND C.TABLE_SCHEMA LIKE ? "
822                     + "AND C.TABLE_NAME = ? "
823                     + "AND I.PRIMARY_KEY = TRUE "
824                     + "ORDER BY SCOPE");
825             prep.setInt(1, DatabaseMetaData.bestRowSession); // SCOPE
826
prep.setInt(2, DatabaseMetaData.bestRowNotPseudo); // PSEUDO_COLUMN
827
prep.setString(3, getCatalogPattern(catalog));
828             prep.setString(4, getSchemaPattern(schema));
829             prep.setString(5, tableName);
830             return prep.executeQuery();
831         } catch(Throwable JavaDoc e) {
832             throw logAndConvert(e);
833         }
834     }
835
836     /**
837      * Get the list of columns that are update when any value is updated.
838      *
839      * <ul>
840      * <li>1 SCOPE (int) not used
841      * <li>2 COLUMN_NAME (String) column name
842      * <li>3 DATA_TYPE (int) SQL data type - see also java.sql.Types
843      * <li>4 TYPE_NAME (String) data type name
844      * <li>5 COLUMN_SIZE (int) precision
845      * <li>6 BUFFER_LENGTH (int) length (bytes)
846      * <li>7 DECIMAL_DIGITS (int) scale
847      * <li>8 PSEUDO_COLUMN (int) is this column a pseudo column
848      * </ul>
849      *
850      * @param catalog null (to get all objects) or the catalog name
851      * @param schema schema name (must be specified)
852      * @param tableName table name (must be specified)
853      * @return an empty result set
854      * @throws SQLException if the connection is closed
855      */

856     public ResultSet getVersionColumns(String JavaDoc catalog, String JavaDoc schema,
857             String JavaDoc tableName) throws SQLException {
858         try {
859             if(debug()) {
860                 debugCode("getVersionColumns("
861                         +quote(catalog)+", "
862                         +quote(schema)+", "
863                         +quote(tableName)+");");
864             }
865             checkClosed();
866             PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
867                     + "ZERO() SCOPE, "
868                     + "COLUMN_NAME, "
869                     + "CAST(DATA_TYPE AS INT) DATA_TYPE, "
870                     + "TYPE_NAME, "
871                     + "NUMERIC_PRECISION COLUMN_SIZE, "
872                     + "NUMERIC_PRECISION BUFFER_LENGTH, "
873                     + "NUMERIC_PRECISION DECIMAL_DIGITS, "
874                     + "ZERO() PSEUDO_COLUMN "
875                     + "FROM INFORMATION_SCHEMA.COLUMNS "
876                     + "WHERE FALSE");
877             return prep.executeQuery();
878         } catch(Throwable JavaDoc e) {
879             throw logAndConvert(e);
880         }
881     }
882
883     /**
884      * Gets the list of primary key columns that are referenced by a table.
885      * The result set is sorted by PKTABLE_CAT, PKTABLE_SCHEM, PKTABLE_NAME, FK_NAME, KEY_SEQ.
886      *
887      * <ul>
888      * <li>1 PKTABLE_CAT (String) primary catalog
889      * <li>2 PKTABLE_SCHEM (String) primary schema
890      * <li>3 PKTABLE_NAME (String) primary table
891      * <li>4 PKCOLUMN_NAME (String) primary column
892      * <li>5 FKTABLE_CAT (String) foreign catalog
893      * <li>6 FKTABLE_SCHEM (String) foreign schema
894      * <li>7 FKTABLE_NAME (String) foreign table
895      * <li>8 FKCOLUMN_NAME (String) foreign column
896      * <li>9 KEY_SEQ (short) sequence number (1, 2, ...)
897      * <li>10 UPDATE_RULE (short) action on update (see DatabaseMetaData.importedKey...)
898      * <li>11 DELETE_RULE (short) action on delete (see DatabaseMetaData.importedKey...)
899      * <li>12 FK_NAME (String) foreign key name
900      * <li>13 PK_NAME (String) primary key name
901      * <li>14 DEFERRABILITY (short) deferrable or not (always importedKeyNotDeferrable)
902      * </ul>
903      *
904      * @param catalog null (to get all objects) or the catalog name
905      * @param schema the schema name of the foreign table
906      * @param tableName the name of the foreign table
907      * @return the result set
908      * @throws SQLException if the connection is closed
909      */

910     public ResultSet getImportedKeys(String JavaDoc catalog, String JavaDoc schema, String JavaDoc tableName) throws SQLException {
911         try {
912             if(debug()) {
913                 debugCode("getImportedKeys("
914                         +quote(catalog)+", "
915                         +quote(schema)+", "
916                         +quote(tableName)+");");
917             }
918             checkClosed();
919             PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
920                     + "PKTABLE_CATALOG PKTABLE_CAT, "
921                     + "PKTABLE_SCHEMA PKTABLE_SCHEM, "
922                     + "PKTABLE_NAME PKTABLE_NAME, "
923                     + "PKCOLUMN_NAME, "
924                     + "FKTABLE_CATALOG FKTABLE_CAT, "
925                     + "FKTABLE_SCHEMA FKTABLE_SCHEM, "
926                     + "FKTABLE_NAME, "
927                     + "FKCOLUMN_NAME, "
928                     + "ORDINAL_POSITION KEY_SEQ, "
929                     + "UPDATE_RULE, "
930                     + "DELETE_RULE, "
931                     + "FK_NAME, "
932                     + "PK_NAME, "
933                     + "DEFERRABILITY "
934                     + "FROM INFORMATION_SCHEMA.CROSS_REFERENCES "
935                     + "WHERE FKTABLE_CATALOG LIKE ? "
936                     + "AND FKTABLE_SCHEMA LIKE ? "
937                     + "AND FKTABLE_NAME = ? "
938                     + "ORDER BY PKTABLE_CAT, PKTABLE_SCHEM, PKTABLE_NAME, FK_NAME, KEY_SEQ");
939             prep.setString(1, getCatalogPattern(catalog));
940             prep.setString(2, getSchemaPattern(schema));
941             prep.setString(3, tableName);
942             return prep.executeQuery();
943         } catch(Throwable JavaDoc e) {
944             throw logAndConvert(e);
945         }
946     }
947
948     /**
949      * Gets the list of foreign key columns that reference a table.
950      * The result set is sorted by FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, FK_NAME, KEY_SEQ.
951      *
952      * <ul>
953      * <li>1 PKTABLE_CAT (String) primary catalog
954      * <li>2 PKTABLE_SCHEM (String) primary schema
955      * <li>3 PKTABLE_NAME (String) primary table
956      * <li>4 PKCOLUMN_NAME (String) primary column
957      * <li>5 FKTABLE_CAT (String) foreign catalog
958      * <li>6 FKTABLE_SCHEM (String) foreign schema
959      * <li>7 FKTABLE_NAME (String) foreign table
960      * <li>8 FKCOLUMN_NAME (String) foreign column
961      * <li>9 KEY_SEQ (short) sequence number (1,2,...)
962      * <li>10 UPDATE_RULE (short) action on update (see DatabaseMetaData.importedKey...)
963      * <li>11 DELETE_RULE (short) action on delete (see DatabaseMetaData.importedKey...)
964      * <li>12 FK_NAME (String) foreign key name
965      * <li>13 PK_NAME (String) primary key name
966      * <li>14 DEFERRABILITY (short) deferrable or not (always importedKeyNotDeferrable)
967      * </ul>
968      *
969      * @param catalog null (to get all objects) or the catalog name
970      * @param schema the schema name of the primary table
971      * @param tableName the name of the primary table
972      * @return the result set
973      * @throws SQLException if the connection is closed
974      */

975     public ResultSet getExportedKeys(String JavaDoc catalog, String JavaDoc schema, String JavaDoc tableName)
976             throws SQLException {
977         try {
978             if(debug()) {
979                 debugCode("getExportedKeys("
980                         +quote(catalog)+", "
981                         +quote(schema)+", "
982                         +quote(tableName)+");");
983             }
984             checkClosed();
985             PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
986                     + "PKTABLE_CATALOG PKTABLE_CAT, "
987                     + "PKTABLE_SCHEMA PKTABLE_SCHEM, "
988                     + "PKTABLE_NAME PKTABLE_NAME, "
989                     + "PKCOLUMN_NAME, "
990                     + "FKTABLE_CATALOG FKTABLE_CAT, "
991                     + "FKTABLE_SCHEMA FKTABLE_SCHEM, "
992                     + "FKTABLE_NAME, "
993                     + "FKCOLUMN_NAME, "
994                     + "ORDINAL_POSITION KEY_SEQ, "
995                     + "UPDATE_RULE, "
996                     + "DELETE_RULE, "
997                     + "FK_NAME, "
998                     + "PK_NAME, "
999                     + "DEFERRABILITY "
1000                    + "FROM INFORMATION_SCHEMA.CROSS_REFERENCES "
1001                    + "WHERE PKTABLE_CATALOG LIKE ? "
1002                    + "AND PKTABLE_SCHEMA LIKE ? "
1003                    + "AND PKTABLE_NAME = ? "
1004                    + "ORDER BY FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, FK_NAME, KEY_SEQ");
1005            prep.setString(1, getCatalogPattern(catalog));
1006            prep.setString(2, getSchemaPattern(schema));
1007            prep.setString(3, tableName);
1008            return prep.executeQuery();
1009        } catch(Throwable JavaDoc e) {
1010            throw logAndConvert(e);
1011        }
1012    }
1013
1014    /**
1015     * Gets the list of foreign key columns that references a table, as well as
1016     * the list of primary key columns that are references by a table.
1017     * The result set is sorted by FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, FK_NAME, KEY_SEQ.
1018     *
1019     * <ul>
1020     * <li>1 PKTABLE_CAT (String) primary catalog
1021     * <li>2 PKTABLE_SCHEM (String) primary schema
1022     * <li>3 PKTABLE_NAME (String) primary table
1023     * <li>4 PKCOLUMN_NAME (String) primary column
1024     * <li>5 FKTABLE_CAT (String) foreign catalog
1025     * <li>6 FKTABLE_SCHEM (String) foreign schema
1026     * <li>7 FKTABLE_NAME (String) foreign table
1027     * <li>8 FKCOLUMN_NAME (String) foreign column
1028     * <li>9 KEY_SEQ (short) sequence number (1,2,...)
1029     * <li>10 UPDATE_RULE (short) action on update (see DatabaseMetaData.importedKey...)
1030     * <li>11 DELETE_RULE (short) action on delete (see DatabaseMetaData.importedKey...)
1031     * <li>12 FK_NAME (String) foreign key name
1032     * <li>13 PK_NAME (String) primary key name
1033     * <li>14 DEFERRABILITY (short) deferrable or not (always importedKeyNotDeferrable)
1034     * </ul>
1035     *
1036     * @param primaryCatalog ignored
1037     * @param primarySchema the schema name of the primary table (must be specified)
1038     * @param primaryTable the name of the primary table (must be specified)
1039     * @param foreignCatalog ignored
1040     * @param foreignSchema the schema name of the foreign table (must be specified)
1041     * @param foreignTable the name of the foreign table (must be specified)
1042     * @return the result set
1043     * @throws SQLException if the connection is closed
1044     */

1045    public ResultSet getCrossReference(String JavaDoc primaryCatalog,
1046            String JavaDoc primarySchema, String JavaDoc primaryTable, String JavaDoc foreignCatalog,
1047            String JavaDoc foreignSchema, String JavaDoc foreignTable) throws SQLException {
1048        try {
1049            if(debug()) {
1050                debugCode("getCrossReference("
1051                        +quote(primaryCatalog)+", "
1052                        +quote(primarySchema)+", "
1053                        +quote(primaryTable)+", "
1054                        +quote(foreignCatalog)+", "
1055                        +quote(foreignSchema)+", "
1056                        +quote(foreignTable)+");");
1057            }
1058            checkClosed();
1059            PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
1060                    + "PKTABLE_CATALOG PKTABLE_CAT, "
1061                    + "PKTABLE_SCHEMA PKTABLE_SCHEM, "
1062                    + "PKTABLE_NAME PKTABLE_NAME, "
1063                    + "PKCOLUMN_NAME, "
1064                    + "FKTABLE_CATALOG FKTABLE_CAT, "
1065                    + "FKTABLE_SCHEMA FKTABLE_SCHEM, "
1066                    + "FKTABLE_NAME, "
1067                    + "FKCOLUMN_NAME, "
1068                    + "ORDINAL_POSITION KEY_SEQ, "
1069                    + "UPDATE_RULE, "
1070                    + "DELETE_RULE, "
1071                    + "FK_NAME, "
1072                    + "PK_NAME, "
1073                    + "DEFERRABILITY "
1074                    + "FROM INFORMATION_SCHEMA.CROSS_REFERENCES "
1075                    + "WHERE PKTABLE_CATALOG LIKE ? "
1076                    + "AND PKTABLE_SCHEMA LIKE ? "
1077                    + "AND PKTABLE_NAME = ? "
1078                    + "AND FKTABLE_CATALOG LIKE ? "
1079                    + "AND FKTABLE_SCHEMA LIKE ? "
1080                    + "AND FKTABLE_NAME = ? "
1081                    + "ORDER BY FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, FK_NAME, KEY_SEQ");
1082            prep.setString(1, getCatalogPattern(primaryCatalog));
1083            prep.setString(2, getSchemaPattern(primarySchema));
1084            prep.setString(3, primaryTable);
1085            prep.setString(4, getCatalogPattern(foreignCatalog));
1086            prep.setString(5, getSchemaPattern(foreignSchema));
1087            prep.setString(6, foreignTable);
1088            return prep.executeQuery();
1089        } catch(Throwable JavaDoc e) {
1090            throw logAndConvert(e);
1091        }
1092    }
1093
1094    /**
1095     * Gets the list of user defined data types.
1096     * This call returns an empty result set.
1097     *
1098     * <ul>
1099     * <li>1 TYPE_CAT (String) catalog
1100     * <li>2 TYPE_SCHEM (String) schema
1101     * <li>3 TYPE_NAME (String) type name
1102     * <li>4 CLASS_NAME (String) Java class
1103     * <li>5 DATA_TYPE (short) SQL Type - see also java.sql.Types
1104     * <li>6 REMARKS (String) description
1105     * <li>7 BASE_TYPE (short) base type - see also java.sql.Types
1106     * </ul>
1107     *
1108     * @param catalog ignored
1109     * @param schemaPattern ignored
1110     * @param typeNamePattern ignored
1111     * @param types ignored
1112     * @return an empty result set
1113     * @throws SQLException if the connection is closed
1114     */

1115    public ResultSet getUDTs(String JavaDoc catalog, String JavaDoc schemaPattern,
1116            String JavaDoc typeNamePattern, int[] types) throws SQLException {
1117        try {
1118            if(debug()) {
1119                debugCode("getUDTs("
1120                        +quote(catalog)+", "
1121                        +quote(schemaPattern)+", "
1122                        +quote(typeNamePattern)+", "
1123                        +quoteIntArray(types)+");");
1124            }
1125            checkClosed();
1126            PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
1127                    + "CATALOG_NAME TYPE_CAT, "
1128                    + "CATALOG_NAME TYPE_SCHEM, "
1129                    + "CATALOG_NAME TYPE_NAME, "
1130                    + "CATALOG_NAME CLASS_NAME, "
1131                    + "CAST(ZERO() AS SMALLINT) DATA_TYPE, "
1132                    + "CATALOG_NAME REMARKS, "
1133                    + "CAST(ZERO() AS SMALLINT) BASE_TYPE "
1134                    + "FROM INFORMATION_SCHEMA.CATALOGS "
1135                    + "WHERE FALSE");
1136            return prep.executeQuery();
1137        } catch(Throwable JavaDoc e) {
1138            throw logAndConvert(e);
1139        }
1140    }
1141
1142    /**
1143     * Gets the list of data types.
1144     * The result set is sorted by DATA_TYPE and
1145     * afterwards by how closely the data type maps to the corresponding JDBC SQL type
1146     * (best match first).
1147     *
1148     * <ul>
1149     * <li>1 TYPE_NAME (String) type name
1150     * <li>2 DATA_TYPE (short) SQL data type - see also java.sql.Types
1151     * <li>3 PRECISION (int) maximum precision
1152     * <li>4 LITERAL_PREFIX (String) prefix used to quote a literal
1153     * <li>5 LITERAL_SUFFIX (String) suffix used to quote a literal
1154     * <li>6 CREATE_PARAMS (String) parameters used (may be null)
1155     * <li>7 NULLABLE (short) typeNoNulls (NULL not allowed) or typeNullable
1156     * <li>8 CASE_SENSITIVE (boolean) case sensitive
1157     * <li>9 SEARCHABLE (short) typeSearchable
1158     * <li>10 UNSIGNED_ATTRIBUTE (boolean) unsigned
1159     * <li>11 FIXED_PREC_SCALE (boolean) fixed precision
1160     * <li>12 AUTO_INCREMENT (boolean) auto increment
1161     * <li>13 LOCAL_TYPE_NAME (String) localized version of the data type
1162     * <li>14 MINIMUM_SCALE (short) minimum scale
1163     * <li>15 MAXIMUM_SCALE (short) maximum scale
1164     * <li>16 SQL_DATA_TYPE (int) unused
1165     * <li>17 SQL_DATETIME_SUB (int) unused
1166     * <li>18 NUM_PREC_RADIX (int) 2 for binary, 10 for decimal
1167     * </ul>
1168     *
1169     * @return the list of data types
1170     * @throws SQLException if the connection is closed
1171     */

1172    public ResultSet getTypeInfo() throws SQLException {
1173        try {
1174            debugCodeCall("getTypeInfo");
1175            checkClosed();
1176            PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
1177                    + "TYPE_NAME, "
1178                    + "DATA_TYPE, "
1179                    + "PRECISION, "
1180                    + "PREFIX LITERAL_PREFIX, "
1181                    + "SUFFIX LITERAL_SUFFIX, "
1182                    + "PARAMS CREATE_PARAMS, "
1183                    + "NULLABLE, "
1184                    + "CASE_SENSITIVE, "
1185                    + "SEARCHABLE, "
1186                    + "FALSE UNSIGNED_ATTRIBUTE, "
1187                    + "FALSE FIXED_PREC_SCALE, "
1188                    + "AUTO_INCREMENT, "
1189                    + "TYPE_NAME LOCAL_TYPE_NAME, "
1190                    + "MINIMUM_SCALE, "
1191                    + "MAXIMUM_SCALE, "
1192                    + "DATA_TYPE SQL_DATA_TYPE, "
1193                    + "ZERO() SQL_DATETIME_SUB, "
1194                    + "RADIX NUM_PREC_RADIX "
1195                    + "FROM INFORMATION_SCHEMA.TYPE_INFO "
1196                    + "ORDER BY DATA_TYPE, POS");
1197            ResultSet rs = prep.executeQuery();
1198            return rs;
1199        } catch(Throwable JavaDoc e) {
1200            throw logAndConvert(e);
1201        }
1202    }
1203
1204    /**
1205     * Checks if this database store data in local files.
1206     *
1207     * @return true
1208     */

1209    public boolean usesLocalFiles() {
1210        debugCodeCall("usesLocalFiles");
1211        return true;
1212    }
1213
1214    /**
1215     * Checks if this database use one file per table.
1216     *
1217     * @return false
1218     */

1219    public boolean usesLocalFilePerTable() {
1220        debugCodeCall("usesLocalFilePerTable");
1221        return false;
1222    }
1223
1224    /**
1225     * Returns the string used to quote identifiers.
1226     *
1227     * @return a double quote
1228     */

1229    public String JavaDoc getIdentifierQuoteString() {
1230        debugCodeCall("getIdentifierQuoteString");
1231        return "\"";
1232    }
1233
1234    /**
1235     * Gets the comma-separated list of all SQL keywords that are not supported
1236     * as table/column/index name, in addition to the SQL-92 keywords.
1237     *
1238     * @return a list with the keywords
1239     */

1240    public String JavaDoc getSQLKeywords() {
1241        debugCodeCall("getSQLKeywords");
1242        return "";
1243    }
1244
1245    /**
1246     * Returns the list of numeric functions supported by this database.
1247     *
1248     * @return the list
1249     */

1250    public String JavaDoc getNumericFunctions() throws SQLException {
1251        debugCodeCall("getNumericFunctions");
1252        return getFunctions("Functions (Numeric)");
1253    }
1254
1255    /**
1256     * Returns the list of string functions supported by this database.
1257     *
1258     * @return the list
1259     */

1260    public String JavaDoc getStringFunctions() throws SQLException {
1261        debugCodeCall("getStringFunctions");
1262        return getFunctions("Functions (String)");
1263    }
1264
1265    /**
1266     * Returns the list of system functions supported by this database.
1267     *
1268     * @return the list
1269     */

1270    public String JavaDoc getSystemFunctions() throws SQLException {
1271        debugCodeCall("getSystemFunctions");
1272        return getFunctions("Functions (System)");
1273    }
1274
1275    /**
1276     * Returns the list of date and time functions supported by this database.
1277     *
1278     * @return the list
1279     */

1280    public String JavaDoc getTimeDateFunctions() throws SQLException {
1281        debugCodeCall("getTimeDateFunctions");
1282        return getFunctions("Functions (Time and Date)");
1283    }
1284
1285    private String JavaDoc getFunctions(String JavaDoc section) throws SQLException {
1286        try {
1287            StringBuffer JavaDoc buff = new StringBuffer JavaDoc();
1288            checkClosed();
1289            PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT TOPIC "
1290                    + "FROM INFORMATION_SCHEMA.HELP WHERE SECTION = ?");
1291            prep.setString(1, section);
1292            ResultSet rs = prep.executeQuery();
1293            while(rs.next()) {
1294                String JavaDoc s = rs.getString(1).trim();
1295                String JavaDoc[] array = StringUtils.arraySplit(s, ',', true);
1296                for(int i=0; i<array.length; i++) {
1297                    if(buff.length()>0) {
1298                        buff.append(",");
1299                    }
1300                    String JavaDoc f = array[i].trim();
1301                    if(f.indexOf(' ') >= 0) {
1302                        // remove 'Function' from 'INSERT Function'
1303
f = f.substring(0, f.indexOf(' ')).trim();
1304                    }
1305                    buff.append(f);
1306                }
1307            }
1308            rs.close();
1309            prep.close();
1310            return buff.toString();
1311        } catch(Throwable JavaDoc e) {
1312            throw logAndConvert(e);
1313        }
1314    }
1315
1316    /**
1317     * Returns the default escape character for LIKE.
1318     *
1319     * @return the character '\'
1320     */

1321    public String JavaDoc getSearchStringEscape() {
1322        debugCodeCall("getSearchStringEscape");
1323        return "" + Constants.DEFAULT_ESCAPE_CHAR;
1324    }
1325
1326    /**
1327     * Returns the characters that are allowed for identifiers in addiction to
1328     * A-Z, a-z, 0-9 and '_'.
1329     *
1330     * @return an empty String ("")
1331     */

1332    public String JavaDoc getExtraNameCharacters() {
1333        debugCodeCall("getExtraNameCharacters");
1334        return "";
1335    }
1336
1337    /**
1338     * Returns whether alter table with add column is supported.
1339     * @return true
1340     */

1341    public boolean supportsAlterTableWithAddColumn() {
1342        debugCodeCall("supportsAlterTableWithAddColumn");
1343        return true;
1344    }
1345
1346    /**
1347     * Returns whether alter table with drop column is supported.
1348     *
1349     * @return true
1350     */

1351    public boolean supportsAlterTableWithDropColumn() {
1352        debugCodeCall("supportsAlterTableWithDropColumn");
1353        return true;
1354    }
1355
1356    /**
1357     * Returns whether column aliasing is supported.
1358     *
1359     * @return true
1360     */

1361    public boolean supportsColumnAliasing() {
1362        debugCodeCall("supportsColumnAliasing");
1363        return true;
1364    }
1365
1366    /**
1367     * Returns whether NULL+1 is NULL or not.
1368     *
1369     * @return true
1370     */

1371    public boolean nullPlusNonNullIsNull() {
1372        debugCodeCall("nullPlusNonNullIsNull");
1373        return true;
1374    }
1375
1376    /**
1377     * Returns whether CONVERT is supported.
1378     *
1379     * @return true
1380     */

1381    public boolean supportsConvert() {
1382        debugCodeCall("supportsConvert");
1383        return true;
1384    }
1385
1386    /**
1387     * Returns whether CONVERT is supported for one datatype to another.
1388     *
1389     * @return true
1390     */

1391    public boolean supportsConvert(int fromType, int toType) {
1392        if(debug()) {
1393            debugCode("supportsConvert("+fromType+", "+fromType+");");
1394        }
1395        return true;
1396    }
1397
1398    /**
1399     * Returns whether table correlation names (table alias) are supported.
1400     *
1401     * @return true
1402     */

1403    public boolean supportsTableCorrelationNames() {
1404        debugCodeCall("supportsTableCorrelationNames");
1405        return true;
1406    }
1407
1408    /**
1409     * Returns whether table correlation names (table alias) are restricted to
1410     * be different than table names.
1411     *
1412     * @return false
1413     */

1414    public boolean supportsDifferentTableCorrelationNames() {
1415        debugCodeCall("supportsDifferentTableCorrelationNames");
1416        return false;
1417    }
1418
1419    /**
1420     * Returns whether expression in ORDER BY are supported.
1421     *
1422     * @return true
1423     */

1424    public boolean supportsExpressionsInOrderBy() {
1425        debugCodeCall("supportsExpressionsInOrderBy");
1426        return true;
1427    }
1428
1429    /**
1430     * Returns whether ORDER BY is supported if the column is not in the SELECT
1431     * list.
1432     *
1433     * @return true
1434     */

1435    public boolean supportsOrderByUnrelated() {
1436        debugCodeCall("supportsOrderByUnrelated");
1437        return true;
1438    }
1439
1440    /**
1441     * Returns whether GROUP BY is supported.
1442     *
1443     * @return true
1444     */

1445    public boolean supportsGroupBy() {
1446        debugCodeCall("supportsGroupBy");
1447        return true;
1448    }
1449
1450    /**
1451     * Returns whether GROUP BY is supported if the column is not in the SELECT
1452     * list.
1453     *
1454     * @return true
1455     */

1456    public boolean supportsGroupByUnrelated() {
1457        debugCodeCall("supportsGroupByUnrelated");
1458        return true;
1459    }
1460
1461    /**
1462     * Checks whether a GROUP BY clause can use columns that are not in the
1463     * SELECT clause, provided that it specifies all the columns in the SELECT
1464     * clause.
1465     *
1466     * @return true
1467     */

1468    public boolean supportsGroupByBeyondSelect() {
1469        debugCodeCall("supportsGroupByBeyondSelect");
1470        return true;
1471    }
1472
1473    /**
1474     * Returns whether LIKE... ESCAPE is supported.
1475     *
1476     * @return true
1477     */

1478    public boolean supportsLikeEscapeClause() {
1479        debugCodeCall("supportsLikeEscapeClause");
1480        return true;
1481    }
1482
1483    /**
1484     * Returns whether multiple result sets are supported.
1485     *
1486     * @return false
1487     */

1488    public boolean supportsMultipleResultSets() {
1489        debugCodeCall("supportsMultipleResultSets");
1490        return false;
1491    }
1492
1493    /**
1494     * Returns whether multiple transactions (on different connections) are
1495     * supported.
1496     *
1497     * @return true
1498     */

1499    public boolean supportsMultipleTransactions() {
1500        debugCodeCall("supportsMultipleTransactions");
1501        return true;
1502    }
1503
1504    /**
1505     * Returns whether columns with NOT NULL are supported.
1506     *
1507     * @return true
1508     */

1509    public boolean supportsNonNullableColumns() {
1510        debugCodeCall("supportsNonNullableColumns");
1511        return true;
1512    }
1513
1514    /**
1515     * Returns whether ODBC Minimum SQL grammar is supported.
1516     *
1517     * @return true
1518     */

1519    public boolean supportsMinimumSQLGrammar() {
1520        debugCodeCall("supportsMinimumSQLGrammar");
1521        return true;
1522    }
1523
1524    /**
1525     * Returns whether ODBC Core SQL grammar is supported.
1526     *
1527     * @return true
1528     */

1529    public boolean supportsCoreSQLGrammar() {
1530        debugCodeCall("supportsCoreSQLGrammar");
1531        return true;
1532    }
1533
1534    /**
1535     * Returns whether ODBC Extended SQL grammar is supported.
1536     *
1537     * @return false
1538     */

1539    public boolean supportsExtendedSQLGrammar() {
1540        debugCodeCall("supportsExtendedSQLGrammar");
1541        return false;
1542    }
1543
1544    /**
1545     * Returns whether SQL-92 entry level grammar is supported.
1546     *
1547     * @return true
1548     */

1549    public boolean supportsANSI92EntryLevelSQL() {
1550        debugCodeCall("supportsANSI92EntryLevelSQL");
1551        return true;
1552    }
1553
1554    /**
1555     * Returns whether SQL-92 intermediate level grammar is supported.
1556     *
1557     * @return false
1558     */

1559    public boolean supportsANSI92IntermediateSQL() {
1560        debugCodeCall("supportsANSI92IntermediateSQL");
1561        return false;
1562    }
1563
1564    /**
1565     * Returns whether SQL-92 full level grammar is supported.
1566     *
1567     * @return false
1568     */

1569    public boolean supportsANSI92FullSQL() {
1570        debugCodeCall("supportsANSI92FullSQL");
1571        return false;
1572    }
1573
1574    /**
1575     * Returns whether refererential integrity is supported.
1576     *
1577     * @return true
1578     */

1579    public boolean supportsIntegrityEnhancementFacility() {
1580        debugCodeCall("supportsIntegrityEnhancementFacility");
1581        return true;
1582    }
1583
1584    /**
1585     * Returns whether outer joins are supported.
1586     *
1587     * @return true
1588     */

1589    public boolean supportsOuterJoins() {
1590        debugCodeCall("supportsOuterJoins");
1591        return true;
1592    }
1593
1594    /**
1595     * Returns whether full outer joins are supported.
1596     *
1597     * @return false
1598     */

1599    public boolean supportsFullOuterJoins() {
1600        debugCodeCall("supportsFullOuterJoins");
1601        return false;
1602    }
1603
1604    /**
1605     * Returns whether limited outer joins are supported.
1606     *
1607     * @return true
1608     */

1609    public boolean supportsLimitedOuterJoins() {
1610        debugCodeCall("supportsLimitedOuterJoins");
1611        return true;
1612    }
1613
1614    /**
1615     * Returns the term for "schema".
1616     *
1617     * @return "schema"
1618     */

1619    public String JavaDoc getSchemaTerm() {
1620        debugCodeCall("getSchemaTerm");
1621        return "schema";
1622    }
1623
1624    /**
1625     * Returns the term for "procedure".
1626     *
1627     * @return "procedure"
1628     */

1629    public String JavaDoc getProcedureTerm() {
1630        debugCodeCall("getProcedureTerm");
1631        return "procedure";
1632    }
1633
1634    /**
1635     * Returns the term for "catalog".
1636     *
1637     * @return "catalog"
1638     */

1639    public String JavaDoc getCatalogTerm() {
1640        debugCodeCall("getCatalogTerm");
1641        return "catalog";
1642    }
1643
1644    /**
1645     * Returns whether the catalog is at the beginning.
1646     *
1647     * @return true
1648     */

1649    public boolean isCatalogAtStart() {
1650        debugCodeCall("isCatalogAtStart");
1651        return true;
1652    }
1653
1654    /**
1655     * Returns the catalog separator.
1656     *
1657     * @return "."
1658     */

1659    public String JavaDoc getCatalogSeparator() {
1660        debugCodeCall("getCatalogSeparator");
1661        return ".";
1662    }
1663
1664    /**
1665     * Returns whether the schema name in INSERT, UPDATE, DELETE is supported.
1666     *
1667     * @return true
1668     */

1669    public boolean supportsSchemasInDataManipulation() {
1670        debugCodeCall("supportsSchemasInDataManipulation");
1671        return true;
1672    }
1673
1674    /**
1675     * Returns whether the schema name in procedure calls is supported.
1676     *
1677     * @return true
1678     */

1679    public boolean supportsSchemasInProcedureCalls() {
1680        debugCodeCall("supportsSchemasInProcedureCalls");
1681        return true;
1682    }
1683
1684    /**
1685     * Returns whether the schema name in CREATE TABLE is supported.
1686     *
1687     * @return true
1688     */

1689    public boolean supportsSchemasInTableDefinitions() {
1690        debugCodeCall("supportsSchemasInTableDefinitions");
1691        return true;
1692    }
1693
1694    /**
1695     * Returns whether the schema name in CREATE INDEX is supported.
1696     *
1697     * @return true
1698     */

1699    public boolean supportsSchemasInIndexDefinitions() {
1700        debugCodeCall("supportsSchemasInIndexDefinitions");
1701        return true;
1702    }
1703
1704    /**
1705     * Returns whether the schema name in GRANT is supported.
1706     *
1707     * @return true
1708     */

1709    public boolean supportsSchemasInPrivilegeDefinitions() {
1710        debugCodeCall("supportsSchemasInPrivilegeDefinitions");
1711        return true;
1712    }
1713
1714    /**
1715     * Returns whether the catalog name in INSERT, UPDATE, DELETE is supported.
1716     *
1717     * @return false
1718     */

1719    public boolean supportsCatalogsInDataManipulation() {
1720        debugCodeCall("supportsCatalogsInDataManipulation");
1721        return false;
1722    }
1723
1724    /**
1725     * Returns whether the catalog name in procedure calls is supported.
1726     *
1727     * @return false
1728     */

1729    public boolean supportsCatalogsInProcedureCalls() {
1730        debugCodeCall("supportsCatalogsInProcedureCalls");
1731        return false;
1732    }
1733
1734    /**
1735     * Returns whether the catalog name in CREATE TABLE is supported.
1736     *
1737     * @return false
1738      */

1739    public boolean supportsCatalogsInTableDefinitions() {
1740        debugCodeCall("supportsCatalogsInTableDefinitions");
1741        return false;
1742    }
1743
1744    /**
1745     * Returns whether the catalog name in CREATE INDEX is supported.
1746     *
1747     * @return false
1748     */

1749    public boolean supportsCatalogsInIndexDefinitions() {
1750        debugCodeCall("supportsCatalogsInIndexDefinitions");
1751        return false;
1752    }
1753
1754    /**
1755     * Returns whether the catalog name in GRANT is supported.
1756     *
1757     * @return false
1758     */

1759    public boolean supportsCatalogsInPrivilegeDefinitions() {
1760        debugCodeCall("supportsCatalogsInPrivilegeDefinitions");
1761        return false;
1762    }
1763
1764    /**
1765     * Returns whether positioned deletes are supported.
1766     *
1767     * @return true
1768     */

1769    public boolean supportsPositionedDelete() {
1770        debugCodeCall("supportsPositionedDelete");
1771        return true;
1772    }
1773
1774    /**
1775     * Returns whether positioned updates are supported.
1776     *
1777     * @return true
1778     */

1779    public boolean supportsPositionedUpdate() {
1780        debugCodeCall("supportsPositionedUpdate");
1781        return true;
1782    }
1783
1784    /**
1785     * Returns whether SELECT ... FOR UPDATE is supported.
1786     *
1787     * @return true
1788     */

1789    public boolean supportsSelectForUpdate() {
1790        debugCodeCall("supportsSelectForUpdate");
1791        return true;
1792    }
1793
1794    /**
1795     * Returns whether stored procedures are supported.
1796     *
1797     * @return false
1798     */

1799    public boolean supportsStoredProcedures() {
1800        debugCodeCall("supportsStoredProcedures");
1801        return false;
1802    }
1803
1804    /**
1805     * Returns whether subqueries (SELECT) in comparisons are supported.
1806     *
1807     * @return true
1808     */

1809    public boolean supportsSubqueriesInComparisons() {
1810        debugCodeCall("supportsSubqueriesInComparisons");
1811        return true;
1812    }
1813
1814    /**
1815     * Returns whether SELECT in EXISTS is supported.
1816     *
1817     * @return true
1818     */

1819    public boolean supportsSubqueriesInExists() {
1820        debugCodeCall("supportsSubqueriesInExists");
1821        return true;
1822    }
1823
1824    /**
1825     * Returns whether IN(SELECT...) is supported.
1826     *
1827     * @return true
1828     */

1829    public boolean supportsSubqueriesInIns() {
1830        debugCodeCall("supportsSubqueriesInIns");
1831        return true;
1832    }
1833
1834    /**
1835     * Returns whether subqueries in quantified expression are supported.
1836     *
1837     * @return true
1838     */

1839    public boolean supportsSubqueriesInQuantifieds() {
1840        debugCodeCall("supportsSubqueriesInQuantifieds");
1841        return true;
1842    }
1843
1844    /**
1845     * Returns whether correlated subqueries are supported.
1846     *
1847     * @return true
1848     */

1849    public boolean supportsCorrelatedSubqueries() {
1850        debugCodeCall("supportsCorrelatedSubqueries");
1851        return true;
1852    }
1853
1854    /**
1855     * Returns whether UNION SELECT is supported.
1856     *
1857     * @return true
1858     */

1859    public boolean supportsUnion() {
1860        debugCodeCall("supportsUnion");
1861        return true;
1862    }
1863
1864    /**
1865     * Returns whether UNION ALL SELECT is supported.
1866     *
1867     * @return true
1868     */

1869    public boolean supportsUnionAll() {
1870        debugCodeCall("supportsUnionAll");
1871        return true;
1872    }
1873
1874    /**
1875     * Returns whether open result sets accross commits are supported.
1876     *
1877     * @return false
1878     */

1879    public boolean supportsOpenCursorsAcrossCommit() {
1880        debugCodeCall("supportsOpenCursorsAcrossCommit");
1881        return false;
1882    }
1883
1884    /**
1885     * Returns whether open result sets accross rollback are supported.
1886     *
1887     * @return false
1888     */

1889    public boolean supportsOpenCursorsAcrossRollback() {
1890        debugCodeCall("supportsOpenCursorsAcrossRollback");
1891        return false;
1892    }
1893
1894    /**
1895     * Returns whether open statements accross commit are supported.
1896     *
1897     * @return true
1898     */

1899    public boolean supportsOpenStatementsAcrossCommit() {
1900        debugCodeCall("supportsOpenStatementsAcrossCommit");
1901        return true;
1902    }
1903
1904    /**
1905     * Returns whether open statements accross rollback are supported.
1906     *
1907     * @return true
1908     */

1909    public boolean supportsOpenStatementsAcrossRollback() {
1910        debugCodeCall("supportsOpenStatementsAcrossRollback");
1911        return true;
1912    }
1913
1914    /**
1915     * Returns whether transactions are supported.
1916     *
1917     * @return true
1918     */

1919    public boolean supportsTransactions() {
1920        debugCodeCall("supportsTransactions");
1921        return true;
1922    }
1923
1924    /**
1925     * Returns whether a specific transaction isolation level is supported.
1926     *
1927     * @return true
1928     */

1929    public boolean supportsTransactionIsolationLevel(int level) {
1930        debugCodeCall("supportsTransactionIsolationLevel");
1931        return true;
1932    }
1933
1934    /**
1935     * Returns whether data manipulation and CREATE/DROP is supported in
1936     * transactions.
1937     *
1938     * @return false
1939     */

1940    public boolean supportsDataDefinitionAndDataManipulationTransactions() {
1941        debugCodeCall("supportsDataDefinitionAndDataManipulationTransactions");
1942        return false;
1943    }
1944
1945    /**
1946     * Returns whether only data manipulations are supported in transactions.
1947     *
1948     * @return true
1949     */

1950    public boolean supportsDataManipulationTransactionsOnly() {
1951        debugCodeCall("supportsDataManipulationTransactionsOnly");
1952        return true;
1953    }
1954
1955    /**
1956     * Returns whether CREATE/DROP commit an open transaction.
1957     *
1958     * @return true
1959     */

1960    public boolean dataDefinitionCausesTransactionCommit() {
1961        debugCodeCall("dataDefinitionCausesTransactionCommit");
1962        return true;
1963    }
1964
1965    /**
1966     * Returns whether CREATE/DROP do not affect transactions.
1967     *
1968     * @return false
1969     */

1970    public boolean dataDefinitionIgnoredInTransactions() {
1971        debugCodeCall("dataDefinitionIgnoredInTransactions");
1972        return false;
1973    }
1974
1975    /**
1976     * Returns whether a specific result set type is supported.
1977     * ResultSet.TYPE_SCROLL_SENSITIVE is notsupported.
1978     *
1979     * @return true for all types except ResultSet.TYPE_FORWARD_ONLY
1980     */

1981    public boolean supportsResultSetType(int type) {
1982        debugCodeCall("supportsResultSetType", type);
1983        return type != ResultSet.TYPE_SCROLL_SENSITIVE;
1984    }
1985
1986    /**
1987     * Returns whether a specific result set concurrency is supported.
1988     * ResultSet.TYPE_SCROLL_SENSITIVE is notsupported.
1989     *
1990     * @return true if the type is not ResultSet.TYPE_SCROLL_SENSITIVE
1991     */

1992    public boolean supportsResultSetConcurrency(int type, int concurrency) {
1993        if(debug()) {
1994            debugCode("supportsResultSetConcurrency("+type+", "+concurrency+");");
1995        }
1996        return type != ResultSet.TYPE_SCROLL_SENSITIVE;
1997    }
1998
1999    /**
2000     * Returns whether own updates are visible.
2001     *
2002     * @return false
2003     */

2004    public boolean ownUpdatesAreVisible(int type) {
2005        debugCodeCall("ownUpdatesAreVisible", type);
2006        return false;
2007    }
2008
2009    /**
2010     * Returns whether own deletes are visible.
2011     *
2012     * @return false
2013     */

2014    public boolean ownDeletesAreVisible(int type) {
2015        debugCodeCall("ownDeletesAreVisible", type);
2016        return false;
2017    }
2018
2019    /**
2020     * Returns whether own inserts are visible.
2021     * @return false
2022     */

2023    public boolean ownInsertsAreVisible(int type) {
2024        debugCodeCall("ownInsertsAreVisible", type);
2025        return false;
2026    }
2027
2028    /**
2029     * Returns whether other updates are visible.
2030     * @return false
2031     */

2032    public boolean othersUpdatesAreVisible(int type) {
2033        debugCodeCall("othersUpdatesAreVisible", type);
2034        return false;
2035    }
2036
2037    /**
2038     * Returns whether other deletes are visible.
2039     * @return false
2040     */

2041    public boolean othersDeletesAreVisible(int type) {
2042        debugCodeCall("othersDeletesAreVisible", type);
2043        return false;
2044    }
2045
2046    /**
2047     * Returns whether other inserts are visible.
2048     * @return false
2049     */

2050    public boolean othersInsertsAreVisible(int type) {
2051        debugCodeCall("othersInsertsAreVisible", type);
2052        return false;
2053    }
2054
2055    /**
2056     * Returns whether updates are dectected.
2057     * @return false
2058     */

2059    public boolean updatesAreDetected(int type) {
2060        debugCodeCall("updatesAreDetected", type);
2061        return false;
2062    }
2063
2064    /**
2065     * Returns whether deletes are detected.
2066     * @return false
2067     */

2068    public boolean deletesAreDetected(int type) {
2069        debugCodeCall("deletesAreDetected", type);
2070        return false;
2071    }
2072
2073    /**
2074     * Returns whether inserts are detected.
2075     * @return false
2076     */

2077    public boolean insertsAreDetected(int type) {
2078        debugCodeCall("insertsAreDetected", type);
2079        return false;
2080    }
2081
2082    /**
2083     * Returns whether batch updates are supported.
2084     * @return true
2085     */

2086    public boolean supportsBatchUpdates() {
2087        debugCodeCall("supportsBatchUpdates");
2088        return true;
2089    }
2090
2091    /**
2092     * Returns whether the maximum row size includes blobs.
2093     * @return false
2094     */

2095    public boolean doesMaxRowSizeIncludeBlobs() {
2096        debugCodeCall("doesMaxRowSizeIncludeBlobs");
2097        return false;
2098    }
2099
2100    /**
2101     * Returns the default transaction isolation level.
2102     * @return Connection.TRANSACTION_READ_COMMITTED
2103     */

2104    public int getDefaultTransactionIsolation() {
2105        debugCodeCall("getDefaultTransactionIsolation");
2106        return Connection.TRANSACTION_READ_COMMITTED;
2107    }
2108
2109    /**
2110     * Checks if for CREATE TABLE Test(ID INT), getTables returns Test as the
2111     * table name.
2112     * @return false
2113     */

2114    public boolean supportsMixedCaseIdentifiers() {
2115        debugCodeCall("supportsMixedCaseIdentifiers");
2116        return false;
2117    }
2118
2119    /**
2120     * Checks if a table created with CREATE TABLE "Test"(ID INT) is a different
2121     * table than a table created with CREATE TABLE TEST(ID INT).
2122     * @return true
2123     */

2124    public boolean supportsMixedCaseQuotedIdentifiers() {
2125        debugCodeCall("supportsMixedCaseQuotedIdentifiers");
2126        return true;
2127    }
2128
2129    /**
2130     * Checks if for CREATE TABLE Test(ID INT), getTables returns TEST as the
2131     * table name.
2132     * @return true
2133     */

2134    public boolean storesUpperCaseIdentifiers() {
2135        debugCodeCall("storesUpperCaseIdentifiers");
2136        return true;
2137    }
2138
2139    /**
2140     * Checks if for CREATE TABLE Test(ID INT), getTables returns test as the
2141     * table name.
2142     * @return false
2143     */

2144    public boolean storesLowerCaseIdentifiers() {
2145        debugCodeCall("storesLowerCaseIdentifiers");
2146        return false;
2147    }
2148
2149    /**
2150     * Checks if for CREATE TABLE Test(ID INT), getTables returns Test as the
2151     * table name.
2152     * @return false
2153     */

2154    public boolean storesMixedCaseIdentifiers() {
2155        debugCodeCall("storesMixedCaseIdentifiers");
2156        return false;
2157    }
2158
2159    /**
2160     * Checks if for CREATE TABLE "Test"(ID INT), getTables returns TEST as the
2161     * table name.
2162     * @return false
2163     */

2164    public boolean storesUpperCaseQuotedIdentifiers() {
2165        debugCodeCall("storesUpperCaseQuotedIdentifiers");
2166        return false;
2167    }
2168
2169    /**
2170     * Checks if for CREATE TABLE "Test"(ID INT), getTables returns test as the
2171     * table name.
2172     * @return false
2173     */

2174    public boolean storesLowerCaseQuotedIdentifiers() {
2175        debugCodeCall("storesLowerCaseQuotedIdentifiers");
2176        return false;
2177    }
2178
2179    /**
2180     * Checks if for CREATE TABLE "Test"(ID INT), getTables returns Test as the
2181     * table name.
2182     * @return true
2183     */

2184    public boolean storesMixedCaseQuotedIdentifiers() {
2185        debugCodeCall("storesMixedCaseQuotedIdentifiers");
2186        return true;
2187    }
2188
2189    /**
2190     * Returns the maximum length for hex values (characters).
2191     * @return 0 for limit is unknown
2192     */

2193    public int getMaxBinaryLiteralLength() {
2194        debugCodeCall("getMaxBinaryLiteralLength");
2195        return 0;
2196    }
2197
2198    /**
2199     * Returns the maximum length for literals.
2200     * @return 0 for limit is unknown
2201     */

2202    public int getMaxCharLiteralLength() {
2203        debugCodeCall("getMaxCharLiteralLength");
2204        return 0;
2205    }
2206
2207    /**
2208     * Returns the maximum length for column names.
2209     * @return 0 for limit is unknown
2210     */

2211    public int getMaxColumnNameLength() {
2212        debugCodeCall("getMaxColumnNameLength");
2213        return 0;
2214    }
2215
2216    /**
2217     * Returns the maximum number of columns in GROUP BY.
2218     * @return 0 for limit is unknown
2219     */

2220    public int getMaxColumnsInGroupBy() {
2221        debugCodeCall("getMaxColumnsInGroupBy");
2222        return 0;
2223    }
2224
2225    /**
2226     * Returns the maximum number of columns in CREATE INDEX.
2227     * @return 0 for limit is unknown
2228     */

2229    public int getMaxColumnsInIndex() {
2230        debugCodeCall("getMaxColumnsInIndex");
2231        return 0;
2232    }
2233
2234    /**
2235     * Returns the maximum number of columns in ORDER BY.
2236     * @return 0 for limit is unknown
2237     */

2238    public int getMaxColumnsInOrderBy() {
2239        debugCodeCall("getMaxColumnsInOrderBy");
2240        return 0;
2241    }
2242
2243    /**
2244     * Returns the maximum number of columns in SELECT.
2245     * @return 0 for limit is unknown
2246     */

2247    public int getMaxColumnsInSelect() {
2248        debugCodeCall("getMaxColumnsInSelect");
2249        return 0;
2250    }
2251
2252    /**
2253     * Returns the maximum number of columns in CREATE TABLE.
2254     * @return 0 for limit is unknown
2255     */

2256    public int getMaxColumnsInTable() {
2257        debugCodeCall("getMaxColumnsInTable");
2258        return 0;
2259    }
2260
2261    /**
2262     * Returns the maximum number of open connection.
2263     * @return 0 for limit is unknown
2264     */

2265    public int getMaxConnections() {
2266        debugCodeCall("getMaxConnections");
2267        return 0;
2268    }
2269
2270    /**
2271     * Returns the maximum length for a cursor name.
2272     * @return 0 for limit is unknown
2273     */

2274    public int getMaxCursorNameLength() {
2275        debugCodeCall("getMaxCursorNameLength");
2276        return 0;
2277    }
2278
2279    /**
2280     * Returns the maximum length for an index (in bytes).
2281     * @return 0 for limit is unknown
2282     */

2283    public int getMaxIndexLength() {
2284        debugCodeCall("getMaxIndexLength");
2285        return 0;
2286    }
2287
2288    /**
2289     * Returns the maximum length for a schema name.
2290     * @return 0 for limit is unknown
2291     */

2292    public int getMaxSchemaNameLength() {
2293        debugCodeCall("getMaxSchemaNameLength");
2294        return 0;
2295    }
2296
2297    /**
2298     * Returns the maximum length for a procedure name.
2299     * @return 0 for limit is unknown
2300     */

2301    public int getMaxProcedureNameLength() {
2302        debugCodeCall("getMaxProcedureNameLength");
2303        return 0;
2304    }
2305
2306    /**
2307     * Returns the maximum length for a catalog name.
2308     * @return 0 for limit is unknown
2309     */

2310    public int getMaxCatalogNameLength() {
2311        debugCodeCall("getMaxCatalogNameLength");
2312        return 0;
2313    }
2314
2315    /**
2316     * Returns the maximum size of a row (in bytes).
2317     * @return 0 for limit is unknown
2318     */

2319    public int getMaxRowSize() {
2320        debugCodeCall("getMaxRowSize");
2321        return 0;
2322    }
2323
2324    /**
2325     * Returns the maximum length of a statement.
2326     * @return 0 for limit is unknown
2327     */

2328    public int getMaxStatementLength() {
2329        debugCodeCall("getMaxStatementLength");
2330        return 0;
2331    }
2332
2333    /**
2334     * Returns the maximum number of open statements.
2335     * @return 0 for limit is unknown
2336     */

2337    public int getMaxStatements() {
2338        debugCodeCall("getMaxStatements");
2339        return 0;
2340    }
2341
2342    /**
2343     * Returns the maximum length for a table name.
2344     * @return 0 for limit is unknown
2345     */

2346    public int getMaxTableNameLength() {
2347        debugCodeCall("getMaxTableNameLength");
2348        return 0;
2349    }
2350
2351    /**
2352     * Returns the maximum number of tables in a SELECT.
2353     * @return 0 for limit is unknown
2354     */

2355    public int getMaxTablesInSelect() {
2356        debugCodeCall("getMaxTablesInSelect");
2357        return 0;
2358    }
2359
2360    /**
2361     * Returns the maximum length for a user name.
2362     * @return 0 for limit is unknown
2363     */

2364    public int getMaxUserNameLength() {
2365        debugCodeCall("getMaxUserNameLength");
2366        return 0;
2367    }
2368
2369    /**
2370     * Does the database support savepoints.
2371     * @return true
2372     */

2373    public boolean supportsSavepoints() {
2374        debugCodeCall("supportsSavepoints");
2375        return true;
2376    }
2377
2378    /**
2379     * Does the database support named parameters.
2380     * @return false
2381     */

2382    public boolean supportsNamedParameters() {
2383        debugCodeCall("supportsNamedParameters");
2384        return false;
2385    }
2386
2387    /**
2388     * Does the database support multiple open result sets.
2389     * @return true
2390     */

2391    public boolean supportsMultipleOpenResults() {
2392        debugCodeCall("supportsMultipleOpenResults");
2393        return true;
2394    }
2395
2396    /**
2397     * Does the database support getGeneratedKeys.
2398     * @return true
2399     */

2400    public boolean supportsGetGeneratedKeys() {
2401        debugCodeCall("supportsGetGeneratedKeys");
2402        return true;
2403    }
2404
2405    /**
2406     * THIS FEATURE IS NOT SUPPORTED.
2407     *
2408     * @throws SQLException
2409     * Unsupported Feature (SQL State 0A000)
2410     */

2411    public ResultSet getSuperTypes(String JavaDoc catalog, String JavaDoc schemaPattern,
2412            String JavaDoc typeNamePattern) throws SQLException {
2413        try {
2414            if(debug()) {
2415                debugCode("getSuperTypes("
2416                        +quote(catalog)+", "
2417                        +quote(schemaPattern)+", "
2418                        +quote(typeNamePattern)+");");
2419            }
2420            throw Message.getUnsupportedException();
2421        } catch(Throwable JavaDoc e) {
2422            throw logAndConvert(e);
2423        }
2424    }
2425
2426    /**
2427     * Get the list of super tables of a table.
2428     * This method currently returns an empty result set.
2429     *
2430     * <ul>
2431     * <li>1 TABLE_CAT (String) table catalog
2432     * <li>2 TABLE_SCHEM (String) table schema
2433     * <li>3 TABLE_NAME (String) table name
2434     * <li>4 SUPERTABLE_NAME (String) the name of the super table
2435     * </ul>
2436     *
2437     * @return an empty result set
2438     */

2439    public ResultSet getSuperTables(String JavaDoc catalog, String JavaDoc schemaPattern,
2440            String JavaDoc tableNamePattern) throws SQLException {
2441        try {
2442            if(debug()) {
2443                debugCode("getSuperTables("
2444                        +quote(catalog)+", "
2445                        +quote(schemaPattern)+", "
2446                        +quote(tableNamePattern)+");");
2447            }
2448            checkClosed();
2449            PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
2450                    + "CATALOG_NAME TABLE_CAT, "
2451                    + "CATALOG_NAME TABLE_SCHEM, "
2452                    + "CATALOG_NAME TABLE_NAME, "
2453                    + "CATALOG_NAME SUPERTABLE_NAME "
2454                    + "FROM INFORMATION_SCHEMA.CATALOGS "
2455                    + "WHERE FALSE");
2456            return prep.executeQuery();
2457        } catch(Throwable JavaDoc e) {
2458            throw logAndConvert(e);
2459        }
2460    }
2461
2462    /**
2463     * THIS FEATURE IS NOT SUPPORTED.
2464     *
2465     * @throws SQLException
2466     * Unsupported Feature (SQL State 0A000)
2467     */

2468    public ResultSet getAttributes(String JavaDoc catalog, String JavaDoc schemaPattern,
2469            String JavaDoc typeNamePattern, String JavaDoc attributeNamePattern)
2470            throws SQLException {
2471        try {
2472            if(debug()) {
2473                debugCode("getAttributes("
2474                        +quote(catalog)+", "
2475                        +quote(schemaPattern)+", "
2476                        +quote(typeNamePattern)+", "
2477                        +quote(attributeNamePattern)+");");
2478            }
2479            throw Message.getUnsupportedException();
2480        } catch(Throwable JavaDoc e) {
2481            throw logAndConvert(e);
2482        }
2483    }
2484
2485    /**
2486     * Does this database supports a result set holdability.
2487     *
2488     * @param holdability ResultSet.HOLD_CURSORS_OVER_COMMIT or CLOSE_CURSORS_AT_COMMIT
2489     * @return true if the holdability is ResultSet.CLOSE_CURSORS_AT_COMMIT
2490     */

2491//#ifdef JDK14
2492
public boolean supportsResultSetHoldability(int holdability) {
2493        debugCodeCall("supportsResultSetHoldability", holdability);
2494        return holdability == ResultSet.CLOSE_CURSORS_AT_COMMIT;
2495    }
2496//#endif
2497

2498    /**
2499     * Gets the result set holdability.
2500     * @return ResultSet.CLOSE_CURSORS_AT_COMMIT
2501     */

2502//#ifdef JDK14
2503
public int getResultSetHoldability() {
2504        debugCodeCall("getResultSetHoldability");
2505        return ResultSet.CLOSE_CURSORS_AT_COMMIT;
2506    }
2507//#endif
2508

2509    /**
2510     * Gets the major version of the database.
2511     * @return the major version
2512     */

2513    public int getDatabaseMajorVersion() {
2514        debugCodeCall("getDatabaseMajorVersion");
2515        return Constants.VERSION_MAJOR;
2516    }
2517
2518    /**
2519     * Gets the minor version of the database.
2520     * @return the minor version
2521     */

2522    public int getDatabaseMinorVersion() {
2523        debugCodeCall("getDatabaseMinorVersion");
2524        return Constants.VERSION_MINOR;
2525    }
2526
2527    /**
2528     * Gets the major version of the supported JDBC API.
2529     * @return the major version
2530     */

2531    public int getJDBCMajorVersion() throws SQLException {
2532        debugCodeCall("getJDBCMajorVersion");
2533        return Constants.VERSION_JDBC_MAJOR;
2534    }
2535
2536    /**
2537     * Gets the minor version of the supported JDBC API.
2538     * @return the minor version
2539     */

2540    public int getJDBCMinorVersion() throws SQLException {
2541        debugCodeCall("getJDBCMinorVersion");
2542        return Constants.VERSION_JDBC_MINOR;
2543    }
2544
2545    /**
2546     * Gets the SQL State type.
2547     * @return DatabaseMetaData.sqlStateSQL99
2548     */

2549//#ifdef JDK14
2550
public int getSQLStateType() {
2551        debugCodeCall("getSQLStateType");
2552        return DatabaseMetaData.sqlStateSQL99;
2553    }
2554//#endif
2555

2556    /**
2557     * Does the database make a copy before updating.
2558     * @return false
2559     */

2560    public boolean locatorsUpdateCopy() {
2561        debugCodeCall("locatorsUpdateCopy");
2562        return false;
2563    }
2564
2565    /**
2566     * Does the database support statement pooling.
2567     * @return false
2568     */

2569    public boolean supportsStatementPooling() {
2570        debugCodeCall("supportsStatementPooling");
2571        return false;
2572    }
2573
2574    // =============================================================
2575

2576    JdbcDatabaseMetaData(JdbcConnection conn, Trace trace, int id) {
2577        setTrace(trace, TraceObject.DATABASE_META_DATA, id);
2578        this.conn = conn;
2579    }
2580
2581    private void checkClosed() throws SQLException {
2582        conn.checkClosed();
2583    }
2584
2585    private String JavaDoc getPattern(String JavaDoc pattern) {
2586        return pattern == null ? "%" : pattern;
2587    }
2588
2589    private String JavaDoc getSchemaPattern(String JavaDoc pattern) {
2590        return pattern == null ? "%" : pattern.length() == 0 ? Constants.SCHEMA_MAIN : pattern;
2591    }
2592
2593    private String JavaDoc getCatalogPattern(String JavaDoc catalogPattern) {
2594        // Workaround for OpenOffice: getColumns is called with "" as the catalog
2595
return catalogPattern == null || catalogPattern.length()==0 ? "%" : catalogPattern;
2596    }
2597
2598    /**
2599     * Get the lifetime of a rowid.
2600     * @return ROWID_UNSUPPORTED
2601     */

2602    //#ifdef JDK16
2603
/*
2604    public RowIdLifetime getRowIdLifetime() {
2605        debugCodeCall("getRowIdLifetime");
2606        return RowIdLifetime.ROWID_UNSUPPORTED;
2607    }
2608*/

2609    //#endif
2610

2611    /**
2612     * Gets the list of schemas.
2613     * @throws SQLException Unsupported Feature (SQL State 0A000)
2614     */

2615    public ResultSet getSchemas(String JavaDoc catalog, String JavaDoc schemaPattern) throws SQLException {
2616        debugCodeCall("getSchemas");
2617        throw Message.getUnsupportedException();
2618    }
2619
2620    /**
2621     * Returns whether the database supports calling functions using the call syntax.
2622     * @return true
2623     */

2624    public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException {
2625        debugCodeCall("supportsStoredFunctionsUsingCallSyntax");
2626        return true;
2627    }
2628
2629    /**
2630     * Returns whether an exception while autocommit is on closes all result sets.
2631     * @return false
2632     */

2633    public boolean autoCommitFailureClosesAllResultSets() throws SQLException {
2634        debugCodeCall("autoCommitFailureClosesAllResultSets");
2635        return false;
2636    }
2637
2638    /**
2639     * Returns the client info properties.
2640     * @throws SQLException Unsupported Feature (SQL State 0A000)
2641     */

2642    public ResultSet getClientInfoProperties() throws SQLException {
2643        debugCodeCall("getClientInfoProperties");
2644        throw Message.getUnsupportedException();
2645    }
2646
2647    /**
2648     * Return an object of this class if possible.
2649     * @throws SQLException Unsupported Feature (SQL State 0A000)
2650     */

2651    //#ifdef JDK16
2652
/*
2653    public <T> T unwrap(Class<T> iface) throws SQLException {
2654        debugCodeCall("unwrap");
2655        throw Message.getUnsupportedException();
2656    }
2657*/

2658    //#endif
2659

2660    /**
2661     * Checks if unwrap can return an object of this class.
2662     * @throws SQLException Unsupported Feature (SQL State 0A000)
2663     */

2664    //#ifdef JDK16
2665
/*
2666    public boolean isWrapperFor(Class<?> iface) throws SQLException {
2667        debugCodeCall("isWrapperFor");
2668        throw Message.getUnsupportedException();
2669    }
2670*/

2671    //#endif
2672

2673    /**
2674     * Gets the list of function columns.
2675     * @throws SQLException Unsupported Feature (SQL State 0A000)
2676     */

2677    public ResultSet getFunctionColumns(String JavaDoc catalog, String JavaDoc schemaPattern, String JavaDoc functionNamePattern, String JavaDoc columnNamePattern) throws SQLException {
2678        debugCodeCall("getFunctionColumns");
2679        throw Message.getUnsupportedException();
2680    }
2681
2682    /**
2683     * Gets the list of functions.
2684     * @throws SQLException Unsupported Feature (SQL State 0A000)
2685     */

2686    public ResultSet getFunctions(String JavaDoc arg0, String JavaDoc arg1, String JavaDoc arg2) throws SQLException {
2687        debugCodeCall("getFunctions");
2688        throw Message.getUnsupportedException();
2689    }
2690
2691}
2692
2693
Popular Tags