| 1 21 22 package org.apache.derbyTesting.functionTests.tests.jdbcapi; 23 24 import java.sql.Connection ; 25 import java.sql.DriverManager ; 26 import java.sql.DatabaseMetaData ; 27 import java.sql.PreparedStatement ; 28 import java.sql.ResultSetMetaData ; 29 import java.sql.Statement ; 30 import java.sql.CallableStatement ; 31 import java.sql.ResultSet ; 32 import java.sql.SQLException ; 33 import java.sql.Types ; 34 import java.sql.Timestamp ; 35 import java.sql.Time ; 36 import java.sql.Date ; 37 import java.math.BigDecimal ; 38 39 import java.util.Properties ; 40 import java.util.StringTokenizer ; 41 42 import java.lang.reflect.Method ; 43 44 import org.apache.derby.tools.ij; 45 import org.apache.derbyTesting.functionTests.util.TestUtil; 46 import java.lang.reflect.InvocationTargetException ; 47 import java.lang.reflect.Modifier ; 48 49 56 57 public abstract class metadata_test { 58 59 62 protected static final int GET_PROCEDURES = 0; 63 protected static final int GET_PROCEDURE_COLUMNS = 1; 64 protected static final int GET_TABLES = 2; 65 protected static final int GET_COLUMNS = 3; 66 protected static final int GET_COLUMN_PRIVILEGES = 5; 67 protected static final int GET_TABLE_PRIVILEGES = 6; 68 protected static final int GET_BEST_ROW_IDENTIFIER = 7; 69 protected static final int GET_VERSION_COLUMNS = 8; 70 protected static final int GET_PRIMARY_KEYS = 9; 71 protected static final int GET_IMPORTED_KEYS = 10; 72 protected static final int GET_EXPORTED_KEYS = 11; 73 protected static final int GET_CROSS_REFERENCE = 12; 74 protected static final int GET_TYPE_INFO = 13; 75 protected static final int GET_INDEX_INFO = 14; 76 77 protected static final int IGNORE_PROC_ID = -1; 78 79 private static boolean HAVE_DRIVER_CLASS; 81 static{ 82 try{ 83 Class.forName("java.sql.Driver"); 84 HAVE_DRIVER_CLASS = true; 85 } 86 catch(ClassNotFoundException e){ 87 HAVE_DRIVER_CLASS = false; 89 } 90 } 91 92 public Connection con; 95 public static Statement s; 96 97 100 private static final String [][] NUMERIC_FUNCTIONS = 101 { 102 { "ABS", "-25.67" }, 104 { "ACOS", "0.0707" }, 105 { "ASIN", "0.997" }, 106 { "ATAN", "14.10" }, 107 { "ATAN2", "0.56", "1.2" }, 108 { "CEILING", "3.45" }, 109 { "COS", "1.2" }, 110 { "COT", "3.4" }, 111 { "DEGREES", "2.1" }, 112 { "EXP", "2.3" }, 113 { "FLOOR", "3.22" }, 114 { "LOG", "34.1" }, 115 { "LOG10", "18.7" }, 116 { "MOD", "124", "7" }, 117 { "PI" }, 118 { "POWER", "2", "3" }, 119 { "RADIANS", "54" }, 120 { "RAND", "17" }, 121 { "ROUND", "345.345", "1" }, 122 { "SIGN", "-34" }, 123 { "SIN", "0.32" }, 124 { "SQRT", "6.22" }, 125 { "TAN", "0.57", }, 126 { "TRUNCATE", "345.395", "1" } 127 }; 128 129 private static final String [][] TIMEDATE_FUNCTIONS = 130 { 131 { "CURDATE" }, 133 { "CURTIME" }, 134 { "DAYNAME", "{d '1995-12-19'h}" }, 135 { "DAYOFMONTH", "{d '1995-12-19'}" }, 136 { "DAYOFWEEK", "{d '1995-12-19'}" }, 137 { "DAYOFYEAR", "{d '1995-12-19'}" }, 138 { "HOUR", "{t '16:13:03'}" }, 139 { "MINUTE", "{t '16:13:03'}" }, 140 { "MONTH", "{d '1995-12-19'}" }, 141 { "MONTHNAME", "{d '1995-12-19'}" }, 142 { "NOW" }, 143 { "QUARTER", "{d '1995-12-19'}" }, 144 { "SECOND", "{t '16:13:03'}" }, 145 { "TIMESTAMPADD", "SQL_TSI_DAY", "7", "{ts '1995-12-19 12:15:54'}" }, 146 { "TIMESTAMPDIFF", "SQL_TSI_DAY", "{ts '1995-12-19 12:15:54'}", "{ts '1997-11-02 00:15:23'}" }, 147 { "WEEK", "{d '1995-12-19'}" }, 148 { "YEAR", "{d '1995-12-19'}" }, 149 150 }; 151 152 private static final String [][] SYSTEM_FUNCTIONS = 153 { 154 { "DATABASE" }, 156 { "IFNULL", "'this'", "'that'" }, 157 { "USER"}, 158 }; 159 160 private static final String [][] STRING_FUNCTIONS = 161 { 162 { "ASCII" , "'Yellow'" }, 164 { "CHAR", "65" }, 165 { "CONCAT", "'hello'", "'there'" }, 166 { "DIFFERENCE", "'Pires'", "'Piers'" }, 167 { "INSERT", "'Bill Clinton'", "4", "'William'" }, 168 { "LCASE", "'Fernando Alonso'" }, 169 { "LEFT", "'Bonjour'", "3" }, 170 { "LENGTH", "'four '" } , 171 { "LOCATE", "'jour'", "'Bonjour'" }, 172 { "LTRIM", "' left trim '"}, 173 { "REPEAT", "'echo'", "3" }, 174 { "REPLACE", "'to be or not to be'", "'be'", "'England'" }, 175 { "RTRIM", "' right trim '"}, 176 { "SOUNDEX", "'Derby'" }, 177 { "SPACE", "12"}, 178 { "SUBSTRING", "'Ruby the Rubicon Jeep'", "10", "7", }, 179 { "UCASE", "'Fernando Alonso'" } 180 }; 181 182 public void runTest() { 183 184 DatabaseMetaData met; 185 ResultSet rs; 186 ResultSetMetaData rsmet; 187 188 System.out.println("Test metadata starting"); 189 190 try 191 { 192 cleanUp(s); 194 195 s.execute("create table t (i int, s smallint, r real, "+ 198 "d double precision, dt date, t time, ts timestamp, "+ 199 "c char(10), v varchar(40) not null, dc dec(10,2))"); 200 s.execute("insert into t values(1,2,3.3,4.4,date('1990-05-05'),"+ 201 "time('12:06:06'),timestamp('1990-07-07 07:07:07.07'),"+ 202 "'eight','nine', 11.1)"); 203 204 rs = s.executeQuery("select dc from t where dc = 11.1 union select dc from t where i = 1"); 208 rsmet = rs.getMetaData(); 209 metadata_test.showNumericMetaData("Union Result", rsmet, 1); 210 rs.close(); 211 212 rs = s.executeQuery("select dc, r, d, r+dc, d-dc, dc-d from t"); 213 rsmet = rs.getMetaData(); 214 metadata_test.showNumericMetaData("dec(10,2)", rsmet, 1); 215 metadata_test.showNumericMetaData("real", rsmet, 2); 216 metadata_test.showNumericMetaData("double", rsmet, 3); 217 metadata_test.showNumericMetaData("real + dec(10,2)", rsmet, 4); 218 metadata_test.showNumericMetaData("double precision - dec(10,2)", rsmet, 5); 219 metadata_test.showNumericMetaData("dec(10,2) - double precision", rsmet, 6); 220 221 while (rs.next()) 222 System.out.println("result row: " + rs.getString(1) + " " 223 + rs.getString(2) + " " + rs.getString(3) 224 + " " + rs.getString(4) + " " + rs.getString(5) 225 + " " + rs.getString(6) 226 ); 227 rs.close(); 228 229 rsmet = s.executeQuery("VALUES CAST (0.0 AS DECIMAL(10,0))").getMetaData(); 230 metadata_test.showNumericMetaData("DECIMAL(10,0)", rsmet, 1); 231 232 rsmet = s.executeQuery("VALUES CAST (0.0 AS DECIMAL(10,10))").getMetaData(); 233 metadata_test.showNumericMetaData("DECIMAL(10,10)", rsmet, 1); 234 235 rsmet = s.executeQuery("VALUES CAST (0.0 AS DECIMAL(10,2))").getMetaData(); 236 metadata_test.showNumericMetaData("DECIMAL(10,2)", rsmet, 1); 237 238 s.execute("insert into t values(1,2,3.3,4.4,date('1990-05-05'),"+ 239 "time('12:06:06'),timestamp('1990-07-07 07:07:07.07'),"+ 240 "'eight','nine', 11.11)"); 241 242 rs = s.executeQuery("select dc / 2 from t"); 245 rsmet = rs.getMetaData(); 246 System.out.println("Column result scale after division is: " + rsmet.getScale(1)); 247 while (rs.next()) 248 System.out.println("dc / 2 = " + rs.getString(1)); 249 rs.close(); 250 251 252 s.execute("create table louie (i int not null default 10, s smallint not null, " + 253 "c30 char(30) not null, " + 254 "vc10 varchar(10) not null default 'asdf', " + 255 "constraint PRIMKEY primary key(vc10, i), " + 256 "constraint UNIQUEKEY unique(c30, s), " + 257 "ai bigint generated always as identity (start with -10, increment by 2001))"); 258 259 s.execute("create unique index u1 on louie(s, i)"); 261 s.execute("create index u2 on louie(s)"); 263 s.execute("create view screwie as select * from louie"); 265 266 s.execute("create table reftab (vc10 varchar(10), i int, " + 268 "s smallint, c30 char(30), " + 269 "s2 smallint, c302 char(30), " + 270 "dprim decimal(5,1) not null, dfor decimal(5,1) not null, "+ 271 "constraint PKEY_REFTAB primary key (dprim), " + 272 "constraint FKEYSELF foreign key (dfor) references reftab, "+ 273 "constraint FKEY1 foreign key(vc10, i) references louie, " + 274 "constraint FKEY2 foreign key(c30, s2) references louie (c30, s), "+ 275 "constraint FKEY3 foreign key(c30, s) references louie (c30, s))"); 276 277 s.execute("create table reftab2 (t2_vc10 varchar(10), t2_i int, " + 278 "constraint T2_FKEY1 foreign key(t2_vc10, t2_i) references louie)"); 279 280 s.execute("create table alltypes ( "+ 282 "smallintcol smallint, "+ 286 "intcol int default 20, "+ 287 "bigintcol bigint, "+ 288 "realcol real, "+ 289 "doublepreccol double precision default 10, "+ 290 "floatcol float default 8.8, "+ 291 "decimalcol10p4s decimal(10,4), "+ 292 "numericcol20p2s numeric(20,2), "+ 293 "char8col___ char(8), "+ 294 "char8forbitcol___ char(8) for bit data, "+ 295 "varchar9col varchar(9), "+ 296 "varchar9bitcol varchar(9) for bit data, "+ 297 "longvarcharcol long varchar,"+ 298 "longvarbinarycol long varchar for bit data, "+ 299 "blobcol blob(3K), "+ 304 "clobcol clob(3K), "+ 305 "datecol date, "+ 306 "timecol time, "+ 307 "tscol timestamp" 308 + ")" ); 309 s.execute("CREATE TABLE INFLIGHT(FLT_NUM CHAR(20) NOT NULL," + 311 "FLT_ORIGIN CHAR(6), " + 312 "FLT_DEST CHAR(6), " + 313 "FLT_AIRCRAFT CHAR(20), " + 314 "FLT_FLYING_TIME VARCHAR(22), "+ 315 "FLT_DEPT_TIME CHAR(8), "+ 316 "FLT_ARR_TIME CHAR(8), "+ 317 "FLT_NOTES VARCHAR(510), "+ 318 "FLT_DAYS_OF_WK CHAR(14), "+ 319 "FLT_CRAFT_PIC VARCHAR(32672), "+ 320 "PRIMARY KEY(FLT_NUM))"); 321 322 s.execute("create procedure GETPCTEST1 (" + 325 "out outb VARCHAR(3), a VARCHAR(3), b NUMERIC, c SMALLINT, " + 327 "e SMALLINT, f INTEGER, g BIGINT, h FLOAT, i DOUBLE PRECISION, " + 328 "k DATE, l TIME, T TIMESTAMP )"+ 329 "language java external name " + 330 "'org.apache.derbyTesting.functionTests.tests.jdbcapi.metadata.getpc'" + 331 " parameter style java"); 332 s.execute("create procedure GETPCTEST2 (pa INTEGER, pb BIGINT)"+ 333 "language java external name " + 334 "'org.apache.derbyTesting.functionTests.tests.jdbcapi.metadata.getpc'" + 335 " parameter style java"); 336 s.execute("create procedure GETPCTEST3A (STRING1 VARCHAR(5), out STRING2 VARCHAR(5))"+ 337 "language java external name " + 338 "'org.apache.derbyTesting.functionTests.tests.jdbcapi.metadata.getpc'" + 339 " parameter style java"); 340 s.execute("create procedure GETPCTEST3B (in STRING3 VARCHAR(5), inout STRING4 VARCHAR(5))"+ 341 "language java external name " + 342 "'org.apache.derbyTesting.functionTests.tests.jdbcapi.metadata.getpc'" + 343 " parameter style java"); 344 s.execute("create procedure GETPCTEST4A() "+ 345 "language java external name " + 346 "'org.apache.derbyTesting.functionTests.tests.jdbcapi.metadata.getpc4a'"+ 347 " parameter style java"); 348 s.execute("create procedure GETPCTEST4B() "+ 349 "language java external name " + 350 "'org.apache.derbyTesting.functionTests.tests.jdbcapi.metadata.getpc4b'" + 351 " parameter style java"); 352 s.execute("create procedure GETPCTEST4Bx(out retparam INTEGER) "+ 353 "language java external name " + 354 "'org.apache.derbyTesting.functionTests.tests.jdbcapi.metadata.getpc4b'" + 355 " parameter style java"); 356 357 s.execute("CREATE FUNCTION DUMMY1 ( X SMALLINT ) "+ 360 "RETURNS SMALLINT PARAMETER STYLE JAVA "+ 361 "NO SQL LANGUAGE JAVA EXTERNAL "+ 362 "NAME 'java.some.func'"); 363 s.execute("CREATE FUNCTION DUMMY2 ( X INTEGER, Y "+ 364 "SMALLINT ) RETURNS INTEGER PARAMETER STYLE"+ 365 " JAVA NO SQL LANGUAGE JAVA "+ 366 "EXTERNAL NAME 'java.some.func'"); 367 s.execute("CREATE FUNCTION DUMMY3 ( X VARCHAR(16), "+ 368 "Y INTEGER ) RETURNS VARCHAR(16) PARAMETER"+ 369 " STYLE JAVA NO SQL LANGUAGE"+ 370 " JAVA EXTERNAL NAME 'java.some.func'"); 371 s.execute("CREATE FUNCTION DUMMY4 ( X VARCHAR(128), "+ 372 "Y INTEGER ) RETURNS INTEGER PARAMETER "+ 373 "STYLE JAVA NO SQL LANGUAGE "+ 374 "JAVA EXTERNAL NAME 'java.some.func'"); 375 376 met = con.getMetaData(); 377 378 System.out.println("JDBC Driver '" + met.getDriverName() + 379 "', version " + met.getDriverMajorVersion() + 380 "." + met.getDriverMinorVersion() + 381 " (" + met.getDriverVersion() + ")"); 382 383 boolean pass = false; 384 try { 385 pass = TestUtil.compareURL(met.getURL()); 386 }catch (NoSuchMethodError msme) { 387 if(!TestUtil.HAVE_DRIVER_CLASS) 389 pass = true; 390 } catch (Throwable err) { 391 System.out.println("%%getURL() gave the exception: " + err); 392 } 393 394 if(pass) 395 System.out.println("DatabaseMetaData.getURL test passed"); 396 else 397 System.out.println("FAIL: DatabaseMetaData.getURL test failed"); 398 399 System.out.println("allTablesAreSelectable(): " + 400 met.allTablesAreSelectable()); 401 402 System.out.println("maxColumnNameLength(): " + met.getMaxColumnNameLength()); 403 404 System.out.println(); 405 System.out.println("getSchemas():"); 406 dumpRS(met.getSchemas()); 407 408 testGetSchemasWithTwoParams(met); 409 410 System.out.println(); 411 System.out.println("getCatalogs():"); 412 dumpRS(met.getCatalogs()); 413 414 System.out.println("getSearchStringEscape(): " + 415 met.getSearchStringEscape()); 416 417 System.out.println("getSQLKeywords(): " + 418 met.getSQLKeywords()); 419 420 System.out.println("getDefaultTransactionIsolation(): " + 421 met.getDefaultTransactionIsolation()); 422 423 System.out.println("getProcedures():"); 424 dumpRS(GET_PROCEDURES, getMetaDataRS(met, GET_PROCEDURES, 425 new String [] {null, "%", "GETPCTEST%"}, 426 null, null, null)); 427 428 try { 431 Class s = "".getClass(); 432 433 java.lang.reflect.Method gf = 435 met.getClass().getMethod("getFunctions", 436 new Class [] { s, s, s }); 437 if (!java.lang.reflect.Modifier.isAbstract(gf.getModifiers())){ 438 System.out.println("getFunctions(null,null,null):"); 440 dumpRS(IGNORE_PROC_ID, (ResultSet )gf. 441 invoke(met, new String [] {null, null, null})); 442 443 System.out.println("getFunctions(\"Dummy Catalog\",null,"+ 447 "null):"); 448 dumpRS(IGNORE_PROC_ID, (ResultSet )gf. 449 invoke(met, new String [] {"Dummy Catalog", 450 null, null})); 451 452 System.out.println("getFunctions(null,\"%SYS%\",null):"); 454 dumpRS(IGNORE_PROC_ID, (ResultSet )gf. 455 invoke(met, new String [] {null, "SYS%", null})); 456 457 System.out.println("getFunctions(null,null,\"%GET%\"):"); 460 dumpRS(IGNORE_PROC_ID, (ResultSet )gf. 461 invoke(met, new String [] {null, null, "%GET%"})); 462 463 System.out.println("getFunctions(\"\",\"\",null):"); 466 dumpRS(IGNORE_PROC_ID, (ResultSet )gf. 467 invoke(met, new String [] {"", "", null})); 468 469 } 470 471 java.lang.reflect.Method gfp = 473 met.getClass().getMethod("getFunctionColumns", 474 new Class [] { s, s, s, s }); 475 476 if (!java.lang.reflect.Modifier. 477 isAbstract(gfp.getModifiers())){ 478 System.out.println("getFunctionColumns(null,"+ 479 "null,null,null):"); 480 dumpRS(IGNORE_PROC_ID, (ResultSet )gfp. 481 invoke(met, 482 new String [] {null, null, null, null})); 483 484 System.out.println("getFunctionColumns(null,\"APP\","+ 485 "\"DUMMY%\",\"X\"):"); 486 dumpRS(IGNORE_PROC_ID, (ResultSet )gfp. 487 invoke(met, 488 new String [] {null, "APP", "DUMMY%", "X"})); 489 490 System.out.println("getFunctionColumns(null,\"APP\","+ 491 "\"DUMMY%\",\"\"):"); 492 dumpRS(IGNORE_PROC_ID, (ResultSet )gfp. 493 invoke(met, 494 new String [] {null, "APP", "DUMMY%", ""})); 495 496 } 497 } 498 catch (NoSuchMethodException e) { 499 if (org.apache.derby.iapi.services.info.JVMInfo.JDK_ID >= 500 org.apache.derby.iapi.services.info.JVMInfo.J2SE_16) { 501 e.printStackTrace(); 502 } 503 } 504 catch (Exception e) { e.printStackTrace(); } 505 506 System.out.println("getUDTs() with user-named types null :"); 507 dumpRS(met.getUDTs(null, null, null, null)); 508 509 System.out.println("getUDTs() with user-named types in ('JAVA_OBJECT') :"); 510 int[] userNamedTypes = new int[1]; 511 userNamedTypes[0] = java.sql.Types.JAVA_OBJECT; 512 dumpRS(met.getUDTs("a", null, null, userNamedTypes)); 513 514 System.out.println("getUDTs() with user-named types in ('STRUCT') :"); 515 userNamedTypes[0] = java.sql.Types.STRUCT; 516 dumpRS(met.getUDTs("b", null, null, userNamedTypes)); 517 518 System.out.println("getUDTs() with user-named types in ('DISTINCT') :"); 519 userNamedTypes[0] = java.sql.Types.DISTINCT; 520 dumpRS(met.getUDTs("c", null, null, userNamedTypes)); 521 522 System.out.println("getUDTs() with user-named types in ('JAVA_OBJECT', 'STRUCT') :"); 523 userNamedTypes = new int[2]; 524 userNamedTypes[0] = java.sql.Types.JAVA_OBJECT; 525 userNamedTypes[1] = java.sql.Types.STRUCT; 526 dumpRS(met.getUDTs("a", null, null, userNamedTypes)); 527 528 testGetClientInfoProperties(met); 529 530 534 535 536 System.out.println("allProceduresAreCallable(): " + 537 met.allProceduresAreCallable()); 538 System.out.println("getUserName(): " + 539 met.getUserName()); 540 System.out.println("isReadOnly(): " + 541 met.isReadOnly()); 542 System.out.println("nullsAreSortedHigh(): " + 543 met.nullsAreSortedHigh()); 544 System.out.println("nullsAreSortedLow(): " + 545 met.nullsAreSortedLow()); 546 System.out.println("nullsAreSortedAtStart(): " + 547 met.nullsAreSortedAtStart()); 548 System.out.println("nullsAreSortedAtEnd(): " + 549 met.nullsAreSortedAtEnd()); 550 551 552 System.out.println("getDatabaseProductName(): " + met.getDatabaseProductName()); 553 554 String v = met.getDatabaseProductVersion(); 555 System.out.println("getDatabaseProductVersion(): " + v); 556 System.out.println("getDriverVersion(): " + 557 met.getDriverVersion()); 558 System.out.println("usesLocalFiles(): " + 559 met.usesLocalFiles()); 560 System.out.println("usesLocalFilePerTable(): " + 561 met.usesLocalFilePerTable()); 562 System.out.println("supportsMixedCaseIdentifiers(): " + 563 met.supportsMixedCaseIdentifiers()); 564 System.out.println("storesUpperCaseIdentifiers(): " + 565 met.storesUpperCaseIdentifiers()); 566 System.out.println("storesLowerCaseIdentifiers(): " + 567 met.storesLowerCaseIdentifiers()); 568 System.out.println("storesMixedCaseIdentifiers(): " + 569 met.storesMixedCaseIdentifiers()); 570 System.out.println("supportsMixedCaseQuotedIdentifiers(): " + 571 met.supportsMixedCaseQuotedIdentifiers()); 572 System.out.println("storesUpperCaseQuotedIdentifiers(): " + 573 met.storesUpperCaseQuotedIdentifiers()); 574 System.out.println("storesLowerCaseQuotedIdentifiers(): " + 575 met.storesLowerCaseQuotedIdentifiers()); 576 System.out.println("storesMixedCaseQuotedIdentifiers(): " + 577 met.storesMixedCaseQuotedIdentifiers()); 578 System.out.println("getIdentifierQuoteString(): " + 579 met.getIdentifierQuoteString()); 580 System.out.println("getNumericFunctions(): " + 581 met.getNumericFunctions()); 582 System.out.println("getStringFunctions(): " + 583 met.getStringFunctions()); 584 System.out.println("getSystemFunctions(): " + 585 met.getSystemFunctions()); 586 System.out.println("getTimeDateFunctions(): " + 587 met.getTimeDateFunctions()); 588 System.out.println("getExtraNameCharacters(): " + 589 met.getExtraNameCharacters()); 590 System.out.println("supportsAlterTableWithAddColumn(): " + 591 met.supportsAlterTableWithAddColumn()); 592 System.out.println("supportsAlterTableWithDropColumn(): " + 593 met.supportsAlterTableWithDropColumn()); 594 System.out.println("supportsColumnAliasing(): " + 595 met.supportsColumnAliasing()); 596 System.out.println("nullPlusNonNullIsNull(): " + 597 met.nullPlusNonNullIsNull()); 598 System.out.println("supportsConvert(): " + 599 met.supportsConvert()); 600 System.out.println("supportsConvert(Types.INTEGER, Types.SMALLINT): " + 601 met.supportsConvert(Types.INTEGER, Types.SMALLINT)); 602 System.out.println("supportsTableCorrelationNames(): " + 603 met.supportsTableCorrelationNames()); 604 System.out.println("supportsDifferentTableCorrelationNames(): " + 605 met.supportsDifferentTableCorrelationNames()); 606 System.out.println("supportsExpressionsInOrderBy(): " + 607 met.supportsExpressionsInOrderBy()); 608 System.out.println("supportsOrderByUnrelated(): " + 609 met.supportsOrderByUnrelated()); 610 System.out.println("supportsGroupBy(): " + 611 met.supportsGroupBy()); 612 System.out.println("supportsGroupByUnrelated(): " + 613 met.supportsGroupByUnrelated()); 614 System.out.println("supportsGroupByBeyondSelect(): " + 615 met.supportsGroupByBeyondSelect()); 616 System.out.println("supportsLikeEscapeClause(): " + 617 met.supportsLikeEscapeClause()); 618 System.out.println("supportsMultipleResultSets(): " + 619 met.supportsMultipleResultSets()); 620 System.out.println("supportsMultipleTransactions(): " + 621 met.supportsMultipleTransactions()); 622 System.out.println("supportsNonNullableColumns(): " + 623 met.supportsNonNullableColumns()); 624 System.out.println("supportsMinimumSQLGrammar(): " + 625 met.supportsMinimumSQLGrammar()); 626 System.out.println("supportsCoreSQLGrammar(): " + 627 met.supportsCoreSQLGrammar()); 628 System.out.println("supportsExtendedSQLGrammar(): " + 629 met.supportsExtendedSQLGrammar()); 630 System.out.println("supportsANSI92EntryLevelSQL(): " + 631 met.supportsANSI92EntryLevelSQL()); 632 System.out.println("supportsANSI92IntermediateSQL(): " + 633 met.supportsANSI92IntermediateSQL()); 634 System.out.println("supportsANSI92FullSQL(): " + 635 met.supportsANSI92FullSQL()); 636 System.out.println("supportsIntegrityEnhancementFacility(): " + 637 met.supportsIntegrityEnhancementFacility()); 638 System.out.println("supportsOuterJoins(): " + 639 met.supportsOuterJoins()); 640 System.out.println("supportsFullOuterJoins(): " + 641 met.supportsFullOuterJoins()); 642 System.out.println("supportsLimitedOuterJoins(): " + 643 met.supportsLimitedOuterJoins()); 644 System.out.println("getSchemaTerm(): " + 645 met.getSchemaTerm()); 646 System.out.println("getProcedureTerm(): " + 647 met.getProcedureTerm()); 648 System.out.println("getCatalogTerm(): " + 649 met.getCatalogTerm()); 650 System.out.println("isCatalogAtStart(): " + 651 met.isCatalogAtStart()); 652 System.out.println("getCatalogSeparator(): " + 653 met.getCatalogSeparator()); 654 System.out.println("supportsSchemasInDataManipulation(): " + 655 met.supportsSchemasInDataManipulation()); 656 System.out.println("supportsSchemasInProcedureCalls(): " + 657 met.supportsSchemasInProcedureCalls()); 658 System.out.println("supportsSchemasInTableDefinitions(): " + 659 met.supportsSchemasInTableDefinitions()); 660 System.out.println("supportsSchemasInIndexDefinitions(): " + 661 met.supportsSchemasInIndexDefinitions()); 662 System.out.println("supportsSchemasInPrivilegeDefinitions(): " + 663 met.supportsSchemasInPrivilegeDefinitions()); 664 System.out.println("supportsCatalogsInDataManipulation(): " + 665 met.supportsCatalogsInDataManipulation()); 666 System.out.println("supportsCatalogsInProcedureCalls(): " + 667 met.supportsCatalogsInProcedureCalls()); 668 System.out.println("supportsCatalogsInTableDefinitions(): " + 669 met.supportsCatalogsInTableDefinitions()); 670 System.out.println("supportsCatalogsInIndexDefinitions(): " + 671 met.supportsCatalogsInIndexDefinitions()); 672 System.out.println("supportsCatalogsInPrivilegeDefinitions(): " + 673 met.supportsCatalogsInPrivilegeDefinitions()); 674 System.out.println("supportsPositionedDelete(): " + 675 met.supportsPositionedDelete()); 676 System.out.println("supportsPositionedUpdate(): " + 677 met.supportsPositionedUpdate()); 678 System.out.println("supportsSelectForUpdate(): " + 679 met.supportsSelectForUpdate()); 680 System.out.println("supportsStoredProcedures(): " + 681 met.supportsStoredProcedures()); 682 System.out.println("supportsSubqueriesInComparisons(): " + 683 met.supportsSubqueriesInComparisons()); 684 System.out.println("supportsSubqueriesInExists(): " + 685 met.supportsSubqueriesInExists()); 686 System.out.println("supportsSubqueriesInIns(): " + 687 met.supportsSubqueriesInIns()); 688 System.out.println("supportsSubqueriesInQuantifieds(): " + 689 met.supportsSubqueriesInQuantifieds()); 690 System.out.println("supportsCorrelatedSubqueries(): " + 691 met.supportsCorrelatedSubqueries()); 692 System.out.println("supportsUnion(): " + 693 met.supportsUnion()); 694 System.out.println("supportsUnionAll(): " + 695 met.supportsUnionAll()); 696 System.out.println("supportsOpenCursorsAcrossCommit(): " + 697 met.supportsOpenCursorsAcrossCommit()); 698 System.out.println("supportsOpenCursorsAcrossRollback(): " + 699 met.supportsOpenCursorsAcrossRollback()); 700 System.out.println("supportsOpenStatementsAcrossCommit(): " + 701 met.supportsOpenStatementsAcrossCommit()); 702 System.out.println("supportsOpenStatementsAcrossRollback(): " + 703 met.supportsOpenStatementsAcrossRollback()); 704 System.out.println("getMaxBinaryLiteralLength(): " + 705 met.getMaxBinaryLiteralLength()); 706 System.out.println("getMaxCharLiteralLength(): " + 707 met.getMaxCharLiteralLength()); 708 System.out.println("getMaxColumnsInGroupBy(): " + 709 met.getMaxColumnsInGroupBy()); 710 System.out.println("getMaxColumnsInIndex(): " + 711 met.getMaxColumnsInIndex()); 712 System.out.println("getMaxColumnsInOrderBy(): " + 713 met.getMaxColumnsInOrderBy()); 714 System.out.println("getMaxColumnsInSelect(): " + 715 met.getMaxColumnsInSelect()); 716 System.out.println("getMaxColumnsInTable(): " + 717 met.getMaxColumnsInTable()); 718 System.out.println("getMaxConnections(): " + 719 met.getMaxConnections()); 720 System.out.println("getMaxCursorNameLength(): " + 721 met.getMaxCursorNameLength()); 722 System.out.println("getMaxIndexLength(): " + 723 met.getMaxIndexLength()); 724 System.out.println("getMaxSchemaNameLength(): " + 725 met.getMaxSchemaNameLength()); 726 System.out.println("getMaxProcedureNameLength(): " + 727 met.getMaxProcedureNameLength()); 728 System.out.println("getMaxCatalogNameLength(): " + 729 met.getMaxCatalogNameLength()); 730 System.out.println("getMaxRowSize(): " + 731 met.getMaxRowSize()); 732 System.out.println("doesMaxRowSizeIncludeBlobs(): " + 733 met.doesMaxRowSizeIncludeBlobs()); 734 System.out.println("getMaxStatementLength(): " + 735 met.getMaxStatementLength()); 736 System.out.println("getMaxStatements(): " + 737 met.getMaxStatements()); 738 System.out.println("getMaxTableNameLength(): " + 739 met.getMaxTableNameLength()); 740 System.out.println("getMaxTablesInSelect(): " + 741 met.getMaxTablesInSelect()); 742 System.out.println("getMaxUserNameLength(): " + 743 met.getMaxUserNameLength()); 744 System.out.println("supportsTransactions(): " + 745 met.supportsTransactions()); 746 System.out.println("supportsTransactionIsolationLevel(Connection.TRANSACTION_NONE): " + 747 met.supportsTransactionIsolationLevel(Connection.TRANSACTION_NONE)); 748 System.out.println("supportsTransactionIsolationLevel(Connection.TRANSACTION_REPEATABLE_READ): " + 749 met.supportsTransactionIsolationLevel(Connection.TRANSACTION_REPEATABLE_READ)); 750 System.out.println("supportsTransactionIsolationLevel(Connection.TRANSACTION_SERIALIZABLE): " + 751 met.supportsTransactionIsolationLevel(Connection.TRANSACTION_SERIALIZABLE)); 752 System.out.println("supportsDataDefinitionAndDataManipulationTransactions(): " + 753 met.supportsDataDefinitionAndDataManipulationTransactions()); 754 System.out.println("supportsDataManipulationTransactionsOnly(): " + 755 met.supportsDataManipulationTransactionsOnly()); 756 System.out.println("dataDefinitionCausesTransactionCommit(): " + 757 met.dataDefinitionCausesTransactionCommit()); 758 System.out.println("dataDefinitionIgnoredInTransactions(): " + 759 met.dataDefinitionIgnoredInTransactions()); 760 761 System.out.println("Test the metadata calls related to visibility of changes made by others for different resultset types"); 762 System.out.println("Since Derby materializes a forward only ResultSet incrementally, it is possible to see changes"); 763 System.out.println("made by others and hence following 3 metadata calls will return true for forward only ResultSets."); 764 System.out.println("othersUpdatesAreVisible(ResultSet.TYPE_FORWARD_ONLY)? " + met.othersUpdatesAreVisible(ResultSet.TYPE_FORWARD_ONLY)); 765 System.out.println("othersDeletesAreVisible(ResultSet.TYPE_FORWARD_ONLY)? " + met.othersDeletesAreVisible(ResultSet.TYPE_FORWARD_ONLY)); 766 System.out.println("othersInsertsAreVisible(ResultSet.TYPE_FORWARD_ONLY)? " + met.othersInsertsAreVisible(ResultSet.TYPE_FORWARD_ONLY)); 767 System.out.println("Scroll insensitive ResultSet by their definition do not see changes made by others and hence following metadata calls return false"); 768 System.out.println("othersUpdatesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)? " + met.othersUpdatesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)); 769 System.out.println("othersDeletesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)? " + met.othersDeletesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)); 770 System.out.println("othersInsertsAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)? " + met.othersInsertsAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)); 771 System.out.println("Derby does not yet implement scroll sensitive resultsets and hence following metadata calls return false"); 772 System.out.println("othersUpdatesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)? " + met.othersUpdatesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)); 773 System.out.println("othersDeletesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)? " + met.othersDeletesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)); 774 System.out.println("othersInsertsAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)? " + met.othersInsertsAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)); 775 776 System.out.println("Test the metadata calls related to visibility of *own* changes for different resultset types"); 777 System.out.println("ownUpdatesAreVisible(ResultSet.TYPE_FORWARD_ONLY)? " + met.ownUpdatesAreVisible(ResultSet.TYPE_FORWARD_ONLY)); 778 System.out.println("ownDeletesAreVisible(ResultSet.TYPE_FORWARD_ONLY)? " + met.ownDeletesAreVisible(ResultSet.TYPE_FORWARD_ONLY)); 779 System.out.println("ownInsertsAreVisible(ResultSet.TYPE_FORWARD_ONLY)? " + met.ownInsertsAreVisible(ResultSet.TYPE_FORWARD_ONLY)); 780 System.out.println("Scroll insensitive ResultSet see updates and deletes, but not inserts"); 781 System.out.println("ownUpdatesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)? " + met.ownUpdatesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)); 782 System.out.println("ownDeletesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)? " + met.ownDeletesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)); 783 System.out.println("ownInsertsAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)? " + met.ownInsertsAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)); 784 System.out.println("Derby does not yet implement scroll sensitive resultsets and hence following metadata calls return false"); 785 System.out.println("ownUpdatesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)? " + met.ownUpdatesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)); 786 System.out.println("ownDeletesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)? " + met.ownDeletesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)); 787 System.out.println("ownInsertsAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)? " + met.othersInsertsAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)); 788 789 System.out.println("Test the metadata calls related to detectability of visible changes for different resultset types"); 790 System.out.println("Expect true for updates and deletes of TYPE_SCROLL_INSENSITIVE, all others should be false"); 791 System.out.println("updatesAreDetected(ResultSet.TYPE_FORWARD_ONLY)? " + met.updatesAreDetected(ResultSet.TYPE_FORWARD_ONLY)); 792 System.out.println("deletesAreDetected(ResultSet.TYPE_FORWARD_ONLY)? " + met.deletesAreDetected(ResultSet.TYPE_FORWARD_ONLY)); 793 System.out.println("insertsAreDetected(ResultSet.TYPE_FORWARD_ONLY)? " + met.insertsAreDetected(ResultSet.TYPE_FORWARD_ONLY)); 794 System.out.println("updatesAreDetected(ResultSet.TYPE_SCROLL_INSENSITIVE)? " + met.updatesAreDetected(ResultSet.TYPE_SCROLL_INSENSITIVE)); 795 System.out.println("deletesAreDetected(ResultSet.TYPE_SCROLL_INSENSITIVE)? " + met.deletesAreDetected(ResultSet.TYPE_SCROLL_INSENSITIVE)); 796 System.out.println("insertsAreDetected(ResultSet.TYPE_SCROLL_INSENSITIVE)? " + met.insertsAreDetected(ResultSet.TYPE_SCROLL_INSENSITIVE)); 797 System.out.println("updatesAreDetected(ResultSet.TYPE_SCROLL_SENSITIVE)? " + met.updatesAreDetected(ResultSet.TYPE_SCROLL_SENSITIVE)); 798 System.out.println("deletesAreDetected(ResultSet.TYPE_SCROLL_SENSITIVE)? " + met.deletesAreDetected(ResultSet.TYPE_SCROLL_SENSITIVE)); 799 System.out.println("insertsAreDetected(ResultSet.TYPE_SCROLL_SENSITIVE)? " + met.insertsAreDetected(ResultSet.TYPE_SCROLL_SENSITIVE)); 800 801 if (!TestUtil.isJCCFramework()) { int[] types = {ResultSet.TYPE_FORWARD_ONLY, 803 ResultSet.TYPE_SCROLL_INSENSITIVE, 804 ResultSet.TYPE_SCROLL_SENSITIVE}; 805 806 int[] conc = {ResultSet.CONCUR_READ_ONLY, 807 ResultSet.CONCUR_UPDATABLE}; 808 809 String [] typesStr = {"TYPE_FORWARD_ONLY", 810 "TYPE_SCROLL_INSENSITIVE", 811 "TYPE_SCROLL_SENSITIVE"}; 812 813 String [] concStr = {"CONCUR_READ_ONLY", 814 "CONCUR_UPDATABLE"}; 815 816 for (int i = 0; i < types.length ; i++) { 817 for (int j = 0; j < conc.length; j++) { 818 System.out.println 819 ("SupportsResultSetConcurrency: " + 820 typesStr[i] + "," + concStr[j] + ": " + 821 met.supportsResultSetConcurrency(types[i], 822 conc[j])); 823 } 824 } 825 } 826 827 System.out.println("getConnection(): "+ 828 ((met.getConnection()==con)?"same connection":"different connection") ); 829 System.out.println("getProcedureColumns():"); 830 dumpRS(GET_PROCEDURE_COLUMNS, getMetaDataRS(met, GET_PROCEDURE_COLUMNS, 831 new String [] {null, "%", "GETPCTEST%", "%"}, 832 null, null, null)); 833 834 System.out.println("getTables() with TABLE_TYPE in ('SYSTEM TABLE') :"); 835 String [] tabTypes = new String [1]; 836 tabTypes[0] = "SYSTEM TABLE"; 837 dumpRS(GET_TABLES, getMetaDataRS(met, GET_TABLES, 838 new String [] {null, null, null}, 839 tabTypes, null, null)); 840 841 System.out.println("getTables() with no types:"); 842 dumpRS(GET_TABLES, getMetaDataRS(met, GET_TABLES, 843 new String [] {"", null, "%"}, 844 null, null, null)); 845 846 System.out.println("getTables() with TABLE_TYPE in ('VIEW','TABLE') :"); 847 tabTypes = new String [2]; 848 tabTypes[0] = "VIEW"; 849 tabTypes[1] = "TABLE"; 850 dumpRS(GET_TABLES, getMetaDataRS(met, GET_TABLES, 851 new String [] {null, null, null}, 852 tabTypes, null, null)); 853 854 855 System.out.println("getTableTypes():"); 856 dumpRS(met.getTableTypes()); 857 858 System.out.println("getColumns():"); 859 dumpRS(GET_COLUMNS, getMetaDataRS(met, GET_COLUMNS, 860 new String [] {"", null, "", ""}, 861 null, null, null)); 862 863 System.out.println("getColumns('SYSTABLES'):"); 864 dumpRS(GET_COLUMNS, getMetaDataRS(met, GET_COLUMNS, 865 new String [] {"", "SYS", "SYSTABLES", null}, 866 null, null, null)); 867 868 System.out.println("getColumns('ALLTYPES'):"); 869 dumpRS(GET_COLUMNS, getMetaDataRS(met, GET_COLUMNS, 870 new String [] {"", "APP", "ALLTYPES", null}, 871 null, null, null)); 872 873 System.out.println("getColumns('LOUIE'):"); 874 dumpRS(GET_COLUMNS, getMetaDataRS(met, GET_COLUMNS, 875 new String [] {"", "APP", "LOUIE", null}, 876 null, null, null)); 877 878 System.out.println("getColumns('INFLIGHT'):"); 880 dumpRS(GET_COLUMNS, getMetaDataRS(met, GET_COLUMNS, 881 new String [] {"", "APP", "INFLIGHT", null}, 882 null, null, null)); 883 884 System.out.println("getColumnPrivileges():"); 885 dumpRS(GET_COLUMN_PRIVILEGES, getMetaDataRS(met, GET_COLUMN_PRIVILEGES, 886 new String [] {"Huey", "Dewey", "Louie", "Frooey"}, 887 null, null, null)); 888 889 System.out.println("getTablePrivileges():"); 890 dumpRS(GET_TABLE_PRIVILEGES, getMetaDataRS(met, GET_TABLE_PRIVILEGES, 891 new String [] {"Huey", "Dewey", "Louie"}, 892 null, null, null)); 893 894 System.out.println("getBestRowIdentifier(\"\",null,\"LOUIE\"):"); 895 dumpRS(GET_BEST_ROW_IDENTIFIER, getMetaDataRS(met, GET_BEST_ROW_IDENTIFIER, 896 new String [] {"", null, "LOUIE"}, null, 897 new int [] {DatabaseMetaData.bestRowTransaction}, 898 new boolean [] {true})); 899 900 System.out.println("getBestRowIdentifier(\"\",\"SYS\",\"SYSTABLES\"):"); 901 dumpRS(GET_BEST_ROW_IDENTIFIER, getMetaDataRS(met, GET_BEST_ROW_IDENTIFIER, 902 new String [] {"", "SYS", "SYSTABLES"}, null, 903 new int [] {DatabaseMetaData.bestRowTransaction}, 904 new boolean [] {true})); 905 906 System.out.println("getVersionColumns():"); 907 dumpRS(GET_VERSION_COLUMNS, getMetaDataRS(met, GET_VERSION_COLUMNS, 908 new String [] {"Huey", "Dewey", "Louie"}, 909 null, null, null)); 910 911 System.out.println("getPrimaryKeys():"); 912 dumpRS(GET_PRIMARY_KEYS, getMetaDataRS(met, GET_PRIMARY_KEYS, 913 new String [] {"", "%", "LOUIE"}, 914 null, null, null)); 915 916 System.out.println("getPrimaryKeys(null, null, tablename):"); 918 dumpRS(GET_PRIMARY_KEYS, getMetaDataRS(met, GET_PRIMARY_KEYS, 919 new String [] {null, null, "LOUIE"}, 920 null, null, null)); 921 922 System.out.println("getImportedKeys():"); 923 dumpRS(GET_IMPORTED_KEYS, getMetaDataRS(met, GET_IMPORTED_KEYS, 924 new String [] {null, null, "%"}, 925 null, null, null)); 926 927 System.out.println("getExportedKeys():"); 928 dumpRS(GET_EXPORTED_KEYS, getMetaDataRS(met, GET_EXPORTED_KEYS, 929 new String [] {null, null, "%"}, 930 null, null, null)); 931 932 System.out.println("---------------------------------------"); 933 System.out.println("getCrossReference('',null,'louie','',null,'reftab' ):"); 934 dumpRS(GET_CROSS_REFERENCE, getMetaDataRS(met, GET_CROSS_REFERENCE, 935 new String [] {"", null, "LOUIE", "", null, "REFTAB"}, 936 null, null, null)); 937 938 System.out.println("\ngetCrossReference('','APP','reftab','',null,'reftab' ):"); 939 dumpRS(GET_CROSS_REFERENCE, getMetaDataRS(met, GET_CROSS_REFERENCE, 940 new String [] {"", "APP", "REFTAB", "", null, "REFTAB"}, 941 null, null, null)); 942 943 System.out.println("\ngetCrossReference('',null,null,'','APP','reftab' ):"); 944 dumpRS(GET_CROSS_REFERENCE, getMetaDataRS(met, GET_CROSS_REFERENCE, 945 new String [] {"", null, "%", "", "APP", "REFTAB"}, 946 null, null, null)); 947 948 System.out.println("\ngetImportedKeys('',null,null,'','APP','reftab' ):"); 949 dumpRS(GET_IMPORTED_KEYS, getMetaDataRS(met, GET_IMPORTED_KEYS, 950 new String [] {"", "APP", "REFTAB"}, 951 null, null, null)); 952 953 System.out.println("\ngetCrossReference('',null,'louie','','APP',null):"); 954 dumpRS(GET_CROSS_REFERENCE, getMetaDataRS(met, GET_CROSS_REFERENCE, 955 new String [] {"", null, "LOUIE", "", "APP", "%"}, 956 null, null, null)); 957 958 System.out.println("\ngetExportedKeys('',null,'louie,'','APP',null ):"); 959 dumpRS(GET_EXPORTED_KEYS, getMetaDataRS(met, GET_EXPORTED_KEYS, 960 new String [] {"", null, "LOUIE"}, 961 null, null, null)); 962 963 System.out.println("\ngetCrossReference('','badschema','LOUIE','','APP','REFTAB' ):"); 964 dumpRS(GET_CROSS_REFERENCE, getMetaDataRS(met, GET_CROSS_REFERENCE, 965 new String [] {"", "BADSCHEMA", "LOUIE", "", "APP", "REFTAB"}, 966 null, null, null)); 967 968 System.out.println("getTypeInfo():"); 969 dumpRS(GET_TYPE_INFO, getMetaDataRS(met, GET_TYPE_INFO, null, null, null, null)); 970 971 974 System.out.println("getIndexInfo():"); 976 dumpRS(GET_INDEX_INFO, getMetaDataRS(met, GET_INDEX_INFO, 977 new String [] {"", "SYS", "SYSCOLUMNS"}, 978 null, null, new boolean [] {true, false})); 979 980 System.out.println("getIndexInfo():"); 982 dumpRS(GET_INDEX_INFO, getMetaDataRS(met, GET_INDEX_INFO, 983 new String [] {"", "SYS", "SYSCOLUMNS"}, 984 null, null, new boolean [] {false, false})); 985 986 System.out.println("getIndexInfo():"); 987 dumpRS(GET_INDEX_INFO, getMetaDataRS(met, GET_INDEX_INFO, 988 new String [] {"", "SYS", "SYSTABLES"}, 989 null, null, new boolean [] {true, false})); 990 991 rs = s.executeQuery("SELECT * FROM SYS.SYSTABLES"); 992 993 System.out.println("getColumns('SYSTABLES'):"); 994 dumpRS(GET_COLUMNS, getMetaDataRS(met, GET_COLUMNS, 995 new String [] {"", "SYS", "SYSTABLES", null}, 996 null, null, null)); 997 998 try { 999 if (!rs.next()) { 1000 System.out.println("FAIL -- user result set closed by"+ 1001 " intervening getColumns request"); 1002 } 1003 } catch (SQLException se) { 1004 if (this instanceof metadata) { 1005 System.out.println("FAIL -- user result set closed by"+ 1006 " intervening getColumns request"); 1007 } 1008 else { 1009 System.out.println("OK -- user result set closed by"+ 1010 " intervening OBDC getColumns request; this was" + 1011 " expected because of the way the test works."); 1012 } 1013 } 1014 rs.close(); 1015 1016 System.out.println("Test escaped numeric functions - JDBC 3.0 C.1"); 1017 testEscapedFunctions(con, NUMERIC_FUNCTIONS, met.getNumericFunctions()); 1018 1019 System.out.println("Test escaped string functions - JDBC 3.0 C.2"); 1020 testEscapedFunctions(con, STRING_FUNCTIONS, met.getStringFunctions()); 1021 1022 System.out.println("Test escaped date time functions - JDBC 3.0 C.3"); 1023 testEscapedFunctions(con, TIMEDATE_FUNCTIONS, met.getTimeDateFunctions()); 1024 1025 System.out.println("Test escaped system functions - JDBC 3.0 C.4"); 1026 testEscapedFunctions(con, SYSTEM_FUNCTIONS, met.getSystemFunctions()); 1027 1028 System.out.println("---------------------------------------"); 1032 System.out.println("Referential action values"); 1035 System.out.println("RESTRICT = "+ DatabaseMetaData.importedKeyRestrict); 1036 System.out.println("NO ACTION = "+ DatabaseMetaData.importedKeyNoAction); 1037 System.out.println("CASCADE = "+ DatabaseMetaData.importedKeyCascade); 1038 System.out.println("SETNULL = "+ DatabaseMetaData.importedKeySetNull); 1039 System.out.println("SETDEFAULT = "+ DatabaseMetaData.importedKeySetDefault); 1040 s.execute("create table refaction1(a int not null primary key)"); 1041 s.execute("create table refactnone(a int references refaction1(a))"); 1042 s.execute("create table refactrestrict(a int references refaction1(a) on delete restrict)"); 1043 s.execute("create table refactnoaction(a int references refaction1(a) on delete no action)"); 1044 s.execute("create table refactcascade(a int references refaction1(a) on delete cascade)"); 1045 s.execute("create table refactsetnull(a int references refaction1(a) on delete set null)"); 1046 System.out.println("getCrossReference('','APP','REFACTION1','','APP','REFACTIONNONE' ):"); 1047 s.execute("create table refactupdrestrict(a int references refaction1(a) on update restrict)"); 1048 s.execute("create table refactupdnoaction(a int references refaction1(a) on update no action)"); 1049 dumpRS(GET_CROSS_REFERENCE, getMetaDataRS(met, GET_CROSS_REFERENCE, 1050 new String [] {"", "APP", "REFACTION1", "", "APP", "REFACTNONE"}, 1051 null, null, null)); 1052 System.out.println("\ngetCrossReference('','APP','REFACTION1','','APP','REFACTRESTRICT' ):"); 1053 dumpRS(GET_CROSS_REFERENCE, getMetaDataRS(met, GET_CROSS_REFERENCE, 1054 new String [] {"", "APP", "REFACTION1", "", "APP", "REFACTRESTRICT"}, 1055 null, null, null)); 1056 System.out.println("\ngetCrossReference('','APP','REFACTION1','','APP','REFACTNOACTION' ):"); 1057 dumpRS(GET_CROSS_REFERENCE, getMetaDataRS(met, GET_CROSS_REFERENCE, 1058 new String [] {"", "APP", "REFACTION1", "", "APP", "REFACTNOACTION"}, 1059 null, null, null)); 1060 System.out.println("\ngetCrossReference('','APP','REFACTION1','','APP','REFACTCASCADE' ):"); 1061 dumpRS(GET_CROSS_REFERENCE, getMetaDataRS(met, GET_CROSS_REFERENCE, 1062 new String [] {"", "APP", "REFACTION1", "", "APP", "REFACTCASCADE"}, 1063 null, null, null)); 1064 System.out.println("\ngetCrossReference('','APP','REFACTION1','','APP','REFACTSETNULL' ):"); 1065 dumpRS(GET_CROSS_REFERENCE, getMetaDataRS(met, GET_CROSS_REFERENCE, 1066 new String [] {"", "APP", "REFACTION1", "", "APP", "REFACTSETNULL"}, 1067 null, null, null)); 1068 System.out.println("\ngetCrossReference('','APP','REFACTION1','','APP','REFACTUPDRESTRICT' ):"); 1069 dumpRS(GET_CROSS_REFERENCE, getMetaDataRS(met, GET_CROSS_REFERENCE, 1070 new String [] {"", "APP", "REFACTION1", "", "APP", "REFACTUPDRESTRICT"}, 1071 null, null, null)); 1072 System.out.println("\ngetCrossReference('','APP','REFACTION1','','APP','REFACTUPDNOACTION' ):"); 1073 dumpRS(GET_CROSS_REFERENCE, getMetaDataRS(met, GET_CROSS_REFERENCE, 1074 new String [] {"", "APP", "REFACTION1", "", "APP", "REFACTUPDNOACTION"}, 1075 null, null, null)); 1076 1077 ResultSet refrs = getMetaDataRS(met, GET_IMPORTED_KEYS, 1078 new String [] {"", "APP", "REFACTNONE"}, null, null, null); 1079 1080 if (refrs.next()) 1081 { 1082 if (refrs.getShort(11) != DatabaseMetaData.importedKeyNoAction) 1084 System.out.println("\ngetImportedKeys - none update Failed - action = " + refrs.getShort(11) + " required value = " + DatabaseMetaData.importedKeyNoAction); 1085 else 1086 System.out.println("\ngetImportedKeys - none update Passed"); 1087 if (refrs.getShort(11) != DatabaseMetaData.importedKeyNoAction) 1089 System.out.println("\ngetImportedKeys - none delete Failed - action = " + refrs.getShort(11) + " required value = " + DatabaseMetaData.importedKeyNoAction); 1090 else 1091 System.out.println("\ngetImportedKeys - none delete Passed"); 1092 } 1093 else 1094 System.out.println("\ngetImportedKeys - none Failed no rows"); 1095 1096 refrs.close(); 1097 refrs = getMetaDataRS(met, GET_IMPORTED_KEYS, 1098 new String [] {"", "APP", "REFACTRESTRICT"}, null, null, null); 1099 1100 if (refrs.next()) 1101 { 1102 if (refrs.getShort(11) != DatabaseMetaData.importedKeyRestrict) 1103 System.out.println("\ngetImportedKeys - delete Restrict Failed - action = " + refrs.getShort(11) + " required value = " + DatabaseMetaData.importedKeyRestrict); 1104 else 1105 System.out.println("\ngetImportedKeys - delete Restrict Passed"); 1106 } 1107 else 1108 System.out.println("\ngetImportedKeys - delete Restrict Failed no rows"); 1109 1110 refrs.close(); 1111 refrs = getMetaDataRS(met, GET_IMPORTED_KEYS, 1112 new String [] {"", "APP", "REFACTNOACTION"}, null, null, null); 1113 1114 if (refrs.next()) 1115 { 1116 if (refrs.getShort(11) != DatabaseMetaData.importedKeyNoAction) 1117 System.out.println("\ngetImportedKeys - delete NO ACTION Failed - action = " + refrs.getShort(11) + " required value = " + DatabaseMetaData.importedKeyNoAction); 1118 else 1119 System.out.println("\ngetImportedKeys - delete NO ACTION Passed"); 1120 } 1121 else 1122 System.out.println("\ngetImportedKeys - delete NO ACTION Failed no rows"); 1123 1124 refrs.close(); 1125 refrs = getMetaDataRS(met, GET_IMPORTED_KEYS, 1126 new String [] {"", "APP", "REFACTCASCADE"}, null, null, null); 1127 1128 if (refrs.next()) 1129 { 1130 if (refrs.getShort(11) != DatabaseMetaData.importedKeyCascade) 1131 System.out.println("\ngetImportedKeys - delete CASCADE Failed - action = " + refrs.getShort(11) + " required value = " + DatabaseMetaData.importedKeyCascade); 1132 else 1133 System.out.println("\ngetImportedKeys - delete CASCADE Passed"); 1134 } 1135 else 1136 System.out.println("\ngetImportedKeys - delete CASCADE Failed no rows"); 1137 1138 refrs.close(); 1139 refrs = getMetaDataRS(met, GET_IMPORTED_KEYS, 1140 new String [] {"", "APP", "REFACTSETNULL"}, null, null, null); 1141 1142 if (refrs.next()) 1143 { 1144 if (refrs.getShort(11) != DatabaseMetaData.importedKeySetNull) 1145 System.out.println("\ngetImportedKeys - delete SET NULL Failed - action = " + refrs.getShort(11) + " required value = " + DatabaseMetaData.importedKeySetNull); 1146 else 1147 System.out.println("\ngetImportedKeys - delete SET NULL Passed"); 1148 } 1149 else 1150 System.out.println("\ngetImportedKeys - SET NULL Failed no rows"); 1151 1152 refrs.close(); 1153 refrs = getMetaDataRS(met, GET_IMPORTED_KEYS, 1154 new String [] {"", "APP", "REFACTRESTRICT"}, null, null, null); 1155 1156 if (refrs.next()) 1157 { 1158 if (refrs.getShort(11) != DatabaseMetaData.importedKeyRestrict) 1160 System.out.println("\ngetImportedKeys - update Restrict Failed - action = " + refrs.getShort(11) + " required value = " + DatabaseMetaData.importedKeyRestrict); 1161 else 1162 System.out.println("\ngetImportedKeys - update Restrict Passed"); 1163 } 1164 else 1165 System.out.println("\ngetImportedKeys - update Restrict Failed no rows"); 1166 1167 refrs.close(); 1168 refrs = getMetaDataRS(met, GET_IMPORTED_KEYS, 1169 new String [] {"", "APP", "REFACTNOACTION"}, null, null, null); 1170 1171 if (refrs.next()) 1172 { 1173 if (refrs.getShort(11) != DatabaseMetaData.importedKeyNoAction) 1174 System.out.println("\ngetImportedKeys - update NO ACTION Failed - action = " + refrs.getShort(11) + " required value = " + DatabaseMetaData.importedKeyNoAction); 1175 else 1176 System.out.println("\ngetImportedKeys - update NO ACTION Passed"); 1177 } 1178 else 1179 System.out.println("\ngetImportedKeys - update NO ACTION Failed no rows"); 1180 refrs.close(); 1181 1182 System.out.println("\ngetExportedKeys('',null,null,'','APP','REFACTION1' ):"); 1183 dumpRS(GET_EXPORTED_KEYS, getMetaDataRS(met, GET_EXPORTED_KEYS, 1184 new String [] {"", "APP", "REFACTION1"}, 1185 null, null, null)); 1186 1187 System.out.println("---------------------------------------"); 1188 1189 s.execute("drop table refactnone"); 1191 s.execute("drop table refactupdrestrict"); 1192 s.execute("drop table refactupdnoaction"); 1193 s.execute("drop table refactrestrict"); 1194 s.execute("drop table refactnoaction"); 1195 s.execute("drop table refactcascade"); 1196 s.execute("drop table refactsetnull"); 1197 s.execute("drop table inflight"); 1198 s.execute("drop table refaction1"); 1199 1200 s.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)"); 1202 1203 String schema = "APP"; 1204 String tableName = "T1"; 1205 DatabaseMetaData dmd = con.getMetaData(); 1206 1207 System.out.println("getColumns for '" + tableName + "'"); 1208 1209 rs = getMetaDataRS(dmd, GET_COLUMNS, 1210 new String [] {null, schema, tableName, null}, 1211 null, null, null); 1212 1213 try 1214 { 1215 while (rs.next()) 1216 { 1217 String col = rs.getString(4); 1218 String type = rs.getString(6); 1219 String defval = rs.getString(13); 1220 if (defval == null) 1221 System.out.println(" Next line is real null."); 1222 System.out.println("defval for col " + col + 1223 " type " + type + " DEFAULT '" + defval + "' wasnull " + rs.wasNull()); 1224 } 1225 1226 } 1227 finally 1228 { 1229 if (rs != null) 1230 rs.close(); 1231 } 1232 s.execute("drop table t1"); 1233 1234 s.execute("CREATE TABLE Derby655t1(c11_ID BIGINT NOT NULL)"); 1241 s.execute("CREATE TABLE Derby655t2 (c21_ID BIGINT NOT NULL primary key)"); 1242 s.execute("ALTER TABLE Derby655t1 ADD CONSTRAINT F_12 Foreign Key (c11_ID) REFERENCES Derby655t2 (c21_ID) ON DELETE CASCADE ON UPDATE NO ACTION"); 1243 s.execute("CREATE TABLE Derby655t3(c31_ID BIGINT NOT NULL primary key)"); 1244 s.execute("ALTER TABLE Derby655t2 ADD CONSTRAINT F_443 Foreign Key (c21_ID) REFERENCES Derby655t3(c31_ID) ON DELETE CASCADE ON UPDATE NO ACTION"); 1245 dmd = con.getMetaData(); 1246 System.out.println("\ngetImportedKeys('',null,null,'','APP','Derby655t1' ):"); 1247 dumpRS(met.getImportedKeys("", "APP", "DERBY655T1")); 1248 s.execute("drop table Derby655t1"); 1249 s.execute("drop table Derby655t2"); 1250 s.execute("drop table Derby655t3"); 1251 1252 if(HAVE_DRIVER_CLASS){ 1256 s.execute("create procedure isReadO() language java external name " + 1257 "'org.apache.derbyTesting.functionTests.tests.jdbcapi.metadata.isro'" + 1258 " parameter style java"); 1259 s.execute("call isReadO()"); 1260 } 1261 cleanUp(s); 1262 1263 s.close(); 1264 1265 if (con.getAutoCommit() == false) 1266 con.commit(); 1267 1268 1269 con.close(); 1270 1271 } 1272 catch (SQLException e) { 1273 dumpSQLExceptions(e); 1274 } 1275 catch (Throwable e) { 1276 System.out.println("FAIL -- unexpected exception:"); 1277 e.printStackTrace(System.out); 1278 } 1279 1280 System.out.println("Test metadata finished"); 1281 } 1282 1283 1298 private static void testEscapedFunctions(Connection conn, String [][] specList, String metaDataList) 1299 throws SQLException  1300 { 1301 boolean[] seenFunction = new boolean[specList.length]; 1302 1303 System.out.println("TEST FUNCTIONS DECLARED IN DATABASEMETADATA LIST"); 1304 StringTokenizer st = new StringTokenizer (metaDataList, ","); 1305 while (st.hasMoreTokens()) 1306 { 1307 String function = st.nextToken(); 1308 1309 boolean isSpecFunction = false; 1311 for (int f = 0; f < specList.length; f++) 1312 { 1313 String [] specDetails = specList[f]; 1314 if (function.equals(specDetails[0])) 1315 { 1316 if (seenFunction[f]) 1318 System.out.println("FAIL Function in list twice: " + function); 1319 seenFunction[f] = true; 1320 isSpecFunction = true; 1321 1322 if (!executeEscaped(conn, specDetails)) 1323 System.out.println("FAIL Function failed to execute "+ function); 1324 break; 1325 } 1326 } 1327 1328 if (!isSpecFunction) 1329 { 1330 System.out.println("FAIL Non-JDBC spec function in list: " + function); 1331 } 1332 } 1333 1334 System.out.println("TEST FUNCTIONS NOT DECLARED IN DATABASEMETADATA LIST"); 1336 for (int f = 0; f < specList.length; f++) 1337 { 1338 if (seenFunction[f]) 1339 continue; 1340 String [] specDetails = specList[f]; 1341 if (executeEscaped(conn, specDetails)) 1342 System.out.println("FAIL function works but not declared in list: " + specDetails[0]); 1343 1344 } 1345 } 1346 1347 private static boolean executeEscaped(Connection conn, String [] specDetails) 1348 { 1349 1350 String sql = "VALUES { fn " + specDetails[0] + "("; 1351 1352 for (int p = 0; p < specDetails.length - 1; p++) 1353 { 1354 if (p != 0) 1355 sql = sql + ", "; 1356 1357 sql = sql + specDetails[p + 1]; 1358 } 1359 1360 sql = sql + ") }"; 1361 1362 if ("CURDATE".equals(specDetails[0])) 1367 sql = "VALUES CASE WHEN { fn CURDATE()} = CURRENT_DATE THEN 'OK' ELSE 'wrong' END"; 1368 else if ("CURTIME".equals(specDetails[0])) 1369 sql = "VALUES CASE WHEN { fn CURTIME()} = CURRENT_TIME THEN 'OK' ELSE 'wrong' END"; 1370 else if ("NOW".equals(specDetails[0])) 1371 sql = "VALUES CASE WHEN { fn NOW()} = CURRENT_TIMESTAMP THEN 'OK' ELSE 'wrong' END"; 1372 1373 1374 System.out.print("Executing " + sql + " -- "); 1375 1376 try { 1377 PreparedStatement ps = conn.prepareStatement(sql); 1378 ResultSet rs = ps.executeQuery(); 1379 1380 while (rs.next()) 1381 { 1382 String res = rs.getString(1); 1385 1386 switch (rs.getMetaData().getColumnType(1)) 1387 { 1388 case Types.DOUBLE: 1389 case Types.REAL: 1390 case Types.FLOAT: 1391 if (res.length() > 4) 1392 res = res.substring(0, 4); 1393 break; 1394 default: 1395 break; 1396 } 1397 System.out.print(" = >" + res + "< "); 1398 } 1399 rs.close(); 1400 ps.close(); 1401 System.out.println(" << "); 1402 return true; 1403 } catch (SQLException e) { 1404 System.out.println(""); 1405 showSQLExceptions(e); 1406 return false; 1407 } 1408 1409 } 1410 1411 1417 private void testGetSchemasWithTwoParams(DatabaseMetaData dmd) { 1418 if (TestUtil.isJCCFramework()) return; 1420 1421 Class [] paramTypes = { String .class, String .class }; 1422 1423 Method method = null; 1424 try { 1425 method = dmd.getClass().getMethod("getSchemas", paramTypes); 1426 } catch (NoSuchMethodException nsme) { } 1427 1428 if (method == null || Modifier.isAbstract(method.getModifiers())) { 1429 System.out.println("DatabaseMetaData.getSchemas(String, String) " + 1430 "is not available."); 1431 return; 1432 } 1433 1434 System.out.println(); 1435 System.out.println("getSchemas(String, String):"); 1436 1437 String [][] args = { 1439 { null, null }, 1441 { null, "SYS%" }, 1443 { null, "APP" }, 1445 { null, "BLAH" }, 1447 }; 1448 1449 for (int i = 0; i < args.length; ++i) { 1450 try { 1451 dumpRS((ResultSet ) method.invoke(dmd, args[i])); 1452 } catch (Exception e) { 1453 dumpAllExceptions(e); 1454 } 1455 } 1456 } 1457 1458 1464 private void testGetClientInfoProperties(DatabaseMetaData dmd) { 1465 if (TestUtil.isJCCFramework()) return; 1467 1468 Method method = null; 1469 try { 1470 method = dmd.getClass().getMethod("getClientInfoProperties", null); 1471 } catch (NoSuchMethodException nsme) {} 1472 1473 if (method == null || Modifier.isAbstract(method.getModifiers())) { 1474 System.out.println("DatabaseMetaData.getClientInfoProperties() " + 1475 "is not available."); 1476 return; 1477 } 1478 1479 System.out.println(); 1480 System.out.println("getClientInfoProperties():"); 1481 1482 try { 1483 dumpRS((ResultSet ) method.invoke(dmd, null)); 1484 } catch (Exception e) { 1485 dumpAllExceptions(e); 1486 } 1487 } 1488 1489 static private void showSQLExceptions (SQLException se) { 1490 while (se != null) { 1491 System.out.println("SQLSTATE("+se.getSQLState()+"): " + se.getMessage()); 1492 se = se.getNextException(); 1493 } 1494 } 1495 1496 static protected void dumpSQLExceptions (SQLException se) { 1497 System.out.println("FAIL -- unexpected exception"); 1498 while (se != null) { 1499 System.out.print("SQLSTATE("+se.getSQLState()+"):"); 1500 se.printStackTrace(System.out); 1501 se = se.getNextException(); 1502 } 1503 } 1504 1505 1510 private static void dumpAllExceptions(Throwable t) { 1511 System.out.println("FAIL -- unexpected exception"); 1512 do { 1513 t.printStackTrace(System.out); 1514 if (t instanceof SQLException ) { 1515 t = ((SQLException ) t).getNextException(); 1516 } else if (t instanceof InvocationTargetException ) { 1517 t = ((InvocationTargetException ) t).getTargetException(); 1518 } else { 1519 break; 1520 } 1521 } while (t != null); 1522 } 1523 1524 1531 abstract protected ResultSet getMetaDataRS(DatabaseMetaData dmd, int procId, 1532 String [] sArgs, String [] argArray, int [] iArgs, boolean [] bArgs) 1533 throws SQLException ; 1534 1535 1538 protected void dumpRS(ResultSet rs) throws SQLException { 1539 dumpRS(IGNORE_PROC_ID, rs); 1540 } 1541 1542 1545 abstract protected void dumpRS(int procId, ResultSet s) throws SQLException ; 1546 1547 1550 protected Connection createConnection(String [] args) throws Exception { 1551 1552 Connection con; 1553 1554 ij.getPropertyArg(args); 1557 con = ij.startJBMS(); 1558 con.setAutoCommit(false); 1560 1561 return con; 1562 1563 } 1564 1565 protected void cleanUp(Statement stmt) throws SQLException { 1566 con.setAutoCommit(true); 1567 String [] testObjects = {"table t", "table t1", "view screwie", 1568 "table reftab", "table reftab2", "table inflight" , "table alltypes", 1569 "table louie", 1570 "procedure getpctest1", "procedure getpctest2", 1571 "procedure getpctest3a", "procedure getpctest3b", 1572 "procedure getpctest4a", "procedure getpctest4b", "procedure getpctest4bx", 1573 "procedure isreadO", "FUNCTION DUMMY1", "FUNCTION DUMMY2", 1574 "FUNCTION DUMMY3", "FUNCTION DUMMY4" }; 1575 TestUtil.cleanUpTest(stmt, testObjects); 1576 } 1577 1578 1585 private static void showNumericMetaData(String expression, 1586 ResultSetMetaData rsmd, int col) 1587 throws SQLException  1588 { 1589 System.out.print(expression); 1590 System.out.print(" --"); 1591 1592 System.out.print(" precision: "); 1593 System.out.print(rsmd.getPrecision(col)); 1594 1595 System.out.print(" scale: "); 1596 System.out.print(rsmd.getScale(col)); 1597 1598 System.out.print(" display size: "); 1599 System.out.print(rsmd.getColumnDisplaySize(col)); 1600 1601 System.out.print(" type name: "); 1602 System.out.print(rsmd.getColumnTypeName(col)); 1603 1604 System.out.println(""); 1605 1606 } 1607} 1608 1609 | Popular Tags |