Source Code Cross Referenced for metadata_test.java in  » Database-DBMS » db-derby-10.2 » org » apache » derbyTesting » functionTests » tests » jdbcapi » 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 » db derby 10.2 » org.apache.derbyTesting.functionTests.tests.jdbcapi 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:
0003:           Derby - Class org.apache.derbyTesting.functionTests.tests.jdbcapi.metadata_test
0004:
0005:           Licensed to the Apache Software Foundation (ASF) under one or more
0006:           contributor license agreements.  See the NOTICE file distributed with
0007:           this work for additional information regarding copyright ownership.
0008:           The ASF licenses this file to You under the Apache License, Version 2.0
0009:           (the "License"); you may not use this file except in compliance with
0010:           the License.  You may obtain a copy of the License at
0011:
0012:              http://www.apache.org/licenses/LICENSE-2.0
0013:
0014:           Unless required by applicable law or agreed to in writing, software
0015:           distributed under the License is distributed on an "AS IS" BASIS,
0016:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0017:           See the License for the specific language governing permissions and
0018:           limitations under the License.
0019:
0020:         */
0021:
0022:        package org.apache.derbyTesting.functionTests.tests.jdbcapi;
0023:
0024:        import java.sql.Connection;
0025:        import java.sql.DriverManager;
0026:        import java.sql.DatabaseMetaData;
0027:        import java.sql.PreparedStatement;
0028:        import java.sql.ResultSetMetaData;
0029:        import java.sql.Statement;
0030:        import java.sql.CallableStatement;
0031:        import java.sql.ResultSet;
0032:        import java.sql.SQLException;
0033:        import java.sql.Types;
0034:        import java.sql.Timestamp;
0035:        import java.sql.Time;
0036:        import java.sql.Date;
0037:        import java.math.BigDecimal;
0038:
0039:        import java.util.Properties;
0040:        import java.util.StringTokenizer;
0041:
0042:        import java.lang.reflect.Method;
0043:
0044:        import org.apache.derby.tools.ij;
0045:        import org.apache.derbyTesting.functionTests.util.TestUtil;
0046:        import java.lang.reflect.InvocationTargetException;
0047:        import java.lang.reflect.Modifier;
0048:
0049:        /**
0050:         * Test of database meta-data.  This program simply calls each of the meta-data
0051:         * methods, one by one, and prints the results.  The test passes if the printed
0052:         * results match a previously stored "master".  Thus this test cannot actually
0053:         * discern whether it passes or not.
0054:         *
0055:         */
0056:
0057:        public abstract class metadata_test {
0058:
0059:            // Ids for the Derby internal procedures that are used to fetch
0060:            // some of the metadata.
0061:
0062:            protected static final int GET_PROCEDURES = 0;
0063:            protected static final int GET_PROCEDURE_COLUMNS = 1;
0064:            protected static final int GET_TABLES = 2;
0065:            protected static final int GET_COLUMNS = 3;
0066:            protected static final int GET_COLUMN_PRIVILEGES = 5;
0067:            protected static final int GET_TABLE_PRIVILEGES = 6;
0068:            protected static final int GET_BEST_ROW_IDENTIFIER = 7;
0069:            protected static final int GET_VERSION_COLUMNS = 8;
0070:            protected static final int GET_PRIMARY_KEYS = 9;
0071:            protected static final int GET_IMPORTED_KEYS = 10;
0072:            protected static final int GET_EXPORTED_KEYS = 11;
0073:            protected static final int GET_CROSS_REFERENCE = 12;
0074:            protected static final int GET_TYPE_INFO = 13;
0075:            protected static final int GET_INDEX_INFO = 14;
0076:
0077:            protected static final int IGNORE_PROC_ID = -1;
0078:
0079:            //Used for JSR169
0080:            private static boolean HAVE_DRIVER_CLASS;
0081:            static {
0082:                try {
0083:                    Class.forName("java.sql.Driver");
0084:                    HAVE_DRIVER_CLASS = true;
0085:                } catch (ClassNotFoundException e) {
0086:                    //Used for JSR169
0087:                    HAVE_DRIVER_CLASS = false;
0088:                }
0089:            }
0090:
0091:            // We leave it up to the classes which extend this one to
0092:            // initialize the following fields at construct time.
0093:            public Connection con;
0094:            public static Statement s;
0095:
0096:            /*
0097:             ** Escaped function testing
0098:             */
0099:            private static final String[][] NUMERIC_FUNCTIONS = {
0100:                    // Section C.1 JDBC 3.0 spec.
0101:                    { "ABS", "-25.67" }, { "ACOS", "0.0707" },
0102:                    { "ASIN", "0.997" }, { "ATAN", "14.10" },
0103:                    { "ATAN2", "0.56", "1.2" }, { "CEILING", "3.45" },
0104:                    { "COS", "1.2" }, { "COT", "3.4" }, { "DEGREES", "2.1" },
0105:                    { "EXP", "2.3" }, { "FLOOR", "3.22" }, { "LOG", "34.1" },
0106:                    { "LOG10", "18.7" }, { "MOD", "124", "7" }, { "PI" },
0107:                    { "POWER", "2", "3" }, { "RADIANS", "54" },
0108:                    { "RAND", "17" }, { "ROUND", "345.345", "1" },
0109:                    { "SIGN", "-34" }, { "SIN", "0.32" }, { "SQRT", "6.22" },
0110:                    { "TAN", "0.57", }, { "TRUNCATE", "345.395", "1" } };
0111:
0112:            private static final String[][] TIMEDATE_FUNCTIONS = {
0113:                    // Section C.3 JDBC 3.0 spec.
0114:                    { "CURDATE" },
0115:                    { "CURTIME" },
0116:                    { "DAYNAME", "{d '1995-12-19'h}" },
0117:                    { "DAYOFMONTH", "{d '1995-12-19'}" },
0118:                    { "DAYOFWEEK", "{d '1995-12-19'}" },
0119:                    { "DAYOFYEAR", "{d '1995-12-19'}" },
0120:                    { "HOUR", "{t '16:13:03'}" },
0121:                    { "MINUTE", "{t '16:13:03'}" },
0122:                    { "MONTH", "{d '1995-12-19'}" },
0123:                    { "MONTHNAME", "{d '1995-12-19'}" },
0124:                    { "NOW" },
0125:                    { "QUARTER", "{d '1995-12-19'}" },
0126:                    { "SECOND", "{t '16:13:03'}" },
0127:                    { "TIMESTAMPADD", "SQL_TSI_DAY", "7",
0128:                            "{ts '1995-12-19 12:15:54'}" },
0129:                    { "TIMESTAMPDIFF", "SQL_TSI_DAY",
0130:                            "{ts '1995-12-19 12:15:54'}",
0131:                            "{ts '1997-11-02 00:15:23'}" },
0132:                    { "WEEK", "{d '1995-12-19'}" },
0133:                    { "YEAR", "{d '1995-12-19'}" },
0134:
0135:            };
0136:
0137:            private static final String[][] SYSTEM_FUNCTIONS = {
0138:                    // Section C.4 JDBC 3.0 spec.
0139:                    { "DATABASE" }, { "IFNULL", "'this'", "'that'" },
0140:                    { "USER" }, };
0141:
0142:            private static final String[][] STRING_FUNCTIONS = {
0143:                    // Section C.2 JDBC 3.0 spec.
0144:                    { "ASCII", "'Yellow'" }, { "CHAR", "65" },
0145:                    { "CONCAT", "'hello'", "'there'" },
0146:                    { "DIFFERENCE", "'Pires'", "'Piers'" },
0147:                    { "INSERT", "'Bill Clinton'", "4", "'William'" },
0148:                    { "LCASE", "'Fernando Alonso'" },
0149:                    { "LEFT", "'Bonjour'", "3" }, { "LENGTH", "'four    '" },
0150:                    { "LOCATE", "'jour'", "'Bonjour'" },
0151:                    { "LTRIM", "'   left trim   '" },
0152:                    { "REPEAT", "'echo'", "3" },
0153:                    { "REPLACE", "'to be or not to be'", "'be'", "'England'" },
0154:                    { "RTRIM", "'  right trim   '" }, { "SOUNDEX", "'Derby'" },
0155:                    { "SPACE", "12" },
0156:                    { "SUBSTRING", "'Ruby the Rubicon Jeep'", "10", "7", },
0157:                    { "UCASE", "'Fernando Alonso'" } };
0158:
0159:            public void runTest() {
0160:
0161:                DatabaseMetaData met;
0162:                ResultSet rs;
0163:                ResultSetMetaData rsmet;
0164:
0165:                System.out.println("Test metadata starting");
0166:
0167:                try {
0168:                    //Cleanup any leftover database objects from previous test run
0169:                    cleanUp(s);
0170:
0171:                    // test decimal type and other numeric types precision, scale,
0172:                    // and display width after operations, beetle 3875, 3906
0173:                    s
0174:                            .execute("create table t (i int, s smallint, r real, "
0175:                                    + "d double precision, dt date, t time, ts timestamp, "
0176:                                    + "c char(10), v varchar(40) not null, dc dec(10,2))");
0177:                    s
0178:                            .execute("insert into t values(1,2,3.3,4.4,date('1990-05-05'),"
0179:                                    + "time('12:06:06'),timestamp('1990-07-07 07:07:07.07'),"
0180:                                    + "'eight','nine', 11.1)");
0181:
0182:                    // test decimal type and other numeric types precision, scale,
0183:                    // and display width after operations, beetle 3875, 3906
0184:                    //rs = s.executeQuery("select dc from t where tn = 10 union select dc from t where i = 1");
0185:                    rs = s
0186:                            .executeQuery("select dc from t where dc = 11.1 union select dc from t where i = 1");
0187:                    rsmet = rs.getMetaData();
0188:                    metadata_test.showNumericMetaData("Union Result", rsmet, 1);
0189:                    rs.close();
0190:
0191:                    rs = s
0192:                            .executeQuery("select dc, r, d, r+dc, d-dc, dc-d from t");
0193:                    rsmet = rs.getMetaData();
0194:                    metadata_test.showNumericMetaData("dec(10,2)", rsmet, 1);
0195:                    metadata_test.showNumericMetaData("real", rsmet, 2);
0196:                    metadata_test.showNumericMetaData("double", rsmet, 3);
0197:                    metadata_test.showNumericMetaData("real + dec(10,2)",
0198:                            rsmet, 4);
0199:                    metadata_test.showNumericMetaData(
0200:                            "double precision - dec(10,2)", rsmet, 5);
0201:                    metadata_test.showNumericMetaData(
0202:                            "dec(10,2) - double precision", rsmet, 6);
0203:
0204:                    while (rs.next())
0205:                        System.out.println("result row: " + rs.getString(1)
0206:                                + " " + rs.getString(2) + " " + rs.getString(3)
0207:                                + " " + rs.getString(4) + " " + rs.getString(5)
0208:                                + " " + rs.getString(6));
0209:                    rs.close();
0210:
0211:                    rsmet = s
0212:                            .executeQuery("VALUES CAST (0.0 AS DECIMAL(10,0))")
0213:                            .getMetaData();
0214:                    metadata_test
0215:                            .showNumericMetaData("DECIMAL(10,0)", rsmet, 1);
0216:
0217:                    rsmet = s.executeQuery(
0218:                            "VALUES CAST (0.0 AS DECIMAL(10,10))")
0219:                            .getMetaData();
0220:                    metadata_test.showNumericMetaData("DECIMAL(10,10)", rsmet,
0221:                            1);
0222:
0223:                    rsmet = s
0224:                            .executeQuery("VALUES CAST (0.0 AS DECIMAL(10,2))")
0225:                            .getMetaData();
0226:                    metadata_test
0227:                            .showNumericMetaData("DECIMAL(10,2)", rsmet, 1);
0228:
0229:                    s
0230:                            .execute("insert into t values(1,2,3.3,4.4,date('1990-05-05'),"
0231:                                    + "time('12:06:06'),timestamp('1990-07-07 07:07:07.07'),"
0232:                                    + "'eight','nine', 11.11)");
0233:
0234:                    // test decimal/integer static column result scale consistent
0235:                    // with result set metadata after division, beetle 3901
0236:                    rs = s.executeQuery("select dc / 2 from t");
0237:                    rsmet = rs.getMetaData();
0238:                    System.out
0239:                            .println("Column result scale after division is: "
0240:                                    + rsmet.getScale(1));
0241:                    while (rs.next())
0242:                        System.out.println("dc / 2 = " + rs.getString(1));
0243:                    rs.close();
0244:
0245:                    s
0246:                            .execute("create table louie (i int not null default 10, s smallint not null, "
0247:                                    + "c30 char(30) not null, "
0248:                                    + "vc10 varchar(10) not null default 'asdf', "
0249:                                    + "constraint PRIMKEY primary key(vc10, i), "
0250:                                    + "constraint UNIQUEKEY unique(c30, s), "
0251:                                    + "ai bigint generated always as identity (start with -10, increment by 2001))");
0252:
0253:                    // Create another unique index on louie
0254:                    s.execute("create unique index u1 on louie(s, i)");
0255:                    // Create a non-unique index on louie
0256:                    s.execute("create index u2 on louie(s)");
0257:                    // Create a view on louie
0258:                    s.execute("create view screwie as select * from louie");
0259:
0260:                    // Create a foreign key
0261:                    s
0262:                            .execute("create table reftab (vc10 varchar(10), i int, "
0263:                                    + "s smallint, c30 char(30), "
0264:                                    + "s2 smallint, c302 char(30), "
0265:                                    + "dprim decimal(5,1) not null, dfor decimal(5,1) not null, "
0266:                                    + "constraint PKEY_REFTAB	primary key (dprim), "
0267:                                    + "constraint FKEYSELF 		foreign key (dfor) references reftab, "
0268:                                    + "constraint FKEY1 		foreign key(vc10, i) references louie, "
0269:                                    + "constraint FKEY2 		foreign key(c30, s2) references louie (c30, s), "
0270:                                    + "constraint FKEY3 		foreign key(c30, s) references louie (c30, s))");
0271:
0272:                    s
0273:                            .execute("create table reftab2 (t2_vc10 varchar(10), t2_i int, "
0274:                                    + "constraint T2_FKEY1 		foreign key(t2_vc10, t2_i) references louie)");
0275:
0276:                    // Create a table with all types
0277:                    s.execute("create table alltypes ( "
0278:                            +
0279:                            //"bitcol16_______ bit(16), "+
0280:                            //"bitvaryingcol32 bit varying(32), "+ 
0281:                            //"tinyintcol tinyint, "+
0282:                            "smallintcol smallint, "
0283:                            + "intcol int default 20, "
0284:                            + "bigintcol bigint, "
0285:                            + "realcol real, "
0286:                            + "doublepreccol double precision default 10, "
0287:                            + "floatcol float default 8.8, "
0288:                            + "decimalcol10p4s decimal(10,4), "
0289:                            + "numericcol20p2s numeric(20,2), "
0290:                            + "char8col___ char(8), "
0291:                            + "char8forbitcol___ char(8) for bit data, "
0292:                            + "varchar9col varchar(9), "
0293:                            + "varchar9bitcol varchar(9) for bit data, "
0294:                            + "longvarcharcol long varchar,"
0295:                            + "longvarbinarycol long varchar for bit data, "
0296:                            +
0297:                            //"nchar10col nchar(10)"
0298:                            //+ ", nvarchar8col nvarchar(8)"
0299:                            //+ ", longnvarchar long nvarchar"
0300:                            //+ ", 
0301:                            "blobcol blob(3K), " + "clobcol clob(3K), "
0302:                            + "datecol date, " + "timecol time, "
0303:                            + "tscol timestamp" + ")");
0304:                    // test for beetle 4620
0305:                    s
0306:                            .execute("CREATE TABLE INFLIGHT(FLT_NUM CHAR(20) NOT NULL,"
0307:                                    + "FLT_ORIGIN CHAR(6), "
0308:                                    + "FLT_DEST CHAR(6),  "
0309:                                    + "FLT_AIRCRAFT CHAR(20), "
0310:                                    + "FLT_FLYING_TIME VARCHAR(22), "
0311:                                    + "FLT_DEPT_TIME CHAR(8),  "
0312:                                    + "FLT_ARR_TIME CHAR(8),  "
0313:                                    + "FLT_NOTES VARCHAR(510), "
0314:                                    + "FLT_DAYS_OF_WK CHAR(14), "
0315:                                    + "FLT_CRAFT_PIC VARCHAR(32672), "
0316:                                    + "PRIMARY KEY(FLT_NUM))");
0317:
0318:                    // Create procedures so we can test 
0319:                    // getProcedureColumns()
0320:                    s
0321:                            .execute("create procedure GETPCTEST1 ("
0322:                                    +
0323:                                    // for creating, the procedure's params do not need to exactly match the method's
0324:                                    "out outb VARCHAR(3), a VARCHAR(3), b NUMERIC, c SMALLINT, "
0325:                                    + "e SMALLINT, f INTEGER, g BIGINT, h FLOAT, i DOUBLE PRECISION, "
0326:                                    + "k DATE, l TIME, T TIMESTAMP )"
0327:                                    + "language java external name "
0328:                                    + "'org.apache.derbyTesting.functionTests.tests.jdbcapi.metadata.getpc'"
0329:                                    + " parameter style java");
0330:                    s
0331:                            .execute("create procedure GETPCTEST2 (pa INTEGER, pb BIGINT)"
0332:                                    + "language java external name "
0333:                                    + "'org.apache.derbyTesting.functionTests.tests.jdbcapi.metadata.getpc'"
0334:                                    + " parameter style java");
0335:                    s
0336:                            .execute("create procedure GETPCTEST3A (STRING1 VARCHAR(5), out STRING2 VARCHAR(5))"
0337:                                    + "language java external name "
0338:                                    + "'org.apache.derbyTesting.functionTests.tests.jdbcapi.metadata.getpc'"
0339:                                    + " parameter style java");
0340:                    s
0341:                            .execute("create procedure GETPCTEST3B (in STRING3 VARCHAR(5), inout STRING4 VARCHAR(5))"
0342:                                    + "language java external name "
0343:                                    + "'org.apache.derbyTesting.functionTests.tests.jdbcapi.metadata.getpc'"
0344:                                    + " parameter style java");
0345:                    s
0346:                            .execute("create procedure GETPCTEST4A()  "
0347:                                    + "language java external name "
0348:                                    + "'org.apache.derbyTesting.functionTests.tests.jdbcapi.metadata.getpc4a'"
0349:                                    + " parameter style java");
0350:                    s
0351:                            .execute("create procedure GETPCTEST4B() "
0352:                                    + "language java external name "
0353:                                    + "'org.apache.derbyTesting.functionTests.tests.jdbcapi.metadata.getpc4b'"
0354:                                    + " parameter style java");
0355:                    s
0356:                            .execute("create procedure GETPCTEST4Bx(out retparam INTEGER) "
0357:                                    + "language java external name "
0358:                                    + "'org.apache.derbyTesting.functionTests.tests.jdbcapi.metadata.getpc4b'"
0359:                                    + " parameter style java");
0360:
0361:                    // Create functions so we can test
0362:                    // getFunctions()
0363:                    s.execute("CREATE FUNCTION DUMMY1 ( X SMALLINT ) "
0364:                            + "RETURNS SMALLINT PARAMETER STYLE JAVA "
0365:                            + "NO SQL LANGUAGE JAVA EXTERNAL "
0366:                            + "NAME 'java.some.func'");
0367:                    s.execute("CREATE FUNCTION DUMMY2 ( X INTEGER, Y "
0368:                            + "SMALLINT ) RETURNS INTEGER PARAMETER STYLE"
0369:                            + " JAVA NO SQL LANGUAGE JAVA "
0370:                            + "EXTERNAL NAME 'java.some.func'");
0371:                    s.execute("CREATE FUNCTION DUMMY3 ( X VARCHAR(16), "
0372:                            + "Y INTEGER ) RETURNS VARCHAR(16) PARAMETER"
0373:                            + " STYLE JAVA NO SQL LANGUAGE"
0374:                            + " JAVA EXTERNAL NAME 'java.some.func'");
0375:                    s.execute("CREATE FUNCTION DUMMY4 ( X VARCHAR(128), "
0376:                            + "Y INTEGER ) RETURNS INTEGER PARAMETER "
0377:                            + "STYLE JAVA NO SQL LANGUAGE "
0378:                            + "JAVA EXTERNAL NAME 'java.some.func'");
0379:
0380:                    met = con.getMetaData();
0381:
0382:                    System.out.println("JDBC Driver '" + met.getDriverName()
0383:                            + "', version " + met.getDriverMajorVersion() + "."
0384:                            + met.getDriverMinorVersion() + " ("
0385:                            + met.getDriverVersion() + ")");
0386:
0387:                    boolean pass = false;
0388:                    try {
0389:                        pass = TestUtil.compareURL(met.getURL());
0390:                    } catch (NoSuchMethodError msme) {
0391:                        // DatabaseMetaData.getURL not present - correct for JSR169
0392:                        if (!TestUtil.HAVE_DRIVER_CLASS)
0393:                            pass = true;
0394:                    } catch (Throwable err) {
0395:                        System.out.println("%%getURL() gave the exception: "
0396:                                + err);
0397:                    }
0398:
0399:                    if (pass)
0400:                        System.out
0401:                                .println("DatabaseMetaData.getURL test passed");
0402:                    else
0403:                        System.out
0404:                                .println("FAIL: DatabaseMetaData.getURL test failed");
0405:
0406:                    System.out.println("allTablesAreSelectable(): "
0407:                            + met.allTablesAreSelectable());
0408:
0409:                    System.out.println("maxColumnNameLength(): "
0410:                            + met.getMaxColumnNameLength());
0411:
0412:                    System.out.println();
0413:                    System.out.println("getSchemas():");
0414:                    dumpRS(met.getSchemas());
0415:
0416:                    testGetSchemasWithTwoParams(met);
0417:
0418:                    System.out.println();
0419:                    System.out.println("getCatalogs():");
0420:                    dumpRS(met.getCatalogs());
0421:
0422:                    System.out.println("getSearchStringEscape(): "
0423:                            + met.getSearchStringEscape());
0424:
0425:                    System.out.println("getSQLKeywords(): "
0426:                            + met.getSQLKeywords());
0427:
0428:                    System.out.println("getDefaultTransactionIsolation(): "
0429:                            + met.getDefaultTransactionIsolation());
0430:
0431:                    System.out.println("getProcedures():");
0432:                    dumpRS(GET_PROCEDURES, getMetaDataRS(met, GET_PROCEDURES,
0433:                            new String[] { null, "%", "GETPCTEST%" }, null,
0434:                            null, null));
0435:
0436:                    // Using reflection to check if we have getFunctions in the
0437:                    // the current version of Derby
0438:                    try {
0439:                        Class s = "".getClass();
0440:
0441:                        // Make sure the method is actually implemented
0442:                        java.lang.reflect.Method gf = met.getClass().getMethod(
0443:                                "getFunctions", new Class[] { s, s, s });
0444:                        if (!java.lang.reflect.Modifier.isAbstract(gf
0445:                                .getModifiers())) {
0446:                            // Any function in any schema in any catalog
0447:                            System.out.println("getFunctions(null,null,null):");
0448:                            dumpRS(IGNORE_PROC_ID, (ResultSet) gf.invoke(met,
0449:                                    new String[] { null, null, null }));
0450:
0451:                            // Any function in any schema in "Dummy
0452:                            // Catalog". Same as above since the catalog
0453:                            // argument is ignored (is always null)
0454:                            System.out
0455:                                    .println("getFunctions(\"Dummy Catalog\",null,"
0456:                                            + "null):");
0457:                            dumpRS(IGNORE_PROC_ID, (ResultSet) gf
0458:                                    .invoke(met, new String[] {
0459:                                            "Dummy Catalog", null, null }));
0460:
0461:                            // Any function in a schema starting with "SYS"
0462:                            System.out
0463:                                    .println("getFunctions(null,\"%SYS%\",null):");
0464:                            dumpRS(IGNORE_PROC_ID, (ResultSet) gf.invoke(met,
0465:                                    new String[] { null, "SYS%", null }));
0466:
0467:                            // All functions containing "GET" in any schema
0468:                            // (and any catalog)
0469:                            System.out
0470:                                    .println("getFunctions(null,null,\"%GET%\"):");
0471:                            dumpRS(IGNORE_PROC_ID, (ResultSet) gf.invoke(met,
0472:                                    new String[] { null, null, "%GET%" }));
0473:
0474:                            // Any function that belongs to NO schema and
0475:                            // NO catalog (none)
0476:                            System.out.println("getFunctions(\"\",\"\",null):");
0477:                            dumpRS(IGNORE_PROC_ID, (ResultSet) gf.invoke(met,
0478:                                    new String[] { "", "", null }));
0479:
0480:                        }
0481:
0482:                        // Test getFunctionColumns(String,String,String,String)
0483:                        java.lang.reflect.Method gfp = met.getClass()
0484:                                .getMethod("getFunctionColumns",
0485:                                        new Class[] { s, s, s, s });
0486:
0487:                        if (!java.lang.reflect.Modifier.isAbstract(gfp
0488:                                .getModifiers())) {
0489:                            System.out.println("getFunctionColumns(null,"
0490:                                    + "null,null,null):");
0491:                            dumpRS(IGNORE_PROC_ID, (ResultSet) gfp.invoke(met,
0492:                                    new String[] { null, null, null, null }));
0493:
0494:                            System.out
0495:                                    .println("getFunctionColumns(null,\"APP\","
0496:                                            + "\"DUMMY%\",\"X\"):");
0497:                            dumpRS(IGNORE_PROC_ID, (ResultSet) gfp
0498:                                    .invoke(met, new String[] { null, "APP",
0499:                                            "DUMMY%", "X" }));
0500:
0501:                            System.out
0502:                                    .println("getFunctionColumns(null,\"APP\","
0503:                                            + "\"DUMMY%\",\"\"):");
0504:                            dumpRS(IGNORE_PROC_ID, (ResultSet) gfp.invoke(met,
0505:                                    new String[] { null, "APP", "DUMMY%", "" }));
0506:
0507:                        }
0508:                    } catch (NoSuchMethodException e) {
0509:                        if (org.apache.derby.iapi.services.info.JVMInfo.JDK_ID >= org.apache.derby.iapi.services.info.JVMInfo.J2SE_16) {
0510:                            e.printStackTrace();
0511:                        }
0512:                    } catch (Exception e) {
0513:                        e.printStackTrace();
0514:                    }
0515:
0516:                    System.out
0517:                            .println("getUDTs() with user-named types null :");
0518:                    dumpRS(met.getUDTs(null, null, null, null));
0519:
0520:                    System.out
0521:                            .println("getUDTs() with user-named types in ('JAVA_OBJECT') :");
0522:                    int[] userNamedTypes = new int[1];
0523:                    userNamedTypes[0] = java.sql.Types.JAVA_OBJECT;
0524:                    dumpRS(met.getUDTs("a", null, null, userNamedTypes));
0525:
0526:                    System.out
0527:                            .println("getUDTs() with user-named types in ('STRUCT') :");
0528:                    userNamedTypes[0] = java.sql.Types.STRUCT;
0529:                    dumpRS(met.getUDTs("b", null, null, userNamedTypes));
0530:
0531:                    System.out
0532:                            .println("getUDTs() with user-named types in ('DISTINCT') :");
0533:                    userNamedTypes[0] = java.sql.Types.DISTINCT;
0534:                    dumpRS(met.getUDTs("c", null, null, userNamedTypes));
0535:
0536:                    System.out
0537:                            .println("getUDTs() with user-named types in ('JAVA_OBJECT', 'STRUCT') :");
0538:                    userNamedTypes = new int[2];
0539:                    userNamedTypes[0] = java.sql.Types.JAVA_OBJECT;
0540:                    userNamedTypes[1] = java.sql.Types.STRUCT;
0541:                    dumpRS(met.getUDTs("a", null, null, userNamedTypes));
0542:
0543:                    testGetClientInfoProperties(met);
0544:
0545:                    /*
0546:                     * any methods that were not tested above using code written
0547:                     * specifically for it will now be tested in a generic way.
0548:                     */
0549:
0550:                    System.out.println("allProceduresAreCallable(): "
0551:                            + met.allProceduresAreCallable());
0552:                    System.out.println("getUserName(): " + met.getUserName());
0553:                    System.out.println("isReadOnly(): " + met.isReadOnly());
0554:                    System.out.println("nullsAreSortedHigh(): "
0555:                            + met.nullsAreSortedHigh());
0556:                    System.out.println("nullsAreSortedLow(): "
0557:                            + met.nullsAreSortedLow());
0558:                    System.out.println("nullsAreSortedAtStart(): "
0559:                            + met.nullsAreSortedAtStart());
0560:                    System.out.println("nullsAreSortedAtEnd(): "
0561:                            + met.nullsAreSortedAtEnd());
0562:
0563:                    System.out.println("getDatabaseProductName(): "
0564:                            + met.getDatabaseProductName());
0565:
0566:                    String v = met.getDatabaseProductVersion();
0567:                    System.out.println("getDatabaseProductVersion(): " + v);
0568:                    System.out.println("getDriverVersion(): "
0569:                            + met.getDriverVersion());
0570:                    System.out.println("usesLocalFiles(): "
0571:                            + met.usesLocalFiles());
0572:                    System.out.println("usesLocalFilePerTable(): "
0573:                            + met.usesLocalFilePerTable());
0574:                    System.out.println("supportsMixedCaseIdentifiers(): "
0575:                            + met.supportsMixedCaseIdentifiers());
0576:                    System.out.println("storesUpperCaseIdentifiers(): "
0577:                            + met.storesUpperCaseIdentifiers());
0578:                    System.out.println("storesLowerCaseIdentifiers(): "
0579:                            + met.storesLowerCaseIdentifiers());
0580:                    System.out.println("storesMixedCaseIdentifiers(): "
0581:                            + met.storesMixedCaseIdentifiers());
0582:                    System.out.println("supportsMixedCaseQuotedIdentifiers(): "
0583:                            + met.supportsMixedCaseQuotedIdentifiers());
0584:                    System.out.println("storesUpperCaseQuotedIdentifiers(): "
0585:                            + met.storesUpperCaseQuotedIdentifiers());
0586:                    System.out.println("storesLowerCaseQuotedIdentifiers(): "
0587:                            + met.storesLowerCaseQuotedIdentifiers());
0588:                    System.out.println("storesMixedCaseQuotedIdentifiers(): "
0589:                            + met.storesMixedCaseQuotedIdentifiers());
0590:                    System.out.println("getIdentifierQuoteString(): "
0591:                            + met.getIdentifierQuoteString());
0592:                    System.out.println("getNumericFunctions(): "
0593:                            + met.getNumericFunctions());
0594:                    System.out.println("getStringFunctions(): "
0595:                            + met.getStringFunctions());
0596:                    System.out.println("getSystemFunctions(): "
0597:                            + met.getSystemFunctions());
0598:                    System.out.println("getTimeDateFunctions(): "
0599:                            + met.getTimeDateFunctions());
0600:                    System.out.println("getExtraNameCharacters(): "
0601:                            + met.getExtraNameCharacters());
0602:                    System.out.println("supportsAlterTableWithAddColumn(): "
0603:                            + met.supportsAlterTableWithAddColumn());
0604:                    System.out.println("supportsAlterTableWithDropColumn(): "
0605:                            + met.supportsAlterTableWithDropColumn());
0606:                    System.out.println("supportsColumnAliasing(): "
0607:                            + met.supportsColumnAliasing());
0608:                    System.out.println("nullPlusNonNullIsNull(): "
0609:                            + met.nullPlusNonNullIsNull());
0610:                    System.out.println("supportsConvert(): "
0611:                            + met.supportsConvert());
0612:                    System.out
0613:                            .println("supportsConvert(Types.INTEGER, Types.SMALLINT): "
0614:                                    + met.supportsConvert(Types.INTEGER,
0615:                                            Types.SMALLINT));
0616:                    System.out.println("supportsTableCorrelationNames(): "
0617:                            + met.supportsTableCorrelationNames());
0618:                    System.out
0619:                            .println("supportsDifferentTableCorrelationNames(): "
0620:                                    + met
0621:                                            .supportsDifferentTableCorrelationNames());
0622:                    System.out.println("supportsExpressionsInOrderBy(): "
0623:                            + met.supportsExpressionsInOrderBy());
0624:                    System.out.println("supportsOrderByUnrelated(): "
0625:                            + met.supportsOrderByUnrelated());
0626:                    System.out.println("supportsGroupBy(): "
0627:                            + met.supportsGroupBy());
0628:                    System.out.println("supportsGroupByUnrelated(): "
0629:                            + met.supportsGroupByUnrelated());
0630:                    System.out.println("supportsGroupByBeyondSelect(): "
0631:                            + met.supportsGroupByBeyondSelect());
0632:                    System.out.println("supportsLikeEscapeClause(): "
0633:                            + met.supportsLikeEscapeClause());
0634:                    System.out.println("supportsMultipleResultSets(): "
0635:                            + met.supportsMultipleResultSets());
0636:                    System.out.println("supportsMultipleTransactions(): "
0637:                            + met.supportsMultipleTransactions());
0638:                    System.out.println("supportsNonNullableColumns(): "
0639:                            + met.supportsNonNullableColumns());
0640:                    System.out.println("supportsMinimumSQLGrammar(): "
0641:                            + met.supportsMinimumSQLGrammar());
0642:                    System.out.println("supportsCoreSQLGrammar(): "
0643:                            + met.supportsCoreSQLGrammar());
0644:                    System.out.println("supportsExtendedSQLGrammar(): "
0645:                            + met.supportsExtendedSQLGrammar());
0646:                    System.out.println("supportsANSI92EntryLevelSQL(): "
0647:                            + met.supportsANSI92EntryLevelSQL());
0648:                    System.out.println("supportsANSI92IntermediateSQL(): "
0649:                            + met.supportsANSI92IntermediateSQL());
0650:                    System.out.println("supportsANSI92FullSQL(): "
0651:                            + met.supportsANSI92FullSQL());
0652:                    System.out
0653:                            .println("supportsIntegrityEnhancementFacility(): "
0654:                                    + met
0655:                                            .supportsIntegrityEnhancementFacility());
0656:                    System.out.println("supportsOuterJoins(): "
0657:                            + met.supportsOuterJoins());
0658:                    System.out.println("supportsFullOuterJoins(): "
0659:                            + met.supportsFullOuterJoins());
0660:                    System.out.println("supportsLimitedOuterJoins(): "
0661:                            + met.supportsLimitedOuterJoins());
0662:                    System.out.println("getSchemaTerm(): "
0663:                            + met.getSchemaTerm());
0664:                    System.out.println("getProcedureTerm(): "
0665:                            + met.getProcedureTerm());
0666:                    System.out.println("getCatalogTerm(): "
0667:                            + met.getCatalogTerm());
0668:                    System.out.println("isCatalogAtStart(): "
0669:                            + met.isCatalogAtStart());
0670:                    System.out.println("getCatalogSeparator(): "
0671:                            + met.getCatalogSeparator());
0672:                    System.out.println("supportsSchemasInDataManipulation(): "
0673:                            + met.supportsSchemasInDataManipulation());
0674:                    System.out.println("supportsSchemasInProcedureCalls(): "
0675:                            + met.supportsSchemasInProcedureCalls());
0676:                    System.out.println("supportsSchemasInTableDefinitions(): "
0677:                            + met.supportsSchemasInTableDefinitions());
0678:                    System.out.println("supportsSchemasInIndexDefinitions(): "
0679:                            + met.supportsSchemasInIndexDefinitions());
0680:                    System.out
0681:                            .println("supportsSchemasInPrivilegeDefinitions(): "
0682:                                    + met
0683:                                            .supportsSchemasInPrivilegeDefinitions());
0684:                    System.out.println("supportsCatalogsInDataManipulation(): "
0685:                            + met.supportsCatalogsInDataManipulation());
0686:                    System.out.println("supportsCatalogsInProcedureCalls(): "
0687:                            + met.supportsCatalogsInProcedureCalls());
0688:                    System.out.println("supportsCatalogsInTableDefinitions(): "
0689:                            + met.supportsCatalogsInTableDefinitions());
0690:                    System.out.println("supportsCatalogsInIndexDefinitions(): "
0691:                            + met.supportsCatalogsInIndexDefinitions());
0692:                    System.out
0693:                            .println("supportsCatalogsInPrivilegeDefinitions(): "
0694:                                    + met
0695:                                            .supportsCatalogsInPrivilegeDefinitions());
0696:                    System.out.println("supportsPositionedDelete(): "
0697:                            + met.supportsPositionedDelete());
0698:                    System.out.println("supportsPositionedUpdate(): "
0699:                            + met.supportsPositionedUpdate());
0700:                    System.out.println("supportsSelectForUpdate(): "
0701:                            + met.supportsSelectForUpdate());
0702:                    System.out.println("supportsStoredProcedures(): "
0703:                            + met.supportsStoredProcedures());
0704:                    System.out.println("supportsSubqueriesInComparisons(): "
0705:                            + met.supportsSubqueriesInComparisons());
0706:                    System.out.println("supportsSubqueriesInExists(): "
0707:                            + met.supportsSubqueriesInExists());
0708:                    System.out.println("supportsSubqueriesInIns(): "
0709:                            + met.supportsSubqueriesInIns());
0710:                    System.out.println("supportsSubqueriesInQuantifieds(): "
0711:                            + met.supportsSubqueriesInQuantifieds());
0712:                    System.out.println("supportsCorrelatedSubqueries(): "
0713:                            + met.supportsCorrelatedSubqueries());
0714:                    System.out.println("supportsUnion(): "
0715:                            + met.supportsUnion());
0716:                    System.out.println("supportsUnionAll(): "
0717:                            + met.supportsUnionAll());
0718:                    System.out.println("supportsOpenCursorsAcrossCommit(): "
0719:                            + met.supportsOpenCursorsAcrossCommit());
0720:                    System.out.println("supportsOpenCursorsAcrossRollback(): "
0721:                            + met.supportsOpenCursorsAcrossRollback());
0722:                    System.out.println("supportsOpenStatementsAcrossCommit(): "
0723:                            + met.supportsOpenStatementsAcrossCommit());
0724:                    System.out
0725:                            .println("supportsOpenStatementsAcrossRollback(): "
0726:                                    + met
0727:                                            .supportsOpenStatementsAcrossRollback());
0728:                    System.out.println("getMaxBinaryLiteralLength(): "
0729:                            + met.getMaxBinaryLiteralLength());
0730:                    System.out.println("getMaxCharLiteralLength(): "
0731:                            + met.getMaxCharLiteralLength());
0732:                    System.out.println("getMaxColumnsInGroupBy(): "
0733:                            + met.getMaxColumnsInGroupBy());
0734:                    System.out.println("getMaxColumnsInIndex(): "
0735:                            + met.getMaxColumnsInIndex());
0736:                    System.out.println("getMaxColumnsInOrderBy(): "
0737:                            + met.getMaxColumnsInOrderBy());
0738:                    System.out.println("getMaxColumnsInSelect(): "
0739:                            + met.getMaxColumnsInSelect());
0740:                    System.out.println("getMaxColumnsInTable(): "
0741:                            + met.getMaxColumnsInTable());
0742:                    System.out.println("getMaxConnections(): "
0743:                            + met.getMaxConnections());
0744:                    System.out.println("getMaxCursorNameLength(): "
0745:                            + met.getMaxCursorNameLength());
0746:                    System.out.println("getMaxIndexLength(): "
0747:                            + met.getMaxIndexLength());
0748:                    System.out.println("getMaxSchemaNameLength(): "
0749:                            + met.getMaxSchemaNameLength());
0750:                    System.out.println("getMaxProcedureNameLength(): "
0751:                            + met.getMaxProcedureNameLength());
0752:                    System.out.println("getMaxCatalogNameLength(): "
0753:                            + met.getMaxCatalogNameLength());
0754:                    System.out.println("getMaxRowSize(): "
0755:                            + met.getMaxRowSize());
0756:                    System.out.println("doesMaxRowSizeIncludeBlobs(): "
0757:                            + met.doesMaxRowSizeIncludeBlobs());
0758:                    System.out.println("getMaxStatementLength(): "
0759:                            + met.getMaxStatementLength());
0760:                    System.out.println("getMaxStatements(): "
0761:                            + met.getMaxStatements());
0762:                    System.out.println("getMaxTableNameLength(): "
0763:                            + met.getMaxTableNameLength());
0764:                    System.out.println("getMaxTablesInSelect(): "
0765:                            + met.getMaxTablesInSelect());
0766:                    System.out.println("getMaxUserNameLength(): "
0767:                            + met.getMaxUserNameLength());
0768:                    System.out.println("supportsTransactions(): "
0769:                            + met.supportsTransactions());
0770:                    System.out
0771:                            .println("supportsTransactionIsolationLevel(Connection.TRANSACTION_NONE): "
0772:                                    + met
0773:                                            .supportsTransactionIsolationLevel(Connection.TRANSACTION_NONE));
0774:                    System.out
0775:                            .println("supportsTransactionIsolationLevel(Connection.TRANSACTION_REPEATABLE_READ): "
0776:                                    + met
0777:                                            .supportsTransactionIsolationLevel(Connection.TRANSACTION_REPEATABLE_READ));
0778:                    System.out
0779:                            .println("supportsTransactionIsolationLevel(Connection.TRANSACTION_SERIALIZABLE): "
0780:                                    + met
0781:                                            .supportsTransactionIsolationLevel(Connection.TRANSACTION_SERIALIZABLE));
0782:                    System.out
0783:                            .println("supportsDataDefinitionAndDataManipulationTransactions(): "
0784:                                    + met
0785:                                            .supportsDataDefinitionAndDataManipulationTransactions());
0786:                    System.out
0787:                            .println("supportsDataManipulationTransactionsOnly(): "
0788:                                    + met
0789:                                            .supportsDataManipulationTransactionsOnly());
0790:                    System.out
0791:                            .println("dataDefinitionCausesTransactionCommit(): "
0792:                                    + met
0793:                                            .dataDefinitionCausesTransactionCommit());
0794:                    System.out
0795:                            .println("dataDefinitionIgnoredInTransactions(): "
0796:                                    + met.dataDefinitionIgnoredInTransactions());
0797:
0798:                    System.out
0799:                            .println("Test the metadata calls related to visibility of changes made by others for different resultset types");
0800:                    System.out
0801:                            .println("Since Derby materializes a forward only ResultSet incrementally, it is possible to see changes");
0802:                    System.out
0803:                            .println("made by others and hence following 3 metadata calls will return true for forward only ResultSets.");
0804:                    System.out
0805:                            .println("othersUpdatesAreVisible(ResultSet.TYPE_FORWARD_ONLY)? "
0806:                                    + met
0807:                                            .othersUpdatesAreVisible(ResultSet.TYPE_FORWARD_ONLY));
0808:                    System.out
0809:                            .println("othersDeletesAreVisible(ResultSet.TYPE_FORWARD_ONLY)? "
0810:                                    + met
0811:                                            .othersDeletesAreVisible(ResultSet.TYPE_FORWARD_ONLY));
0812:                    System.out
0813:                            .println("othersInsertsAreVisible(ResultSet.TYPE_FORWARD_ONLY)? "
0814:                                    + met
0815:                                            .othersInsertsAreVisible(ResultSet.TYPE_FORWARD_ONLY));
0816:                    System.out
0817:                            .println("Scroll insensitive ResultSet by their definition do not see changes made by others and hence following metadata calls return false");
0818:                    System.out
0819:                            .println("othersUpdatesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)? "
0820:                                    + met
0821:                                            .othersUpdatesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE));
0822:                    System.out
0823:                            .println("othersDeletesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)? "
0824:                                    + met
0825:                                            .othersDeletesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE));
0826:                    System.out
0827:                            .println("othersInsertsAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)? "
0828:                                    + met
0829:                                            .othersInsertsAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE));
0830:                    System.out
0831:                            .println("Derby does not yet implement scroll sensitive resultsets and hence following metadata calls return false");
0832:                    System.out
0833:                            .println("othersUpdatesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)? "
0834:                                    + met
0835:                                            .othersUpdatesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE));
0836:                    System.out
0837:                            .println("othersDeletesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)? "
0838:                                    + met
0839:                                            .othersDeletesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE));
0840:                    System.out
0841:                            .println("othersInsertsAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)? "
0842:                                    + met
0843:                                            .othersInsertsAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE));
0844:
0845:                    System.out
0846:                            .println("Test the metadata calls related to visibility of *own* changes for different resultset types");
0847:                    System.out
0848:                            .println("ownUpdatesAreVisible(ResultSet.TYPE_FORWARD_ONLY)? "
0849:                                    + met
0850:                                            .ownUpdatesAreVisible(ResultSet.TYPE_FORWARD_ONLY));
0851:                    System.out
0852:                            .println("ownDeletesAreVisible(ResultSet.TYPE_FORWARD_ONLY)? "
0853:                                    + met
0854:                                            .ownDeletesAreVisible(ResultSet.TYPE_FORWARD_ONLY));
0855:                    System.out
0856:                            .println("ownInsertsAreVisible(ResultSet.TYPE_FORWARD_ONLY)? "
0857:                                    + met
0858:                                            .ownInsertsAreVisible(ResultSet.TYPE_FORWARD_ONLY));
0859:                    System.out
0860:                            .println("Scroll insensitive ResultSet see updates and deletes, but not inserts");
0861:                    System.out
0862:                            .println("ownUpdatesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)? "
0863:                                    + met
0864:                                            .ownUpdatesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE));
0865:                    System.out
0866:                            .println("ownDeletesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)? "
0867:                                    + met
0868:                                            .ownDeletesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE));
0869:                    System.out
0870:                            .println("ownInsertsAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)? "
0871:                                    + met
0872:                                            .ownInsertsAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE));
0873:                    System.out
0874:                            .println("Derby does not yet implement scroll sensitive resultsets and hence following metadata calls return false");
0875:                    System.out
0876:                            .println("ownUpdatesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)? "
0877:                                    + met
0878:                                            .ownUpdatesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE));
0879:                    System.out
0880:                            .println("ownDeletesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)? "
0881:                                    + met
0882:                                            .ownDeletesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE));
0883:                    System.out
0884:                            .println("ownInsertsAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)? "
0885:                                    + met
0886:                                            .othersInsertsAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE));
0887:
0888:                    System.out
0889:                            .println("Test the metadata calls related to detectability of visible changes for different resultset types");
0890:                    System.out
0891:                            .println("Expect true for updates and deletes of TYPE_SCROLL_INSENSITIVE, all others should be false");
0892:                    System.out
0893:                            .println("updatesAreDetected(ResultSet.TYPE_FORWARD_ONLY)? "
0894:                                    + met
0895:                                            .updatesAreDetected(ResultSet.TYPE_FORWARD_ONLY));
0896:                    System.out
0897:                            .println("deletesAreDetected(ResultSet.TYPE_FORWARD_ONLY)? "
0898:                                    + met
0899:                                            .deletesAreDetected(ResultSet.TYPE_FORWARD_ONLY));
0900:                    System.out
0901:                            .println("insertsAreDetected(ResultSet.TYPE_FORWARD_ONLY)? "
0902:                                    + met
0903:                                            .insertsAreDetected(ResultSet.TYPE_FORWARD_ONLY));
0904:                    System.out
0905:                            .println("updatesAreDetected(ResultSet.TYPE_SCROLL_INSENSITIVE)? "
0906:                                    + met
0907:                                            .updatesAreDetected(ResultSet.TYPE_SCROLL_INSENSITIVE));
0908:                    System.out
0909:                            .println("deletesAreDetected(ResultSet.TYPE_SCROLL_INSENSITIVE)? "
0910:                                    + met
0911:                                            .deletesAreDetected(ResultSet.TYPE_SCROLL_INSENSITIVE));
0912:                    System.out
0913:                            .println("insertsAreDetected(ResultSet.TYPE_SCROLL_INSENSITIVE)? "
0914:                                    + met
0915:                                            .insertsAreDetected(ResultSet.TYPE_SCROLL_INSENSITIVE));
0916:                    System.out
0917:                            .println("updatesAreDetected(ResultSet.TYPE_SCROLL_SENSITIVE)? "
0918:                                    + met
0919:                                            .updatesAreDetected(ResultSet.TYPE_SCROLL_SENSITIVE));
0920:                    System.out
0921:                            .println("deletesAreDetected(ResultSet.TYPE_SCROLL_SENSITIVE)? "
0922:                                    + met
0923:                                            .deletesAreDetected(ResultSet.TYPE_SCROLL_SENSITIVE));
0924:                    System.out
0925:                            .println("insertsAreDetected(ResultSet.TYPE_SCROLL_SENSITIVE)? "
0926:                                    + met
0927:                                            .insertsAreDetected(ResultSet.TYPE_SCROLL_SENSITIVE));
0928:
0929:                    if (!TestUtil.isJCCFramework()) { // gives false on all.. bug
0930:                        int[] types = { ResultSet.TYPE_FORWARD_ONLY,
0931:                                ResultSet.TYPE_SCROLL_INSENSITIVE,
0932:                                ResultSet.TYPE_SCROLL_SENSITIVE };
0933:
0934:                        int[] conc = { ResultSet.CONCUR_READ_ONLY,
0935:                                ResultSet.CONCUR_UPDATABLE };
0936:
0937:                        String[] typesStr = { "TYPE_FORWARD_ONLY",
0938:                                "TYPE_SCROLL_INSENSITIVE",
0939:                                "TYPE_SCROLL_SENSITIVE" };
0940:
0941:                        String[] concStr = { "CONCUR_READ_ONLY",
0942:                                "CONCUR_UPDATABLE" };
0943:
0944:                        for (int i = 0; i < types.length; i++) {
0945:                            for (int j = 0; j < conc.length; j++) {
0946:                                System.out
0947:                                        .println("SupportsResultSetConcurrency: "
0948:                                                + typesStr[i]
0949:                                                + ","
0950:                                                + concStr[j]
0951:                                                + ": "
0952:                                                + met
0953:                                                        .supportsResultSetConcurrency(
0954:                                                                types[i],
0955:                                                                conc[j]));
0956:                            }
0957:                        }
0958:                    }
0959:
0960:                    System.out.println("getConnection(): "
0961:                            + ((met.getConnection() == con) ? "same connection"
0962:                                    : "different connection"));
0963:                    System.out.println("getProcedureColumns():");
0964:                    dumpRS(GET_PROCEDURE_COLUMNS, getMetaDataRS(met,
0965:                            GET_PROCEDURE_COLUMNS, new String[] { null, "%",
0966:                                    "GETPCTEST%", "%" }, null, null, null));
0967:
0968:                    System.out
0969:                            .println("getTables() with TABLE_TYPE in ('SYSTEM TABLE') :");
0970:                    String[] tabTypes = new String[1];
0971:                    tabTypes[0] = "SYSTEM TABLE";
0972:                    dumpRS(GET_TABLES, getMetaDataRS(met, GET_TABLES,
0973:                            new String[] { null, null, null }, tabTypes, null,
0974:                            null));
0975:
0976:                    System.out.println("getTables() with no types:");
0977:                    dumpRS(GET_TABLES, getMetaDataRS(met, GET_TABLES,
0978:                            new String[] { "", null, "%" }, null, null, null));
0979:
0980:                    System.out
0981:                            .println("getTables() with TABLE_TYPE in ('VIEW','TABLE') :");
0982:                    tabTypes = new String[2];
0983:                    tabTypes[0] = "VIEW";
0984:                    tabTypes[1] = "TABLE";
0985:                    dumpRS(GET_TABLES, getMetaDataRS(met, GET_TABLES,
0986:                            new String[] { null, null, null }, tabTypes, null,
0987:                            null));
0988:
0989:                    System.out.println("getTableTypes():");
0990:                    dumpRS(met.getTableTypes());
0991:
0992:                    System.out.println("getColumns():");
0993:                    dumpRS(GET_COLUMNS,
0994:                            getMetaDataRS(met, GET_COLUMNS, new String[] { "",
0995:                                    null, "", "" }, null, null, null));
0996:
0997:                    System.out.println("getColumns('SYSTABLES'):");
0998:                    dumpRS(GET_COLUMNS, getMetaDataRS(met, GET_COLUMNS,
0999:                            new String[] { "", "SYS", "SYSTABLES", null },
1000:                            null, null, null));
1001:
1002:                    System.out.println("getColumns('ALLTYPES'):");
1003:                    dumpRS(GET_COLUMNS, getMetaDataRS(met, GET_COLUMNS,
1004:                            new String[] { "", "APP", "ALLTYPES", null }, null,
1005:                            null, null));
1006:
1007:                    System.out.println("getColumns('LOUIE'):");
1008:                    dumpRS(GET_COLUMNS, getMetaDataRS(met, GET_COLUMNS,
1009:                            new String[] { "", "APP", "LOUIE", null }, null,
1010:                            null, null));
1011:
1012:                    // test for beetle 4620
1013:                    System.out.println("getColumns('INFLIGHT'):");
1014:                    dumpRS(GET_COLUMNS, getMetaDataRS(met, GET_COLUMNS,
1015:                            new String[] { "", "APP", "INFLIGHT", null }, null,
1016:                            null, null));
1017:
1018:                    System.out.println("getColumnPrivileges():");
1019:                    dumpRS(GET_COLUMN_PRIVILEGES, getMetaDataRS(met,
1020:                            GET_COLUMN_PRIVILEGES, new String[] { "Huey",
1021:                                    "Dewey", "Louie", "Frooey" }, null, null,
1022:                            null));
1023:
1024:                    System.out.println("getTablePrivileges():");
1025:                    dumpRS(GET_TABLE_PRIVILEGES, getMetaDataRS(met,
1026:                            GET_TABLE_PRIVILEGES, new String[] { "Huey",
1027:                                    "Dewey", "Louie" }, null, null, null));
1028:
1029:                    System.out
1030:                            .println("getBestRowIdentifier(\"\",null,\"LOUIE\"):");
1031:                    dumpRS(GET_BEST_ROW_IDENTIFIER, getMetaDataRS(met,
1032:                            GET_BEST_ROW_IDENTIFIER, new String[] { "", null,
1033:                                    "LOUIE" }, null,
1034:                            new int[] { DatabaseMetaData.bestRowTransaction },
1035:                            new boolean[] { true }));
1036:
1037:                    System.out
1038:                            .println("getBestRowIdentifier(\"\",\"SYS\",\"SYSTABLES\"):");
1039:                    dumpRS(GET_BEST_ROW_IDENTIFIER, getMetaDataRS(met,
1040:                            GET_BEST_ROW_IDENTIFIER, new String[] { "", "SYS",
1041:                                    "SYSTABLES" }, null,
1042:                            new int[] { DatabaseMetaData.bestRowTransaction },
1043:                            new boolean[] { true }));
1044:
1045:                    System.out.println("getVersionColumns():");
1046:                    dumpRS(GET_VERSION_COLUMNS, getMetaDataRS(met,
1047:                            GET_VERSION_COLUMNS, new String[] { "Huey",
1048:                                    "Dewey", "Louie" }, null, null, null));
1049:
1050:                    System.out.println("getPrimaryKeys():");
1051:                    dumpRS(GET_PRIMARY_KEYS,
1052:                            getMetaDataRS(met, GET_PRIMARY_KEYS, new String[] {
1053:                                    "", "%", "LOUIE" }, null, null, null));
1054:
1055:                    //beetle 4571
1056:                    System.out
1057:                            .println("getPrimaryKeys(null, null, tablename):");
1058:                    dumpRS(GET_PRIMARY_KEYS, getMetaDataRS(met,
1059:                            GET_PRIMARY_KEYS, new String[] { null, null,
1060:                                    "LOUIE" }, null, null, null));
1061:
1062:                    System.out.println("getImportedKeys():");
1063:                    dumpRS(GET_IMPORTED_KEYS, getMetaDataRS(met,
1064:                            GET_IMPORTED_KEYS,
1065:                            new String[] { null, null, "%" }, null, null, null));
1066:
1067:                    System.out.println("getExportedKeys():");
1068:                    dumpRS(GET_EXPORTED_KEYS, getMetaDataRS(met,
1069:                            GET_EXPORTED_KEYS,
1070:                            new String[] { null, null, "%" }, null, null, null));
1071:
1072:                    System.out
1073:                            .println("---------------------------------------");
1074:                    System.out
1075:                            .println("getCrossReference('',null,'louie','',null,'reftab' ):");
1076:                    dumpRS(GET_CROSS_REFERENCE, getMetaDataRS(met,
1077:                            GET_CROSS_REFERENCE, new String[] { "", null,
1078:                                    "LOUIE", "", null, "REFTAB" }, null, null,
1079:                            null));
1080:
1081:                    System.out
1082:                            .println("\ngetCrossReference('','APP','reftab','',null,'reftab' ):");
1083:                    dumpRS(GET_CROSS_REFERENCE, getMetaDataRS(met,
1084:                            GET_CROSS_REFERENCE, new String[] { "", "APP",
1085:                                    "REFTAB", "", null, "REFTAB" }, null, null,
1086:                            null));
1087:
1088:                    System.out
1089:                            .println("\ngetCrossReference('',null,null,'','APP','reftab' ):");
1090:                    dumpRS(GET_CROSS_REFERENCE, getMetaDataRS(met,
1091:                            GET_CROSS_REFERENCE, new String[] { "", null, "%",
1092:                                    "", "APP", "REFTAB" }, null, null, null));
1093:
1094:                    System.out
1095:                            .println("\ngetImportedKeys('',null,null,'','APP','reftab' ):");
1096:                    dumpRS(GET_IMPORTED_KEYS, getMetaDataRS(met,
1097:                            GET_IMPORTED_KEYS, new String[] { "", "APP",
1098:                                    "REFTAB" }, null, null, null));
1099:
1100:                    System.out
1101:                            .println("\ngetCrossReference('',null,'louie','','APP',null):");
1102:                    dumpRS(GET_CROSS_REFERENCE,
1103:                            getMetaDataRS(met, GET_CROSS_REFERENCE,
1104:                                    new String[] { "", null, "LOUIE", "",
1105:                                            "APP", "%" }, null, null, null));
1106:
1107:                    System.out
1108:                            .println("\ngetExportedKeys('',null,'louie,'','APP',null ):");
1109:                    dumpRS(GET_EXPORTED_KEYS, getMetaDataRS(met,
1110:                            GET_EXPORTED_KEYS,
1111:                            new String[] { "", null, "LOUIE" }, null, null,
1112:                            null));
1113:
1114:                    System.out
1115:                            .println("\ngetCrossReference('','badschema','LOUIE','','APP','REFTAB' ):");
1116:                    dumpRS(GET_CROSS_REFERENCE, getMetaDataRS(met,
1117:                            GET_CROSS_REFERENCE,
1118:                            new String[] { "", "BADSCHEMA", "LOUIE", "", "APP",
1119:                                    "REFTAB" }, null, null, null));
1120:
1121:                    System.out.println("getTypeInfo():");
1122:                    dumpRS(GET_TYPE_INFO, getMetaDataRS(met, GET_TYPE_INFO,
1123:                            null, null, null, null));
1124:
1125:                    /* NOTE - we call getIndexInfo() only on system tables here
1126:                     * so that there will be no diffs due to generated names.
1127:                     */
1128:                    // unique indexes on SYSCOLUMNS
1129:                    System.out.println("getIndexInfo():");
1130:                    dumpRS(GET_INDEX_INFO, getMetaDataRS(met, GET_INDEX_INFO,
1131:                            new String[] { "", "SYS", "SYSCOLUMNS" }, null,
1132:                            null, new boolean[] { true, false }));
1133:
1134:                    // all indexes on SYSCOLUMNS
1135:                    System.out.println("getIndexInfo():");
1136:                    dumpRS(GET_INDEX_INFO, getMetaDataRS(met, GET_INDEX_INFO,
1137:                            new String[] { "", "SYS", "SYSCOLUMNS" }, null,
1138:                            null, new boolean[] { false, false }));
1139:
1140:                    System.out.println("getIndexInfo():");
1141:                    dumpRS(GET_INDEX_INFO, getMetaDataRS(met, GET_INDEX_INFO,
1142:                            new String[] { "", "SYS", "SYSTABLES" }, null,
1143:                            null, new boolean[] { true, false }));
1144:
1145:                    rs = s.executeQuery("SELECT * FROM SYS.SYSTABLES");
1146:
1147:                    System.out.println("getColumns('SYSTABLES'):");
1148:                    dumpRS(GET_COLUMNS, getMetaDataRS(met, GET_COLUMNS,
1149:                            new String[] { "", "SYS", "SYSTABLES", null },
1150:                            null, null, null));
1151:
1152:                    try {
1153:                        if (!rs.next()) {
1154:                            System.out
1155:                                    .println("FAIL -- user result set closed by"
1156:                                            + " intervening getColumns request");
1157:                        }
1158:                    } catch (SQLException se) {
1159:                        if (this  instanceof  metadata) {
1160:                            System.out
1161:                                    .println("FAIL -- user result set closed by"
1162:                                            + " intervening getColumns request");
1163:                        } else {
1164:                            System.out
1165:                                    .println("OK -- user result set closed by"
1166:                                            + " intervening OBDC getColumns request; this was"
1167:                                            + " expected because of the way the test works.");
1168:                        }
1169:                    }
1170:                    rs.close();
1171:
1172:                    System.out
1173:                            .println("Test escaped numeric functions - JDBC 3.0 C.1");
1174:                    testEscapedFunctions(con, NUMERIC_FUNCTIONS, met
1175:                            .getNumericFunctions());
1176:
1177:                    System.out
1178:                            .println("Test escaped string functions - JDBC 3.0 C.2");
1179:                    testEscapedFunctions(con, STRING_FUNCTIONS, met
1180:                            .getStringFunctions());
1181:
1182:                    System.out
1183:                            .println("Test escaped date time functions - JDBC 3.0 C.3");
1184:                    testEscapedFunctions(con, TIMEDATE_FUNCTIONS, met
1185:                            .getTimeDateFunctions());
1186:
1187:                    System.out
1188:                            .println("Test escaped system functions - JDBC 3.0 C.4");
1189:                    testEscapedFunctions(con, SYSTEM_FUNCTIONS, met
1190:                            .getSystemFunctions());
1191:
1192:                    //
1193:                    // Test referential actions on delete
1194:                    //
1195:                    System.out
1196:                            .println("---------------------------------------");
1197:                    //create tables to test that we get the delete and update 
1198:                    // referential action correct
1199:                    System.out.println("Referential action values");
1200:                    System.out.println("RESTRICT = "
1201:                            + DatabaseMetaData.importedKeyRestrict);
1202:                    System.out.println("NO ACTION = "
1203:                            + DatabaseMetaData.importedKeyNoAction);
1204:                    System.out.println("CASCADE = "
1205:                            + DatabaseMetaData.importedKeyCascade);
1206:                    System.out.println("SETNULL = "
1207:                            + DatabaseMetaData.importedKeySetNull);
1208:                    System.out.println("SETDEFAULT = "
1209:                            + DatabaseMetaData.importedKeySetDefault);
1210:                    s
1211:                            .execute("create table refaction1(a int not null primary key)");
1212:                    s
1213:                            .execute("create table refactnone(a int references refaction1(a))");
1214:                    s
1215:                            .execute("create table refactrestrict(a int references refaction1(a) on delete restrict)");
1216:                    s
1217:                            .execute("create table refactnoaction(a int references refaction1(a) on delete no action)");
1218:                    s
1219:                            .execute("create table refactcascade(a int references refaction1(a) on delete cascade)");
1220:                    s
1221:                            .execute("create table refactsetnull(a int references refaction1(a) on delete set null)");
1222:                    System.out
1223:                            .println("getCrossReference('','APP','REFACTION1','','APP','REFACTIONNONE' ):");
1224:                    s
1225:                            .execute("create table refactupdrestrict(a int references refaction1(a) on update restrict)");
1226:                    s
1227:                            .execute("create table refactupdnoaction(a int references refaction1(a) on update no action)");
1228:                    dumpRS(GET_CROSS_REFERENCE, getMetaDataRS(met,
1229:                            GET_CROSS_REFERENCE, new String[] { "", "APP",
1230:                                    "REFACTION1", "", "APP", "REFACTNONE" },
1231:                            null, null, null));
1232:                    System.out
1233:                            .println("\ngetCrossReference('','APP','REFACTION1','','APP','REFACTRESTRICT' ):");
1234:                    dumpRS(GET_CROSS_REFERENCE, getMetaDataRS(met,
1235:                            GET_CROSS_REFERENCE,
1236:                            new String[] { "", "APP", "REFACTION1", "", "APP",
1237:                                    "REFACTRESTRICT" }, null, null, null));
1238:                    System.out
1239:                            .println("\ngetCrossReference('','APP','REFACTION1','','APP','REFACTNOACTION' ):");
1240:                    dumpRS(GET_CROSS_REFERENCE, getMetaDataRS(met,
1241:                            GET_CROSS_REFERENCE,
1242:                            new String[] { "", "APP", "REFACTION1", "", "APP",
1243:                                    "REFACTNOACTION" }, null, null, null));
1244:                    System.out
1245:                            .println("\ngetCrossReference('','APP','REFACTION1','','APP','REFACTCASCADE' ):");
1246:                    dumpRS(GET_CROSS_REFERENCE, getMetaDataRS(met,
1247:                            GET_CROSS_REFERENCE, new String[] { "", "APP",
1248:                                    "REFACTION1", "", "APP", "REFACTCASCADE" },
1249:                            null, null, null));
1250:                    System.out
1251:                            .println("\ngetCrossReference('','APP','REFACTION1','','APP','REFACTSETNULL' ):");
1252:                    dumpRS(GET_CROSS_REFERENCE, getMetaDataRS(met,
1253:                            GET_CROSS_REFERENCE, new String[] { "", "APP",
1254:                                    "REFACTION1", "", "APP", "REFACTSETNULL" },
1255:                            null, null, null));
1256:                    System.out
1257:                            .println("\ngetCrossReference('','APP','REFACTION1','','APP','REFACTUPDRESTRICT' ):");
1258:                    dumpRS(GET_CROSS_REFERENCE, getMetaDataRS(met,
1259:                            GET_CROSS_REFERENCE, new String[] { "", "APP",
1260:                                    "REFACTION1", "", "APP",
1261:                                    "REFACTUPDRESTRICT" }, null, null, null));
1262:                    System.out
1263:                            .println("\ngetCrossReference('','APP','REFACTION1','','APP','REFACTUPDNOACTION' ):");
1264:                    dumpRS(GET_CROSS_REFERENCE, getMetaDataRS(met,
1265:                            GET_CROSS_REFERENCE, new String[] { "", "APP",
1266:                                    "REFACTION1", "", "APP",
1267:                                    "REFACTUPDNOACTION" }, null, null, null));
1268:
1269:                    ResultSet refrs = getMetaDataRS(met, GET_IMPORTED_KEYS,
1270:                            new String[] { "", "APP", "REFACTNONE" }, null,
1271:                            null, null);
1272:
1273:                    if (refrs.next()) {
1274:                        //check update rule
1275:                        if (refrs.getShort(11) != DatabaseMetaData.importedKeyNoAction)
1276:                            System.out
1277:                                    .println("\ngetImportedKeys - none update Failed - action = "
1278:                                            + refrs.getShort(11)
1279:                                            + " required value = "
1280:                                            + DatabaseMetaData.importedKeyNoAction);
1281:                        else
1282:                            System.out
1283:                                    .println("\ngetImportedKeys - none update Passed");
1284:                        //check delete rule
1285:                        if (refrs.getShort(11) != DatabaseMetaData.importedKeyNoAction)
1286:                            System.out
1287:                                    .println("\ngetImportedKeys - none delete Failed - action = "
1288:                                            + refrs.getShort(11)
1289:                                            + " required value = "
1290:                                            + DatabaseMetaData.importedKeyNoAction);
1291:                        else
1292:                            System.out
1293:                                    .println("\ngetImportedKeys - none delete Passed");
1294:                    } else
1295:                        System.out
1296:                                .println("\ngetImportedKeys - none Failed no rows");
1297:
1298:                    refrs.close();
1299:                    refrs = getMetaDataRS(met, GET_IMPORTED_KEYS, new String[] {
1300:                            "", "APP", "REFACTRESTRICT" }, null, null, null);
1301:
1302:                    if (refrs.next()) {
1303:                        if (refrs.getShort(11) != DatabaseMetaData.importedKeyRestrict)
1304:                            System.out
1305:                                    .println("\ngetImportedKeys - delete Restrict Failed - action = "
1306:                                            + refrs.getShort(11)
1307:                                            + " required value = "
1308:                                            + DatabaseMetaData.importedKeyRestrict);
1309:                        else
1310:                            System.out
1311:                                    .println("\ngetImportedKeys - delete Restrict Passed");
1312:                    } else
1313:                        System.out
1314:                                .println("\ngetImportedKeys - delete Restrict Failed no rows");
1315:
1316:                    refrs.close();
1317:                    refrs = getMetaDataRS(met, GET_IMPORTED_KEYS, new String[] {
1318:                            "", "APP", "REFACTNOACTION" }, null, null, null);
1319:
1320:                    if (refrs.next()) {
1321:                        if (refrs.getShort(11) != DatabaseMetaData.importedKeyNoAction)
1322:                            System.out
1323:                                    .println("\ngetImportedKeys - delete NO ACTION Failed - action = "
1324:                                            + refrs.getShort(11)
1325:                                            + " required value = "
1326:                                            + DatabaseMetaData.importedKeyNoAction);
1327:                        else
1328:                            System.out
1329:                                    .println("\ngetImportedKeys - delete NO ACTION Passed");
1330:                    } else
1331:                        System.out
1332:                                .println("\ngetImportedKeys - delete NO ACTION Failed no rows");
1333:
1334:                    refrs.close();
1335:                    refrs = getMetaDataRS(met, GET_IMPORTED_KEYS, new String[] {
1336:                            "", "APP", "REFACTCASCADE" }, null, null, null);
1337:
1338:                    if (refrs.next()) {
1339:                        if (refrs.getShort(11) != DatabaseMetaData.importedKeyCascade)
1340:                            System.out
1341:                                    .println("\ngetImportedKeys - delete CASCADE Failed - action = "
1342:                                            + refrs.getShort(11)
1343:                                            + " required value = "
1344:                                            + DatabaseMetaData.importedKeyCascade);
1345:                        else
1346:                            System.out
1347:                                    .println("\ngetImportedKeys - delete CASCADE Passed");
1348:                    } else
1349:                        System.out
1350:                                .println("\ngetImportedKeys - delete CASCADE Failed no rows");
1351:
1352:                    refrs.close();
1353:                    refrs = getMetaDataRS(met, GET_IMPORTED_KEYS, new String[] {
1354:                            "", "APP", "REFACTSETNULL" }, null, null, null);
1355:
1356:                    if (refrs.next()) {
1357:                        if (refrs.getShort(11) != DatabaseMetaData.importedKeySetNull)
1358:                            System.out
1359:                                    .println("\ngetImportedKeys - delete SET NULL Failed - action = "
1360:                                            + refrs.getShort(11)
1361:                                            + " required value = "
1362:                                            + DatabaseMetaData.importedKeySetNull);
1363:                        else
1364:                            System.out
1365:                                    .println("\ngetImportedKeys - delete SET NULL Passed");
1366:                    } else
1367:                        System.out
1368:                                .println("\ngetImportedKeys - SET NULL Failed no rows");
1369:
1370:                    refrs.close();
1371:                    refrs = getMetaDataRS(met, GET_IMPORTED_KEYS, new String[] {
1372:                            "", "APP", "REFACTRESTRICT" }, null, null, null);
1373:
1374:                    if (refrs.next()) {
1375:                        // test update rule
1376:                        if (refrs.getShort(11) != DatabaseMetaData.importedKeyRestrict)
1377:                            System.out
1378:                                    .println("\ngetImportedKeys - update Restrict Failed - action = "
1379:                                            + refrs.getShort(11)
1380:                                            + " required value = "
1381:                                            + DatabaseMetaData.importedKeyRestrict);
1382:                        else
1383:                            System.out
1384:                                    .println("\ngetImportedKeys - update Restrict Passed");
1385:                    } else
1386:                        System.out
1387:                                .println("\ngetImportedKeys - update Restrict Failed no rows");
1388:
1389:                    refrs.close();
1390:                    refrs = getMetaDataRS(met, GET_IMPORTED_KEYS, new String[] {
1391:                            "", "APP", "REFACTNOACTION" }, null, null, null);
1392:
1393:                    if (refrs.next()) {
1394:                        if (refrs.getShort(11) != DatabaseMetaData.importedKeyNoAction)
1395:                            System.out
1396:                                    .println("\ngetImportedKeys - update NO ACTION Failed - action = "
1397:                                            + refrs.getShort(11)
1398:                                            + " required value = "
1399:                                            + DatabaseMetaData.importedKeyNoAction);
1400:                        else
1401:                            System.out
1402:                                    .println("\ngetImportedKeys - update NO ACTION Passed");
1403:                    } else
1404:                        System.out
1405:                                .println("\ngetImportedKeys - update NO ACTION Failed no rows");
1406:                    refrs.close();
1407:
1408:                    System.out
1409:                            .println("\ngetExportedKeys('',null,null,'','APP','REFACTION1' ):");
1410:                    dumpRS(GET_EXPORTED_KEYS, getMetaDataRS(met,
1411:                            GET_EXPORTED_KEYS, new String[] { "", "APP",
1412:                                    "REFACTION1" }, null, null, null));
1413:
1414:                    System.out
1415:                            .println("---------------------------------------");
1416:
1417:                    // drop referential action test tables
1418:                    s.execute("drop table refactnone");
1419:                    s.execute("drop table refactupdrestrict");
1420:                    s.execute("drop table refactupdnoaction");
1421:                    s.execute("drop table refactrestrict");
1422:                    s.execute("drop table refactnoaction");
1423:                    s.execute("drop table refactcascade");
1424:                    s.execute("drop table refactsetnull");
1425:                    s.execute("drop table inflight");
1426:                    s.execute("drop table refaction1");
1427:
1428:                    // test beetle 5195
1429:                    s
1430:                            .execute("create table t1 (c1 int not null, c2 int, c3 int default null, c4 char(10) not null, c5 char(10) default null, c6 char(10) default 'NULL', c7 int default 88)");
1431:
1432:                    String schema = "APP";
1433:                    String tableName = "T1";
1434:                    DatabaseMetaData dmd = con.getMetaData();
1435:
1436:                    System.out.println("getColumns for '" + tableName + "'");
1437:
1438:                    rs = getMetaDataRS(dmd, GET_COLUMNS, new String[] { null,
1439:                            schema, tableName, null }, null, null, null);
1440:
1441:                    try {
1442:                        while (rs.next()) {
1443:                            String col = rs.getString(4);
1444:                            String type = rs.getString(6);
1445:                            String defval = rs.getString(13);
1446:                            if (defval == null)
1447:                                System.out.println("  Next line is real null.");
1448:                            System.out.println("defval for col " + col
1449:                                    + " type " + type + " DEFAULT '" + defval
1450:                                    + "' wasnull " + rs.wasNull());
1451:                        }
1452:
1453:                    } finally {
1454:                        if (rs != null)
1455:                            rs.close();
1456:                    }
1457:                    s.execute("drop table t1");
1458:
1459:                    // test DERBY-655, DERBY-1343
1460:                    // If a table has duplicate backing index, then it will share the 
1461:                    // physical conglomerate with the existing index, but the duplicate
1462:                    // indexes should have their own unique logical congomerates 
1463:                    // associated with them. That way, it will be possible to 
1464:                    // distinguish the 2 indexes in SYSCONGLOMERATES from each other.
1465:                    s
1466:                            .execute("CREATE TABLE Derby655t1(c11_ID BIGINT NOT NULL)");
1467:                    s
1468:                            .execute("CREATE TABLE Derby655t2 (c21_ID BIGINT NOT NULL primary key)");
1469:                    s
1470:                            .execute("ALTER TABLE Derby655t1 ADD CONSTRAINT F_12 Foreign Key (c11_ID) REFERENCES Derby655t2 (c21_ID) ON DELETE CASCADE ON UPDATE NO ACTION");
1471:                    s
1472:                            .execute("CREATE TABLE Derby655t3(c31_ID BIGINT NOT NULL primary key)");
1473:                    s
1474:                            .execute("ALTER TABLE Derby655t2 ADD CONSTRAINT F_443 Foreign Key (c21_ID) REFERENCES Derby655t3(c31_ID) ON DELETE CASCADE ON UPDATE NO ACTION");
1475:                    dmd = con.getMetaData();
1476:                    System.out
1477:                            .println("\ngetImportedKeys('',null,null,'','APP','Derby655t1' ):");
1478:                    dumpRS(met.getImportedKeys("", "APP", "DERBY655T1"));
1479:                    s.execute("drop table Derby655t1");
1480:                    s.execute("drop table Derby655t2");
1481:                    s.execute("drop table Derby655t3");
1482:
1483:                    // tiny test moved over from no longer used metadata2.sql
1484:                    // This checks for a bug where you get incorrect behavior on a nested connection.
1485:                    // if you do not get an error, the bug does not occur.			
1486:                    if (HAVE_DRIVER_CLASS) {
1487:                        s
1488:                                .execute("create procedure isReadO() language java external name "
1489:                                        + "'org.apache.derbyTesting.functionTests.tests.jdbcapi.metadata.isro'"
1490:                                        + " parameter style java");
1491:                        s.execute("call isReadO()");
1492:                    }
1493:                    cleanUp(s);
1494:
1495:                    s.close();
1496:
1497:                    if (con.getAutoCommit() == false)
1498:                        con.commit();
1499:
1500:                    con.close();
1501:
1502:                } catch (SQLException e) {
1503:                    dumpSQLExceptions(e);
1504:                } catch (Throwable e) {
1505:                    System.out.println("FAIL -- unexpected exception:");
1506:                    e.printStackTrace(System.out);
1507:                }
1508:
1509:                System.out.println("Test metadata finished");
1510:            }
1511:
1512:            /**
1513:             * Test escaped functions. Working from the list of escaped functions defined
1514:             * by JDBC, compared to the list returned by the driver.
1515:             * <OL>
1516:             * <LI> See that all functions defined by the driver are in the spec list
1517:             * and that they work.
1518:             * <LI> See that only functions defined by the spec are in the driver's list.
1519:             * <LI> See that any functions defined by the spec that work are in the driver's list.
1520:             * </OL>
1521:             * FAIL will be printed for any issues.
1522:             * @param conn
1523:             * @param specList
1524:             * @param metaDataList
1525:             * @throws SQLException
1526:             */
1527:            private static void testEscapedFunctions(Connection conn,
1528:                    String[][] specList, String metaDataList)
1529:                    throws SQLException {
1530:                boolean[] seenFunction = new boolean[specList.length];
1531:
1532:                System.out
1533:                        .println("TEST FUNCTIONS DECLARED IN DATABASEMETADATA LIST");
1534:                StringTokenizer st = new StringTokenizer(metaDataList, ",");
1535:                while (st.hasMoreTokens()) {
1536:                    String function = st.nextToken();
1537:
1538:                    // find this function in the list
1539:                    boolean isSpecFunction = false;
1540:                    for (int f = 0; f < specList.length; f++) {
1541:                        String[] specDetails = specList[f];
1542:                        if (function.equals(specDetails[0])) {
1543:                            // Matched spec.
1544:                            if (seenFunction[f])
1545:                                System.out
1546:                                        .println("FAIL Function in list twice: "
1547:                                                + function);
1548:                            seenFunction[f] = true;
1549:                            isSpecFunction = true;
1550:
1551:                            if (!executeEscaped(conn, specDetails))
1552:                                System.out
1553:                                        .println("FAIL Function failed to execute "
1554:                                                + function);
1555:                            break;
1556:                        }
1557:                    }
1558:
1559:                    if (!isSpecFunction) {
1560:                        System.out
1561:                                .println("FAIL Non-JDBC spec function in list: "
1562:                                        + function);
1563:                    }
1564:                }
1565:
1566:                // Now see if any speced functions are not in the metadata list
1567:                System.out
1568:                        .println("TEST FUNCTIONS NOT DECLARED IN DATABASEMETADATA LIST");
1569:                for (int f = 0; f < specList.length; f++) {
1570:                    if (seenFunction[f])
1571:                        continue;
1572:                    String[] specDetails = specList[f];
1573:                    if (executeEscaped(conn, specDetails))
1574:                        System.out
1575:                                .println("FAIL function works but not declared in list: "
1576:                                        + specDetails[0]);
1577:
1578:                }
1579:            }
1580:
1581:            private static boolean executeEscaped(Connection conn,
1582:                    String[] specDetails) {
1583:
1584:                String sql = "VALUES { fn " + specDetails[0] + "(";
1585:
1586:                for (int p = 0; p < specDetails.length - 1; p++) {
1587:                    if (p != 0)
1588:                        sql = sql + ", ";
1589:
1590:                    sql = sql + specDetails[p + 1];
1591:                }
1592:
1593:                sql = sql + ") }";
1594:
1595:                // Special processing for functions that return
1596:                // current date, time or timestamp. This is to
1597:                // ensure we don't have output that depends on
1598:                // the time the test is run.
1599:                if ("CURDATE".equals(specDetails[0]))
1600:                    sql = "VALUES CASE WHEN { fn CURDATE()} = CURRENT_DATE THEN 'OK' ELSE 'wrong' END";
1601:                else if ("CURTIME".equals(specDetails[0]))
1602:                    sql = "VALUES CASE WHEN { fn CURTIME()} = CURRENT_TIME THEN 'OK' ELSE 'wrong' END";
1603:                else if ("NOW".equals(specDetails[0]))
1604:                    sql = "VALUES CASE WHEN { fn NOW()} = CURRENT_TIMESTAMP THEN 'OK' ELSE 'wrong' END";
1605:
1606:                System.out.print("Executing " + sql + " -- ");
1607:
1608:                try {
1609:                    PreparedStatement ps = conn.prepareStatement(sql);
1610:                    ResultSet rs = ps.executeQuery();
1611:
1612:                    while (rs.next()) {
1613:                        // truncate numbers to avoid multiple master files
1614:                        // with double values.
1615:                        String res = rs.getString(1);
1616:
1617:                        switch (rs.getMetaData().getColumnType(1)) {
1618:                        case Types.DOUBLE:
1619:                        case Types.REAL:
1620:                        case Types.FLOAT:
1621:                            if (res.length() > 4)
1622:                                res = res.substring(0, 4);
1623:                            break;
1624:                        default:
1625:                            break;
1626:                        }
1627:                        System.out.print("  = >" + res + "< ");
1628:                    }
1629:                    rs.close();
1630:                    ps.close();
1631:                    System.out.println(" << ");
1632:                    return true;
1633:                } catch (SQLException e) {
1634:                    System.out.println("");
1635:                    showSQLExceptions(e);
1636:                    return false;
1637:                }
1638:
1639:            }
1640:
1641:            /**
1642:             * Run tests for <code>getSchemas()</code> with two
1643:             * parameters. (New method introduced by JDBC 4.0.)
1644:             *
1645:             * @param dmd a <code>DatabaseMetaData</code> object
1646:             */
1647:            private void testGetSchemasWithTwoParams(DatabaseMetaData dmd) {
1648:                // not implemented in JCC
1649:                if (TestUtil.isJCCFramework())
1650:                    return;
1651:
1652:                Class[] paramTypes = { String.class, String.class };
1653:
1654:                Method method = null;
1655:                try {
1656:                    method = dmd.getClass().getMethod("getSchemas", paramTypes);
1657:                } catch (NoSuchMethodException nsme) {
1658:                }
1659:
1660:                if (method == null
1661:                        || Modifier.isAbstract(method.getModifiers())) {
1662:                    System.out
1663:                            .println("DatabaseMetaData.getSchemas(String, String) "
1664:                                    + "is not available.");
1665:                    return;
1666:                }
1667:
1668:                System.out.println();
1669:                System.out.println("getSchemas(String, String):");
1670:
1671:                // array of argument lists
1672:                String[][] args = {
1673:                // no qualifiers
1674:                        { null, null },
1675:                        // wildcard
1676:                        { null, "SYS%" },
1677:                        // exact match
1678:                        { null, "APP" },
1679:                        // no match
1680:                        { null, "BLAH" }, };
1681:
1682:                for (int i = 0; i < args.length; ++i) {
1683:                    try {
1684:                        dumpRS((ResultSet) method.invoke(dmd, args[i]));
1685:                    } catch (Exception e) {
1686:                        dumpAllExceptions(e);
1687:                    }
1688:                }
1689:            }
1690:
1691:            /**
1692:             * Run tests for <code>getClientInfoProperties()</code> introduced
1693:             * by JDBC 4.0.
1694:             *
1695:             * @param dmd a <code>DatabaseMetaData</code> object
1696:             */
1697:            private void testGetClientInfoProperties(DatabaseMetaData dmd) {
1698:                // not implemented in JCC
1699:                if (TestUtil.isJCCFramework())
1700:                    return;
1701:
1702:                Method method = null;
1703:                try {
1704:                    method = dmd.getClass().getMethod(
1705:                            "getClientInfoProperties", null);
1706:                } catch (NoSuchMethodException nsme) {
1707:                }
1708:
1709:                if (method == null
1710:                        || Modifier.isAbstract(method.getModifiers())) {
1711:                    System.out
1712:                            .println("DatabaseMetaData.getClientInfoProperties() "
1713:                                    + "is not available.");
1714:                    return;
1715:                }
1716:
1717:                System.out.println();
1718:                System.out.println("getClientInfoProperties():");
1719:
1720:                try {
1721:                    dumpRS((ResultSet) method.invoke(dmd, null));
1722:                } catch (Exception e) {
1723:                    dumpAllExceptions(e);
1724:                }
1725:            }
1726:
1727:            static private void showSQLExceptions(SQLException se) {
1728:                while (se != null) {
1729:                    System.out.println("SQLSTATE(" + se.getSQLState() + "): "
1730:                            + se.getMessage());
1731:                    se = se.getNextException();
1732:                }
1733:            }
1734:
1735:            static protected void dumpSQLExceptions(SQLException se) {
1736:                System.out.println("FAIL -- unexpected exception");
1737:                while (se != null) {
1738:                    System.out.print("SQLSTATE(" + se.getSQLState() + "):");
1739:                    se.printStackTrace(System.out);
1740:                    se = se.getNextException();
1741:                }
1742:            }
1743:
1744:            /**
1745:             * Print the entire exception chain.
1746:             *
1747:             * @param t a <code>Throwable</code>
1748:             */
1749:            private static void dumpAllExceptions(Throwable t) {
1750:                System.out.println("FAIL -- unexpected exception");
1751:                do {
1752:                    t.printStackTrace(System.out);
1753:                    if (t instanceof  SQLException) {
1754:                        t = ((SQLException) t).getNextException();
1755:                    } else if (t instanceof  InvocationTargetException) {
1756:                        t = ((InvocationTargetException) t)
1757:                                .getTargetException();
1758:                    } else {
1759:                        break;
1760:                    }
1761:                } while (t != null);
1762:            }
1763:
1764:            /**
1765:             * This method is responsible for executing a metadata query and returning
1766:             * the result set.  We do it like this so that the metadata.java and
1767:             * odbc_metadata.java classes can implement this method in their
1768:             * own ways (which is needed because we have to extra work to
1769:             * get the ODBC versions of the metadata).
1770:             */
1771:            abstract protected ResultSet getMetaDataRS(DatabaseMetaData dmd,
1772:                    int procId, String[] sArgs, String[] argArray, int[] iArgs,
1773:                    boolean[] bArgs) throws SQLException;
1774:
1775:            /**
1776:             * Dump the values in the received result set to output.
1777:             */
1778:            protected void dumpRS(ResultSet rs) throws SQLException {
1779:                dumpRS(IGNORE_PROC_ID, rs);
1780:            }
1781:
1782:            /**
1783:             * Dump the values in the received result set to output.
1784:             */
1785:            abstract protected void dumpRS(int procId, ResultSet s)
1786:                    throws SQLException;
1787:
1788:            /**
1789:             * Create a connect based on the test arguments passed in.
1790:             */
1791:            protected Connection createConnection(String[] args)
1792:                    throws Exception {
1793:
1794:                Connection con;
1795:
1796:                // use the ij utility to read the property file and
1797:                // make the initial connection.
1798:                ij.getPropertyArg(args);
1799:                con = ij.startJBMS();
1800:                //con.setAutoCommit(true); // make sure it is true
1801:                con.setAutoCommit(false);
1802:
1803:                return con;
1804:
1805:            }
1806:
1807:            protected void cleanUp(Statement stmt) throws SQLException {
1808:                con.setAutoCommit(true);
1809:                String[] testObjects = { "table t", "table t1", "view screwie",
1810:                        "table reftab", "table reftab2", "table inflight",
1811:                        "table alltypes", "table louie",
1812:                        "procedure getpctest1", "procedure getpctest2",
1813:                        "procedure getpctest3a", "procedure getpctest3b",
1814:                        "procedure getpctest4a", "procedure getpctest4b",
1815:                        "procedure getpctest4bx", "procedure isreadO",
1816:                        "FUNCTION DUMMY1", "FUNCTION DUMMY2",
1817:                        "FUNCTION DUMMY3", "FUNCTION DUMMY4" };
1818:                TestUtil.cleanUpTest(stmt, testObjects);
1819:            }
1820:
1821:            /**
1822:             * Display the numeric JDBC metadata for a column
1823:             * @param expression Description of the expression
1824:             * @param rsmd thje meta data
1825:             * @param col which column
1826:             * @throws SQLException
1827:             */
1828:            private static void showNumericMetaData(String expression,
1829:                    ResultSetMetaData rsmd, int col) throws SQLException {
1830:                System.out.print(expression);
1831:                System.out.print(" --");
1832:
1833:                System.out.print(" precision: ");
1834:                System.out.print(rsmd.getPrecision(col));
1835:
1836:                System.out.print(" scale: ");
1837:                System.out.print(rsmd.getScale(col));
1838:
1839:                System.out.print(" display size: ");
1840:                System.out.print(rsmd.getColumnDisplaySize(col));
1841:
1842:                System.out.print(" type name: ");
1843:                System.out.print(rsmd.getColumnTypeName(col));
1844:
1845:                System.out.println("");
1846:
1847:            }
1848:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.