Source Code Cross Referenced for TestMetaData.java in  » Database-DBMS » h2database » org » h2 » test » jdbc » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » h2database » org.h2.test.jdbc 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
0003:         * (license2)
0004:         * Initial Developer: H2 Group
0005:         */
0006:        package org.h2.test.jdbc;
0007:
0008:        import java.sql.Connection;
0009:        import java.sql.DatabaseMetaData;
0010:        import java.sql.Driver;
0011:        import java.sql.ResultSet;
0012:        import java.sql.ResultSetMetaData;
0013:        import java.sql.Statement;
0014:        import java.sql.Types;
0015:
0016:        import org.h2.engine.Constants;
0017:        import org.h2.test.TestBase;
0018:        import org.h2.value.DataType;
0019:
0020:        /**
0021:         * Test for the DatabaseMetaData implementation.
0022:         */
0023:        public class TestMetaData extends TestBase {
0024:
0025:            Connection conn;
0026:            DatabaseMetaData meta;
0027:            Statement stat;
0028:            String catalog = "METADATA";
0029:
0030:            public void test() throws Exception {
0031:                deleteDb("metaData");
0032:                conn = getConnection("metaData");
0033:
0034:                testColumnPrecision();
0035:                testColumnDefault();
0036:                testCrossReferences();
0037:                testProcedureColumns();
0038:
0039:                stat = conn.createStatement();
0040:                meta = conn.getMetaData();
0041:                testStatic();
0042:                // TODO test remaining meta data
0043:
0044:                stat
0045:                        .execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))");
0046:                stat.execute("CREATE INDEX IDXNAME ON TEST(NAME)");
0047:
0048:                ResultSet rs;
0049:
0050:                rs = meta.getCatalogs();
0051:                rs.next();
0052:                check(rs.getString(1), catalog);
0053:                checkFalse(rs.next());
0054:
0055:                rs = meta.getSchemas();
0056:                rs.next();
0057:                check(rs.getString("TABLE_SCHEM"), "INFORMATION_SCHEMA");
0058:                rs.next();
0059:                check(rs.getString("TABLE_SCHEM"), "PUBLIC");
0060:                checkFalse(rs.next());
0061:
0062:                rs = meta.getTableTypes();
0063:                rs.next();
0064:                check(rs.getString("TABLE_TYPE"), "SYSTEM TABLE");
0065:                rs.next();
0066:                check(rs.getString("TABLE_TYPE"), "TABLE");
0067:                rs.next();
0068:                check(rs.getString("TABLE_TYPE"), "TABLE LINK");
0069:                rs.next();
0070:                check(rs.getString("TABLE_TYPE"), "VIEW");
0071:                checkFalse(rs.next());
0072:
0073:                rs = meta.getTables(null, Constants.SCHEMA_MAIN, null,
0074:                        new String[] { "TABLE" });
0075:                check(rs.getStatement() == null);
0076:                rs.next();
0077:                check(rs.getString("TABLE_NAME"), "TEST");
0078:                checkFalse(rs.next());
0079:
0080:                rs = meta.getTables(null, "INFORMATION_SCHEMA", null,
0081:                        new String[] { "TABLE", "SYSTEM TABLE" });
0082:                rs.next();
0083:                check("CATALOGS", rs.getString("TABLE_NAME"));
0084:                rs.next();
0085:                check("COLLATIONS", rs.getString("TABLE_NAME"));
0086:                rs.next();
0087:                check("COLUMNS", rs.getString("TABLE_NAME"));
0088:                rs.next();
0089:                check("COLUMN_PRIVILEGES", rs.getString("TABLE_NAME"));
0090:                rs.next();
0091:                check("CONSTANTS", rs.getString("TABLE_NAME"));
0092:                rs.next();
0093:                check("CONSTRAINTS", rs.getString("TABLE_NAME"));
0094:                rs.next();
0095:                check("CROSS_REFERENCES", rs.getString("TABLE_NAME"));
0096:                rs.next();
0097:                check("DOMAINS", rs.getString("TABLE_NAME"));
0098:                rs.next();
0099:                check("FUNCTION_ALIASES", rs.getString("TABLE_NAME"));
0100:                rs.next();
0101:                check("FUNCTION_COLUMNS", rs.getString("TABLE_NAME"));
0102:                rs.next();
0103:                check("HELP", rs.getString("TABLE_NAME"));
0104:                rs.next();
0105:                check("INDEXES", rs.getString("TABLE_NAME"));
0106:                rs.next();
0107:                check("IN_DOUBT", rs.getString("TABLE_NAME"));
0108:                rs.next();
0109:                check("LOCKS", rs.getString("TABLE_NAME"));
0110:                rs.next();
0111:                check("RIGHTS", rs.getString("TABLE_NAME"));
0112:                rs.next();
0113:                check("ROLES", rs.getString("TABLE_NAME"));
0114:                rs.next();
0115:                check("SCHEMATA", rs.getString("TABLE_NAME"));
0116:                rs.next();
0117:                check("SEQUENCES", rs.getString("TABLE_NAME"));
0118:                rs.next();
0119:                check("SESSIONS", rs.getString("TABLE_NAME"));
0120:                rs.next();
0121:                check("SETTINGS", rs.getString("TABLE_NAME"));
0122:                rs.next();
0123:                check("TABLES", rs.getString("TABLE_NAME"));
0124:                rs.next();
0125:                check("TABLE_PRIVILEGES", rs.getString("TABLE_NAME"));
0126:                rs.next();
0127:                check("TABLE_TYPES", rs.getString("TABLE_NAME"));
0128:                rs.next();
0129:                check("TRIGGERS", rs.getString("TABLE_NAME"));
0130:                rs.next();
0131:                check("TYPE_INFO", rs.getString("TABLE_NAME"));
0132:                rs.next();
0133:                check("USERS", rs.getString("TABLE_NAME"));
0134:                rs.next();
0135:                check("VIEWS", rs.getString("TABLE_NAME"));
0136:                checkFalse(rs.next());
0137:
0138:                rs = meta.getColumns(null, null, "TEST", null);
0139:                rs.next();
0140:                check(rs.getString("COLUMN_NAME"), "ID");
0141:                rs.next();
0142:                check(rs.getString("COLUMN_NAME"), "NAME");
0143:                checkFalse(rs.next());
0144:
0145:                rs = meta.getPrimaryKeys(null, null, "TEST");
0146:                rs.next();
0147:                check(rs.getString("COLUMN_NAME"), "ID");
0148:                checkFalse(rs.next());
0149:
0150:                rs = meta.getBestRowIdentifier(null, null, "TEST",
0151:                        DatabaseMetaData.bestRowSession, false);
0152:                rs.next();
0153:                check(rs.getString("COLUMN_NAME"), "ID");
0154:                checkFalse(rs.next());
0155:
0156:                rs = meta.getIndexInfo(null, null, "TEST", false, false);
0157:                rs.next();
0158:                String index = rs.getString("INDEX_NAME");
0159:                check(index.startsWith("PRIMARY_KEY"));
0160:                check(rs.getString("COLUMN_NAME"), "ID");
0161:                rs.next();
0162:                check(rs.getString("INDEX_NAME"), "IDXNAME");
0163:                check(rs.getString("COLUMN_NAME"), "NAME");
0164:                checkFalse(rs.next());
0165:
0166:                rs = meta.getIndexInfo(null, null, "TEST", true, false);
0167:                rs.next();
0168:                index = rs.getString("INDEX_NAME");
0169:                check(index.startsWith("PRIMARY_KEY"));
0170:                check(rs.getString("COLUMN_NAME"), "ID");
0171:                checkFalse(rs.next());
0172:
0173:                rs = meta.getVersionColumns(null, null, "TEST");
0174:                checkFalse(rs.next());
0175:
0176:                stat.execute("DROP TABLE TEST");
0177:
0178:                rs = stat
0179:                        .executeQuery("SELECT * FROM INFORMATION_SCHEMA.SETTINGS");
0180:                while (rs.next()) {
0181:                    String name = rs.getString("NAME");
0182:                    String value = rs.getString("VALUE");
0183:                    trace(name + "=" + value);
0184:                }
0185:
0186:                test(conn);
0187:
0188:                // meta.getTablePrivileges()
0189:
0190:                // meta.getAttributes()
0191:                // meta.getColumnPrivileges()
0192:                // meta.getSuperTables()
0193:                // meta.getSuperTypes()
0194:                // meta.getTypeInfo()
0195:                // meta.getUDTs()
0196:
0197:                conn.close();
0198:                testTempTable();
0199:
0200:            }
0201:
0202:            private void testColumnPrecision() throws Exception {
0203:                Statement stat = conn.createStatement();
0204:                stat.execute("CREATE TABLE ONE(X NUMBER(12,2), Y FLOAT)");
0205:                stat.execute("CREATE TABLE TWO AS SELECT * FROM ONE");
0206:                ResultSet rs;
0207:                ResultSetMetaData meta;
0208:                rs = stat.executeQuery("SELECT * FROM ONE");
0209:                meta = rs.getMetaData();
0210:                check(12, meta.getPrecision(1));
0211:                check(17, meta.getPrecision(2));
0212:                check(Types.DECIMAL, meta.getColumnType(1));
0213:                check(Types.DOUBLE, meta.getColumnType(2));
0214:                rs = stat.executeQuery("SELECT * FROM TWO");
0215:                meta = rs.getMetaData();
0216:                check(12, meta.getPrecision(1));
0217:                check(17, meta.getPrecision(2));
0218:                check(Types.DECIMAL, meta.getColumnType(1));
0219:                check(Types.DOUBLE, meta.getColumnType(2));
0220:                stat.execute("DROP TABLE ONE, TWO");
0221:            }
0222:
0223:            private void testColumnDefault() throws Exception {
0224:                DatabaseMetaData meta = conn.getMetaData();
0225:                ResultSet rs;
0226:                Statement stat = conn.createStatement();
0227:                stat.execute("CREATE TABLE TEST(A INT, B INT DEFAULT NULL)");
0228:                rs = meta.getColumns(null, null, "TEST", null);
0229:                rs.next();
0230:                check("A", rs.getString("COLUMN_NAME"));
0231:                check(null, rs.getString("COLUMN_DEF"));
0232:                rs.next();
0233:                check("B", rs.getString("COLUMN_NAME"));
0234:                check("NULL", rs.getString("COLUMN_DEF"));
0235:                checkFalse(rs.next());
0236:                stat.execute("DROP TABLE TEST");
0237:            }
0238:
0239:            private void testProcedureColumns() throws Exception {
0240:                DatabaseMetaData meta = conn.getMetaData();
0241:                ResultSet rs;
0242:                Statement stat = conn.createStatement();
0243:                stat
0244:                        .execute("CREATE ALIAS PROP FOR \"java.lang.System.getProperty(java.lang.String)\"");
0245:                stat.execute("CREATE ALIAS EXIT FOR \"java.lang.System.exit\"");
0246:                rs = meta.getProcedures(null, null, "EX%");
0247:                testResultSetMeta(rs, 8, new String[] { "PROCEDURE_CAT",
0248:                        "PROCEDURE_SCHEM", "PROCEDURE_NAME",
0249:                        "NUM_INPUT_PARAMS", "NUM_OUTPUT_PARAMS",
0250:                        "NUM_RESULT_SETS", "REMARKS", "PROCEDURE_TYPE" },
0251:                        new int[] { Types.VARCHAR, Types.VARCHAR,
0252:                                Types.VARCHAR, Types.INTEGER, Types.INTEGER,
0253:                                Types.INTEGER, Types.VARCHAR, Types.SMALLINT },
0254:                        null, null);
0255:                testResultSetOrdered(rs, new String[][] { { catalog,
0256:                        Constants.SCHEMA_MAIN, "EXIT", "0", "0", "0", "",
0257:                        "" + DatabaseMetaData.procedureNoResult }, });
0258:                rs = meta.getProcedureColumns(null, null, null, null);
0259:                testResultSetMeta(rs, 13, new String[] { "PROCEDURE_CAT",
0260:                        "PROCEDURE_SCHEM", "PROCEDURE_NAME", "COLUMN_NAME",
0261:                        "COLUMN_TYPE", "DATA_TYPE", "TYPE_NAME", "PRECISION",
0262:                        "LENGTH", "SCALE", "RADIX", "NULLABLE", "REMARKS" },
0263:                        new int[] { Types.VARCHAR, Types.VARCHAR,
0264:                                Types.VARCHAR, Types.VARCHAR, Types.SMALLINT,
0265:                                Types.INTEGER, Types.VARCHAR, Types.INTEGER,
0266:                                Types.INTEGER, Types.SMALLINT, Types.SMALLINT,
0267:                                Types.SMALLINT, Types.VARCHAR }, null, null);
0268:                testResultSetOrdered(rs, new String[][] {
0269:                        { catalog, Constants.SCHEMA_MAIN, "EXIT", "P1",
0270:                                "" + DatabaseMetaData.procedureColumnIn,
0271:                                "" + Types.INTEGER, "INTEGER", "10", "10", "0",
0272:                                "10", "" + DatabaseMetaData.procedureNoNulls },
0273:                        { catalog, Constants.SCHEMA_MAIN, "PROP", "P1",
0274:                                "" + DatabaseMetaData.procedureColumnIn,
0275:                                "" + Types.VARCHAR, "VARCHAR",
0276:                                "" + Integer.MAX_VALUE, "" + Integer.MAX_VALUE,
0277:                                "0", "10",
0278:                                "" + DatabaseMetaData.procedureNullable }, });
0279:                stat.execute("DROP ALIAS EXIT");
0280:                stat.execute("DROP ALIAS PROP");
0281:            }
0282:
0283:            private void testCrossReferences() throws Exception {
0284:                DatabaseMetaData meta = conn.getMetaData();
0285:                ResultSet rs;
0286:                Statement stat = conn.createStatement();
0287:                stat
0288:                        .execute("CREATE TABLE PARENT(A INT, B INT, PRIMARY KEY(A, B))");
0289:                stat
0290:                        .execute("CREATE TABLE CHILD(ID INT PRIMARY KEY, PA INT, PB INT, CONSTRAINT AB FOREIGN KEY(PA, PB) REFERENCES PARENT(A, B))");
0291:                rs = meta.getCrossReference(null, "PUBLIC", "PARENT", null,
0292:                        "PUBLIC", "CHILD");
0293:                checkCrossRef(rs);
0294:                rs = meta.getImportedKeys(null, "PUBLIC", "CHILD");
0295:                checkCrossRef(rs);
0296:                rs = meta.getExportedKeys(null, "PUBLIC", "PARENT");
0297:                checkCrossRef(rs);
0298:                stat.execute("DROP TABLE PARENT");
0299:                stat.execute("DROP TABLE CHILD");
0300:            }
0301:
0302:            private void checkCrossRef(ResultSet rs) throws Exception {
0303:                testResultSetMeta(rs, 14, new String[] { "PKTABLE_CAT",
0304:                        "PKTABLE_SCHEM", "PKTABLE_NAME", "PKCOLUMN_NAME",
0305:                        "FKTABLE_CAT", "FKTABLE_SCHEM", "FKTABLE_NAME",
0306:                        "FKCOLUMN_NAME", "KEY_SEQ", "UPDATE_RULE",
0307:                        "DELETE_RULE", "FK_NAME", "PK_NAME", "DEFERRABILITY" },
0308:                        new int[] { Types.VARCHAR, Types.VARCHAR,
0309:                                Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
0310:                                Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
0311:                                Types.SMALLINT, Types.SMALLINT, Types.SMALLINT,
0312:                                Types.VARCHAR, Types.VARCHAR, Types.SMALLINT },
0313:                        null, null);
0314:                testResultSetOrdered(
0315:                        rs,
0316:                        new String[][] {
0317:                                {
0318:                                        catalog,
0319:                                        Constants.SCHEMA_MAIN,
0320:                                        "PARENT",
0321:                                        "A",
0322:                                        catalog,
0323:                                        Constants.SCHEMA_MAIN,
0324:                                        "CHILD",
0325:                                        "PA",
0326:                                        "1",
0327:                                        ""
0328:                                                + DatabaseMetaData.importedKeyRestrict,
0329:                                        ""
0330:                                                + DatabaseMetaData.importedKeyRestrict,
0331:                                        "AB",
0332:                                        null,
0333:                                        ""
0334:                                                + DatabaseMetaData.importedKeyNotDeferrable },
0335:                                {
0336:                                        catalog,
0337:                                        Constants.SCHEMA_MAIN,
0338:                                        "PARENT",
0339:                                        "B",
0340:                                        catalog,
0341:                                        Constants.SCHEMA_MAIN,
0342:                                        "CHILD",
0343:                                        "PB",
0344:                                        "2",
0345:                                        ""
0346:                                                + DatabaseMetaData.importedKeyRestrict,
0347:                                        ""
0348:                                                + DatabaseMetaData.importedKeyRestrict,
0349:                                        "AB",
0350:                                        null,
0351:                                        ""
0352:                                                + DatabaseMetaData.importedKeyNotDeferrable } });
0353:            }
0354:
0355:            void testTempTable() throws Exception {
0356:                Connection conn = getConnection("metaData");
0357:                Statement stat = conn.createStatement();
0358:                stat.execute("DROP TABLE IF EXISTS TEST_TEMP");
0359:                stat
0360:                        .execute("CREATE TEMP TABLE TEST_TEMP(ID INT PRIMARY KEY, NAME VARCHAR(255))");
0361:                stat.execute("CREATE INDEX IDX_NAME ON TEST_TEMP(NAME)");
0362:                stat
0363:                        .execute("ALTER TABLE TEST_TEMP ADD FOREIGN KEY(ID) REFERENCES(ID)");
0364:                conn.close();
0365:
0366:                conn = getConnection("metaData");
0367:                stat = conn.createStatement();
0368:                stat
0369:                        .execute("CREATE TEMP TABLE TEST_TEMP(ID INT PRIMARY KEY, NAME VARCHAR(255))");
0370:                ResultSet rs = stat
0371:                        .executeQuery("SELECT STORAGE_TYPE FROM "
0372:                                + "INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='TEST_TEMP'");
0373:                rs.next();
0374:                check(rs.getString("STORAGE_TYPE"), "GLOBAL TEMPORARY");
0375:                stat.execute("DROP TABLE IF EXISTS TEST_TEMP");
0376:                conn.close();
0377:            }
0378:
0379:            void testStatic() throws Exception {
0380:                Driver dr = (Driver) Class.forName("org.h2.Driver")
0381:                        .newInstance();
0382:
0383:                check(dr.getMajorVersion(), meta.getDriverMajorVersion());
0384:                check(dr.getMinorVersion(), meta.getDriverMinorVersion());
0385:                check(dr.jdbcCompliant());
0386:
0387:                check(dr.getPropertyInfo(null, null).length, 0);
0388:                check(dr.connect("jdbc:test:false", null) == null);
0389:
0390:                check(meta.getNumericFunctions().length() > 0);
0391:                check(meta.getStringFunctions().length() > 0);
0392:                check(meta.getSystemFunctions().length() > 0);
0393:                check(meta.getTimeDateFunctions().length() > 0);
0394:
0395:                check(meta.allProceduresAreCallable());
0396:                check(meta.allTablesAreSelectable());
0397:                check(meta.dataDefinitionCausesTransactionCommit());
0398:                checkFalse(meta.dataDefinitionIgnoredInTransactions());
0399:                checkFalse(meta.deletesAreDetected(ResultSet.TYPE_FORWARD_ONLY));
0400:                checkFalse(meta
0401:                        .deletesAreDetected(ResultSet.TYPE_SCROLL_INSENSITIVE));
0402:                checkFalse(meta
0403:                        .deletesAreDetected(ResultSet.TYPE_SCROLL_SENSITIVE));
0404:                checkFalse(meta.doesMaxRowSizeIncludeBlobs());
0405:                check(meta.getCatalogSeparator(), ".");
0406:                check(meta.getCatalogTerm(), "catalog");
0407:                check(meta.getConnection() == conn);
0408:                if (config.jdk14) {
0409:                    String versionStart = meta.getDatabaseMajorVersion() + "."
0410:                            + meta.getDatabaseMinorVersion();
0411:                    check(meta.getDatabaseProductVersion().startsWith(
0412:                            versionStart));
0413:                    check(meta.getDriverMajorVersion(), meta
0414:                            .getDatabaseMajorVersion());
0415:                    check(meta.getDriverMinorVersion(), meta
0416:                            .getDatabaseMinorVersion());
0417:                    check(meta.getJDBCMajorVersion(), 3);
0418:                    check(meta.getJDBCMinorVersion(), 0);
0419:                }
0420:                check(meta.getDatabaseProductName(), "H2");
0421:                check(meta.getDefaultTransactionIsolation(),
0422:                        Connection.TRANSACTION_READ_COMMITTED);
0423:                check(meta.getDriverName(), "H2 JDBC Driver");
0424:
0425:                String versionStart = meta.getDriverMajorVersion() + "."
0426:                        + meta.getDriverMinorVersion();
0427:                check(meta.getDriverVersion().startsWith(versionStart));
0428:                check(meta.getExtraNameCharacters(), "");
0429:                check(meta.getIdentifierQuoteString(), "\"");
0430:                check(meta.getMaxBinaryLiteralLength(), 0);
0431:                check(meta.getMaxCatalogNameLength(), 0);
0432:                check(meta.getMaxCharLiteralLength(), 0);
0433:                check(meta.getMaxColumnNameLength(), 0);
0434:                check(meta.getMaxColumnsInGroupBy(), 0);
0435:                check(meta.getMaxColumnsInIndex(), 0);
0436:                check(meta.getMaxColumnsInOrderBy(), 0);
0437:                check(meta.getMaxColumnsInSelect(), 0);
0438:                check(meta.getMaxColumnsInTable(), 0);
0439:                check(meta.getMaxConnections(), 0);
0440:                check(meta.getMaxCursorNameLength(), 0);
0441:                check(meta.getMaxIndexLength(), 0);
0442:                check(meta.getMaxProcedureNameLength(), 0);
0443:                check(meta.getMaxRowSize(), 0);
0444:                check(meta.getMaxSchemaNameLength(), 0);
0445:                check(meta.getMaxStatementLength(), 0);
0446:                check(meta.getMaxStatements(), 0);
0447:                check(meta.getMaxTableNameLength(), 0);
0448:                check(meta.getMaxTablesInSelect(), 0);
0449:                check(meta.getMaxUserNameLength(), 0);
0450:                check(meta.getProcedureTerm(), "procedure");
0451:                if (config.jdk14) {
0452:                    check(meta.getResultSetHoldability(),
0453:                            ResultSet.CLOSE_CURSORS_AT_COMMIT);
0454:                    check(meta.getSQLStateType(),
0455:                            DatabaseMetaData.sqlStateSQL99);
0456:                    checkFalse(meta.locatorsUpdateCopy());
0457:                }
0458:                check(meta.getSchemaTerm(), "schema");
0459:                check(meta.getSearchStringEscape(), "\\");
0460:                check(meta.getSQLKeywords(), "");
0461:
0462:                check(meta.getURL().startsWith("jdbc:h2:"));
0463:                check(meta.getUserName().length() > 1);
0464:                checkFalse(meta.insertsAreDetected(ResultSet.TYPE_FORWARD_ONLY));
0465:                checkFalse(meta
0466:                        .insertsAreDetected(ResultSet.TYPE_SCROLL_INSENSITIVE));
0467:                checkFalse(meta
0468:                        .insertsAreDetected(ResultSet.TYPE_SCROLL_SENSITIVE));
0469:                check(meta.isCatalogAtStart());
0470:                checkFalse(meta.isReadOnly());
0471:                check(meta.nullPlusNonNullIsNull());
0472:                checkFalse(meta.nullsAreSortedAtEnd());
0473:                checkFalse(meta.nullsAreSortedAtStart());
0474:                checkFalse(meta.nullsAreSortedHigh());
0475:                check(meta.nullsAreSortedLow());
0476:                checkFalse(meta
0477:                        .othersDeletesAreVisible(ResultSet.TYPE_FORWARD_ONLY));
0478:                checkFalse(meta
0479:                        .othersDeletesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE));
0480:                checkFalse(meta
0481:                        .othersDeletesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE));
0482:                checkFalse(meta
0483:                        .othersInsertsAreVisible(ResultSet.TYPE_FORWARD_ONLY));
0484:                checkFalse(meta
0485:                        .othersInsertsAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE));
0486:                checkFalse(meta
0487:                        .othersInsertsAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE));
0488:                checkFalse(meta
0489:                        .othersUpdatesAreVisible(ResultSet.TYPE_FORWARD_ONLY));
0490:                checkFalse(meta
0491:                        .othersUpdatesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE));
0492:                checkFalse(meta
0493:                        .othersUpdatesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE));
0494:                checkFalse(meta
0495:                        .ownDeletesAreVisible(ResultSet.TYPE_FORWARD_ONLY));
0496:                checkFalse(meta
0497:                        .ownDeletesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE));
0498:                checkFalse(meta
0499:                        .ownDeletesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE));
0500:                checkFalse(meta
0501:                        .ownInsertsAreVisible(ResultSet.TYPE_FORWARD_ONLY));
0502:                checkFalse(meta
0503:                        .ownInsertsAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE));
0504:                checkFalse(meta
0505:                        .ownInsertsAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE));
0506:                checkFalse(meta
0507:                        .ownUpdatesAreVisible(ResultSet.TYPE_FORWARD_ONLY));
0508:                checkFalse(meta
0509:                        .ownUpdatesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE));
0510:                checkFalse(meta
0511:                        .ownUpdatesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE));
0512:                checkFalse(meta.storesLowerCaseIdentifiers());
0513:                checkFalse(meta.storesLowerCaseQuotedIdentifiers());
0514:                checkFalse(meta.storesMixedCaseIdentifiers());
0515:                check(meta.storesMixedCaseQuotedIdentifiers());
0516:                check(meta.storesUpperCaseIdentifiers());
0517:                checkFalse(meta.storesUpperCaseQuotedIdentifiers());
0518:                check(meta.supportsAlterTableWithAddColumn());
0519:                check(meta.supportsAlterTableWithDropColumn());
0520:                check(meta.supportsANSI92EntryLevelSQL());
0521:                checkFalse(meta.supportsANSI92IntermediateSQL());
0522:                checkFalse(meta.supportsANSI92FullSQL());
0523:                check(meta.supportsBatchUpdates());
0524:                check(meta.supportsCatalogsInDataManipulation());
0525:                check(meta.supportsCatalogsInIndexDefinitions());
0526:                check(meta.supportsCatalogsInPrivilegeDefinitions());
0527:                checkFalse(meta.supportsCatalogsInProcedureCalls());
0528:                check(meta.supportsCatalogsInTableDefinitions());
0529:                check(meta.supportsColumnAliasing());
0530:                check(meta.supportsConvert());
0531:                check(meta.supportsConvert(Types.INTEGER, Types.VARCHAR));
0532:                check(meta.supportsCoreSQLGrammar());
0533:                check(meta.supportsCorrelatedSubqueries());
0534:                checkFalse(meta
0535:                        .supportsDataDefinitionAndDataManipulationTransactions());
0536:                check(meta.supportsDataManipulationTransactionsOnly());
0537:                checkFalse(meta.supportsDifferentTableCorrelationNames());
0538:                check(meta.supportsExpressionsInOrderBy());
0539:                checkFalse(meta.supportsExtendedSQLGrammar());
0540:                checkFalse(meta.supportsFullOuterJoins());
0541:                if (config.jdk14) {
0542:                    check(meta.supportsGetGeneratedKeys());
0543:                    check(meta.supportsMultipleOpenResults());
0544:                    checkFalse(meta.supportsNamedParameters());
0545:                }
0546:                check(meta.supportsGroupBy());
0547:                check(meta.supportsGroupByBeyondSelect());
0548:                check(meta.supportsGroupByUnrelated());
0549:                check(meta.supportsIntegrityEnhancementFacility());
0550:                check(meta.supportsLikeEscapeClause());
0551:                check(meta.supportsLimitedOuterJoins());
0552:                check(meta.supportsMinimumSQLGrammar());
0553:                checkFalse(meta.supportsMixedCaseIdentifiers());
0554:                check(meta.supportsMixedCaseQuotedIdentifiers());
0555:                checkFalse(meta.supportsMultipleResultSets());
0556:                check(meta.supportsMultipleTransactions());
0557:                check(meta.supportsNonNullableColumns());
0558:                checkFalse(meta.supportsOpenCursorsAcrossCommit());
0559:                checkFalse(meta.supportsOpenCursorsAcrossRollback());
0560:                check(meta.supportsOpenStatementsAcrossCommit());
0561:                check(meta.supportsOpenStatementsAcrossRollback());
0562:                check(meta.supportsOrderByUnrelated());
0563:                check(meta.supportsOuterJoins());
0564:                check(meta.supportsPositionedDelete());
0565:                check(meta.supportsPositionedUpdate());
0566:                check(meta
0567:                        .supportsResultSetConcurrency(
0568:                                ResultSet.TYPE_FORWARD_ONLY,
0569:                                ResultSet.CONCUR_READ_ONLY));
0570:                check(meta
0571:                        .supportsResultSetConcurrency(
0572:                                ResultSet.TYPE_FORWARD_ONLY,
0573:                                ResultSet.CONCUR_UPDATABLE));
0574:                check(meta.supportsResultSetConcurrency(
0575:                        ResultSet.TYPE_SCROLL_INSENSITIVE,
0576:                        ResultSet.CONCUR_READ_ONLY));
0577:                check(meta.supportsResultSetConcurrency(
0578:                        ResultSet.TYPE_SCROLL_INSENSITIVE,
0579:                        ResultSet.CONCUR_UPDATABLE));
0580:                checkFalse(meta.supportsResultSetConcurrency(
0581:                        ResultSet.TYPE_SCROLL_SENSITIVE,
0582:                        ResultSet.CONCUR_READ_ONLY));
0583:                checkFalse(meta.supportsResultSetConcurrency(
0584:                        ResultSet.TYPE_SCROLL_SENSITIVE,
0585:                        ResultSet.CONCUR_UPDATABLE));
0586:                if (config.jdk14) {
0587:                    checkFalse(meta
0588:                            .supportsResultSetHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT));
0589:                    check(meta
0590:                            .supportsResultSetHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT));
0591:                    check(meta.supportsSavepoints());
0592:                    checkFalse(meta.supportsStatementPooling());
0593:                }
0594:                check(meta.supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY));
0595:                check(meta
0596:                        .supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE));
0597:                checkFalse(meta
0598:                        .supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE));
0599:                check(meta.supportsSchemasInDataManipulation());
0600:                check(meta.supportsSchemasInIndexDefinitions());
0601:                check(meta.supportsSchemasInPrivilegeDefinitions());
0602:                check(meta.supportsSchemasInProcedureCalls());
0603:                check(meta.supportsSchemasInTableDefinitions());
0604:                check(meta.supportsSelectForUpdate());
0605:                checkFalse(meta.supportsStoredProcedures());
0606:                check(meta.supportsSubqueriesInComparisons());
0607:                check(meta.supportsSubqueriesInExists());
0608:                check(meta.supportsSubqueriesInIns());
0609:                check(meta.supportsSubqueriesInQuantifieds());
0610:                check(meta.supportsTableCorrelationNames());
0611:                check(meta.supportsTransactions());
0612:                check(meta
0613:                        .supportsTransactionIsolationLevel(Connection.TRANSACTION_NONE));
0614:                check(meta
0615:                        .supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_COMMITTED));
0616:                check(meta
0617:                        .supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_UNCOMMITTED));
0618:                check(meta
0619:                        .supportsTransactionIsolationLevel(Connection.TRANSACTION_REPEATABLE_READ));
0620:                check(meta
0621:                        .supportsTransactionIsolationLevel(Connection.TRANSACTION_SERIALIZABLE));
0622:                check(meta.supportsUnion());
0623:                check(meta.supportsUnionAll());
0624:                checkFalse(meta.updatesAreDetected(ResultSet.TYPE_FORWARD_ONLY));
0625:                checkFalse(meta
0626:                        .updatesAreDetected(ResultSet.TYPE_SCROLL_INSENSITIVE));
0627:                checkFalse(meta
0628:                        .updatesAreDetected(ResultSet.TYPE_SCROLL_SENSITIVE));
0629:                checkFalse(meta.usesLocalFilePerTable());
0630:                check(meta.usesLocalFiles());
0631:            }
0632:
0633:            void test(Connection conn) throws Exception {
0634:                DatabaseMetaData meta = conn.getMetaData();
0635:                Statement stat = conn.createStatement();
0636:                ResultSet rs;
0637:
0638:                conn.setReadOnly(true);
0639:                conn.setReadOnly(false);
0640:                checkFalse(conn.isReadOnly());
0641:                check(conn.isReadOnly() == meta.isReadOnly());
0642:
0643:                check(conn == meta.getConnection());
0644:
0645:                // currently, setCatalog is ignored
0646:                conn.setCatalog("XYZ");
0647:                trace(conn.getCatalog());
0648:
0649:                String product = meta.getDatabaseProductName();
0650:                trace("meta.getDatabaseProductName:" + product);
0651:
0652:                String version = meta.getDatabaseProductVersion();
0653:                trace("meta.getDatabaseProductVersion:" + version);
0654:
0655:                int major = meta.getDriverMajorVersion();
0656:                trace("meta.getDriverMajorVersion:" + major);
0657:
0658:                int minor = meta.getDriverMinorVersion();
0659:                trace("meta.getDriverMinorVersion:" + minor);
0660:
0661:                String driverName = meta.getDriverName();
0662:                trace("meta.getDriverName:" + driverName);
0663:
0664:                String driverVersion = meta.getDriverVersion();
0665:                trace("meta.getDriverVersion:" + driverVersion);
0666:
0667:                meta.getSearchStringEscape();
0668:
0669:                String url = meta.getURL();
0670:                trace("meta.getURL:" + url);
0671:
0672:                String user = meta.getUserName();
0673:                trace("meta.getUserName:" + user);
0674:
0675:                trace("meta.nullsAreSortedHigh:" + meta.nullsAreSortedHigh());
0676:                trace("meta.nullsAreSortedLow:" + meta.nullsAreSortedLow());
0677:                trace("meta.nullsAreSortedAtStart:"
0678:                        + meta.nullsAreSortedAtStart());
0679:                trace("meta.nullsAreSortedAtEnd:" + meta.nullsAreSortedAtEnd());
0680:                int count = (meta.nullsAreSortedHigh() ? 1 : 0)
0681:                        + (meta.nullsAreSortedLow() ? 1 : 0)
0682:                        + (meta.nullsAreSortedAtStart() ? 1 : 0)
0683:                        + (meta.nullsAreSortedAtEnd() ? 1 : 0);
0684:                check(count == 1);
0685:
0686:                trace("meta.allProceduresAreCallable:"
0687:                        + meta.allProceduresAreCallable());
0688:                check(meta.allProceduresAreCallable());
0689:
0690:                trace("meta.allTablesAreSelectable:"
0691:                        + meta.allTablesAreSelectable());
0692:                check(meta.allTablesAreSelectable());
0693:
0694:                trace("getTables");
0695:                rs = meta.getTables(null, Constants.SCHEMA_MAIN, null,
0696:                        new String[] { "TABLE" });
0697:                testResultSetMeta(rs, 6, new String[] { "TABLE_CAT",
0698:                        "TABLE_SCHEM", "TABLE_NAME", "TABLE_TYPE", "REMARKS",
0699:                        "SQL" }, new int[] { Types.VARCHAR, Types.VARCHAR,
0700:                        Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
0701:                        Types.VARCHAR }, null, null);
0702:                if (rs.next()) {
0703:                    error("Database is not empty after dropping all tables");
0704:                }
0705:                stat.executeUpdate("CREATE TABLE TEST(" + "ID INT PRIMARY KEY,"
0706:                        + "TEXT_V VARCHAR(120)," + "DEC_V DECIMAL(12,3),"
0707:                        + "DATE_V DATETIME," + "BLOB_V BLOB," + "CLOB_V CLOB"
0708:                        + ")");
0709:                rs = meta.getTables(null, Constants.SCHEMA_MAIN, null,
0710:                        new String[] { "TABLE" });
0711:                testResultSetOrdered(rs, new String[][] { { catalog,
0712:                        Constants.SCHEMA_MAIN, "TEST", "TABLE", "" } });
0713:                trace("getColumns");
0714:                rs = meta.getColumns(null, null, "TEST", null);
0715:                testResultSetMeta(rs, 18, new String[] { "TABLE_CAT",
0716:                        "TABLE_SCHEM", "TABLE_NAME", "COLUMN_NAME",
0717:                        "DATA_TYPE", "TYPE_NAME", "COLUMN_SIZE",
0718:                        "BUFFER_LENGTH", "DECIMAL_DIGITS", "NUM_PREC_RADIX",
0719:                        "NULLABLE", "REMARKS", "COLUMN_DEF", "SQL_DATA_TYPE",
0720:                        "SQL_DATETIME_SUB", "CHAR_OCTET_LENGTH",
0721:                        "ORDINAL_POSITION", "IS_NULLABLE" }, new int[] {
0722:                        Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
0723:                        Types.VARCHAR, Types.SMALLINT, Types.VARCHAR,
0724:                        Types.INTEGER, Types.INTEGER, Types.INTEGER,
0725:                        Types.INTEGER, Types.SMALLINT, Types.VARCHAR,
0726:                        Types.VARCHAR, Types.SMALLINT, Types.INTEGER,
0727:                        Types.INTEGER, Types.INTEGER, Types.VARCHAR }, null,
0728:                        null);
0729:                testResultSetOrdered(rs,
0730:                        new String[][] {
0731:                                { catalog, Constants.SCHEMA_MAIN, "TEST", "ID",
0732:                                        "" + Types.INTEGER, "INTEGER", "10",
0733:                                        "10", "0", "10",
0734:                                        "" + DatabaseMetaData.columnNoNulls,
0735:                                        "", null, "" + Types.INTEGER, "0",
0736:                                        "10", "1", "NO" },
0737:                                { catalog, Constants.SCHEMA_MAIN, "TEST",
0738:                                        "TEXT_V", "" + Types.VARCHAR,
0739:                                        "VARCHAR", "120", "120", "0", "10",
0740:                                        "" + DatabaseMetaData.columnNullable,
0741:                                        "", null, "" + Types.VARCHAR, "0",
0742:                                        "120", "2", "YES" },
0743:                                { catalog, Constants.SCHEMA_MAIN, "TEST",
0744:                                        "DEC_V", "" + Types.DECIMAL, "DECIMAL",
0745:                                        "12", "12", "3", "10",
0746:                                        "" + DatabaseMetaData.columnNullable,
0747:                                        "", null, "" + Types.DECIMAL, "0",
0748:                                        "12", "3", "YES" },
0749:                                { catalog, Constants.SCHEMA_MAIN, "TEST",
0750:                                        "DATE_V", "" + Types.TIMESTAMP,
0751:                                        "TIMESTAMP", "23", "23", "10", "10",
0752:                                        "" + DatabaseMetaData.columnNullable,
0753:                                        "", null, "" + Types.TIMESTAMP, "0",
0754:                                        "23", "4", "YES" },
0755:                                { catalog, Constants.SCHEMA_MAIN, "TEST",
0756:                                        "BLOB_V", "" + Types.BLOB, "BLOB",
0757:                                        "" + Integer.MAX_VALUE,
0758:                                        "" + Integer.MAX_VALUE, "0", "10",
0759:                                        "" + DatabaseMetaData.columnNullable,
0760:                                        "", null, "" + Types.BLOB, "0",
0761:                                        "" + Integer.MAX_VALUE, "5", "YES" },
0762:                                { catalog, Constants.SCHEMA_MAIN, "TEST",
0763:                                        "CLOB_V", "" + Types.CLOB, "CLOB",
0764:                                        "" + Integer.MAX_VALUE,
0765:                                        "" + Integer.MAX_VALUE, "0", "10",
0766:                                        "" + DatabaseMetaData.columnNullable,
0767:                                        "", null, "" + Types.CLOB, "0",
0768:                                        "" + Integer.MAX_VALUE, "6", "YES" } });
0769:                /*
0770:                 * rs=meta.getColumns(null,null,"TEST",null); while(rs.next()) { int
0771:                 * datatype=rs.getInt(5); }
0772:                 */
0773:                trace("getIndexInfo");
0774:                stat
0775:                        .executeUpdate("CREATE INDEX IDX_TEXT_DEC ON TEST(TEXT_V,DEC_V)");
0776:                stat
0777:                        .executeUpdate("CREATE UNIQUE INDEX IDX_DATE ON TEST(DATE_V)");
0778:                rs = meta.getIndexInfo(null, null, "TEST", false, false);
0779:                testResultSetMeta(rs, 14,
0780:                        new String[] { "TABLE_CAT", "TABLE_SCHEM",
0781:                                "TABLE_NAME", "NON_UNIQUE", "INDEX_QUALIFIER",
0782:                                "INDEX_NAME", "TYPE", "ORDINAL_POSITION",
0783:                                "COLUMN_NAME", "ASC_OR_DESC", "CARDINALITY",
0784:                                "PAGES", "FILTER_CONDITION", "SORT_TYPE" },
0785:                        new int[] { Types.VARCHAR, Types.VARCHAR,
0786:                                Types.VARCHAR, DataType.TYPE_BOOLEAN,
0787:                                Types.VARCHAR, Types.VARCHAR, Types.SMALLINT,
0788:                                Types.SMALLINT, Types.VARCHAR, Types.VARCHAR,
0789:                                Types.INTEGER, Types.INTEGER, Types.VARCHAR,
0790:                                Types.INTEGER }, null, null);
0791:                testResultSetOrdered(rs, new String[][] {
0792:                        { catalog, Constants.SCHEMA_MAIN, "TEST", "FALSE",
0793:                                catalog, "IDX_DATE",
0794:                                "" + DatabaseMetaData.tableIndexOther, "1",
0795:                                "DATE_V", "A", "0", "0", "" },
0796:                        { catalog, Constants.SCHEMA_MAIN, "TEST", "FALSE",
0797:                                catalog, "PRIMARY_KEY_2",
0798:                                "" + DatabaseMetaData.tableIndexOther, "1",
0799:                                "ID", "A", "0", "0", "" },
0800:                        { catalog, Constants.SCHEMA_MAIN, "TEST", "TRUE",
0801:                                catalog, "IDX_TEXT_DEC",
0802:                                "" + DatabaseMetaData.tableIndexOther, "1",
0803:                                "TEXT_V", "A", "0", "0", "" },
0804:                        { catalog, Constants.SCHEMA_MAIN, "TEST", "TRUE",
0805:                                catalog, "IDX_TEXT_DEC",
0806:                                "" + DatabaseMetaData.tableIndexOther, "2",
0807:                                "DEC_V", "A", "0", "0", "" }, });
0808:                stat.executeUpdate("DROP INDEX IDX_TEXT_DEC");
0809:                stat.executeUpdate("DROP INDEX IDX_DATE");
0810:                rs = meta.getIndexInfo(null, null, "TEST", false, false);
0811:                testResultSetMeta(rs, 14,
0812:                        new String[] { "TABLE_CAT", "TABLE_SCHEM",
0813:                                "TABLE_NAME", "NON_UNIQUE", "INDEX_QUALIFIER",
0814:                                "INDEX_NAME", "TYPE", "ORDINAL_POSITION",
0815:                                "COLUMN_NAME", "ASC_OR_DESC", "CARDINALITY",
0816:                                "PAGES", "FILTER_CONDITION", "SORT_TYPE" },
0817:                        new int[] { Types.VARCHAR, Types.VARCHAR,
0818:                                Types.VARCHAR, DataType.TYPE_BOOLEAN,
0819:                                Types.VARCHAR, Types.VARCHAR, Types.SMALLINT,
0820:                                Types.SMALLINT, Types.VARCHAR, Types.VARCHAR,
0821:                                Types.INTEGER, Types.INTEGER, Types.VARCHAR,
0822:                                Types.INTEGER }, null, null);
0823:                testResultSetOrdered(rs, new String[][] { { catalog,
0824:                        Constants.SCHEMA_MAIN, "TEST", "FALSE", catalog,
0825:                        "PRIMARY_KEY_2", "" + DatabaseMetaData.tableIndexOther,
0826:                        "1", "ID", "A", "0", "0", "" } });
0827:                trace("getPrimaryKeys");
0828:                rs = meta.getPrimaryKeys(null, null, "TEST");
0829:                testResultSetMeta(rs, 6, new String[] { "TABLE_CAT",
0830:                        "TABLE_SCHEM", "TABLE_NAME", "COLUMN_NAME", "KEY_SEQ",
0831:                        "PK_NAME" }, new int[] { Types.VARCHAR, Types.VARCHAR,
0832:                        Types.VARCHAR, Types.VARCHAR, Types.SMALLINT,
0833:                        Types.VARCHAR }, null, null);
0834:                testResultSetOrdered(rs, new String[][] { { catalog,
0835:                        Constants.SCHEMA_MAIN, "TEST", "ID", "1",
0836:                        "PRIMARY_KEY_2" }, });
0837:                trace("getTables - using a wildcard");
0838:                stat
0839:                        .executeUpdate("CREATE TABLE T_2(B INT,A VARCHAR(6),C INT,PRIMARY KEY(C,A,B))");
0840:                stat
0841:                        .executeUpdate("CREATE TABLE TX2(B INT,A VARCHAR(6),C INT,PRIMARY KEY(C,A,B))");
0842:                rs = meta.getTables(null, null, "T_2", null);
0843:                testResultSetOrdered(rs,
0844:                        new String[][] {
0845:                                { catalog, Constants.SCHEMA_MAIN, "TX2",
0846:                                        "TABLE", "" },
0847:                                { catalog, Constants.SCHEMA_MAIN, "T_2",
0848:                                        "TABLE", "" } });
0849:                trace("getTables - using a quoted _ character");
0850:                rs = meta.getTables(null, null, "T\\_2", null);
0851:                testResultSetOrdered(rs, new String[][] { { catalog,
0852:                        Constants.SCHEMA_MAIN, "T_2", "TABLE", "" } });
0853:                trace("getTables - using the % wildcard");
0854:                rs = meta.getTables(null, Constants.SCHEMA_MAIN, "%",
0855:                        new String[] { "TABLE" });
0856:                testResultSetOrdered(rs,
0857:                        new String[][] {
0858:                                { catalog, Constants.SCHEMA_MAIN, "TEST",
0859:                                        "TABLE", "" },
0860:                                { catalog, Constants.SCHEMA_MAIN, "TX2",
0861:                                        "TABLE", "" },
0862:                                { catalog, Constants.SCHEMA_MAIN, "T_2",
0863:                                        "TABLE", "" } });
0864:                stat.execute("DROP TABLE TEST");
0865:
0866:                trace("getColumns - using wildcards");
0867:                rs = meta.getColumns(null, null, "___", "B%");
0868:                testResultSetOrdered(rs, new String[][] {
0869:                        { catalog, Constants.SCHEMA_MAIN, "TX2", "B",
0870:                                "" + Types.INTEGER, "INTEGER", "10" /*
0871:                                 * ,
0872:                                 * null,
0873:                                 * "0",
0874:                                 * "10", "" +
0875:                                 * DatabaseMetaData.columnNoNulls,
0876:                                 * null,
0877:                                 * null,
0878:                                 * null,
0879:                                 * null,
0880:                                 * null,
0881:                                 * "1",
0882:                                 * "NO"
0883:                                 */},
0884:                        { catalog, Constants.SCHEMA_MAIN, "T_2", "B",
0885:                                "" + Types.INTEGER, "INTEGER", "10" /*
0886:                                 * ,
0887:                                 * null,
0888:                                 * "0",
0889:                                 * "10", "" +
0890:                                 * DatabaseMetaData.columnNoNulls,
0891:                                 * null,
0892:                                 * null,
0893:                                 * null,
0894:                                 * null,
0895:                                 * null,
0896:                                 * "1",
0897:                                 * "NO"
0898:                                 */}, });
0899:                trace("getColumns - using wildcards");
0900:                rs = meta.getColumns(null, null, "_\\__", "%");
0901:                testResultSetOrdered(rs, new String[][] {
0902:                        { catalog, Constants.SCHEMA_MAIN, "T_2", "B",
0903:                                "" + Types.INTEGER, "INTEGER", "10" /*
0904:                                 * ,
0905:                                 * null,
0906:                                 * "0",
0907:                                 * "10", "" +
0908:                                 * DatabaseMetaData.columnNoNulls,
0909:                                 * null,
0910:                                 * null,
0911:                                 * null,
0912:                                 * null,
0913:                                 * null,
0914:                                 * "1",
0915:                                 * "NO"
0916:                                 */},
0917:                        { catalog, Constants.SCHEMA_MAIN, "T_2", "A",
0918:                                "" + Types.VARCHAR, "VARCHAR", "6" /*
0919:                                 * ,
0920:                                 * null,
0921:                                 * "0",
0922:                                 * "10", "" +
0923:                                 * DatabaseMetaData.columnNoNulls,
0924:                                 * null,
0925:                                 * null,
0926:                                 * null,
0927:                                 * null,
0928:                                 * null,
0929:                                 * "2",
0930:                                 * "NO"
0931:                                 */},
0932:                        { catalog, Constants.SCHEMA_MAIN, "T_2", "C",
0933:                                "" + Types.INTEGER, "INTEGER", "10" /*
0934:                                 * ,
0935:                                 * null,
0936:                                 * "0",
0937:                                 * "10", "" +
0938:                                 * DatabaseMetaData.columnNoNulls,
0939:                                 * null,
0940:                                 * null,
0941:                                 * null,
0942:                                 * null,
0943:                                 * null,
0944:                                 * "3",
0945:                                 * "NO"
0946:                                 */}, });
0947:                trace("getIndexInfo");
0948:                stat.executeUpdate("CREATE UNIQUE INDEX A_INDEX ON TX2(B,C,A)");
0949:                stat.executeUpdate("CREATE INDEX B_INDEX ON TX2(A,B,C)");
0950:                rs = meta.getIndexInfo(null, null, "TX2", false, false);
0951:                testResultSetOrdered(rs, new String[][] {
0952:                        { catalog, Constants.SCHEMA_MAIN, "TX2", "FALSE",
0953:                                catalog, "A_INDEX",
0954:                                "" + DatabaseMetaData.tableIndexOther, "1",
0955:                                "B", "A" /*
0956:                                 * ,
0957:                                 * null,
0958:                                 * null,
0959:                                 * null
0960:                                 */},
0961:                        { catalog, Constants.SCHEMA_MAIN, "TX2", "FALSE",
0962:                                catalog, "A_INDEX",
0963:                                "" + DatabaseMetaData.tableIndexOther, "2",
0964:                                "C", "A" /*
0965:                                 * ,
0966:                                 * null,
0967:                                 * null,
0968:                                 * null
0969:                                 */},
0970:                        { catalog, Constants.SCHEMA_MAIN, "TX2", "FALSE",
0971:                                catalog, "A_INDEX",
0972:                                "" + DatabaseMetaData.tableIndexOther, "3",
0973:                                "A", "A" /*
0974:                                 * ,
0975:                                 * null,
0976:                                 * null,
0977:                                 * null
0978:                                 */},
0979:                        { catalog, Constants.SCHEMA_MAIN, "TX2", "FALSE",
0980:                                catalog, "PRIMARY_KEY_14",
0981:                                "" + DatabaseMetaData.tableIndexOther, "1",
0982:                                "C", "A" /*
0983:                                 * ,
0984:                                 * null,
0985:                                 * null,
0986:                                 * null
0987:                                 */},
0988:                        { catalog, Constants.SCHEMA_MAIN, "TX2", "FALSE",
0989:                                catalog, "PRIMARY_KEY_14",
0990:                                "" + DatabaseMetaData.tableIndexOther, "2",
0991:                                "A", "A" /*
0992:                                 * ,
0993:                                 * null,
0994:                                 * null,
0995:                                 * null
0996:                                 */},
0997:                        { catalog, Constants.SCHEMA_MAIN, "TX2", "FALSE",
0998:                                catalog, "PRIMARY_KEY_14",
0999:                                "" + DatabaseMetaData.tableIndexOther, "3",
1000:                                "B", "A"/*
1001:                                 * ,
1002:                                 * null,
1003:                                 * null,
1004:                                 * null
1005:                                 */},
1006:                        { catalog, Constants.SCHEMA_MAIN, "TX2", "TRUE",
1007:                                catalog, "B_INDEX",
1008:                                "" + DatabaseMetaData.tableIndexOther, "1",
1009:                                "A", "A" /*
1010:                                 * ,
1011:                                 * null,
1012:                                 * null,
1013:                                 * null
1014:                                 */},
1015:                        { catalog, Constants.SCHEMA_MAIN, "TX2", "TRUE",
1016:                                catalog, "B_INDEX",
1017:                                "" + DatabaseMetaData.tableIndexOther, "2",
1018:                                "B", "A" /*
1019:                                 * ,
1020:                                 * null,
1021:                                 * null,
1022:                                 * null
1023:                                 */},
1024:                        { catalog, Constants.SCHEMA_MAIN, "TX2", "TRUE",
1025:                                catalog, "B_INDEX",
1026:                                "" + DatabaseMetaData.tableIndexOther, "3",
1027:                                "C", "A" /*
1028:                                 * ,
1029:                                 * null,
1030:                                 * null,
1031:                                 * null
1032:                                 */}, });
1033:                trace("getPrimaryKeys");
1034:                rs = meta.getPrimaryKeys(null, null, "T_2");
1035:                testResultSetOrdered(rs, new String[][] {
1036:                        { catalog, Constants.SCHEMA_MAIN, "T_2", "A", "2",
1037:                                "PRIMARY_KEY_1" },
1038:                        { catalog, Constants.SCHEMA_MAIN, "T_2", "B", "3",
1039:                                "PRIMARY_KEY_1" },
1040:                        { catalog, Constants.SCHEMA_MAIN, "T_2", "C", "1",
1041:                                "PRIMARY_KEY_1" }, });
1042:                stat.executeUpdate("DROP TABLE TX2");
1043:                stat.executeUpdate("DROP TABLE T_2");
1044:                stat.executeUpdate("CREATE TABLE PARENT(ID INT PRIMARY KEY)");
1045:                stat
1046:                        .executeUpdate("CREATE TABLE CHILD(P_ID INT,ID INT,PRIMARY KEY(P_ID,ID),FOREIGN KEY(P_ID) REFERENCES PARENT(ID))");
1047:
1048:                trace("getImportedKeys");
1049:                rs = meta.getImportedKeys(null, null, "CHILD");
1050:                testResultSetMeta(rs, 14, new String[] { "PKTABLE_CAT",
1051:                        "PKTABLE_SCHEM", "PKTABLE_NAME", "PKCOLUMN_NAME",
1052:                        "FKTABLE_CAT", "FKTABLE_SCHEM", "FKTABLE_NAME",
1053:                        "FKCOLUMN_NAME", "KEY_SEQ", "UPDATE_RULE",
1054:                        "DELETE_RULE", "FK_NAME", "PK_NAME", "DEFERRABILITY" },
1055:                        new int[] { Types.VARCHAR, Types.VARCHAR,
1056:                                Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
1057:                                Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
1058:                                Types.SMALLINT, Types.SMALLINT, Types.SMALLINT,
1059:                                Types.VARCHAR, Types.VARCHAR, Types.SMALLINT },
1060:                        null, null);
1061:                // TODO test
1062:                // testResultSetOrdered(rs, new String[][] { { null, null, "PARENT",
1063:                // "ID",
1064:                // null, null, "CHILD", "P_ID", "1",
1065:                // "" + DatabaseMetaData.importedKeyNoAction,
1066:                // "" + DatabaseMetaData.importedKeyNoAction, "FK_1", null,
1067:                // "" + DatabaseMetaData.importedKeyNotDeferrable}});
1068:
1069:                trace("getExportedKeys");
1070:                rs = meta.getExportedKeys(null, null, "PARENT");
1071:                testResultSetMeta(rs, 14, new String[] { "PKTABLE_CAT",
1072:                        "PKTABLE_SCHEM", "PKTABLE_NAME", "PKCOLUMN_NAME",
1073:                        "FKTABLE_CAT", "FKTABLE_SCHEM", "FKTABLE_NAME",
1074:                        "FKCOLUMN_NAME", "KEY_SEQ", "UPDATE_RULE",
1075:                        "DELETE_RULE", "FK_NAME", "PK_NAME", "DEFERRABILITY" },
1076:                        new int[] { Types.VARCHAR, Types.VARCHAR,
1077:                                Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
1078:                                Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
1079:                                Types.SMALLINT, Types.SMALLINT, Types.SMALLINT,
1080:                                Types.VARCHAR, Types.VARCHAR, Types.SMALLINT },
1081:                        null, null);
1082:                // TODO test
1083:                /*
1084:                 * testResultSetOrdered(rs, new String[][]{ { null,null,"PARENT","ID",
1085:                 * null,null,"CHILD","P_ID",
1086:                 * "1",""+DatabaseMetaData.importedKeyNoAction,
1087:                 * ""+DatabaseMetaData.importedKeyNoAction,
1088:                 * null,null,""+DatabaseMetaData.importedKeyNotDeferrable } } );
1089:                 */
1090:                trace("getCrossReference");
1091:                rs = meta.getCrossReference(null, null, "PARENT", null, null,
1092:                        "CHILD");
1093:                testResultSetMeta(rs, 14, new String[] { "PKTABLE_CAT",
1094:                        "PKTABLE_SCHEM", "PKTABLE_NAME", "PKCOLUMN_NAME",
1095:                        "FKTABLE_CAT", "FKTABLE_SCHEM", "FKTABLE_NAME",
1096:                        "FKCOLUMN_NAME", "KEY_SEQ", "UPDATE_RULE",
1097:                        "DELETE_RULE", "FK_NAME", "PK_NAME", "DEFERRABILITY" },
1098:                        new int[] { Types.VARCHAR, Types.VARCHAR,
1099:                                Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
1100:                                Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
1101:                                Types.SMALLINT, Types.SMALLINT, Types.SMALLINT,
1102:                                Types.VARCHAR, Types.VARCHAR, Types.SMALLINT },
1103:                        null, null);
1104:                // TODO test
1105:                /*
1106:                 * testResultSetOrdered(rs, new String[][]{ { null,null,"PARENT","ID",
1107:                 * null,null,"CHILD","P_ID",
1108:                 * "1",""+DatabaseMetaData.importedKeyNoAction,
1109:                 * ""+DatabaseMetaData.importedKeyNoAction,
1110:                 * null,null,""+DatabaseMetaData.importedKeyNotDeferrable } } );
1111:                 */
1112:
1113:                rs = meta.getSchemas();
1114:                testResultSetMeta(rs, 3, new String[] { "TABLE_SCHEM",
1115:                        "TABLE_CATALOG", "IS_DEFAULT" }, new int[] {
1116:                        Types.VARCHAR, Types.VARCHAR, DataType.TYPE_BOOLEAN },
1117:                        null, null);
1118:                check(rs.next());
1119:                check(rs.getString(1), "INFORMATION_SCHEMA");
1120:                check(rs.next());
1121:                check(rs.getString(1), "PUBLIC");
1122:                checkFalse(rs.next());
1123:
1124:                rs = meta.getCatalogs();
1125:                testResultSetMeta(rs, 1, new String[] { "TABLE_CAT" },
1126:                        new int[] { Types.VARCHAR }, null, null);
1127:                testResultSetOrdered(rs, new String[][] { { catalog } });
1128:
1129:                rs = meta.getTableTypes();
1130:                testResultSetMeta(rs, 1, new String[] { "TABLE_TYPE" },
1131:                        new int[] { Types.VARCHAR }, null, null);
1132:                testResultSetOrdered(rs, new String[][] { { "SYSTEM TABLE" },
1133:                        { "TABLE" }, { "TABLE LINK" }, { "VIEW" } });
1134:
1135:                rs = meta.getTypeInfo();
1136:                testResultSetMeta(rs, 18,
1137:                        new String[] { "TYPE_NAME", "DATA_TYPE", "PRECISION",
1138:                                "LITERAL_PREFIX", "LITERAL_SUFFIX",
1139:                                "CREATE_PARAMS", "NULLABLE", "CASE_SENSITIVE",
1140:                                "SEARCHABLE", "UNSIGNED_ATTRIBUTE",
1141:                                "FIXED_PREC_SCALE", "AUTO_INCREMENT",
1142:                                "LOCAL_TYPE_NAME", "MINIMUM_SCALE",
1143:                                "MAXIMUM_SCALE", "SQL_DATA_TYPE",
1144:                                "SQL_DATETIME_SUB", "NUM_PREC_RADIX" },
1145:                        new int[] { Types.VARCHAR, Types.SMALLINT,
1146:                                Types.INTEGER, Types.VARCHAR, Types.VARCHAR,
1147:                                Types.VARCHAR, Types.SMALLINT,
1148:                                DataType.TYPE_BOOLEAN, Types.SMALLINT,
1149:                                DataType.TYPE_BOOLEAN, DataType.TYPE_BOOLEAN,
1150:                                DataType.TYPE_BOOLEAN, Types.VARCHAR,
1151:                                Types.SMALLINT, Types.SMALLINT, Types.SMALLINT,
1152:                                Types.INTEGER, Types.INTEGER }, null, null);
1153:
1154:                rs = meta.getTablePrivileges(null, null, null);
1155:                testResultSetMeta(rs, 7, new String[] { "TABLE_CAT",
1156:                        "TABLE_SCHEM", "TABLE_NAME", "GRANTOR", "GRANTEE",
1157:                        "PRIVILEGE", "IS_GRANTABLE" }, new int[] {
1158:                        Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
1159:                        Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
1160:                        Types.VARCHAR, Types.VARCHAR }, null, null);
1161:
1162:                rs = meta.getColumnPrivileges(null, null, "TEST", null);
1163:                testResultSetMeta(rs, 8, new String[] { "TABLE_CAT",
1164:                        "TABLE_SCHEM", "TABLE_NAME", "COLUMN_NAME", "GRANTOR",
1165:                        "GRANTEE", "PRIVILEGE", "IS_GRANTABLE" }, new int[] {
1166:                        Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
1167:                        Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
1168:                        Types.VARCHAR, Types.VARCHAR, Types.VARCHAR }, null,
1169:                        null);
1170:
1171:                check(conn.getWarnings() == null);
1172:                conn.clearWarnings();
1173:                check(conn.getWarnings() == null);
1174:
1175:            }
1176:
1177:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.