1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package tests.java.sql; 18 19 import dalvik.annotation.KnownFailure; 20 21 import junit.extensions.TestSetup; 22 import junit.framework.Test; 23 import junit.framework.TestCase; 24 import junit.framework.TestSuite; 25 26 import tests.support.DatabaseCreator; 27 import tests.support.Support_SQL; 28 29 import java.sql.Connection; 30 import java.sql.DatabaseMetaData; 31 import java.sql.ResultSet; 32 import java.sql.ResultSetMetaData; 33 import java.sql.SQLException; 34 import java.sql.Statement; 35 import java.util.HashSet; 36 37 public class DatabaseMetaDataNotSupportedTest extends TestCase { 38 39 private static String VIEW_NAME = "myView"; 40 41 private static String CREATE_VIEW_QUERY = "CREATE VIEW " + VIEW_NAME 42 + " AS SELECT * FROM " + DatabaseCreator.TEST_TABLE1; 43 44 private static String DROP_VIEW_QUERY = "DROP VIEW " + VIEW_NAME; 45 46 protected static Connection conn; 47 48 protected static DatabaseMetaData meta; 49 50 protected static Statement statement; 51 52 protected static Statement statementForward; 53 54 private static int id = 1; 55 56 public void setUp() throws Exception { 57 super.setUp(); 58 Support_SQL.loadDriver(); 59 try { 60 conn = Support_SQL.getConnection(); 61 meta = conn.getMetaData(); 62 statement = conn.createStatement(); 63 createTestTables(); 64 } catch (SQLException e) { 65 System.out.println("Error in test setup: "+e.getMessage()); 66 } 67 } 68 69 public void tearDown() throws Exception { 70 try { 71 conn = Support_SQL.getConnection(); 72 meta = conn.getMetaData(); 73 statement = conn.createStatement(); 74 deleteTestTables(); 75 } catch (SQLException e) { 76 System.out.println("Error in teardown: "+e.getMessage()); 77 } finally { 78 try { 79 conn.close(); 80 } catch (SQLException e) { 81 } 82 } 83 super.tearDown(); 84 } 85 86 private void createTestTables() { 87 try { 88 ResultSet userTab = meta.getTables(null, null, null, null); 89 while (userTab.next()) { 90 String tableName = userTab.getString("TABLE_NAME"); 91 if (tableName.equals(DatabaseCreator.TEST_TABLE1)) { 92 statement.execute(DatabaseCreator.DROP_TABLE1); 93 } else if (tableName 94 .equals(DatabaseCreator.TEST_TABLE3)) { 95 statement.execute(DatabaseCreator.DROP_TABLE3); 96 } else if (tableName.equals(VIEW_NAME)) { 97 statement.execute(DROP_VIEW_QUERY); 98 } 99 } 100 userTab.close(); 101 statement.execute(DatabaseCreator.CREATE_TABLE3); 102 statement.execute(DatabaseCreator.CREATE_TABLE1); 103 statement.execute(CREATE_VIEW_QUERY); 104 meta = conn.getMetaData(); 105 } catch (SQLException e) { 106 fail("Unexpected SQLException " + e.toString()); 107 } 108 } 109 110 private void deleteTestTables() { 111 try { 112 statement.execute(DatabaseCreator.DROP_TABLE1); 113 statement.execute(DatabaseCreator.DROP_TABLE3); 114 statement.execute(DROP_VIEW_QUERY); 115 } catch (SQLException e) { 116 fail("Unexpected SQLException " + e.toString()); 117 } finally { 118 try { 119 if (! conn.isClosed()) { 120 conn.close(); 121 } 122 } catch (SQLException e) { 123 124 } 125 } 126 } 127 128 /** 129 * java.sql.DatabaseMetaData#allProceduresAreCallable() 130 */ 131 public void test_allProceduresAreCallable() throws SQLException { 132 assertFalse(meta.allProceduresAreCallable()); 133 } 134 135 @KnownFailure("Not supported ops applied") 136 public void test_allTablesAreSelectable() throws SQLException { 137 // grant SELECT privileges 138 139 String query = "GRANT CREATE, SELECT ON " + DatabaseCreator.TEST_TABLE1 140 + " TO " + Support_SQL.sqlUser; 141 statement.execute(query); 142 Connection userConn = Support_SQL.getConnection(Support_SQL.sqlUrl, 143 Support_SQL.sqlUser, Support_SQL.sqlUser); 144 DatabaseMetaData userMeta = userConn.getMetaData(); 145 ResultSet userTab = userMeta.getTables(null, null, null, null); 146 147 assertTrue("Tables are not obtained", userTab.next()); 148 assertEquals("Incorrect name of obtained table", 149 DatabaseCreator.TEST_TABLE1.toLowerCase(), userTab.getString( 150 "TABLE_NAME").toLowerCase()); 151 assertTrue("Not all of obtained tables are selectable", userMeta 152 .allTablesAreSelectable()); 153 154 userTab.close(); 155 // revoke SELECT privileges 156 query = "REVOKE SELECT ON " + DatabaseCreator.TEST_TABLE1 + " FROM " 157 + Support_SQL.sqlUser; 158 statement.execute(query); 159 160 userTab = userMeta.getTables(null, null, null, null); 161 162 assertTrue("Tables are not obtained", userTab.next()); 163 assertEquals("Incorrect name of obtained table", 164 DatabaseCreator.TEST_TABLE1.toLowerCase(), userTab.getString( 165 "TABLE_NAME").toLowerCase()); 166 assertFalse("No SELECT privileges", userMeta.allTablesAreSelectable()); 167 168 userTab.close(); 169 // revoke CREATE privileges 170 query = "REVOKE CREATE ON " + DatabaseCreator.TEST_TABLE1 + " FROM " 171 + Support_SQL.sqlUser; 172 statement.execute(query); 173 userConn.close(); 174 } 175 176 /** 177 * java.sql.DatabaseMetaData#dataDefinitionCausesTransactionCommit() 178 */ 179 public void test_dataDefinitionCausesTransactionCommit() throws SQLException { 180 // NOT_FEASIBLE: SQLITE does not implement this functionality 181 } 182 183 /** 184 * java.sql.DatabaseMetaData#dataDefinitionIgnoredInTransactions() 185 */ 186 public void test_dataDefinitionIgnoredInTransactions() throws SQLException { 187 assertFalse(meta.dataDefinitionIgnoredInTransactions()); 188 } 189 190 /** 191 * java.sql.DatabaseMetaData#deletesAreDetected(int) 192 */ 193 public void test_deletesAreDetectedI() throws SQLException { 194 assertFalse(meta.deletesAreDetected(0)); 195 } 196 197 /** 198 * java.sql.DatabaseMetaData#doesMaxRowSizeIncludeBlobs() 199 */ 200 @KnownFailure("not supported") 201 public void test_doesMaxRowSizeIncludeBlobs() throws SQLException { 202 assertFalse(meta.doesMaxRowSizeIncludeBlobs()); 203 } 204 205 /** 206 * java.sql.DatabaseMetaData #getAttributes(java.lang.String, 207 * java.lang.String, java.lang.String, java.lang.String) 208 */ 209 public void test_getAttributesLjava_lang_StringLjava_lang_StringLjava_lang_StringLjava_lang_String() 210 throws SQLException { 211 } 212 213 public void test_getCatalogs() throws SQLException { 214 ResultSet rs = meta.getCatalogs(); 215 // NOT_FEASIBLE getCatalog is not supported 216 // while (rs.next()) { 217 //if (rs.getString("TABLE_CAT").equalsIgnoreCase(conn.getCatalog())) { 218 // rs.close(); 219 // return; 220 //} 221 // } 222 rs.close(); 223 // fail("Incorrect a set of catalogs"); 224 } 225 226 /** 227 * java.sql.DatabaseMetaData#getCatalogSeparator() 228 */ 229 public void test_getCatalogSeparator() throws SQLException { 230 assertTrue("Incorrect catalog separator", "".equals(meta 231 .getCatalogSeparator().trim())); 232 } 233 234 /** 235 * java.sql.DatabaseMetaData#getCatalogTerm() 236 */ 237 public void test_getCatalogTerm() throws SQLException { 238 assertTrue("Incorrect catalog term", "".equals(meta 239 .getCatalogSeparator().trim())); 240 } 241 242 /** 243 * java.sql.DatabaseMetaData#getExtraNameCharacters() 244 */ 245 public void test_getExtraNameCharacters() throws SQLException { 246 assertNotNull("Incorrect extra name characters", meta 247 .getExtraNameCharacters()); 248 249 } 250 251 @KnownFailure("not supported") 252 public void test_getIndexInfoLjava_lang_StringLjava_lang_StringLjava_lang_StringZZ() 253 throws SQLException { 254 boolean unique = false; 255 ResultSet rs = meta.getIndexInfo(conn.getCatalog(), null, 256 DatabaseCreator.TEST_TABLE1, unique, true); 257 ResultSetMetaData rsmd = rs.getMetaData(); 258 assertTrue("Rows do not obtained", rs.next()); 259 int col = rsmd.getColumnCount(); 260 assertEquals("Incorrect number of columns", 13, col); 261 String[] columnNames = { "TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", 262 "NON_UNIQUE", "INDEX_QUALIFIER", "INDEX_NAME", "TYPE", 263 "ORDINAL_POSITION", "COLUMN_NAME", "ASC_OR_DESC", 264 "CARDINALITY", "PAGES", "FILTER_CONDITION" }; 265 for (int c = 1; c <= col; ++c) { 266 assertEquals("Incorrect column name", columnNames[c - 1], rsmd 267 .getColumnName(c)); 268 } 269 270 assertEquals("Incorrect table catalog", conn.getCatalog(), rs 271 .getString("TABLE_CAT")); 272 assertEquals("Incorrect table schema", null, rs 273 .getString("TABLE_SCHEM")); 274 assertEquals("Incorrect table name", DatabaseCreator.TEST_TABLE1, rs 275 .getString("TABLE_NAME")); 276 assertEquals("Incorrect state of uniquess", unique, rs 277 .getBoolean("NON_UNIQUE")); 278 assertEquals("Incorrect index catalog", "", rs 279 .getString("INDEX_QUALIFIER")); 280 assertEquals("Incorrect index name", "primary", rs.getString( 281 "INDEX_NAME").toLowerCase()); 282 assertEquals("Incorrect index type", DatabaseMetaData.tableIndexOther, 283 rs.getShort("TYPE")); 284 assertEquals("Incorrect column sequence number within index", 1, rs 285 .getShort("ORDINAL_POSITION")); 286 assertEquals("Incorrect column name", "id", rs.getString("COLUMN_NAME")); 287 assertEquals("Incorrect column sort sequence", "a", rs.getString( 288 "ASC_OR_DESC").toLowerCase()); 289 assertEquals("Incorrect cardinality", 1, rs.getInt("CARDINALITY")); 290 assertEquals("Incorrect value of pages", 0, rs.getInt("PAGES")); 291 assertEquals("Incorrect filter condition", null, rs 292 .getString("FILTER_CONDITION")); 293 rs.close(); 294 } 295 296 @KnownFailure("not supported. Privileges are not supported.") 297 public void test_getColumnPrivilegesLjava_lang_StringLjava_lang_StringLjava_lang_StringLjava_lang_String() 298 throws SQLException { 299 ResultSet rs = meta.getColumnPrivileges(conn.getCatalog(), null, 300 DatabaseCreator.TEST_TABLE1, "id"); 301 ResultSetMetaData rsmd = rs.getMetaData(); 302 assertFalse("Rows are obtained", rs.next()); 303 rs.close(); 304 305 String query = "GRANT REFERENCES(id) ON " + DatabaseCreator.TEST_TABLE1 306 + " TO " + Support_SQL.sqlLogin; 307 statement.execute(query); 308 309 rs = meta.getColumnPrivileges(conn.getCatalog(), null, 310 DatabaseCreator.TEST_TABLE1, "id"); 311 rsmd = rs.getMetaData(); 312 assertTrue("Rows do not obtained", rs.next()); 313 int col = rsmd.getColumnCount(); 314 assertEquals("Incorrect number of columns", 8, col); 315 String[] columnNames = { "TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", 316 "COLUMN_NAME", "GRANTOR", "GRANTEE", "PRIVILEGE", 317 "IS_GRANTABLE" }; 318 for (int c = 1; c <= col; ++c) { 319 assertEquals("Incorrect column name", columnNames[c - 1], rsmd 320 .getColumnName(c)); 321 } 322 assertEquals("Incorrect table catalogue", conn.getCatalog(), rs 323 .getString("TABLE_CAT").toLowerCase()); 324 assertEquals("Incorrect table schema", null, rs 325 .getString("TABLE_SCHEM")); 326 assertEquals("Incorrect table name", DatabaseCreator.TEST_TABLE1, rs 327 .getString("TABLE_NAME").toLowerCase()); 328 assertEquals("Incorrect column name", "id", rs.getString("COLUMN_NAME") 329 .toLowerCase()); 330 assertEquals("Incorrect grantor", Support_SQL.sqlLogin + "@" 331 + Support_SQL.sqlHost, rs.getString("GRANTOR").toLowerCase()); 332 assertTrue("Incorrect grantee", 333 rs.getString("GRANTEE").indexOf("root") != -1); 334 assertEquals("Incorrect privilege", "references", rs.getString( 335 "PRIVILEGE").toLowerCase()); 336 337 query = "REVOKE REFERENCES(id) ON " + DatabaseCreator.TEST_TABLE1 338 + " FROM " + Support_SQL.sqlLogin; 339 statement.execute(query); 340 rs.close(); 341 } 342 343 344 @KnownFailure("not supported") 345 public void test_getExportedKeysLjava_lang_StringLjava_lang_StringLjava_lang_String() 346 throws SQLException { 347 ResultSet rs = meta.getExportedKeys(conn.getCatalog(), null, 348 DatabaseCreator.TEST_TABLE3); 349 ResultSetMetaData rsmd = rs.getMetaData(); 350 assertTrue("Rows do not obtained", rs.next()); 351 int col = rsmd.getColumnCount(); 352 assertEquals("Incorrect number of columns", 14, col); 353 String[] columnNames = { "PKTABLE_CAT", "PKTABLE_SCHEM", 354 "PKTABLE_NAME", "PKCOLUMN_NAME", "FKTABLE_CAT", 355 "FKTABLE_SCHEM", "FKTABLE_NAME", "FKCOLUMN_NAME", "KEY_SEQ", 356 "UPDATE_RULE", "DELETE_RULE", "FK_NAME", "PK_NAME", 357 "DEFERRABILITY" }; 358 for (int c = 1; c <= col; ++c) { 359 assertEquals("Incorrect column name", columnNames[c - 1], rsmd 360 .getColumnName(c)); 361 } 362 363 assertEquals("Incorrect primary key table catalog", conn.getCatalog(), 364 rs.getString("PKTABLE_CAT")); 365 assertEquals("Incorrect primary key table schema", null, rs 366 .getString("PKTABLE_SCHEM")); 367 assertEquals("Incorrect primary key table name", 368 DatabaseCreator.TEST_TABLE3, rs.getString("PKTABLE_NAME")); 369 assertEquals("Incorrect primary key column name", "fk", rs 370 .getString("PKCOLUMN_NAME")); 371 assertEquals("Incorrect foreign key table catalog", conn.getCatalog(), 372 rs.getString("FKTABLE_CAT")); 373 assertEquals("Incorrect foreign key table schema", null, rs 374 .getString("FKTABLE_SCHEM")); 375 assertEquals("Incorrect foreign key table name", 376 DatabaseCreator.TEST_TABLE1, rs.getString("FKTABLE_NAME")); 377 assertEquals("Incorrect foreign key column name", "fkey", rs 378 .getString("FKCOLUMN_NAME")); 379 assertEquals("Incorrect sequence number within foreign key", 1, rs 380 .getShort("KEY_SEQ")); 381 assertEquals("Incorrect update rule value", 382 DatabaseMetaData.importedKeyNoAction, rs 383 .getShort("UPDATE_RULE")); 384 assertEquals("Incorrect delete rule value", 385 DatabaseMetaData.importedKeyNoAction, rs 386 .getShort("DELETE_RULE")); 387 assertNotNull("Incorrect foreign key name", rs.getString("FK_NAME")); 388 assertEquals("Incorrect primary key name", null, rs 389 .getString("PK_NAME")); 390 assertEquals("Incorrect deferrability", 391 DatabaseMetaData.importedKeyNotDeferrable, rs 392 .getShort("DEFERRABILITY")); 393 rs.close(); 394 } 395 396 public void test_getProcedureColumnsLjava_lang_StringLjava_lang_StringLjava_lang_StringLjava_lang_String() 397 throws SQLException { 398 meta.getProcedureColumns("", "", "", ""); 399 } 400 401 public void test_getProceduresLjava_lang_StringLjava_lang_StringLjava_lang_String() 402 throws SQLException { 403 // NOT_FEASIBLE: SQLITE does not implement this functionality 404 } 405 406 /** 407 * java.sql.DatabaseMetaData#getProcedureTerm() 408 */ 409 @KnownFailure("Exception test fails") 410 public void test_getProcedureTerm() throws SQLException { 411 assertTrue("Incorrect procedure term", "".equals(meta 412 .getProcedureTerm().trim())); 413 414 //Exception checking 415 conn.close(); 416 417 try { 418 meta.getProcedureTerm(); 419 fail("SQLException not thrown"); 420 } catch (SQLException e) { 421 //ok 422 } 423 } 424 425 /** 426 * java.sql.DatabaseMetaData#getSchemaTerm() 427 */ 428 @KnownFailure("Exception test fails") 429 public void test_getSchemaTerm() throws SQLException { 430 String term = meta.getSchemaTerm(); 431 assertNotNull("Incorrect schema term", term ); 432 433 assertTrue("".equals(term)); 434 435 //Exception checking 436 conn.close(); 437 438 try { 439 meta.getSchemaTerm(); 440 fail("SQLException not thrown"); 441 } catch (SQLException e) { 442 //ok 443 } 444 } 445 446 public void test_getSuperTablesLjava_lang_StringLjava_lang_StringLjava_lang_String() 447 throws SQLException { 448 // NOT_FEASIBLE: SQLITE does not implement this functionality 449 } 450 451 public void test_getSuperTypesLjava_lang_StringLjava_lang_StringLjava_lang_String() 452 throws SQLException { 453 // NOT_FEASIBLE: SQLITE does not implement this functionality 454 } 455 456 @KnownFailure("not supported. Privileges are not supported.") 457 public void test_getTablePrivilegesLjava_lang_StringLjava_lang_StringLjava_lang_String() 458 throws SQLException { 459 // case 1. Get privileges when no privilegies exist for one table 460 ResultSet privileges = meta.getTablePrivileges(conn.getCatalog(), "%", 461 DatabaseCreator.TEST_TABLE3); 462 assertFalse("Some privilegies exist", privileges.next()); 463 privileges.close(); 464 465 // case 2. Get privileges when no privilegies exist for all tables 466 privileges = meta.getTablePrivileges(null, null, null); 467 assertFalse("Some privilegies exist", privileges.next()); 468 privileges.close(); 469 470 // case 3. grant CREATE and SELECT privileges ang get them 471 HashSet<String> expectedPrivs = new HashSet<String>(); 472 expectedPrivs.add("CREATE"); 473 expectedPrivs.add("SELECT"); 474 475 String query = "GRANT CREATE, SELECT ON " + DatabaseCreator.TEST_TABLE3 476 + " TO " + Support_SQL.sqlUser; 477 statement.execute(query); 478 479 privileges = meta.getTablePrivileges(conn.getCatalog(), null, 480 DatabaseCreator.TEST_TABLE3); 481 482 while (privileges.next()) { 483 assertEquals("Wrong catalog name", Support_SQL.sqlCatalog, 484 privileges.getString("TABLE_CAT")); 485 assertNull("Wrong schema", privileges.getString("TABLE_SCHEM")); 486 assertEquals("Wrong table name", DatabaseCreator.TEST_TABLE3, 487 privileges.getString("TABLE_NAME")); 488 assertTrue("Wrong privilege " + privileges.getString("PRIVILEGE"), 489 expectedPrivs.remove(privileges.getString("PRIVILEGE"))); 490 assertEquals("Wrong grantor", Support_SQL.sqlLogin + "@" 491 + Support_SQL.sqlHost, privileges.getString("GRANTOR")); 492 assertEquals("Wrong grantee", Support_SQL.sqlUser + "@%", 493 privileges.getString("GRANTEE")); 494 assertNull("Wrong value of IS_GRANTABLE", privileges 495 .getString("IS_GRANTABLE")); 496 } 497 privileges.close(); 498 assertTrue("Wrong privileges were returned", expectedPrivs.isEmpty()); 499 500 query = "REVOKE CREATE, SELECT ON " + DatabaseCreator.TEST_TABLE3 501 + " FROM " + Support_SQL.sqlUser; 502 statement.execute(query); 503 504 // case 4. grant all privileges ang get them 505 String[] privs = new String[] { "ALTER", "CREATE", "CREATE VIEW", 506 "DELETE", "DROP", "INDEX", "INSERT", "REFERENCES", "SELECT", 507 "SHOW VIEW", "UPDATE" }; 508 expectedPrivs = new HashSet<String>(); 509 for (int i = 0; i < privs.length; i++) { 510 expectedPrivs.add(privs[i]); 511 } 512 query = "GRANT ALL ON " + DatabaseCreator.TEST_TABLE3 + " TO " 513 + Support_SQL.sqlUser; 514 statement.execute(query); 515 516 privileges = meta.getTablePrivileges(conn.getCatalog(), null, 517 DatabaseCreator.TEST_TABLE3); 518 519 while (privileges.next()) { 520 assertEquals("Wrong catalog name", Support_SQL.sqlCatalog, 521 privileges.getString("TABLE_CAT")); 522 assertNull("Wrong schema", privileges.getString("TABLE_SCHEM")); 523 assertEquals("Wrong table name", DatabaseCreator.TEST_TABLE3, 524 privileges.getString("TABLE_NAME")); 525 assertTrue("Wrong privilege " + privileges.getString("PRIVILEGE"), 526 expectedPrivs.remove(privileges.getString("PRIVILEGE"))); 527 assertEquals("Wrong grantor", Support_SQL.sqlLogin + "@" 528 + Support_SQL.sqlHost, privileges.getString("GRANTOR")); 529 assertEquals("Wrong grantee", Support_SQL.sqlUser + "@%", 530 privileges.getString("GRANTEE")); 531 assertNull("Wrong value of IS_GRANTABLE", privileges 532 .getString("IS_GRANTABLE")); 533 } 534 privileges.close(); 535 assertTrue("Wrong privileges were returned", expectedPrivs.isEmpty()); 536 537 query = "REVOKE ALL ON " + DatabaseCreator.TEST_TABLE3 + " FROM " 538 + Support_SQL.sqlUser; 539 statement.execute(query); 540 541 // case 5. check no privelegies after revoke 542 privileges = meta.getTablePrivileges(conn.getCatalog(), "%", 543 DatabaseCreator.TEST_TABLE3); 544 assertFalse("Some privilegies exist", privileges.next()); 545 privileges.close(); 546 547 privileges = meta.getTablePrivileges(null, null, null); 548 assertFalse("Some privilegies exist", privileges.next()); 549 privileges.close(); 550 } 551 552 public void test_getUDTsLjava_lang_StringLjava_lang_StringLjava_lang_String$I() 553 throws SQLException { 554 // NOT_FEASIBLE: JDBC does not implement this functionality 555 } 556 557 @KnownFailure("Not supported ops applied") 558 public void test_getVersionColumnsLjava_lang_StringLjava_lang_StringLjava_lang_String() 559 throws SQLException { 560 DatabaseMetaDataTest.insertNewRecord(); 561 562 String triggerName = "updateTrigger"; 563 String triggerQuery = "CREATE TRIGGER " + triggerName 564 + " AFTER UPDATE ON " + DatabaseCreator.TEST_TABLE1 565 + " FOR EACH ROW BEGIN INSERT INTO " 566 + DatabaseCreator.TEST_TABLE3 + " SET fk = 10; END;"; 567 statementForward.execute(triggerQuery); 568 569 String updateQuery = "UPDATE " + DatabaseCreator.TEST_TABLE1 570 + " SET field1='fffff' WHERE id=1"; 571 statementForward.execute(updateQuery); 572 573 ResultSet rs = meta.getVersionColumns(conn.getCatalog(), null, 574 DatabaseCreator.TEST_TABLE1); 575 assertTrue("Result set is empty", rs.next()); 576 rs.close(); 577 } 578 579 /** 580 * java.sql.DatabaseMetaData#isCatalogAtStart() 581 */ 582 @KnownFailure("Exception test fails") 583 public void test_isCatalogAtStart() throws SQLException { 584 assertFalse( 585 "catalog doesn't appear at the start of a fully qualified table name", 586 meta.isCatalogAtStart()); 587 588 //Exception checking 589 conn.close(); 590 591 try { 592 meta.isCatalogAtStart(); 593 fail("SQLException not thrown"); 594 } catch (SQLException e) { 595 //ok 596 } 597 } 598 599 @KnownFailure("not supported") 600 public void test_locatorsUpdateCopy() throws SQLException { 601 assertFalse(meta.locatorsUpdateCopy()); 602 } 603 604 public void test_nullPlusNonNullIsNull() throws SQLException { 605 assertFalse(meta.nullPlusNonNullIsNull()); 606 } 607 608 public void test_nullsAreSortedAtEnd() throws SQLException { 609 assertFalse(meta.nullsAreSortedAtEnd()); 610 } 611 612 public void test_nullsAreSortedAtStart() throws SQLException { 613 assertFalse(meta.nullsAreSortedAtStart()); 614 } 615 616 public void test_nullsAreSortedHigh() throws SQLException { 617 assertFalse(meta.nullsAreSortedHigh()); 618 } 619 620 public void test_nullsAreSortedLow() throws SQLException { 621 assertFalse(meta.nullsAreSortedLow()); 622 } 623 624 /** 625 * java.sql.DatabaseMetaData#ownDeletesAreVisible(int) 626 */ 627 public void test_ownDeletesAreVisibleI() throws SQLException { 628 // NOT_FEASIBLE not supported 629 // assertFalse( 630 // "result set's own deletes are visible for TYPE_FORWARD_ONLY type", 631 // meta.ownDeletesAreVisible(ResultSet.TYPE_FORWARD_ONLY)); 632 // assertFalse( 633 // "result set's own deletes are visible for TYPE_SCROLL_INSENSITIVE type", 634 // meta.ownDeletesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)); 635 // assertFalse( 636 // "result set's own deletes are visible for TYPE_SCROLL_SENSITIVE type", 637 // meta.ownDeletesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)); 638 assertFalse("result set's own deletes are visible for unknown type", 639 meta.ownDeletesAreVisible(100)); 640 } 641 642 /** 643 * java.sql.DatabaseMetaData#ownInsertsAreVisible(int) 644 */ 645 public void test_ownInsertsAreVisibleI() throws SQLException { 646 // assertFalse( 647 // "result set's own inserts are visible for TYPE_FORWARD_ONLY type", 648 // meta.ownInsertsAreVisible(ResultSet.TYPE_FORWARD_ONLY)); 649 // assertFalse( 650 // "result set's own inserts are visible for TYPE_SCROLL_INSENSITIVE type", 651 // meta.ownInsertsAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)); 652 // assertFalse( 653 // "result set's own inserts are visible for TYPE_SCROLL_SENSITIVE type", 654 // meta.ownInsertsAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)); 655 assertFalse("result set's own inserts are visible for unknown type", 656 meta.ownInsertsAreVisible(100)); 657 } 658 659 public void test_ownUpdatesAreVisibleI() throws SQLException { 660 assertTrue( 661 "result set's own updates are visible for TYPE_FORWARD_ONLY type", 662 meta.ownUpdatesAreVisible(ResultSet.TYPE_FORWARD_ONLY)); 663 assertTrue( 664 "result set's own updates are visible for TYPE_SCROLL_INSENSITIVE type", 665 meta.ownUpdatesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)); 666 assertTrue( 667 "result set's own updates are visible for TYPE_SCROLL_SENSITIVE type", 668 meta.ownUpdatesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)); 669 assertFalse("result set's own updates are visible for unknown type", 670 meta.ownUpdatesAreVisible(100)); 671 } 672 673 public void test_storesLowerCaseIdentifiers() throws SQLException { 674 assertFalse(meta.storesLowerCaseIdentifiers()); 675 } 676 677 public void test_storesLowerCaseQuotedIdentifiers() throws SQLException { 678 assertFalse(meta.storesLowerCaseQuotedIdentifiers()); 679 } 680 681 public void test_storesUpperCaseIdentifiers() throws SQLException { 682 assertFalse(meta.storesUpperCaseIdentifiers()); 683 } 684 685 public void test_storesUpperCaseQuotedIdentifiers() throws SQLException { 686 assertFalse(meta.storesUpperCaseQuotedIdentifiers()); 687 } 688 689 @KnownFailure("not supported") 690 public void test_supportsANSI92EntryLevelSQL() throws SQLException { 691 assertFalse(meta.supportsANSI92EntryLevelSQL()); 692 } 693 694 public void test_supportsANSI92FullSQL() throws SQLException { 695 assertFalse(meta.supportsANSI92FullSQL()); 696 } 697 698 public void test_supportsANSI92IntermediateSQL() throws SQLException { 699 assertFalse(meta.supportsANSI92IntermediateSQL()); 700 } 701 702 public void test_supportsAlterTableWithAddColumn() throws SQLException { 703 assertFalse(meta.supportsAlterTableWithAddColumn()); 704 } 705 706 public void test_supportsAlterTableWithDropColumn() throws SQLException { 707 assertFalse(meta.supportsAlterTableWithDropColumn()); 708 } 709 710 public void test_supportsBatchUpdates() throws SQLException { 711 assertTrue(meta.supportsBatchUpdates()); 712 } 713 714 public void test_supportsCatalogsInDataManipulation() throws SQLException { 715 assertFalse(meta.supportsCatalogsInDataManipulation()); 716 } 717 718 public void test_supportsCatalogsInIndexDefinitions() throws SQLException { 719 assertFalse(meta.supportsCatalogsInIndexDefinitions()); 720 } 721 722 public void test_supportsCatalogsInPrivilegeDefinitions() throws SQLException { 723 assertFalse(meta.supportsCatalogsInPrivilegeDefinitions()); 724 } 725 726 public void test_supportsCatalogsInProcedureCalls() throws SQLException { 727 assertFalse(meta.supportsCatalogsInProcedureCalls()); 728 } 729 730 public void test_supportsCatalogsInTableDefinitions() throws SQLException { 731 assertFalse(meta.supportsCatalogsInTableDefinitions()); 732 } 733 734 public void test_supportsConvert() throws SQLException { 735 assertFalse(meta.supportsConvert()); 736 } 737 738 public void test_supportsConvertII() throws SQLException { 739 assertFalse(meta.supportsConvert()); 740 } 741 742 public void test_supportsCoreSQLGrammar() throws SQLException { 743 assertFalse(meta.supportsCoreSQLGrammar()); 744 } 745 746 public void test_supportsCorrelatedSubqueries() throws SQLException { 747 assertFalse(meta.supportsCorrelatedSubqueries()); 748 } 749 750 @KnownFailure("not supported") 751 public void test_supportsDataDefinitionAndDataManipulationTransactions() throws SQLException { 752 assertFalse(meta.supportsDataDefinitionAndDataManipulationTransactions()); 753 } 754 755 public void test_supportsDataManipulationTransactionsOnly() throws SQLException { 756 assertFalse(meta.supportsDataManipulationTransactionsOnly()); 757 } 758 759 public void test_supportsDifferentTableCorrelationNames() throws SQLException { 760 assertFalse(meta.supportsDifferentTableCorrelationNames()); 761 } 762 763 public void test_supportsExtendedSQLGrammar() throws SQLException { 764 assertFalse(meta.supportsExtendedSQLGrammar()); 765 } 766 767 public void test_supportsFullOuterJoins() throws SQLException { 768 assertFalse(meta.supportsFullOuterJoins()); 769 } 770 771 public void test_supportsGetGeneratedKeys() throws SQLException { 772 assertFalse(meta.supportsGetGeneratedKeys()); 773 } 774 775 public void test_supportsGroupByBeyondSelect() throws SQLException { 776 assertFalse(meta.supportsGroupByBeyondSelect()); 777 } 778 779 public void test_supportsIntegrityEnhancementFacility() throws SQLException { 780 assertFalse(meta.supportsIntegrityEnhancementFacility()); 781 } 782 783 public void test_supportsLikeEscapeClause() throws SQLException { 784 assertFalse(meta.supportsLikeEscapeClause()); 785 } 786 787 public void test_supportsLimitedOuterJoins() throws SQLException { 788 assertFalse(meta.supportsLimitedOuterJoins()); 789 } 790 791 @KnownFailure("not supported") 792 public void test_supportsMinimumSQLGrammar() throws SQLException { 793 assertFalse(meta.supportsMinimumSQLGrammar()); 794 } 795 796 public void test_supportsMixedCaseIdentifiers() throws SQLException { 797 assertFalse(meta.supportsMixedCaseIdentifiers()); 798 } 799 800 public void test_supportsMixedCaseQuotedIdentifiers() throws SQLException { 801 assertFalse(meta.supportsMixedCaseQuotedIdentifiers()); 802 } 803 804 public void test_supportsMultipleOpenResults() throws SQLException { 805 assertFalse(meta.supportsMultipleOpenResults()); 806 } 807 808 public void test_supportsMultipleResultSets() throws SQLException { 809 assertFalse(meta.supportsMultipleResultSets()); 810 } 811 812 public void test_supportsMultipleTransactions() throws SQLException { 813 assertFalse(meta.supportsMultipleTransactions()); 814 } 815 816 public void test_supportsNamedParameters() throws SQLException { 817 assertFalse(meta.supportsNamedParameters()); 818 } 819 820 public void test_supportsOpenCursorsAcrossCommit() throws SQLException { 821 assertFalse(meta.supportsOpenCursorsAcrossCommit()); 822 } 823 824 public void test_supportsOpenCursorsAcrossRollback() throws SQLException { 825 assertFalse(meta.supportsOpenCursorsAcrossRollback()); 826 } 827 828 public void test_supportsOpenStatementsAcrossCommit() throws SQLException { 829 assertFalse(meta.supportsOpenStatementsAcrossCommit()); 830 } 831 832 public void test_supportsOpenStatementsAcrossRollback() throws SQLException { 833 assertFalse(meta.supportsOpenStatementsAcrossRollback()); 834 } 835 836 public void test_supportsOuterJoins() throws SQLException { 837 assertFalse(meta.supportsOuterJoins()); 838 } 839 840 public void test_supportsPositionedDelete() throws SQLException { 841 assertFalse(meta.supportsPositionedDelete()); 842 } 843 844 public void test_supportsPositionedUpdate() throws SQLException { 845 assertFalse(meta.supportsPositionedUpdate()); 846 } 847 848 public void test_supportsResultSetConcurrencyII() throws SQLException { 849 assertFalse(meta.supportsResultSetConcurrency(0,0)); 850 } 851 852 public void test_supportsResultSetHoldabilityI() throws SQLException { 853 assertFalse(meta.supportsResultSetHoldability(0)); 854 } 855 856 @KnownFailure("not supported") 857 public void test_supportsResultSetTypeI() throws SQLException { 858 assertTrue("database supports TYPE_FORWARD_ONLY type", meta 859 .supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY)); 860 assertFalse("database doesn't support TYPE_SCROLL_INSENSITIVE type", 861 meta.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE)); 862 assertFalse("database supports TYPE_SCROLL_SENSITIVE type", meta 863 .supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE)); 864 assertFalse("database supports unknown type", meta 865 .supportsResultSetType(100)); 866 } 867 868 public void test_supportsSavepoints() throws SQLException { 869 assertFalse(meta.supportsSavepoints()); 870 } 871 872 public void test_supportsSchemasInDataManipulation() throws SQLException { 873 assertFalse(meta.supportsSchemasInDataManipulation()); 874 } 875 876 public void test_supportsSchemasInIndexDefinitions() throws SQLException { 877 assertFalse(meta.supportsSchemasInIndexDefinitions()); 878 } 879 880 public void test_supportsSchemasInPrivilegeDefinitions() throws SQLException { 881 // NOT_FEASIBLE: SQLITE does not implement this functionality 882 } 883 884 public void test_supportsSchemasInProcedureCalls() throws SQLException { 885 assertFalse(meta.supportsSchemasInProcedureCalls()); 886 } 887 888 public void test_supportsSchemasInTableDefinitions() throws SQLException { 889 assertFalse(meta.supportsSchemasInTableDefinitions()); 890 } 891 892 public void test_supportsStatementPooling() throws SQLException { 893 assertFalse(meta.supportsStatementPooling()); 894 } 895 896 public void test_supportsStoredProcedures() throws SQLException { 897 assertFalse(meta.supportsStoredProcedures()); 898 } 899 900 @KnownFailure("not supported") 901 public void test_supportsSubqueriesInComparisons() throws SQLException { 902 assertFalse(meta.supportsSubqueriesInComparisons()); 903 } 904 905 @KnownFailure("not supported") 906 public void test_supportsSubqueriesInIns() throws SQLException { 907 assertFalse(meta.supportsSubqueriesInIns()); 908 } 909 910 public void test_supportsSubqueriesInQuantifieds() throws SQLException { 911 assertFalse(meta.supportsSubqueriesInQuantifieds()); 912 } 913 914 @KnownFailure("not supported") 915 public void test_supportsTransactions() throws SQLException { 916 assertFalse(meta.supportsTransactions()); 917 } 918 919 public void test_supportsUnion() throws SQLException { 920 assertTrue(meta.supportsUnion()); 921 } 922 923 public void test_supportsUnionAll() throws SQLException { 924 assertTrue(meta.supportsUnionAll()); 925 } 926 927 public void test_usesLocalFilePerTable() throws SQLException { 928 assertFalse(meta.usesLocalFilePerTable()); 929 } 930 931 @KnownFailure("not supported") 932 public void test_usesLocalFiles() throws SQLException { 933 assertFalse(meta.usesLocalFiles()); 934 } 935 936 /** 937 * java.sql.DatabaseMetaData#getMaxBinaryLiteralLength() 938 */ 939 public void test_getMaxBinaryLiteralLength() throws SQLException { 940 assertTrue("Incorrect binary literal length", meta 941 .getMaxBinaryLiteralLength() == 0); 942 } 943 944 /** 945 * java.sql.DatabaseMetaData#getMaxCatalogNameLength() 946 */ 947 public void test_getMaxCatalogNameLength() throws SQLException { 948 assertTrue("Incorrect name length", meta.getMaxCatalogNameLength() == 0); 949 } 950 951 /** 952 * java.sql.DatabaseMetaData#getMaxCharLiteralLength() 953 */ 954 public void test_getMaxCharLiteralLength() throws SQLException { 955 assertTrue("Incorrect char literal length", meta 956 .getMaxCharLiteralLength() == 0); 957 } 958 959 /** 960 * java.sql.DatabaseMetaData#getMaxColumnNameLength() 961 */ 962 public void test_getMaxColumnNameLength() throws SQLException { 963 assertTrue("Incorrect column name length", meta 964 .getMaxColumnNameLength() == 0); 965 } 966 967 /** 968 * java.sql.DatabaseMetaData#getMaxColumnsInGroupBy() 969 */ 970 public void test_getMaxColumnsInGroupBy() throws SQLException { 971 assertTrue("Incorrect number of columns", 972 meta.getMaxColumnsInGroupBy() == 0); 973 } 974 975 /** 976 * java.sql.DatabaseMetaData#getMaxColumnsInIndex() 977 */ 978 public void test_getMaxColumnsInIndex() throws SQLException { 979 assertTrue("Incorrect number of columns", 980 meta.getMaxColumnsInIndex() == 0); 981 } 982 983 /** 984 * java.sql.DatabaseMetaData#getMaxColumnsInOrderBy() 985 */ 986 public void test_getMaxColumnsInOrderBy() throws SQLException { 987 assertTrue("Incorrect number of columns", 988 meta.getMaxColumnsInOrderBy() == 0); 989 } 990 991 /** 992 * java.sql.DatabaseMetaData#getMaxColumnsInSelect() 993 */ 994 public void test_getMaxColumnsInSelect() throws SQLException { 995 assertTrue("Incorrect number of columns", 996 meta.getMaxColumnsInSelect() == 0); 997 } 998 999 /** 1000 * java.sql.DatabaseMetaData#getMaxColumnsInTable() 1001 */ 1002 public void test_getMaxColumnsInTable() throws SQLException { 1003 assertTrue("Incorrect number of columns", 1004 meta.getMaxColumnsInTable() == 0); 1005 } 1006 1007 /** 1008 * java.sql.DatabaseMetaData#getMaxConnections() 1009 */ 1010 public void test_getMaxConnections() throws SQLException { 1011 assertTrue("Incorrect number of connections", 1012 meta.getMaxConnections() == 0); 1013 } 1014 1015 /** 1016 * java.sql.DatabaseMetaData#getMaxIndexLength() 1017 */ 1018 public void test_getMaxIndexLength() throws SQLException { 1019 assertTrue("Incorrect length of index", meta.getMaxIndexLength() == 0); 1020 } 1021 1022 /** 1023 * java.sql.DatabaseMetaData#getMaxProcedureNameLength() 1024 */ 1025 public void test_getMaxProcedureNameLength() throws SQLException { 1026 assertTrue("Incorrect length of procedure name", meta 1027 .getMaxProcedureNameLength() == 0); 1028 } 1029 1030 /** 1031 * java.sql.DatabaseMetaData#getMaxRowSize() 1032 */ 1033 public void test_getMaxRowSize() throws SQLException { 1034 assertTrue("Incorrect size of row", meta.getMaxRowSize() == 0); 1035 } 1036 1037 /** 1038 * java.sql.DatabaseMetaData#getMaxSchemaNameLength() 1039 */ 1040 public void test_getMaxSchemaNameLength() throws SQLException { 1041 assertTrue("Incorrect length of schema name", meta 1042 .getMaxSchemaNameLength() == 0); 1043 } 1044 1045 /** 1046 * java.sql.DatabaseMetaData#getMaxStatementLength() 1047 */ 1048 public void test_getMaxStatementLength() throws SQLException { 1049 assertTrue("Incorrect length of statement", meta 1050 .getMaxStatementLength() == 0); 1051 } 1052 1053 /** 1054 * java.sql.DatabaseMetaData#getMaxStatements() 1055 */ 1056 public void test_getMaxStatements() throws SQLException { 1057 assertTrue("Incorrect number of statements", 1058 meta.getMaxStatements() == 0); 1059 } 1060 1061 /** 1062 * java.sql.DatabaseMetaData#getMaxTableNameLength() 1063 */ 1064 @KnownFailure("Exception test fails") 1065 public void test_getMaxTableNameLength() throws SQLException { 1066 assertTrue("Now supported", meta 1067 .getMaxTableNameLength() == 0); 1068 1069 //Exception checking 1070 conn.close(); 1071 1072 try { 1073 meta.getMaxTableNameLength(); 1074 fail("SQLException not thrown"); 1075 } catch (SQLException e) { 1076 //ok 1077 } 1078 } 1079 1080 /** 1081 * java.sql.DatabaseMetaData#getMaxTablesInSelect() 1082 */ 1083 @KnownFailure("Exception test fails") 1084 public void test_getMaxTablesInSelect() throws SQLException { 1085 assertTrue("Tables in select is now supported: change test implementation\"", 1086 meta.getMaxTablesInSelect() == 0); 1087 1088 //Exception checking 1089 conn.close(); 1090 1091 try { 1092 meta.getMaxTablesInSelect(); 1093 fail("SQLException not thrown"); 1094 } catch (SQLException e) { 1095 //ok 1096 } 1097 } 1098 1099 /** 1100 * java.sql.DatabaseMetaData#getMaxUserNameLength() 1101 */ 1102 @KnownFailure("Exception test fails") 1103 public void test_getMaxUserNameLength() throws SQLException { 1104 assertTrue("Usernames are now supported: change test implementation", 1105 meta.getMaxUserNameLength() == 0); 1106 1107 //Excpetion checking 1108 conn.close(); 1109 1110 try { 1111 meta.getMaxUserNameLength(); 1112 fail("SQLException not thrown"); 1113 } catch (SQLException e) { 1114 //ok 1115 } 1116 } 1117 1118 1119 } 1120