comparison tests/JDBC_API_Tester.java @ 448:d7bac8d0fb93

Converted and added example program SQLcopyinto() to JDBC_API_Tester.java
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Wed, 03 Mar 2021 15:21:47 +0100 (2021-03-03)
parents 7147d1252828
children b9f82064fe0c
comparison
equal deleted inserted replaced
447:7147d1252828 448:d7bac8d0fb93
92 jt.Bug_PrepStmtSetObject_CLOB_6349(); 92 jt.Bug_PrepStmtSetObject_CLOB_6349();
93 jt.Bug_PrepStmtSetString_6382(); 93 jt.Bug_PrepStmtSetString_6382();
94 jt.Bug_PrepStmt_With_Errors_Jira292(); 94 jt.Bug_PrepStmt_With_Errors_Jira292();
95 jt.BugResultSetMetaData_Bug_6183(); 95 jt.BugResultSetMetaData_Bug_6183();
96 jt.BugSetQueryTimeout_Bug_3357(); 96 jt.BugSetQueryTimeout_Bug_3357();
97 jt.SQLcopyinto();
97 98
98 jt.closeConx(jt.con); 99 jt.closeConx(jt.con);
99 } 100 }
100 101
101 private void Test_Cautocommit(String arg0) { 102 private void Test_Cautocommit(String arg0) {
250 // >> true: auto commit should be on by default 251 // >> true: auto commit should be on by default
251 sb.append("0. true\t").append(con.getAutoCommit()).append("\n"); 252 sb.append("0. true\t").append(con.getAutoCommit()).append("\n");
252 stmt = con.createStatement(); 253 stmt = con.createStatement();
253 254
254 // sending big script with many simple queries 255 // sending big script with many simple queries
255 sb.append("1. executing script").append("\n"); 256 sb.append("1. executing script\n");
256 stmt.execute(bigq.toString()); 257 stmt.execute(bigq.toString());
257 258
258 int i = 1; // we skip the first "getResultSet()" 259 int i = 1; // we skip the first "getResultSet()"
259 while (stmt.getMoreResults() != false) { 260 while (stmt.getMoreResults() != false) {
260 i++; 261 i++;
261 } 262 }
262 if (stmt.getUpdateCount() != -1) { 263 if (stmt.getUpdateCount() != -1) {
263 sb.append("Error: found an update count for a SELECT query").append("\n"); 264 sb.append("Error: found an update count for a SELECT query\n");
264 } 265 }
265 if (i != size) { 266 if (i != size) {
266 sb.append("Error: expecting ").append(size).append(" tuples, only got ").append(i).append("\n"); 267 sb.append("Error: expecting ").append(size).append(" tuples, only got ").append(i).append("\n");
267 } 268 }
268 sb.append("2. queries processed").append("\n"); 269 sb.append("2. queries processed\n");
269 } catch (SQLException e) { 270 } catch (SQLException e) {
270 sb.append("FAILED: ").append(e.getMessage()).append("\n"); 271 sb.append("FAILED: ").append(e.getMessage()).append("\n");
271 } 272 }
272 273
273 closeStmtResSet(stmt, null); 274 closeStmtResSet(stmt, null);
343 344
344 stmt1 = con.createStatement(); 345 stmt1 = con.createStatement();
345 // test commit by checking if a change is visible in another connection 346 // test commit by checking if a change is visible in another connection
346 sb.append("1. create... "); 347 sb.append("1. create... ");
347 stmt1.executeUpdate("CREATE TABLE table_Test_Creplysize ( id int )"); 348 stmt1.executeUpdate("CREATE TABLE table_Test_Creplysize ( id int )");
348 sb.append("passed").append("\n"); 349 sb.append("passed\n");
349 350
350 sb.append("2. populating with 21 records... "); 351 sb.append("2. populating with 21 records... ");
351 for (int i = 0; i < 21; i++) 352 for (int i = 0; i < 21; i++)
352 stmt1.executeUpdate("INSERT INTO table_Test_Creplysize (id) values (" + (i + 1) + ")"); 353 stmt1.executeUpdate("INSERT INTO table_Test_Creplysize (id) values (" + (i + 1) + ")");
353 sb.append("passed").append("\n"); 354 sb.append("passed\n");
354 355
355 sb.append("3. hinting the driver to use fetchsize 10... "); 356 sb.append("3. hinting the driver to use fetchsize 10... ");
356 stmt1.setFetchSize(10); 357 stmt1.setFetchSize(10);
357 sb.append("passed").append("\n"); 358 sb.append("passed\n");
358 359
359 sb.append("4. selecting all values... "); 360 sb.append("4. selecting all values... ");
360 rs = stmt1.executeQuery("SELECT * FROM table_Test_Creplysize"); 361 rs = stmt1.executeQuery("SELECT * FROM table_Test_Creplysize");
361 int i = 0; 362 int i = 0;
362 while (rs.next()) 363 while (rs.next())
369 } 370 }
370 sb.append("\n"); 371 sb.append("\n");
371 372
372 sb.append("5. resetting driver fetchsize hint... "); 373 sb.append("5. resetting driver fetchsize hint... ");
373 stmt1.setFetchSize(0); 374 stmt1.setFetchSize(0);
374 sb.append("passed").append("\n"); 375 sb.append("passed\n");
375 376
376 sb.append("6. instructing the driver to return at max 10 rows... "); 377 sb.append("6. instructing the driver to return at max 10 rows... ");
377 stmt1.setMaxRows(10); 378 stmt1.setMaxRows(10);
378 sb.append("passed").append("\n"); 379 sb.append("passed\n");
379 380
380 sb.append("7. selecting all values... "); 381 sb.append("7. selecting all values... ");
381 rs = stmt1.executeQuery("SELECT * FROM table_Test_Creplysize"); 382 rs = stmt1.executeQuery("SELECT * FROM table_Test_Creplysize");
382 i = 0; 383 i = 0;
383 while (rs.next()) 384 while (rs.next())
390 } 391 }
391 sb.append("\n"); 392 sb.append("\n");
392 393
393 sb.append("8. hinting the driver to use fetchsize 5... "); 394 sb.append("8. hinting the driver to use fetchsize 5... ");
394 stmt1.setFetchSize(5); 395 stmt1.setFetchSize(5);
395 sb.append("passed").append("\n"); 396 sb.append("passed\n");
396 397
397 sb.append("9. selecting all values... "); 398 sb.append("9. selecting all values... ");
398 rs = stmt1.executeQuery("SELECT * FROM table_Test_Creplysize"); 399 rs = stmt1.executeQuery("SELECT * FROM table_Test_Creplysize");
399 i = 0; 400 i = 0;
400 while (rs.next()) 401 while (rs.next())
407 } 408 }
408 sb.append("\n"); 409 sb.append("\n");
409 410
410 sb.append("10. drop... "); 411 sb.append("10. drop... ");
411 stmt1.executeUpdate("DROP TABLE table_Test_Creplysize"); 412 stmt1.executeUpdate("DROP TABLE table_Test_Creplysize");
412 sb.append("passed").append("\n"); 413 sb.append("passed\n");
413 414
414 con.rollback(); 415 con.rollback();
415 416
416 // restore auto commit mode 417 // restore auto commit mode
417 con.setAutoCommit(true); 418 con.setAutoCommit(true);
459 sb.append("0. false\t").append(con.getAutoCommit()).append("\n"); 460 sb.append("0. false\t").append(con.getAutoCommit()).append("\n");
460 461
461 sb.append("2. savepoint..."); 462 sb.append("2. savepoint...");
462 /* make a savepoint, and discard it */ 463 /* make a savepoint, and discard it */
463 con.setSavepoint(); 464 con.setSavepoint();
464 sb.append("passed").append("\n"); 465 sb.append("passed\n");
465 466
466 stmt = con.createStatement(); 467 stmt = con.createStatement();
467 stmt.executeUpdate("CREATE TABLE table_Test_Csavepoints ( id int, PRIMARY KEY (id) )"); 468 stmt.executeUpdate("CREATE TABLE table_Test_Csavepoints ( id int, PRIMARY KEY (id) )");
468 469
469 sb.append("3. savepoint..."); 470 sb.append("3. savepoint...");
470 Savepoint sp2 = con.setSavepoint("empty table"); 471 Savepoint sp2 = con.setSavepoint("empty table");
471 sb.append("passed").append("\n"); 472 sb.append("passed\n");
472 473
473 rs = stmt.executeQuery("SELECT id FROM table_Test_Csavepoints"); 474 rs = stmt.executeQuery("SELECT id FROM table_Test_Csavepoints");
474 int i = 0; 475 int i = 0;
475 int items = 0; 476 int items = 0;
476 sb.append("4. table ").append(items).append(" items"); 477 sb.append("4. table ").append(items).append(" items");
479 i++; 480 i++;
480 } 481 }
481 if (i != items) { 482 if (i != items) {
482 sb.append(" FAILED (").append(i).append(")"); 483 sb.append(" FAILED (").append(i).append(")");
483 } 484 }
484 sb.append(" passed").append("\n"); 485 sb.append(" passed\n");
485 486
486 stmt.executeUpdate("INSERT INTO table_Test_Csavepoints VALUES (1)"); 487 stmt.executeUpdate("INSERT INTO table_Test_Csavepoints VALUES (1)");
487 stmt.executeUpdate("INSERT INTO table_Test_Csavepoints VALUES (2)"); 488 stmt.executeUpdate("INSERT INTO table_Test_Csavepoints VALUES (2)");
488 stmt.executeUpdate("INSERT INTO table_Test_Csavepoints VALUES (3)"); 489 stmt.executeUpdate("INSERT INTO table_Test_Csavepoints VALUES (3)");
489 490
490 sb.append("5. savepoint..."); 491 sb.append("5. savepoint...");
491 Savepoint sp3 = con.setSavepoint("three values"); 492 Savepoint sp3 = con.setSavepoint("three values");
492 sb.append("passed").append("\n"); 493 sb.append("passed\n");
493 494
494 rs = stmt.executeQuery("SELECT id FROM table_Test_Csavepoints"); 495 rs = stmt.executeQuery("SELECT id FROM table_Test_Csavepoints");
495 i = 0; 496 i = 0;
496 items = 3; 497 items = 3;
497 sb.append("6. table ").append(items).append(" items"); 498 sb.append("6. table ").append(items).append(" items");
500 i++; 501 i++;
501 } 502 }
502 if (i != items) { 503 if (i != items) {
503 sb.append(" FAILED (").append(i).append(")"); 504 sb.append(" FAILED (").append(i).append(")");
504 } 505 }
505 sb.append(" passed").append("\n"); 506 sb.append(" passed\n");
506 507
507 sb.append("7. release..."); 508 sb.append("7. release...");
508 con.releaseSavepoint(sp3); 509 con.releaseSavepoint(sp3);
509 sb.append("passed").append("\n"); 510 sb.append("passed\n");
510 511
511 rs = stmt.executeQuery("SELECT id FROM table_Test_Csavepoints"); 512 rs = stmt.executeQuery("SELECT id FROM table_Test_Csavepoints");
512 i = 0; 513 i = 0;
513 items = 3; 514 items = 3;
514 sb.append("8. table ").append(items).append(" items"); 515 sb.append("8. table ").append(items).append(" items");
517 i++; 518 i++;
518 } 519 }
519 if (i != items) { 520 if (i != items) {
520 sb.append(" FAILED (").append(i).append(") :("); 521 sb.append(" FAILED (").append(i).append(") :(");
521 } 522 }
522 sb.append(" passed").append("\n"); 523 sb.append(" passed\n");
523 524
524 sb.append("9. rollback..."); 525 sb.append("9. rollback...");
525 con.rollback(sp2); 526 con.rollback(sp2);
526 sb.append("passed").append("\n"); 527 sb.append("passed\n");
527 528
528 rs = stmt.executeQuery("SELECT id FROM table_Test_Csavepoints"); 529 rs = stmt.executeQuery("SELECT id FROM table_Test_Csavepoints");
529 i = 0; 530 i = 0;
530 items = 0; 531 items = 0;
531 sb.append("10. table ").append(items).append(" items"); 532 sb.append("10. table ").append(items).append(" items");
584 sb.append("2. false\t").append(con.getAutoCommit()).append("\n"); 585 sb.append("2. false\t").append(con.getAutoCommit()).append("\n");
585 586
586 // a change would not be visible now 587 // a change would not be visible now
587 sb.append("3. commit..."); 588 sb.append("3. commit...");
588 con.commit(); 589 con.commit();
589 sb.append("passed").append("\n"); 590 sb.append("passed\n");
590 591
591 sb.append("4. commit..."); 592 sb.append("4. commit...");
592 con.commit(); 593 con.commit();
593 sb.append("passed").append("\n"); 594 sb.append("passed\n");
594 595
595 sb.append("5. rollback..."); 596 sb.append("5. rollback...");
596 con.rollback(); 597 con.rollback();
597 sb.append("passed"); 598 sb.append("passed");
598 } catch (SQLException e) { 599 } catch (SQLException e) {
608 sb.append("6. true\t").append(con.getAutoCommit()).append("\n"); 609 sb.append("6. true\t").append(con.getAutoCommit()).append("\n");
609 610
610 stmt = con.createStatement(); 611 stmt = con.createStatement();
611 sb.append("7. start transaction..."); 612 sb.append("7. start transaction...");
612 stmt.executeUpdate("START TRANSACTION"); 613 stmt.executeUpdate("START TRANSACTION");
613 sb.append("passed").append("\n"); 614 sb.append("passed\n");
614 615
615 sb.append("8. commit..."); 616 sb.append("8. commit...");
616 con.commit(); 617 con.commit();
617 sb.append("passed").append("\n"); 618 sb.append("passed\n");
618 619
619 sb.append("9. true\t").append(con.getAutoCommit()); 620 sb.append("9. true\t").append(con.getAutoCommit());
620 sb.append("\n"); 621 sb.append("\n");
621 622
622 sb.append("10. start transaction..."); 623 sb.append("10. start transaction...");
623 stmt.executeUpdate("START TRANSACTION"); 624 stmt.executeUpdate("START TRANSACTION");
624 sb.append("passed").append("\n"); 625 sb.append("passed\n");
625 626
626 sb.append("11. rollback..."); 627 sb.append("11. rollback...");
627 con.rollback(); 628 con.rollback();
628 sb.append("passed").append("\n"); 629 sb.append("passed\n");
629 630
630 sb.append("12. true\t").append(con.getAutoCommit()); 631 sb.append("12. true\t").append(con.getAutoCommit());
631 } catch (SQLException e) { 632 } catch (SQLException e) {
632 sb.append("FAILED: ").append(e.getMessage()); 633 sb.append("FAILED: ").append(e.getMessage());
633 } 634 }
756 private void compareResultSet(ResultSet rs, String methodnm, String expected) throws SQLException { 757 private void compareResultSet(ResultSet rs, String methodnm, String expected) throws SQLException {
757 sb.setLength(0); // clear the output log buffer 758 sb.setLength(0); // clear the output log buffer
758 759
759 ResultSetMetaData rsmd = rs.getMetaData(); 760 ResultSetMetaData rsmd = rs.getMetaData();
760 int columnCount = rsmd.getColumnCount(); 761 int columnCount = rsmd.getColumnCount();
761 sb.append("Resultset with ").append(columnCount).append(" columns").append("\n"); 762 sb.append("Resultset with ").append(columnCount).append(" columns\n");
762 for (int col = 1; col <= columnCount; col++) { 763 for (int col = 1; col <= columnCount; col++) {
763 if (col > 1) 764 if (col > 1)
764 sb.append("\t"); 765 sb.append("\t");
765 sb.append(rsmd.getColumnName(col)); 766 sb.append(rsmd.getColumnName(col));
766 } 767 }
856 rs.next(); 857 rs.next();
857 BigInteger biRes = rs.getBigDecimal(1).toBigInteger(); 858 BigInteger biRes = rs.getBigDecimal(1).toBigInteger();
858 rs.close(); 859 rs.close();
859 sb.append("Expecting " + bi + ", got " + biRes).append("\n"); 860 sb.append("Expecting " + bi + ", got " + biRes).append("\n");
860 if (!bi.equals(biRes)) { 861 if (!bi.equals(biRes)) {
861 sb.append("value of bi is NOT equal to biRes!").append("\n"); 862 sb.append("value of bi is NOT equal to biRes!\n");
862 } 863 }
863 864
864 rs = stmt.executeQuery("SELECT I FROM HUGEDECT"); 865 rs = stmt.executeQuery("SELECT I FROM HUGEDECT");
865 rs.next(); 866 rs.next();
866 BigDecimal bdRes = rs.getBigDecimal(1); 867 BigDecimal bdRes = rs.getBigDecimal(1);
867 rs.close(); 868 rs.close();
868 sb.append("Expecting " + bd + ", got " + bdRes).append("\n"); 869 sb.append("Expecting " + bd + ", got " + bdRes).append("\n");
869 if (!bd.equals(bdRes)) { 870 if (!bd.equals(bdRes)) {
870 sb.append("value of bd is NOT equal to bdRes!").append("\n"); 871 sb.append("value of bd is NOT equal to bdRes!\n");
871 } 872 }
872 } catch (SQLException e) { 873 } catch (SQLException e) {
873 sb.append("FAILED: ").append(e.getMessage()).append("\n"); 874 sb.append("FAILED: ").append(e.getMessage()).append("\n");
874 } 875 }
875 876
876 // cleanup 877 // cleanup
877 try { 878 try {
878 stmt.executeUpdate("DROP TABLE IF EXISTS HUGEINTT"); 879 stmt.executeUpdate("DROP TABLE IF EXISTS HUGEINTT");
879 stmt.executeUpdate("DROP TABLE IF EXISTS HUGEDECT"); 880 stmt.executeUpdate("DROP TABLE IF EXISTS HUGEDECT");
880 sb.append("SUCCESS").append("\n"); 881 sb.append("SUCCESS\n");
881 } catch (SQLException e) { 882 } catch (SQLException e) {
882 sb.append("FAILED: ").append(e.getMessage()).append("\n"); 883 sb.append("FAILED: ").append(e.getMessage()).append("\n");
883 } 884 }
884 closeStmtResSet(insertStatement, null); 885 closeStmtResSet(insertStatement, null);
885 closeStmtResSet(stmt, rs); 886 closeStmtResSet(stmt, rs);
920 921
921 sb.append("1. inserting 3 records..."); 922 sb.append("1. inserting 3 records...");
922 pstmt.executeUpdate(); 923 pstmt.executeUpdate();
923 pstmt.executeUpdate(); 924 pstmt.executeUpdate();
924 pstmt.executeUpdate(); 925 pstmt.executeUpdate();
925 sb.append("success").append("\n"); 926 sb.append("success\n");
926 927
927 // now get the generated keys 928 // now get the generated keys
928 sb.append("2. getting generated keys..."); 929 sb.append("2. getting generated keys...");
929 keys = pstmt.getGeneratedKeys(); 930 keys = pstmt.getGeneratedKeys();
930 if (keys == null) { 931 if (keys == null) {
931 sb.append("there are no keys!").append("\n"); 932 sb.append("there are no keys!\n");
932 } else { 933 } else {
933 while (keys.next()) { 934 while (keys.next()) {
934 sb.append("generated key index: ").append(keys.getInt(1)).append("\n"); 935 sb.append("generated key index: ").append(keys.getInt(1)).append("\n");
935 } 936 }
936 if (keys.getStatement() == null) { 937 if (keys.getStatement() == null) {
937 sb.append("ResultSet.getStatement() should never return null!").append("\n"); 938 sb.append("ResultSet.getStatement() should never return null!\n");
938 } 939 }
939 keys.close(); 940 keys.close();
940 } 941 }
941 pstmt.close(); 942 pstmt.close();
942 } catch (SQLException e) { 943 } catch (SQLException e) {
968 sb.append("0. false\t").append(con.getAutoCommit()).append("\n"); 969 sb.append("0. false\t").append(con.getAutoCommit()).append("\n");
969 970
970 stmt = con.createStatement(); 971 stmt = con.createStatement();
971 sb.append("1. creating test table..."); 972 sb.append("1. creating test table...");
972 stmt.executeUpdate("CREATE TABLE table_Test_PSgetObject (ti tinyint, si smallint, i int, bi bigint)"); 973 stmt.executeUpdate("CREATE TABLE table_Test_PSgetObject (ti tinyint, si smallint, i int, bi bigint)");
973 sb.append("success").append("\n"); 974 sb.append("success\n");
974 stmt.close(); 975 stmt.close();
975 } catch (SQLException e) { 976 } catch (SQLException e) {
976 sb.append("FAILED: ").append(e.getMessage()).append("\n"); 977 sb.append("FAILED: ").append(e.getMessage()).append("\n");
977 } 978 }
978 closeStmtResSet(stmt, null); 979 closeStmtResSet(stmt, null);
999 pstmt.setInt (3, -1270000); 1000 pstmt.setInt (3, -1270000);
1000 pstmt.setLong(4, (long)-127000000); 1001 pstmt.setLong(4, (long)-127000000);
1001 pstmt.addBatch(); 1002 pstmt.addBatch();
1002 1003
1003 pstmt.executeBatch(); 1004 pstmt.executeBatch();
1004 sb.append(" passed").append("\n"); 1005 sb.append(" passed\n");
1005 1006
1006 sb.append("2b. closing PreparedStatement..."); 1007 sb.append("2b. closing PreparedStatement...");
1007 pstmt.close(); 1008 pstmt.close();
1008 sb.append(" passed").append("\n"); 1009 sb.append(" passed\n");
1009 } catch (SQLException e) { 1010 } catch (SQLException e) {
1010 sb.append("FAILED to INSERT data: ").append(e.getMessage()).append("\n"); 1011 sb.append("FAILED to INSERT data: ").append(e.getMessage()).append("\n");
1011 while ((e = e.getNextException()) != null) 1012 while ((e = e.getNextException()) != null)
1012 sb.append("FAILED: ").append(e.getMessage()).append("\n"); 1013 sb.append("FAILED: ").append(e.getMessage()).append("\n");
1013 } 1014 }
1014 1015
1015 try { 1016 try {
1016 sb.append("3a. selecting records..."); 1017 sb.append("3a. selecting records...");
1017 pstmt = con.prepareStatement("SELECT ti,si,i,bi FROM table_Test_PSgetObject ORDER BY ti,si,i,bi"); 1018 pstmt = con.prepareStatement("SELECT ti,si,i,bi FROM table_Test_PSgetObject ORDER BY ti,si,i,bi");
1018 rs = pstmt.executeQuery(); 1019 rs = pstmt.executeQuery();
1019 sb.append(" passed").append("\n"); 1020 sb.append(" passed\n");
1020 1021
1021 while (rs.next()) { 1022 while (rs.next()) {
1022 // test fix for https://www.monetdb.org/bugzilla/show_bug.cgi?id=4026 1023 // test fix for https://www.monetdb.org/bugzilla/show_bug.cgi?id=4026
1023 Short ti = (Short) rs.getObject(1); 1024 Short ti = (Short) rs.getObject(1);
1024 Short si = (Short) rs.getObject(2); 1025 Short si = (Short) rs.getObject(2);
1028 sb.append(" Retrieved row data: ti=").append(ti).append(" si=").append(si).append(" i=").append(i).append(" bi=").append(bi).append("\n"); 1029 sb.append(" Retrieved row data: ti=").append(ti).append(" si=").append(si).append(" i=").append(i).append(" bi=").append(bi).append("\n");
1029 } 1030 }
1030 1031
1031 sb.append("3b. closing ResultSet..."); 1032 sb.append("3b. closing ResultSet...");
1032 rs.close(); 1033 rs.close();
1033 sb.append(" passed").append("\n"); 1034 sb.append(" passed\n");
1034 1035
1035 sb.append("3c. closing PreparedStatement..."); 1036 sb.append("3c. closing PreparedStatement...");
1036 pstmt.close(); 1037 pstmt.close();
1037 sb.append(" passed").append("\n"); 1038 sb.append(" passed\n");
1038 } catch (SQLException e) { 1039 } catch (SQLException e) {
1039 sb.append("FAILED to RETRIEVE data: ").append(e.getMessage()).append("\n"); 1040 sb.append("FAILED to RETRIEVE data: ").append(e.getMessage()).append("\n");
1040 while ((e = e.getNextException()) != null) 1041 while ((e = e.getNextException()) != null)
1041 sb.append("FAILED: ").append(e.getMessage()).append("\n"); 1042 sb.append("FAILED: ").append(e.getMessage()).append("\n");
1042 } 1043 }
1043 closeStmtResSet(pstmt, rs); 1044 closeStmtResSet(pstmt, rs);
1044 1045
1045 try { 1046 try {
1046 sb.append("4. Rollback changes..."); 1047 sb.append("4. Rollback changes...");
1047 con.rollback(); 1048 con.rollback();
1048 sb.append(" passed").append("\n"); 1049 sb.append(" passed\n");
1049 1050
1050 // restore default setting 1051 // restore default setting
1051 con.setAutoCommit(true); 1052 con.setAutoCommit(true);
1052 } catch (SQLException e) { 1053 } catch (SQLException e) {
1053 sb.append("FAILED to rollback: ").append(e.getMessage()).append("\n"); 1054 sb.append("FAILED to rollback: ").append(e.getMessage()).append("\n");
1086 sb.append("0. true\t").append(con.getAutoCommit()).append("\n"); 1087 sb.append("0. true\t").append(con.getAutoCommit()).append("\n");
1087 1088
1088 stmt = con.createStatement(); 1089 stmt = con.createStatement();
1089 sb.append("1. creating test table..."); 1090 sb.append("1. creating test table...");
1090 stmt.execute("CREATE TABLE Test_PSlargebatchval (c INT, a CLOB, b DOUBLE)"); 1091 stmt.execute("CREATE TABLE Test_PSlargebatchval (c INT, a CLOB, b DOUBLE)");
1091 sb.append("success").append("\n"); 1092 sb.append("success\n");
1092 1093
1093 sb.append("2. prepare insert..."); 1094 sb.append("2. prepare insert...");
1094 pstmt = con.prepareStatement("INSERT INTO Test_PSlargebatchval VALUES (?,?,?)"); 1095 pstmt = con.prepareStatement("INSERT INTO Test_PSlargebatchval VALUES (?,?,?)");
1095 sb.append("success").append("\n"); 1096 sb.append("success\n");
1096 1097
1097 pstmt.setLong(1, 1L); 1098 pstmt.setLong(1, 1L);
1098 pstmt.setString(2, largeStr); 1099 pstmt.setString(2, largeStr);
1099 pstmt.setDouble(3, 1.0); 1100 pstmt.setDouble(3, 1.0);
1100 pstmt.addBatch(); 1101 pstmt.addBatch();
1101 pstmt.executeBatch(); 1102 pstmt.executeBatch();
1102 sb.append("3. inserted 1 large string").append("\n"); 1103 sb.append("3. inserted 1 large string\n");
1103 1104
1104 /* test issue reported at https://www.monetdb.org/bugzilla/show_bug.cgi?id=3470 */ 1105 /* test issue reported at https://www.monetdb.org/bugzilla/show_bug.cgi?id=3470 */
1105 pstmt.setLong(1, -2L); 1106 pstmt.setLong(1, -2L);
1106 pstmt.setClob(2, new StringReader(largeStr)); 1107 pstmt.setClob(2, new StringReader(largeStr));
1107 pstmt.setDouble(3, -2.0); 1108 pstmt.setDouble(3, -2.0);
1108 pstmt.addBatch(); 1109 pstmt.addBatch();
1109 pstmt.executeBatch(); 1110 pstmt.executeBatch();
1110 sb.append("4. inserted 1 large clob via StringReader() object").append("\n"); 1111 sb.append("4. inserted 1 large clob via StringReader() object\n");
1111 1112
1112 Clob myClob = con.createClob(); 1113 Clob myClob = con.createClob();
1113 myClob.setString(1L, largeStr); 1114 myClob.setString(1L, largeStr);
1114 1115
1115 pstmt.setLong(1, 123456789L); 1116 pstmt.setLong(1, 123456789L);
1116 pstmt.setClob(2, myClob); 1117 pstmt.setClob(2, myClob);
1117 pstmt.setDouble(3, 12345678901.98765); 1118 pstmt.setDouble(3, 12345678901.98765);
1118 pstmt.addBatch(); 1119 pstmt.addBatch();
1119 pstmt.executeBatch(); 1120 pstmt.executeBatch();
1120 sb.append("5. inserted 1 large clob via createClob() object").append("\n"); 1121 sb.append("5. inserted 1 large clob via createClob() object\n");
1121 1122
1122 pstmt.close(); 1123 pstmt.close();
1123 1124
1124 sb.append("6. select count(*)... "); 1125 sb.append("6. select count(*)... ");
1125 rs = stmt.executeQuery("SELECT COUNT(*) FROM Test_PSlargebatchval"); 1126 rs = stmt.executeQuery("SELECT COUNT(*) FROM Test_PSlargebatchval");
1126 if (rs.next()) 1127 if (rs.next())
1127 sb.append(rs.getInt(1)).append(" rows inserted.").append("\n"); 1128 sb.append(rs.getInt(1)).append(" rows inserted.\n");
1128 rs.close(); 1129 rs.close();
1129 1130
1130 sb.append("7. drop table..."); 1131 sb.append("7. drop table...");
1131 stmt.execute("DROP TABLE Test_PSlargebatchval"); 1132 stmt.execute("DROP TABLE Test_PSlargebatchval");
1132 sb.append("success").append("\n"); 1133 sb.append("success\n");
1133 stmt.close(); 1134 stmt.close();
1134 } catch (SQLException e) { 1135 } catch (SQLException e) {
1135 sb.append("FAILED: ").append(e.getMessage()).append("\n"); 1136 sb.append("FAILED: ").append(e.getMessage()).append("\n");
1136 while ((e = e.getNextException()) != null) 1137 while ((e = e.getNextException()) != null)
1137 sb.append("FAILED: ").append(e.getMessage()).append("\n"); 1138 sb.append("FAILED: ").append(e.getMessage()).append("\n");
1167 1168
1168 pstmt = con.prepareStatement("select * from columns"); 1169 pstmt = con.prepareStatement("select * from columns");
1169 sb.append("2. empty call..."); 1170 sb.append("2. empty call...");
1170 // should succeed (no arguments given) 1171 // should succeed (no arguments given)
1171 pstmt.execute(); 1172 pstmt.execute();
1172 sb.append(" passed").append("\n"); 1173 sb.append(" passed\n");
1173 } catch (SQLException e) { 1174 } catch (SQLException e) {
1174 sb.append("FAILED: ").append(e.getMessage()).append("\n"); 1175 sb.append("FAILED: ").append(e.getMessage()).append("\n");
1175 } 1176 }
1176 closeStmtResSet(pstmt, null); 1177 closeStmtResSet(pstmt, null);
1177 1178
1484 ResultSet rs = null; 1485 ResultSet rs = null;
1485 try { 1486 try {
1486 // >> true: auto commit should be on 1487 // >> true: auto commit should be on
1487 sb.append("0. true\t").append(con.getAutoCommit()).append("\n"); 1488 sb.append("0. true\t").append(con.getAutoCommit()).append("\n");
1488 1489
1489 sb.append("1. Preparing and executing a unique statement").append("\n"); 1490 sb.append("1. Preparing and executing a unique statement\n");
1490 for (int i = 0; i < 120; i++) { 1491 for (int i = 0; i < 120; i++) {
1491 pstmt = con.prepareStatement("select " + i + ", " + i + " = ?"); 1492 pstmt = con.prepareStatement("select " + i + ", " + i + " = ?");
1492 pstmt.setInt(1, i); 1493 pstmt.setInt(1, i);
1493 rs = pstmt.executeQuery(); 1494 rs = pstmt.executeQuery();
1494 if (rs.next() && i % 20 == 0) { 1495 if (rs.next() && i % 20 == 0) {
1566 ResultSetMetaData rsmd = rs.getMetaData(); 1567 ResultSetMetaData rsmd = rs.getMetaData();
1567 for (int i = 1; rs.next(); i++) { 1568 for (int i = 1; rs.next(); i++) {
1568 for (int col = 1; col <= rsmd.getColumnCount(); col++) { 1569 for (int col = 1; col <= rsmd.getColumnCount(); col++) {
1569 Object x = rs.getObject(col); 1570 Object x = rs.getObject(col);
1570 if (x == null || rs.wasNull()) { 1571 if (x == null || rs.wasNull()) {
1571 sb.append(i).append(".\t<null>").append("\n"); 1572 sb.append(i).append(".\t<null>\n");
1572 } else { 1573 } else {
1573 sb.append(i).append(".\t").append(x.toString()).append("\n"); 1574 sb.append(i).append(".\t").append(x.toString()).append("\n");
1574 if (x instanceof INET) { 1575 if (x instanceof INET) {
1575 INET inet = (INET)x; 1576 INET inet = (INET)x;
1576 sb.append(" ").append(inet.getAddress()).append("/").append(inet.getNetmaskBits()).append("\n"); 1577 sb.append(" ").append(inet.getAddress()).append("/").append(inet.getNetmaskBits()).append("\n");
2041 cstmt.setNull(1, Types.INTEGER); 2042 cstmt.setNull(1, Types.INTEGER);
2042 cstmt.executeUpdate(); 2043 cstmt.executeUpdate();
2043 sb.append("Called Prepared procedure (with NULLs): ").append(proc_nm).append("\n"); 2044 sb.append("Called Prepared procedure (with NULLs): ").append(proc_nm).append("\n");
2044 showTblContents(tbl_nm); 2045 showTblContents(tbl_nm);
2045 2046
2046 sb.append("Test completed. Cleanup procedure and table.").append("\n"); 2047 sb.append("Test completed. Cleanup procedure and table.\n");
2047 stmt.execute("DROP PROCEDURE IF EXISTS " + proc_nm + ";"); 2048 stmt.execute("DROP PROCEDURE IF EXISTS " + proc_nm + ";");
2048 stmt.execute("DROP TABLE IF EXISTS " + tbl_nm + ";"); 2049 stmt.execute("DROP TABLE IF EXISTS " + tbl_nm + ";");
2049 2050
2050 } catch (SQLException e) { 2051 } catch (SQLException e) {
2051 sb.append("FAILED: ").append(e.getMessage()).append("\n"); 2052 sb.append("FAILED: ").append(e.getMessage()).append("\n");
2578 for (int i = 1; rs.next(); i++) { 2579 for (int i = 1; rs.next(); i++) {
2579 for (int col = 1; col <= rsmd.getColumnCount(); col++) { 2580 for (int col = 1; col <= rsmd.getColumnCount(); col++) {
2580 sb.append(i).append(".\t"); 2581 sb.append(i).append(".\t");
2581 Object x = rs.getObject(col); 2582 Object x = rs.getObject(col);
2582 if (x == null) { 2583 if (x == null) {
2583 sb.append("<null>").append("\n"); 2584 sb.append("<null>\n");
2584 } else { 2585 } else {
2585 sb.append(x.toString()).append("\n"); 2586 sb.append(x.toString()).append("\n");
2586 if (x instanceof INET) { 2587 if (x instanceof INET) {
2587 INET inet = (INET)x; 2588 INET inet = (INET)x;
2588 sb.append("\t").append(inet.getAddress()).append("/").append(inet.getNetmaskBits()).append("\n"); 2589 sb.append("\t").append(inet.getAddress()).append("/").append(inet.getNetmaskBits()).append("\n");
2963 sb.append("0. true\t").append(con.getAutoCommit()).append("\n"); 2964 sb.append("0. true\t").append(con.getAutoCommit()).append("\n");
2964 2965
2965 stmt = con.createStatement(); 2966 stmt = con.createStatement();
2966 sb.append("1. more results?..."); 2967 sb.append("1. more results?...");
2967 if (stmt.getMoreResults() != false || stmt.getUpdateCount() != -1) 2968 if (stmt.getMoreResults() != false || stmt.getUpdateCount() != -1)
2968 sb.append("more results on an unitialised Statement, how can that be?").append("\n"); 2969 sb.append("more results on an unitialised Statement, how can that be?\n");
2969 sb.append(" nope :)").append("\n"); 2970 sb.append(" nope :)\n");
2970 2971
2971 sb.append("2. SELECT 1..."); 2972 sb.append("2. SELECT 1...");
2972 if (stmt.execute("SELECT 1;") == false) 2973 if (stmt.execute("SELECT 1;") == false)
2973 sb.append("SELECT 1 returns update or no results").append("\n"); 2974 sb.append("SELECT 1 returns update or no results\n");
2974 sb.append(" ResultSet :)").append("\n"); 2975 sb.append(" ResultSet :)\n");
2975 2976
2976 sb.append("3. more results?..."); 2977 sb.append("3. more results?...");
2977 if (stmt.getMoreResults() != false || stmt.getUpdateCount() != -1) 2978 if (stmt.getMoreResults() != false || stmt.getUpdateCount() != -1)
2978 sb.append("more results after SELECT 1 query, how can that be?").append("\n"); 2979 sb.append("more results after SELECT 1 query, how can that be?\n");
2979 sb.append(" nope :)").append("\n"); 2980 sb.append(" nope :)\n");
2980 2981
2981 sb.append("4. even more results?..."); 2982 sb.append("4. even more results?...");
2982 if (stmt.getMoreResults() != false) 2983 if (stmt.getMoreResults() != false)
2983 sb.append("still more results after SELECT 1 query, how can that be?").append("\n"); 2984 sb.append("still more results after SELECT 1 query, how can that be?\n");
2984 sb.append(" nope :)").append("\n"); 2985 sb.append(" nope :)\n");
2985 2986
2986 } catch (SQLException e) { 2987 } catch (SQLException e) {
2987 sb.append("FAILED: ").append(e.getMessage()).append("\n"); 2988 sb.append("FAILED: ").append(e.getMessage()).append("\n");
2988 } 2989 }
2989 2990
3144 sb.append("0. true\t").append(con1.getAutoCommit()).append("\n"); 3145 sb.append("0. true\t").append(con1.getAutoCommit()).append("\n");
3145 sb.append("0. true\t").append(con2.getAutoCommit()).append("\n"); 3146 sb.append("0. true\t").append(con2.getAutoCommit()).append("\n");
3146 sb.append("0. true\t").append(con3.getAutoCommit()).append("\n"); 3147 sb.append("0. true\t").append(con3.getAutoCommit()).append("\n");
3147 3148
3148 // test the creation of a table with concurrent clients 3149 // test the creation of a table with concurrent clients
3149 sb.append("1.1. create table t1 using client 1...").append("\n"); 3150 sb.append("1.1. create table t1 using client 1...\n");
3150 stmt1.executeUpdate("CREATE TABLE t1 ( id int, name varchar(1024) )"); 3151 stmt1.executeUpdate("CREATE TABLE t1 ( id int, name varchar(1024) )");
3151 sb.append("passed :)").append("\n"); 3152 sb.append("passed :)\n");
3152 3153
3153 sb.append("1.2. check table existence in client 2...").append("\n"); 3154 sb.append("1.2. check table existence in client 2...\n");
3154 rs2 = stmt2.executeQuery("SELECT name FROM tables where name LIKE 't1'"); 3155 rs2 = stmt2.executeQuery("SELECT name FROM tables where name LIKE 't1'");
3155 while (rs2.next()) 3156 while (rs2.next())
3156 sb.append(rs2.getString("name")).append("\n"); 3157 sb.append(rs2.getString("name")).append("\n");
3157 sb.append("passed :)").append("\n"); 3158 sb.append("passed :)\n");
3158 3159
3159 sb.append("1.3. check table existence in client 3...").append("\n"); 3160 sb.append("1.3. check table existence in client 3...\n");
3160 rs3 = stmt3.executeQuery("SELECT name FROM tables where name LIKE 't1'"); 3161 rs3 = stmt3.executeQuery("SELECT name FROM tables where name LIKE 't1'");
3161 while (rs3.next()) 3162 while (rs3.next())
3162 sb.append(rs3.getString("name")).append("\n"); 3163 sb.append(rs3.getString("name")).append("\n");
3163 sb.append("passed :)").append("\n"); 3164 sb.append("passed :)\n");
3164 3165
3165 // test the insertion of values with concurrent clients 3166 // test the insertion of values with concurrent clients
3166 sb.append("2 insert into t1 using client 1...").append("\n"); 3167 sb.append("2 insert into t1 using client 1...\n");
3167 stmt1.executeUpdate("INSERT INTO t1 values( 1, 'monetdb' )"); 3168 stmt1.executeUpdate("INSERT INTO t1 values( 1, 'monetdb' )");
3168 sb.append("passed :)").append("\n"); 3169 sb.append("passed :)\n");
3169 stmt1.executeUpdate("INSERT INTO t1 values( 2, 'monet' )"); 3170 stmt1.executeUpdate("INSERT INTO t1 values( 2, 'monet' )");
3170 sb.append("passed :)").append("\n"); 3171 sb.append("passed :)\n");
3171 stmt1.executeUpdate("INSERT INTO t1 values( 3, 'mon' )"); 3172 stmt1.executeUpdate("INSERT INTO t1 values( 3, 'mon' )");
3172 sb.append("passed :)").append("\n"); 3173 sb.append("passed :)\n");
3173 3174
3174 sb.append("2.1. check table status with client 1...").append("\n"); 3175 sb.append("2.1. check table status with client 1...\n");
3175 rs1 = stmt1.executeQuery("SELECT * FROM t1"); 3176 rs1 = stmt1.executeQuery("SELECT * FROM t1");
3176 while (rs1.next()) 3177 while (rs1.next())
3177 sb.append(rs1.getInt("id")).append(", ").append(rs1.getString("name")).append("\n"); 3178 sb.append(rs1.getInt("id")).append(", ").append(rs1.getString("name")).append("\n");
3178 sb.append("passed :)").append("\n"); 3179 sb.append("passed :)\n");
3179 3180
3180 sb.append("2.2. check table status with client 2...").append("\n"); 3181 sb.append("2.2. check table status with client 2...\n");
3181 rs2 = stmt2.executeQuery("SELECT * FROM t1"); 3182 rs2 = stmt2.executeQuery("SELECT * FROM t1");
3182 while (rs2.next()) 3183 while (rs2.next())
3183 sb.append(rs2.getInt("id")).append(", ").append(rs2.getString("name")).append("\n"); 3184 sb.append(rs2.getInt("id")).append(", ").append(rs2.getString("name")).append("\n");
3184 sb.append("passed :)").append("\n"); 3185 sb.append("passed :)\n");
3185 3186
3186 sb.append("2.3. check table status with client 3...").append("\n"); 3187 sb.append("2.3. check table status with client 3...\n");
3187 rs3 = stmt3.executeQuery("SELECT * FROM t1"); 3188 rs3 = stmt3.executeQuery("SELECT * FROM t1");
3188 while (rs3.next()) 3189 while (rs3.next())
3189 sb.append(rs3.getInt("id")).append(", ").append(rs3.getString("name")).append("\n"); 3190 sb.append(rs3.getInt("id")).append(", ").append(rs3.getString("name")).append("\n");
3190 sb.append("passed :)").append("\n"); 3191 sb.append("passed :)\n");
3191 3192
3192 // test the insertion of values with concurrent clients 3193 // test the insertion of values with concurrent clients
3193 sb.append("3 insert into t1 using client 2...").append("\n"); 3194 sb.append("3 insert into t1 using client 2...\n");
3194 stmt2.executeUpdate("INSERT INTO t1 values( 4, 'monetdb' )"); 3195 stmt2.executeUpdate("INSERT INTO t1 values( 4, 'monetdb' )");
3195 sb.append("passed :)").append("\n"); 3196 sb.append("passed :)\n");
3196 stmt2.executeUpdate("INSERT INTO t1 values( 5, 'monet' )"); 3197 stmt2.executeUpdate("INSERT INTO t1 values( 5, 'monet' )");
3197 sb.append("passed :)").append("\n"); 3198 sb.append("passed :)\n");
3198 stmt2.executeUpdate("INSERT INTO t1 values( 6, 'mon' )"); 3199 stmt2.executeUpdate("INSERT INTO t1 values( 6, 'mon' )");
3199 sb.append("passed :)").append("\n"); 3200 sb.append("passed :)\n");
3200 3201
3201 sb.append("3.1. check table status with client 1...").append("\n"); 3202 sb.append("3.1. check table status with client 1...\n");
3202 rs1 = stmt1.executeQuery("SELECT * FROM t1"); 3203 rs1 = stmt1.executeQuery("SELECT * FROM t1");
3203 while (rs1.next()) 3204 while (rs1.next())
3204 sb.append(rs1.getInt("id")).append(", ").append(rs1.getString("name")).append("\n"); 3205 sb.append(rs1.getInt("id")).append(", ").append(rs1.getString("name")).append("\n");
3205 sb.append("passed :)").append("\n"); 3206 sb.append("passed :)\n");
3206 3207
3207 sb.append("3.2. check table status with client 2...").append("\n"); 3208 sb.append("3.2. check table status with client 2...\n");
3208 rs2 = stmt2.executeQuery("SELECT * FROM t1"); 3209 rs2 = stmt2.executeQuery("SELECT * FROM t1");
3209 while (rs2.next()) 3210 while (rs2.next())
3210 sb.append(rs2.getInt("id")).append(", ").append(rs2.getString("name")).append("\n"); 3211 sb.append(rs2.getInt("id")).append(", ").append(rs2.getString("name")).append("\n");
3211 sb.append("passed :)").append("\n"); 3212 sb.append("passed :)\n");
3212 3213
3213 sb.append("3.3. check table status with client 3...").append("\n"); 3214 sb.append("3.3. check table status with client 3...\n");
3214 rs3 = stmt3.executeQuery("SELECT * FROM t1"); 3215 rs3 = stmt3.executeQuery("SELECT * FROM t1");
3215 while (rs3.next()) 3216 while (rs3.next())
3216 sb.append(rs3.getInt("id")).append(", ").append(rs3.getString("name")).append("\n"); 3217 sb.append(rs3.getInt("id")).append(", ").append(rs3.getString("name")).append("\n");
3217 sb.append("passed :)").append("\n"); 3218 sb.append("passed :)\n");
3218 3219
3219 // test the insertion of values with concurrent clients 3220 // test the insertion of values with concurrent clients
3220 sb.append("4 insert into t1 using client 3...").append("\n"); 3221 sb.append("4 insert into t1 using client 3...\n");
3221 stmt3.executeUpdate("INSERT INTO t1 values( 7, 'monetdb' )"); 3222 stmt3.executeUpdate("INSERT INTO t1 values( 7, 'monetdb' )");
3222 sb.append("passed :)").append("\n"); 3223 sb.append("passed :)\n");
3223 stmt3.executeUpdate("INSERT INTO t1 values( 8, 'monet' )"); 3224 stmt3.executeUpdate("INSERT INTO t1 values( 8, 'monet' )");
3224 sb.append("passed :)").append("\n"); 3225 sb.append("passed :)\n");
3225 stmt3.executeUpdate("INSERT INTO t1 values( 9, 'mon' )"); 3226 stmt3.executeUpdate("INSERT INTO t1 values( 9, 'mon' )");
3226 sb.append("passed :)").append("\n"); 3227 sb.append("passed :)\n");
3227 3228
3228 sb.append("4.1. check table status with client 1...").append("\n"); 3229 sb.append("4.1. check table status with client 1...\n");
3229 rs1 = stmt1.executeQuery("SELECT * FROM t1"); 3230 rs1 = stmt1.executeQuery("SELECT * FROM t1");
3230 while (rs1.next()) 3231 while (rs1.next())
3231 sb.append(rs1.getInt("id")).append(", ").append(rs1.getString("name")).append("\n"); 3232 sb.append(rs1.getInt("id")).append(", ").append(rs1.getString("name")).append("\n");
3232 sb.append("passed :)").append("\n"); 3233 sb.append("passed :)\n");
3233 3234
3234 sb.append("4.2. check table status with client 2...").append("\n"); 3235 sb.append("4.2. check table status with client 2...\n");
3235 rs2 = stmt2.executeQuery("SELECT * FROM t1"); 3236 rs2 = stmt2.executeQuery("SELECT * FROM t1");
3236 while (rs2.next()) 3237 while (rs2.next())
3237 sb.append(rs2.getInt("id")).append(", ").append(rs2.getString("name")).append("\n"); 3238 sb.append(rs2.getInt("id")).append(", ").append(rs2.getString("name")).append("\n");
3238 sb.append("passed :)").append("\n"); 3239 sb.append("passed :)\n");
3239 3240
3240 sb.append("4.3. check table status with client 3...").append("\n"); 3241 sb.append("4.3. check table status with client 3...\n");
3241 rs3 = stmt3.executeQuery("SELECT * FROM t1"); 3242 rs3 = stmt3.executeQuery("SELECT * FROM t1");
3242 while (rs3.next()) 3243 while (rs3.next())
3243 sb.append(rs3.getInt("id")).append(", ").append(rs3.getString("name")).append("\n"); 3244 sb.append(rs3.getInt("id")).append(", ").append(rs3.getString("name")).append("\n");
3244 sb.append("passed :)").append("\n"); 3245 sb.append("passed :)\n");
3245 } catch (SQLException e) { 3246 } catch (SQLException e) {
3246 sb.append("FAILED: ").append(e.getMessage()).append("\n"); 3247 sb.append("FAILED: ").append(e.getMessage()).append("\n");
3247 } 3248 }
3248 3249
3249 // cleanup 3250 // cleanup
3250 try { 3251 try {
3251 sb.append("Cleanup TABLE t1").append("\n"); 3252 sb.append("Cleanup TABLE t1\n");
3252 stmt3.executeUpdate("DROP TABLE t1"); 3253 stmt3.executeUpdate("DROP TABLE t1");
3253 } catch (SQLException e) { 3254 } catch (SQLException e) {
3254 sb.append("FAILED: ").append(e.getMessage()).append("\n"); 3255 sb.append("FAILED: ").append(e.getMessage()).append("\n");
3255 } 3256 }
3256 3257
3378 sb.append("0. true\t").append(con2.getAutoCommit()).append("\n"); 3379 sb.append("0. true\t").append(con2.getAutoCommit()).append("\n");
3379 3380
3380 // create a table 3381 // create a table
3381 sb.append("1. create table t1 using client 1... "); 3382 sb.append("1. create table t1 using client 1... ");
3382 stmt1.executeUpdate("CREATE TABLE t1 ( id serial, who varchar(12) )"); 3383 stmt1.executeUpdate("CREATE TABLE t1 ( id serial, who varchar(12) )");
3383 sb.append("passed :)").append("\n"); 3384 sb.append("passed :)\n");
3384 3385
3385 // test the insertion of values with concurrent clients 3386 // test the insertion of values with concurrent clients
3386 sb.append("2. insert into t1 using client 1 and 2... "); 3387 sb.append("2. insert into t1 using client 1 and 2... ");
3387 stmt1.executeUpdate("INSERT INTO t1(who) VALUES('client1')"); 3388 stmt1.executeUpdate("INSERT INTO t1(who) VALUES('client1')");
3388 sb.append("client 1 passed :)").append("\n"); 3389 sb.append("client 1 passed :)\n");
3390
3389 con2.setAutoCommit(false); 3391 con2.setAutoCommit(false);
3390 stmt2.executeUpdate("INSERT INTO t1(who) VALUES('client2')"); 3392 stmt2.executeUpdate("INSERT INTO t1(who) VALUES('client2')");
3391 sb.append("transaction on client 2 :)").append("\n"); 3393 sb.append("transaction on client 2 :)\n");
3394
3392 stmt1.executeUpdate("INSERT INTO t1(who) VALUES('client1')"); 3395 stmt1.executeUpdate("INSERT INTO t1(who) VALUES('client1')");
3393 sb.append("client 1 passed :)").append("\n"); 3396 sb.append("client 1 passed :)\n");
3397
3394 try { 3398 try {
3395 con2.commit(); 3399 con2.commit();
3396 sb.append("transaction client 2 PASSED :(").append("\n"); 3400 sb.append("transaction client 2 PASSED :(\n");
3397 } catch (SQLException e) { 3401 } catch (SQLException e) {
3398 sb.append("transaction client 2 failed :)").append("\n"); 3402 sb.append("transaction client 2 failed :)\n");
3399 } 3403 }
3400 con2.setAutoCommit(true); 3404 con2.setAutoCommit(true);
3401 stmt2.executeUpdate("INSERT INTO t1(who) VALUES('client2')"); 3405 stmt2.executeUpdate("INSERT INTO t1(who) VALUES('client2')");
3402 sb.append("passed :)").append("\n"); 3406 sb.append("passed :)\n");
3403 3407
3404 sb.append("2.1. check table status with client 1...").append("\n"); 3408 sb.append("2.1. check table status with client 1...\n");
3405 rs1 = stmt1.executeQuery("SELECT * FROM t1"); 3409 rs1 = stmt1.executeQuery("SELECT * FROM t1");
3406 while (rs1.next()) 3410 while (rs1.next())
3407 sb.append(rs1.getInt("id")).append(", ").append(rs1.getString("who")).append("\n"); 3411 sb.append(rs1.getInt("id")).append(", ").append(rs1.getString("who")).append("\n");
3408 sb.append("passed :)").append("\n"); 3412 sb.append("passed :)\n");
3409 3413
3410 sb.append("2.2. check table status with client 2...").append("\n"); 3414 sb.append("2.2. check table status with client 2...\n");
3411 rs2 = stmt2.executeQuery("SELECT * FROM t1"); 3415 rs2 = stmt2.executeQuery("SELECT * FROM t1");
3412 while (rs2.next()) 3416 while (rs2.next())
3413 sb.append(rs2.getInt("id")).append(", ").append(rs2.getString("who")).append("\n"); 3417 sb.append(rs2.getInt("id")).append(", ").append(rs2.getString("who")).append("\n");
3414 sb.append("passed :)").append("\n"); 3418 sb.append("passed :)\n");
3415 3419
3416 // drop the table (not dropping the sequence) from client 1 3420 // drop the table (not dropping the sequence) from client 1
3417 sb.append("3.1. drop table t1 using client 1... "); 3421 sb.append("3.1. drop table t1 using client 1... ");
3418 stmt1.executeUpdate("DROP TABLE t1"); 3422 stmt1.executeUpdate("DROP TABLE t1");
3419 sb.append("passed :)").append("\n"); 3423 sb.append("passed :)\n");
3420 3424
3421 sb.append("3.1. recreate t1 using client 1... "); 3425 sb.append("3.1. recreate t1 using client 1... ");
3422 stmt1.executeUpdate("CREATE TABLE t1 ( id serial, who varchar(12) )"); 3426 stmt1.executeUpdate("CREATE TABLE t1 ( id serial, who varchar(12) )");
3423 sb.append("passed :)").append("\n"); 3427 sb.append("passed :)\n");
3424 } catch (SQLException e) { 3428 } catch (SQLException e) {
3425 sb.append("FAILED: ").append(e.getMessage()).append("\n"); 3429 sb.append("FAILED: ").append(e.getMessage()).append("\n");
3426 } 3430 }
3427 3431
3428 try { 3432 try {
3432 con2.close(); 3436 con2.close();
3433 con1 = DriverManager.getConnection(arg0); 3437 con1 = DriverManager.getConnection(arg0);
3434 con2 = DriverManager.getConnection(arg0); 3438 con2 = DriverManager.getConnection(arg0);
3435 stmt1 = con1.createStatement(); 3439 stmt1 = con1.createStatement();
3436 stmt2 = con2.createStatement(); 3440 stmt2 = con2.createStatement();
3437 sb.append("passed :)").append("\n"); 3441 sb.append("passed :)\n");
3438 3442
3439 // insert and print, should get 1,2 3443 // insert and print, should get 1,2
3440 sb.append("4. insert into t1 using client 1 and 2...").append("\n"); 3444 sb.append("4. insert into t1 using client 1 and 2...\n");
3441 stmt1.executeUpdate("INSERT INTO t1(who) VALUES('client1')"); 3445 stmt1.executeUpdate("INSERT INTO t1(who) VALUES('client1')");
3442 sb.append("passed :)").append("\n"); 3446 sb.append("passed :)\n");
3443 con2.setAutoCommit(false); 3447 con2.setAutoCommit(false);
3444 stmt2.executeUpdate("INSERT INTO t1(who) VALUES('client2')"); 3448 stmt2.executeUpdate("INSERT INTO t1(who) VALUES('client2')");
3445 con2.commit(); 3449 con2.commit();
3446 con2.setAutoCommit(true); 3450 con2.setAutoCommit(true);
3447 sb.append("passed :)").append("\n"); 3451 sb.append("passed :)\n");
3448 3452
3449 sb.append("4.1. check table status with client 1...").append("\n"); 3453 sb.append("4.1. check table status with client 1...\n");
3450 rs1 = stmt1.executeQuery("SELECT * FROM t1 ORDER BY who"); 3454 rs1 = stmt1.executeQuery("SELECT * FROM t1 ORDER BY who");
3451 for (int cntr = 1; rs1.next(); cntr++) { 3455 for (int cntr = 1; rs1.next(); cntr++) {
3452 int id = rs1.getInt("id"); 3456 int id = rs1.getInt("id");
3453 sb.append(id).append(", ").append(rs1.getString("who")).append("\n"); 3457 sb.append(id).append(", ").append(rs1.getString("who")).append("\n");
3454 if (id != cntr) 3458 if (id != cntr)
3455 sb.append("!! expected ").append(cntr).append(", got ").append(id); 3459 sb.append("!! expected ").append(cntr).append(", got ").append(id);
3456 } 3460 }
3457 sb.append("passed :)").append("\n"); 3461 sb.append("passed :)\n");
3458 3462
3459 sb.append("4.2. check table status with client 2...").append("\n"); 3463 sb.append("4.2. check table status with client 2...\n");
3460 rs2 = stmt2.executeQuery("SELECT * FROM t1 ORDER BY who"); 3464 rs2 = stmt2.executeQuery("SELECT * FROM t1 ORDER BY who");
3461 for (int cntr = 1; rs2.next(); cntr++) { 3465 for (int cntr = 1; rs2.next(); cntr++) {
3462 int id = rs2.getInt("id"); 3466 int id = rs2.getInt("id");
3463 sb.append(id).append(", ").append(rs2.getString("who")).append("\n"); 3467 sb.append(id).append(", ").append(rs2.getString("who")).append("\n");
3464 if (id != cntr) 3468 if (id != cntr)
3465 sb.append("!! expected ").append(cntr).append(", got ").append(id); 3469 sb.append("!! expected ").append(cntr).append(", got ").append(id);
3466 } 3470 }
3467 sb.append("passed :)").append("\n"); 3471 sb.append("passed :)\n");
3468 } catch (SQLException e) { 3472 } catch (SQLException e) {
3469 sb.append("FAILED: ").append(e.getMessage()).append("\n"); 3473 sb.append("FAILED: ").append(e.getMessage()).append("\n");
3470 } 3474 }
3471 3475
3472 // cleanup 3476 // cleanup
3473 try { 3477 try {
3474 sb.append("Cleanup TABLE t1").append("\n"); 3478 sb.append("Cleanup TABLE t1\n");
3475 stmt2.executeUpdate("DROP TABLE t1"); 3479 stmt2.executeUpdate("DROP TABLE t1");
3476 } catch (SQLException e) { 3480 } catch (SQLException e) {
3477 sb.append("FAILED: ").append(e.getMessage()).append("\n"); 3481 sb.append("FAILED: ").append(e.getMessage()).append("\n");
3478 } 3482 }
3479 3483
3523 sb.setLength(0); // clear the output log buffer 3527 sb.setLength(0); // clear the output log buffer
3524 3528
3525 Statement stmt1 = null; 3529 Statement stmt1 = null;
3526 // create user, schema and alter schema default schema 3530 // create user, schema and alter schema default schema
3527 try { 3531 try {
3528 sb.append("1. CREATE USER voc").append("\n"); 3532 sb.append("1. CREATE USER voc\n");
3529 stmt1 = con.createStatement(); 3533 stmt1 = con.createStatement();
3530 stmt1.executeUpdate("CREATE USER \"voc\" WITH PASSWORD 'voc' NAME 'VOC Explorer' SCHEMA \"sys\""); 3534 stmt1.executeUpdate("CREATE USER \"voc\" WITH PASSWORD 'voc' NAME 'VOC Explorer' SCHEMA \"sys\"");
3531 sb.append("2. CREATE SCHEMA voc").append("\n"); 3535 sb.append("2. CREATE SCHEMA voc\n");
3532 stmt1.executeUpdate("CREATE SCHEMA \"voc\" AUTHORIZATION \"voc\""); 3536 stmt1.executeUpdate("CREATE SCHEMA \"voc\" AUTHORIZATION \"voc\"");
3533 sb.append("3. ALTER USER voc").append("\n"); 3537 sb.append("3. ALTER USER voc\n");
3534 stmt1.executeUpdate("ALTER USER \"voc\" SET SCHEMA \"voc\""); 3538 stmt1.executeUpdate("ALTER USER \"voc\" SET SCHEMA \"voc\"");
3535 sb.append("creation succeeded :)").append("\n"); 3539 sb.append("creation succeeded :)\n");
3536 } catch (SQLException e) { 3540 } catch (SQLException e) {
3537 sb.append("FAILED creating user and schema voc. ").append(e.getMessage()).append("\n"); 3541 sb.append("FAILED creating user and schema voc. ").append(e.getMessage()).append("\n");
3538 } 3542 }
3539 3543
3540 Connection con2 = null; 3544 Connection con2 = null;
3541 ResultSet rs2 = null; 3545 ResultSet rs2 = null;
3542 try { 3546 try {
3543 sb.append("4.1. connect as user: voc").append("\n"); 3547 sb.append("4.1. connect as user: voc\n");
3544 con2 = DriverManager.getConnection(arg0.replace("=monetdb", "=voc")); 3548 con2 = DriverManager.getConnection(arg0.replace("=monetdb", "=voc"));
3545 sb.append("connected :)").append("\n"); 3549 sb.append("connected :)\n");
3546 3550
3547 DatabaseMetaData dbmd = con2.getMetaData(); 3551 DatabaseMetaData dbmd = con2.getMetaData();
3548 3552
3549 sb.append("4.2. getUserName()").append("\n"); 3553 sb.append("4.2. getUserName()\n");
3550 sb.append("UserName = ").append(dbmd.getUserName()).append("\n"); 3554 sb.append("UserName = ").append(dbmd.getUserName()).append("\n");
3551 3555
3552 sb.append("4.3. getMaxConnections()").append("\n"); 3556 sb.append("4.3. getMaxConnections()\n");
3553 sb.append("MaxConnections = ").append(dbmd.getMaxConnections()).append("\n"); 3557 sb.append("MaxConnections = ").append(dbmd.getMaxConnections()).append("\n");
3554 3558
3555 sb.append("4.4. getDatabaseProductVersion()").append("\n"); 3559 sb.append("4.4. getDatabaseProductVersion()\n");
3556 String dbmsVersion = dbmd.getDatabaseProductVersion(); // should be 11.35.1 or higher 3560 String dbmsVersion = dbmd.getDatabaseProductVersion(); // should be 11.35.1 or higher
3557 boolean postNov2019 = ("11.35.1".compareTo(dbmsVersion) <= 0); 3561 boolean postNov2019 = ("11.35.1".compareTo(dbmsVersion) <= 0);
3558 sb.append("DatabaseProductVersion = ").append((postNov2019 ? "11.35.+" : dbmsVersion)).append("\n"); 3562 sb.append("DatabaseProductVersion = ").append((postNov2019 ? "11.35.+" : dbmsVersion)).append("\n");
3559 3563
3560 sb.append("4.5. getDatabaseMajorVersion()").append("\n"); 3564 sb.append("4.5. getDatabaseMajorVersion()\n");
3561 sb.append("DatabaseMajorVersion = ").append(dbmd.getDatabaseMajorVersion()).append("\n"); // should be 11 3565 sb.append("DatabaseMajorVersion = ").append(dbmd.getDatabaseMajorVersion()).append("\n"); // should be 11
3562 3566
3563 sb.append("4.6. getDatabaseMinorVersion()").append("\n"); 3567 sb.append("4.6. getDatabaseMinorVersion()\n");
3564 int dbmsMinorVersion = dbmd.getDatabaseMinorVersion(); // should be 35 or higher 3568 int dbmsMinorVersion = dbmd.getDatabaseMinorVersion(); // should be 35 or higher
3565 sb.append("DatabaseMinorVersion = ").append((dbmsMinorVersion >= 35 ? "35+" : dbmsMinorVersion)).append("\n"); 3569 sb.append("DatabaseMinorVersion = ").append((dbmsMinorVersion >= 35 ? "35+" : dbmsMinorVersion)).append("\n");
3566 3570
3567 sb.append("4.7. getTables(null, 'tmp', null, null)").append("\n"); 3571 sb.append("4.7. getTables(null, 'tmp', null, null)\n");
3568 rs2 = dbmd.getTables(null, "tmp", null, null); 3572 rs2 = dbmd.getTables(null, "tmp", null, null);
3569 if (rs2 != null) { 3573 if (rs2 != null) {
3570 sb.append("List Tables in schema tmp:").append("\n"); 3574 sb.append("List Tables in schema tmp:\n");
3571 while (rs2.next()) { 3575 while (rs2.next()) {
3572 sb.append(rs2.getString(3)).append("\n"); 3576 sb.append(rs2.getString(3)).append("\n");
3573 } 3577 }
3574 rs2.close(); 3578 rs2.close();
3575 } 3579 }
3576 sb.append("completed listing Tables in schema tmp").append("\n"); 3580 sb.append("completed listing Tables in schema tmp\n");
3577 3581
3578 sb.append("4.8. getTableTypes()").append("\n"); 3582 sb.append("4.8. getTableTypes()\n");
3579 rs2 = dbmd.getTableTypes(); 3583 rs2 = dbmd.getTableTypes();
3580 if (rs2 != null) { 3584 if (rs2 != null) {
3581 sb.append("List TableTypes:").append("\n"); 3585 sb.append("List TableTypes:\n");
3582 while (rs2.next()) { 3586 while (rs2.next()) {
3583 // post Oct2020 releases the STREAM TABLE type is removed, so filter it out for a stable output 3587 // post Oct2020 releases the STREAM TABLE type is removed, so filter it out for a stable output
3584 if (!"STREAM TABLE".equals(rs2.getString(1))) 3588 if (!"STREAM TABLE".equals(rs2.getString(1)))
3585 sb.append(rs2.getString(1)).append("\n"); 3589 sb.append(rs2.getString(1)).append("\n");
3586 } 3590 }
3587 rs2.close(); 3591 rs2.close();
3588 } 3592 }
3589 sb.append("completed listing TableTypes").append("\n"); 3593 sb.append("completed listing TableTypes\n");
3590 3594
3591 sb.append("voc meta data Test completed successfully").append("\n"); 3595 sb.append("voc meta data Test completed successfully\n");
3592 } catch (SQLException e) { 3596 } catch (SQLException e) {
3593 sb.append("FAILED fetching MonetDatabaseMetaData. ").append(e.getMessage()).append("\n"); 3597 sb.append("FAILED fetching MonetDatabaseMetaData. ").append(e.getMessage()).append("\n");
3594 } finally { 3598 } finally {
3595 try { 3599 try {
3596 con2.close(); 3600 con2.close();
3599 } 3603 }
3600 } 3604 }
3601 3605
3602 // cleanup: drop user, schema and alter schema default schema in reverse order 3606 // cleanup: drop user, schema and alter schema default schema in reverse order
3603 try { 3607 try {
3604 sb.append("Cleanup created objects").append("\n"); 3608 sb.append("Cleanup created objects\n");
3605 sb.append("5. ALTER USER voc").append("\n"); 3609 sb.append("5. ALTER USER voc\n");
3606 stmt1.executeUpdate("ALTER USER \"voc\" SET SCHEMA \"sys\""); 3610 stmt1.executeUpdate("ALTER USER \"voc\" SET SCHEMA \"sys\"");
3607 sb.append("6. DROP SCHEMA voc").append("\n"); 3611 sb.append("6. DROP SCHEMA voc\n");
3608 stmt1.executeUpdate("DROP SCHEMA \"voc\""); 3612 stmt1.executeUpdate("DROP SCHEMA \"voc\"");
3609 sb.append("7. DROP USER voc").append("\n"); 3613 sb.append("7. DROP USER voc\n");
3610 stmt1.executeUpdate("DROP USER \"voc\""); 3614 stmt1.executeUpdate("DROP USER \"voc\"");
3611 sb.append("cleanup succeeded :)").append("\n"); 3615 sb.append("cleanup succeeded :)\n");
3612 } catch (SQLException e) { 3616 } catch (SQLException e) {
3613 sb.append("FAILED dropping user and schema voc. ").append(e.getMessage()).append("\n"); 3617 sb.append("FAILED dropping user and schema voc. ").append(e.getMessage()).append("\n");
3614 } 3618 }
3615 3619
3616 closeConx(con2); 3620 closeConx(con2);
3754 executeDML(stmt, "DELETE FROM t3350 WHERE \"keyword\" = 'Bug_3350'"); // should delete 1 row 3758 executeDML(stmt, "DELETE FROM t3350 WHERE \"keyword\" = 'Bug_3350'"); // should delete 1 row
3755 executeDML(stmt, "DELETE FROM t3350 WHERE \"keyword\" = 'Bug_3350'"); // should delete 0 rows 3759 executeDML(stmt, "DELETE FROM t3350 WHERE \"keyword\" = 'Bug_3350'"); // should delete 0 rows
3756 executeDML(stmt, "UPDATE t3350 set \"keyword\" = keyword||'_ext'"); // should update 4 rows 3760 executeDML(stmt, "UPDATE t3350 set \"keyword\" = keyword||'_ext'"); // should update 4 rows
3757 executeDML(stmt, "DELETE FROM t3350"); // should delete 4 rows 3761 executeDML(stmt, "DELETE FROM t3350"); // should delete 4 rows
3758 con.commit(); 3762 con.commit();
3759
3760 stmt.execute("DROP TABLE t3350");
3761 con.commit();
3762 } catch (SQLException se) { 3763 } catch (SQLException se) {
3763 sb.append(se.getMessage()).append("\n"); 3764 sb.append(se.getMessage()).append("\n");
3764 } 3765 }
3765 closeStmtResSet(stmt, null); 3766 closeStmtResSet(stmt, null);
3766 3767
3767 // cleanup 3768 // cleanup
3768 try { 3769 try {
3770 stmt.execute("DROP TABLE IF EXISTS t3350");
3771 con.commit();
3769 con.setAutoCommit(true); // enable auto commit 3772 con.setAutoCommit(true); // enable auto commit
3770 } catch (SQLException e) { 3773 } catch (SQLException e) {
3771 sb.append("FAILED: ").append(e.getMessage()).append("\n"); 3774 sb.append("FAILED: ").append(e.getMessage()).append("\n");
3772 } 3775 }
3773 3776
3810 3813
3811 Connection con2 = null; 3814 Connection con2 = null;
3812 Statement st = null; 3815 Statement st = null;
3813 try { 3816 try {
3814 con2 = DriverManager.getConnection(arg0); 3817 con2 = DriverManager.getConnection(arg0);
3815 sb.append("connected :)").append("\n"); 3818 sb.append("connected :)\n");
3816 3819
3817 st = con2.createStatement(); 3820 st = con2.createStatement();
3818 st.setQueryTimeout(5); 3821 st.setQueryTimeout(5);
3819 sb.append("getQueryTimeout must give 5: ").append(st.getQueryTimeout()).append("\n"); 3822 sb.append("getQueryTimeout must give 5: ").append(st.getQueryTimeout()).append("\n");
3820 st.close(); 3823 st.close();
3869 sb.append("Inserting rows. "); 3872 sb.append("Inserting rows. ");
3870 String insertCmd = "INSERT INTO " + tbl_nm + " VALUES ('activeset_default_fiets', '" + largedata + "');"; 3873 String insertCmd = "INSERT INTO " + tbl_nm + " VALUES ('activeset_default_fiets', '" + largedata + "');";
3871 int ins = stmt.executeUpdate(insertCmd); 3874 int ins = stmt.executeUpdate(insertCmd);
3872 ins += stmt.executeUpdate(insertCmd); 3875 ins += stmt.executeUpdate(insertCmd);
3873 ins += stmt.executeUpdate(insertCmd); 3876 ins += stmt.executeUpdate(insertCmd);
3874 sb.append(ins).append(" rows inserted").append("\n"); 3877 sb.append(ins).append(" rows inserted\n");
3875 } catch (SQLException se) { 3878 } catch (SQLException se) {
3876 sb.append(se.getMessage()).append("\n"); 3879 sb.append(se.getMessage()).append("\n");
3877 } 3880 }
3878 closeStmtResSet(stmt, null); 3881 closeStmtResSet(stmt, null);
3879 3882
3889 sb.append("Cleaned up TABLE ").append(tbl_nm).append("\n"); 3892 sb.append("Cleaned up TABLE ").append(tbl_nm).append("\n");
3890 } catch (SQLException se) { 3893 } catch (SQLException se) {
3891 sb.append(se.getMessage()).append("\n"); 3894 sb.append(se.getMessage()).append("\n");
3892 } 3895 }
3893 3896
3894 sb.append("Test completed without hanging").append("\n"); 3897 sb.append("Test completed without hanging\n");
3895 3898
3896 compareExpectedOutput("Bug_LargeQueries_6571_6693", 3899 compareExpectedOutput("Bug_LargeQueries_6571_6693",
3897 "Created table: tbl6693\n" + 3900 "Created table: tbl6693\n" +
3898 "Inserting rows. 3 rows inserted\n" + 3901 "Inserting rows. 3 rows inserted\n" +
3899 "Script size is 83256\n" + 3902 "Script size is 83256\n" +
3928 process_script(stmt, script, 1, 3, 6); 3931 process_script(stmt, script, 1, 3, 6);
3929 } 3932 }
3930 } 3933 }
3931 sb.append("\n"); 3934 sb.append("\n");
3932 } 3935 }
3933 sb.append("Completed first test").append("\n"); 3936 sb.append("Completed first test\n");
3934 3937
3935 // also try to make the execution hang after many iterations of making connections (each their own socket) and sending large scripts 3938 // also try to make the execution hang after many iterations of making connections (each their own socket) and sending large scripts
3936 sb.append("Second test repeat " + iterations + " times. "); 3939 sb.append("Second test repeat " + iterations + " times. ");
3937 sb.append("Iteration: "); 3940 sb.append("Iteration: ");
3938 for (int i = 1; i <= iterations; i++) { 3941 for (int i = 1; i <= iterations; i++) {
3945 process_script(stmt, script, 1, 3, 6); 3948 process_script(stmt, script, 1, 3, 6);
3946 } 3949 }
3947 } 3950 }
3948 } 3951 }
3949 sb.append("\n"); 3952 sb.append("\n");
3950 sb.append("Completed second test").append("\n"); 3953 sb.append("Completed second test\n");
3951 3954
3952 // next try to make the execution hang by sending very many queries combined in 1 large script 3955 // next try to make the execution hang by sending very many queries combined in 1 large script
3953 final int queries = 260; 3956 final int queries = 260;
3954 StringBuilder qry = new StringBuilder(queries * 13); 3957 StringBuilder qry = new StringBuilder(queries * 13);
3955 for (int i = 1; i <= queries; i++) 3958 for (int i = 1; i <= queries; i++)
3956 qry.append(" SELECT ").append(i).append(';'); 3959 qry.append(" SELECT ").append(i).append(';');
3957 script = qry.toString(); 3960 script = qry.toString();
3958 sb.append("Script size is " + script.length()).append("\n"); 3961 sb.append("Script size is " + script.length()).append("\n");
3959 iterations = 9; 3962 iterations = 9;
3960 sb.append("Third test repeat " + iterations + " times.").append("\n"); 3963 sb.append("Third test repeat " + iterations + " times.\n");
3961 try (Connection con = DriverManager.getConnection(conURL)) { 3964 try (Connection con = DriverManager.getConnection(conURL)) {
3962 sb.append("Iteration: "); 3965 sb.append("Iteration: ");
3963 for (int i = 1; i <= iterations; i++) { 3966 for (int i = 1; i <= iterations; i++) {
3964 sb.append(i).append(" "); 3967 sb.append(i).append(" ");
3965 try (Statement stmt = con.createStatement()) { 3968 try (Statement stmt = con.createStatement()) {
3966 process_script(stmt, script, queries, queries, 0); 3969 process_script(stmt, script, queries, queries, 0);
3967 } 3970 }
3968 } 3971 }
3969 sb.append("\n"); 3972 sb.append("\n");
3970 } 3973 }
3971 sb.append("Completed third test").append("\n"); 3974 sb.append("Completed third test\n");
3972 } 3975 }
3973 3976
3974 private void process_script(Statement stmt, String script, 3977 private void process_script(Statement stmt, String script,
3975 int expectedResults, int expectedTotalRows, int expectedUpdates) throws SQLException { 3978 int expectedResults, int expectedTotalRows, int expectedUpdates) throws SQLException {
3976 int results = 0; 3979 int results = 0;
4027 sb.append("Query ResultSet has ").append(rsmd.getColumnCount()).append(" columns. Type of first is: ").append(rsmd.getColumnTypeName(1)).append("\n"); 4030 sb.append("Query ResultSet has ").append(rsmd.getColumnCount()).append(" columns. Type of first is: ").append(rsmd.getColumnTypeName(1)).append("\n");
4028 4031
4029 boolean has_row = rs.next(); 4032 boolean has_row = rs.next();
4030 boolean has_rows = rs.next(); 4033 boolean has_rows = rs.next();
4031 if (has_row == false || has_rows == true) 4034 if (has_row == false || has_rows == true)
4032 sb.append("Fetching Query ResultSet failed").append("\n"); 4035 sb.append("Fetching Query ResultSet failed\n");
4033 } catch (SQLException se) { 4036 } catch (SQLException se) {
4034 sb.append(se.getMessage()).append("\n"); 4037 sb.append(se.getMessage()).append("\n");
4035 } 4038 }
4036 4039
4037 // cleanup 4040 // cleanup
4038 try { 4041 try {
4039 stmt.executeUpdate("DROP TABLE PrepStmtSetObject_CLOB"); 4042 stmt.executeUpdate("DROP TABLE PrepStmtSetObject_CLOB");
4040 sb.append("Table dropped").append("\n"); 4043 sb.append("Table dropped\n");
4041 } catch (SQLException se) { 4044 } catch (SQLException se) {
4042 sb.append(se.getMessage()).append("\n"); 4045 sb.append(se.getMessage()).append("\n");
4043 } 4046 }
4044 closeStmtResSet(stmt, null); 4047 closeStmtResSet(stmt, null);
4045 closeStmtResSet(pstmt, rs); 4048 closeStmtResSet(pstmt, rs);
4095 pstmt.setNull(4, 0); 4098 pstmt.setNull(4, 0);
4096 pstmt.setNull(5, 0); 4099 pstmt.setNull(5, 0);
4097 pstmt.setNull(6, 0); 4100 pstmt.setNull(6, 0);
4098 sb.append("Inserting row ").append(row).append("\n"); 4101 sb.append("Inserting row ").append(row).append("\n");
4099 int inserted = pstmt.executeUpdate(); 4102 int inserted = pstmt.executeUpdate();
4100 sb.append("Inserted ").append(inserted).append(" row").append("\n"); 4103 sb.append("Inserted ").append(inserted).append(" row\n");
4101 4104
4102 row++; // row 7 4105 row++; // row 7
4103 pstmt.setShort(1, (short)row); 4106 pstmt.setShort(1, (short)row);
4104 pstmt.setNString(2, "row " + row); 4107 pstmt.setNString(2, "row " + row);
4105 pstmt.setNull(3, 0); 4108 pstmt.setNull(3, 0);
4106 pstmt.setString(4, "4a148b7d-8d47-4e1e-a21e-09a71abf2215"); 4109 pstmt.setString(4, "4a148b7d-8d47-4e1e-a21e-09a71abf2215");
4107 sb.append("Inserting row ").append(row).append("\n"); 4110 sb.append("Inserting row ").append(row).append("\n");
4108 inserted = pstmt.executeUpdate(); 4111 inserted = pstmt.executeUpdate();
4109 sb.append("Inserted ").append(inserted).append(" row").append("\n"); 4112 sb.append("Inserted ").append(inserted).append(" row\n");
4110 4113
4111 row++; // row 8 4114 row++; // row 8
4112 pstmt.setLong(1, (long)row); 4115 pstmt.setLong(1, (long)row);
4113 pstmt.setString(2, "row " + row); 4116 pstmt.setString(2, "row " + row);
4114 pstmt.setObject(3, "+3.1415E-06"); 4117 pstmt.setObject(3, "+3.1415E-06");
4118 } catch (java.net.MalformedURLException mfe) { 4121 } catch (java.net.MalformedURLException mfe) {
4119 sb.append(mfe).append("\n"); 4122 sb.append(mfe).append("\n");
4120 } 4123 }
4121 sb.append("Inserting row ").append(row).append("\n"); 4124 sb.append("Inserting row ").append(row).append("\n");
4122 inserted = pstmt.executeUpdate(); 4125 inserted = pstmt.executeUpdate();
4123 sb.append("Inserted ").append(inserted).append(" row").append("\n"); 4126 sb.append("Inserted ").append(inserted).append(" row\n");
4124 4127
4125 row++; // row 9 4128 row++; // row 9
4126 pstmt.setBigDecimal(1, new java.math.BigDecimal(row)); 4129 pstmt.setBigDecimal(1, new java.math.BigDecimal(row));
4127 pstmt.setNString(2, "row " + row); 4130 pstmt.setNString(2, "row " + row);
4128 pstmt.setNull(5, 0); 4131 pstmt.setNull(5, 0);
4129 pstmt.setString(6, "127.255.255.255"); 4132 pstmt.setString(6, "127.255.255.255");
4130 sb.append("Inserting row ").append(row).append("\n"); 4133 sb.append("Inserting row ").append(row).append("\n");
4131 inserted = pstmt.executeUpdate(); 4134 inserted = pstmt.executeUpdate();
4132 sb.append("Inserted ").append(inserted).append(" row").append("\n"); 4135 sb.append("Inserted ").append(inserted).append(" row\n");
4133 4136
4134 /* also test generic setObject(int, String) */ 4137 /* also test generic setObject(int, String) */
4135 row++; // row 10 4138 row++; // row 10
4136 pstmt.setObject(1, Integer.valueOf(row)); 4139 pstmt.setObject(1, Integer.valueOf(row));
4137 pstmt.setObject(2, "row " + row); 4140 pstmt.setObject(2, "row " + row);
4139 pstmt.setObject(4, "b39dc76e-4faf-4fd9-bc1e-17df48acf764"); 4142 pstmt.setObject(4, "b39dc76e-4faf-4fd9-bc1e-17df48acf764");
4140 pstmt.setObject(5, "https://en.wikipedia.org/wiki/IP_address"); 4143 pstmt.setObject(5, "https://en.wikipedia.org/wiki/IP_address");
4141 pstmt.setObject(6, "223.255.255.255"); 4144 pstmt.setObject(6, "223.255.255.255");
4142 sb.append("Inserting row ").append(row).append("\n"); 4145 sb.append("Inserting row ").append(row).append("\n");
4143 inserted = pstmt.executeUpdate(); 4146 inserted = pstmt.executeUpdate();
4144 sb.append("Inserted ").append(inserted).append(" row").append("\n"); 4147 sb.append("Inserted ").append(inserted).append(" row\n");
4145 4148
4146 row++; // row 11 4149 row++; // row 11
4147 pstmt.setObject(1, new java.math.BigDecimal(row)); 4150 pstmt.setObject(1, new java.math.BigDecimal(row));
4148 pstmt.setObject(2, "row " + row); 4151 pstmt.setObject(2, "row " + row);
4149 pstmt.setObject(3, "null"); 4152 pstmt.setObject(3, "null");
4158 INET myINET = new INET(); 4161 INET myINET = new INET();
4159 myINET.fromString("223.234.245.255"); 4162 myINET.fromString("223.234.245.255");
4160 pstmt.setObject(6, myINET); 4163 pstmt.setObject(6, myINET);
4161 sb.append("Inserting row ").append(row).append("\n"); 4164 sb.append("Inserting row ").append(row).append("\n");
4162 inserted = pstmt.executeUpdate(); 4165 inserted = pstmt.executeUpdate();
4163 sb.append("Inserted ").append(inserted).append(" row").append("\n"); 4166 sb.append("Inserted ").append(inserted).append(" row\n");
4164 4167
4165 sb.append("List contents of TABLE ").append(tableName).append(" after ").append(row).append(" rows inserted").append("\n"); 4168 sb.append("List contents of TABLE ").append(tableName).append(" after ").append(row).append(" rows inserted\n");
4166 rs = stmt.executeQuery("SELECT * FROM " + tableName + " ORDER BY 1"); 4169 rs = stmt.executeQuery("SELECT * FROM " + tableName + " ORDER BY 1");
4167 ResultSetMetaData rsmd = rs.getMetaData(); 4170 ResultSetMetaData rsmd = rs.getMetaData();
4168 int colcount = rsmd.getColumnCount(); 4171 int colcount = rsmd.getColumnCount();
4169 sb.append("Query has ").append(colcount).append(" output columns.").append((colcount != 6 ? " ERROR: Expected 6 columns!" : "")).append("\n"); 4172 sb.append("Query has ").append(colcount).append(" output columns.").append((colcount != 6 ? " ERROR: Expected 6 columns!" : "")).append("\n");
4170 row = 0; 4173 row = 0;
4269 stmt = con.createStatement(); 4272 stmt = con.createStatement();
4270 stmt.executeUpdate("drop table if exists abacus;"); 4273 stmt.executeUpdate("drop table if exists abacus;");
4271 stmt.executeUpdate("create table abacus ( \"'Zeitachse'\" date,\"'Abo_ID'\" int,\"'description'\" varchar(256),\"'Klassierungs-Typ'\" clob,\"'KlassierungApplikation'\" clob,\"'EP Netto'\" decimal,\"'Nettoumsatz'\" decimal,\"'validfrom'\" date,\"'validuntil'\" date,\"'Abo_aufgeschaltet'\" int,\"'Abo_deaktiviert'\" int,\"'Differenz'\" decimal,\"'User_ID'\" int,\"'UserName'\" varchar(256),\"'client'\" varchar(256),\"'Installations_ID'\" int,\"'InstallationsName'\" varchar(256),\"'Installationsprovider_ID'\" int,\"'InstallationsproviderName'\" varchar(256),\"'INR'\" bigint,\"'NAME'\" varchar(256),\"'PLZ'\" varchar(256),\"'ORT'\" varchar(256),\"'STAAT'\" varchar(256),\"'Reseller_ID'\" int,\"'ResellerName'\" varchar(256),\"'ET_ABO'\" clob,\"'UserName_1'\" varchar(256),\"'Anzahl_Abos'\" decimal,\"'Anzahl_User'\" decimal,\"'Jahr'\" decimal,\"'Monat'\" decimal,\"'Jahr_Monat'\" clob,\"'IFJ'\" clob,\"'RECNUM$'\" int,\"'InlineCalc_Year_Zeitachse'\" int);"); 4274 stmt.executeUpdate("create table abacus ( \"'Zeitachse'\" date,\"'Abo_ID'\" int,\"'description'\" varchar(256),\"'Klassierungs-Typ'\" clob,\"'KlassierungApplikation'\" clob,\"'EP Netto'\" decimal,\"'Nettoumsatz'\" decimal,\"'validfrom'\" date,\"'validuntil'\" date,\"'Abo_aufgeschaltet'\" int,\"'Abo_deaktiviert'\" int,\"'Differenz'\" decimal,\"'User_ID'\" int,\"'UserName'\" varchar(256),\"'client'\" varchar(256),\"'Installations_ID'\" int,\"'InstallationsName'\" varchar(256),\"'Installationsprovider_ID'\" int,\"'InstallationsproviderName'\" varchar(256),\"'INR'\" bigint,\"'NAME'\" varchar(256),\"'PLZ'\" varchar(256),\"'ORT'\" varchar(256),\"'STAAT'\" varchar(256),\"'Reseller_ID'\" int,\"'ResellerName'\" varchar(256),\"'ET_ABO'\" clob,\"'UserName_1'\" varchar(256),\"'Anzahl_Abos'\" decimal,\"'Anzahl_User'\" decimal,\"'Jahr'\" decimal,\"'Monat'\" decimal,\"'Jahr_Monat'\" clob,\"'IFJ'\" clob,\"'RECNUM$'\" int,\"'InlineCalc_Year_Zeitachse'\" int);");
4272 stmt.executeUpdate("insert into abacus values ('2019-10-30',2239,'description','Klassierungs-Typ','Klassierung-Applikation',73.28,68.29,'2018-01-01','2018-12-01',563,63,56.3,852,'UserName','client',134,'InstallationsName',892,'InstallationsproviderName',9348,'NAME','PLZ','ORT','STAAT',934,'ResellerName','ET_ABO','UserName_1',849.2739,1742.718,395.824,39.824,'Jahr_Monat','IFJ',395824,3789);"); 4275 stmt.executeUpdate("insert into abacus values ('2019-10-30',2239,'description','Klassierungs-Typ','Klassierung-Applikation',73.28,68.29,'2018-01-01','2018-12-01',563,63,56.3,852,'UserName','client',134,'InstallationsName',892,'InstallationsproviderName',9348,'NAME','PLZ','ORT','STAAT',934,'ResellerName','ET_ABO','UserName_1',849.2739,1742.718,395.824,39.824,'Jahr_Monat','IFJ',395824,3789);");
4273 4276
4274 sb.append("1. table created and inserted 1 row").append("\n"); 4277 sb.append("1. table created and inserted 1 row\n");
4275 4278
4276 String qry = "SELECT \"'ResellerName'\" FROM abacus WHERE ( ( (\"'InstallationsproviderName'\"='Bienz Pius Treuhand- und Revisions AG')) AND ( (\"'validuntil'\"='2018-01-01' AND \"'description'\"='ABEA 2' AND (EXTRACT(YEAR FROM \"'Zeitachse'\")*100 + EXTRACT(MONTH FROM \"'Zeitachse'\"))/100.0='2019.010' AND \"'UserName'\"='AL - Astrid Lincke (Delphys)' AND \"'validfrom'\"='2016-12-01')) AND ( (\"'IFJ'\"='ohne IFJ')) AND ( (\"'InlineCalc_Year_Zeitachse'\"='2019'))) GROUP BY \"'ResellerName'\" LIMIT 1001 OFFSET 0;"; 4279 String qry = "SELECT \"'ResellerName'\" FROM abacus WHERE ( ( (\"'InstallationsproviderName'\"='Bienz Pius Treuhand- und Revisions AG')) AND ( (\"'validuntil'\"='2018-01-01' AND \"'description'\"='ABEA 2' AND (EXTRACT(YEAR FROM \"'Zeitachse'\")*100 + EXTRACT(MONTH FROM \"'Zeitachse'\"))/100.0='2019.010' AND \"'UserName'\"='AL - Astrid Lincke (Delphys)' AND \"'validfrom'\"='2016-12-01')) AND ( (\"'IFJ'\"='ohne IFJ')) AND ( (\"'InlineCalc_Year_Zeitachse'\"='2019'))) GROUP BY \"'ResellerName'\" LIMIT 1001 OFFSET 0;";
4277 try { 4280 try {
4278 sb.append("2. before select query execution").append("\n"); 4281 sb.append("2. before select query execution\n");
4279 rs = stmt.executeQuery(qry); 4282 rs = stmt.executeQuery(qry);
4280 sb.append("2a. select query executed").append("\n"); 4283 sb.append("2a. select query executed\n");
4281 if (rs != null) { 4284 if (rs != null) {
4282 if (rs.next()) { 4285 if (rs.next()) {
4283 sb.append("2b. select query returned: " + rs.getString(1)).append("\n"); 4286 sb.append("2b. select query returned: " + rs.getString(1)).append("\n");
4284 } 4287 }
4285 rs.close(); 4288 rs.close();
4286 rs = null; 4289 rs = null;
4287 sb.append("2c. closed select query resultset").append("\n"); 4290 sb.append("2c. closed select query resultset\n");
4288 } 4291 }
4289 sb.append("2d. normal end of select query").append("\n"); 4292 sb.append("2d. normal end of select query\n");
4290 } catch (SQLException se) { 4293 } catch (SQLException se) {
4291 sb.append("select query Exception: "+ se.getMessage()).append("\n"); 4294 sb.append("select query Exception: "+ se.getMessage()).append("\n");
4292 while ((se = se.getNextException()) != null) 4295 while ((se = se.getNextException()) != null)
4293 sb.append("next Exception: "+ se.getMessage()).append("\n"); 4296 sb.append("next Exception: "+ se.getMessage()).append("\n");
4294 } 4297 }
4295 4298
4296 try { 4299 try {
4297 sb.append("3. before creating a prepared select query").append("\n"); 4300 sb.append("3. before creating a prepared select query\n");
4298 pstmt = con.prepareStatement(qry); 4301 pstmt = con.prepareStatement(qry);
4299 sb.append("3a. prepared select query").append("\n"); 4302 sb.append("3a. prepared select query\n");
4300 4303
4301 ParameterMetaData pmd = pstmt.getParameterMetaData(); 4304 ParameterMetaData pmd = pstmt.getParameterMetaData();
4302 sb.append("3b. Prepared Query has " + pmd.getParameterCount() + " parameters."); // "Type of first is: " + pmd.getParameterTypeName(1)).append("\n"); 4305 sb.append("3b. Prepared Query has " + pmd.getParameterCount() + " parameters."); // "Type of first is: " + pmd.getParameterTypeName(1)).append("\n");
4303 ResultSetMetaData rsmd = pstmt.getMetaData(); 4306 ResultSetMetaData rsmd = pstmt.getMetaData();
4304 sb.append("3c. Prepared Query has " + rsmd.getColumnCount() + " columns. Type of first is: " + rsmd.getColumnTypeName(1)).append("\n"); 4307 sb.append("3c. Prepared Query has " + rsmd.getColumnCount() + " columns. Type of first is: " + rsmd.getColumnTypeName(1)).append("\n");
4305 4308
4306 sb.append("3d. before executing the prepared select query").append("\n"); 4309 sb.append("3d. before executing the prepared select query\n");
4307 rs = pstmt.executeQuery(); 4310 rs = pstmt.executeQuery();
4308 sb.append("3e. prepared select query executed").append("\n"); 4311 sb.append("3e. prepared select query executed\n");
4309 if (rs != null) { 4312 if (rs != null) {
4310 rsmd = rs.getMetaData(); 4313 rsmd = rs.getMetaData();
4311 sb.append("3f. prepared Query ResultSet has " + rsmd.getColumnCount() + " columns. Type of first is: " + rsmd.getColumnTypeName(1)).append("\n"); 4314 sb.append("3f. prepared Query ResultSet has " + rsmd.getColumnCount() + " columns. Type of first is: " + rsmd.getColumnTypeName(1)).append("\n");
4312 4315
4313 if (rs.next()) { 4316 if (rs.next()) {
4314 sb.append("3g. prepared select query returned: " + rs.getString(1)).append("\n"); 4317 sb.append("3g. prepared select query returned: " + rs.getString(1)).append("\n");
4315 } 4318 }
4316 rs.close(); 4319 rs.close();
4317 rs = null; 4320 rs = null;
4318 sb.append("3h. closed prepared select query resultset").append("\n"); 4321 sb.append("3h. closed prepared select query resultset\n");
4319 } 4322 }
4320 sb.append("3i. normal end of prepared select query").append("\n"); 4323 sb.append("3i. normal end of prepared select query\n");
4321 } catch (SQLException se) { 4324 } catch (SQLException se) {
4322 sb.append("prepared select query Exception: "+ se.getMessage()).append("\n"); 4325 sb.append("prepared select query Exception: "+ se.getMessage()).append("\n");
4323 while ((se = se.getNextException()) != null) 4326 while ((se = se.getNextException()) != null)
4324 sb.append("next Exception: "+ se.getMessage()).append("\n"); 4327 sb.append("next Exception: "+ se.getMessage()).append("\n");
4325 } 4328 }
4326 } catch (SQLException e) { 4329 } catch (SQLException e) {
4327 sb.append("FAILED: ").append(e.getMessage()).append("\n"); 4330 sb.append("FAILED: ").append(e.getMessage()).append("\n");
4328 } 4331 }
4329 4332
4330 try { 4333 try {
4331 sb.append("4. drop table").append("\n"); 4334 sb.append("4. drop table\n");
4332 stmt.executeUpdate("drop table abacus"); 4335 stmt.executeUpdate("drop table abacus");
4333 sb.append("5. normal end of test").append("\n"); 4336 sb.append("5. normal end of test\n");
4334 } catch (SQLException e) { 4337 } catch (SQLException e) {
4335 sb.append("FAILED: ").append(e.getMessage()).append("\n"); 4338 sb.append("FAILED: ").append(e.getMessage()).append("\n");
4336 } 4339 }
4337 4340
4338 closeStmtResSet(pstmt, rs); 4341 closeStmtResSet(pstmt, rs);
4378 4381
4379 stmt = con.createStatement(); 4382 stmt = con.createStatement();
4380 sb.append("1. create table ").append(dqTblName).append("\n"); 4383 sb.append("1. create table ").append(dqTblName).append("\n");
4381 int ret = stmt.executeUpdate(ctsb.toString()); 4384 int ret = stmt.executeUpdate(ctsb.toString());
4382 if (ret != -2) 4385 if (ret != -2)
4383 sb.append(" returned: ").append(ret).append(" (expected -2)").append("\n"); 4386 sb.append(" returned: ").append(ret).append(" (expected -2)\n");
4384 4387
4385 String tblName = dqTblName.substring(1, dqTblName.length() -1); // trim the leading and trailing double quote characters 4388 String tblName = dqTblName.substring(1, dqTblName.length() -1); // trim the leading and trailing double quote characters
4386 sb.append("2. show column names of this new table (").append(tblName).append(") via sys.columns query").append("\n"); 4389 sb.append("2. show column names of this new table (").append(tblName).append(") via sys.columns query\n");
4387 rs = stmt.executeQuery("SELECT number, name, type from sys.columns where table_id in (select id from sys._tables where name = '" + tblName + "') order by number"); 4390 rs = stmt.executeQuery("SELECT number, name, type from sys.columns where table_id in (select id from sys._tables where name = '" + tblName + "') order by number");
4388 showResultAndClose_6183(rs); 4391 showResultAndClose_6183(rs);
4389 4392
4390 sb.append("3. insert 1 row of data with values same as column names").append("\n"); 4393 sb.append("3. insert 1 row of data with values same as column names\n");
4391 ctsb.setLength(0); 4394 ctsb.setLength(0);
4392 ctsb.append("INSERT INTO ").append(dqTblName).append(" VALUES ("); 4395 ctsb.append("INSERT INTO ").append(dqTblName).append(" VALUES (");
4393 for (int n = 0; n < dqColNames.length; n++) { 4396 for (int n = 0; n < dqColNames.length; n++) {
4394 ctsb.append('\''); 4397 ctsb.append('\'');
4395 ctsb.append(dqColNames[n]); 4398 ctsb.append(dqColNames[n]);
4398 ctsb.append(", "); 4401 ctsb.append(", ");
4399 } 4402 }
4400 ctsb.append(')'); 4403 ctsb.append(')');
4401 ret = stmt.executeUpdate(ctsb.toString()); 4404 ret = stmt.executeUpdate(ctsb.toString());
4402 if (ret != 1) 4405 if (ret != 1)
4403 sb.append(" returned: ").append(ret).append(" (expected 1)").append("\n"); 4406 sb.append(" returned: ").append(ret).append(" (expected 1)\n");
4404 4407
4405 sb.append("4. insert 1 row of data with values same as column names but without enclosing double quotes").append("\n"); 4408 sb.append("4. insert 1 row of data with values same as column names but without enclosing double quotes\n");
4406 ctsb.setLength(0); 4409 ctsb.setLength(0);
4407 ctsb.append("INSERT INTO ").append(dqTblName).append(" VALUES ("); 4410 ctsb.append("INSERT INTO ").append(dqTblName).append(" VALUES (");
4408 for (int n = 0; n < dqColNames.length; n++) { 4411 for (int n = 0; n < dqColNames.length; n++) {
4409 ctsb.append('\''); 4412 ctsb.append('\'');
4410 // remove enclosing double quotes 4413 // remove enclosing double quotes
4414 ctsb.append(", "); 4417 ctsb.append(", ");
4415 } 4418 }
4416 ctsb.append(')'); 4419 ctsb.append(')');
4417 ret = stmt.executeUpdate(ctsb.toString()); 4420 ret = stmt.executeUpdate(ctsb.toString());
4418 if (ret != 1) 4421 if (ret != 1)
4419 sb.append(" returned: ").append(ret).append(" (expected 1)").append("\n"); 4422 sb.append(" returned: ").append(ret).append(" (expected 1)\n");
4420 4423
4421 compareExpectedOutput("BugResultSetMetaData_Bug_6183", 4424 compareExpectedOutput("BugResultSetMetaData_Bug_6183",
4422 "1. create table \"my dq_table\"\n" + 4425 "1. create table \"my dq_table\"\n" +
4423 "2. show column names of this new table (my dq_table) via sys.columns query\n" + 4426 "2. show column names of this new table (my dq_table) via sys.columns query\n" +
4424 "Resultset with 3 columns\n" + 4427 "Resultset with 3 columns\n" +
4606 // cleanup 4609 // cleanup
4607 try { 4610 try {
4608 sb.append("Finally drop table ").append(dqTblName).append("\n"); 4611 sb.append("Finally drop table ").append(dqTblName).append("\n");
4609 int ret = stmt.executeUpdate("DROP TABLE " + dqTblName); 4612 int ret = stmt.executeUpdate("DROP TABLE " + dqTblName);
4610 if (ret != -2) 4613 if (ret != -2)
4611 sb.append(" returned: ").append(ret).append(" (expected -2)").append("\n"); 4614 sb.append(" returned: ").append(ret).append(" (expected -2)\n");
4612 } catch (SQLException e) { 4615 } catch (SQLException e) {
4613 sb.append("FAILED: ").append(e.getMessage()).append("\n"); 4616 sb.append("FAILED: ").append(e.getMessage()).append("\n");
4614 } 4617 }
4615 4618
4616 closeStmtResSet(stmt, rs); 4619 closeStmtResSet(stmt, rs);
4626 } 4629 }
4627 4630
4628 private void showResultAndClose_6183(ResultSet rs) throws SQLException { 4631 private void showResultAndClose_6183(ResultSet rs) throws SQLException {
4629 ResultSetMetaData rsmd = rs.getMetaData(); 4632 ResultSetMetaData rsmd = rs.getMetaData();
4630 int rs_col_count = rsmd.getColumnCount(); 4633 int rs_col_count = rsmd.getColumnCount();
4631 sb.append("Resultset with ").append(rs_col_count).append(" columns").append("\n"); 4634 sb.append("Resultset with ").append(rs_col_count).append(" columns\n");
4632 sb.append("\tColumn Name, Column Label:").append("\n"); 4635 sb.append("\tColumn Name, Column Label:\n");
4633 for (int col = 1; col <= rs_col_count; col++) { 4636 for (int col = 1; col <= rs_col_count; col++) {
4634 sb.append(col).append("\t").append(rsmd.getColumnName(col)).append("\t").append(rsmd.getColumnLabel(col)).append("\n"); 4637 sb.append(col).append("\t").append(rsmd.getColumnName(col)).append("\t").append(rsmd.getColumnLabel(col)).append("\n");
4635 } 4638 }
4636 4639
4637 sb.append("Data rows:").append("\n"); 4640 sb.append("Data rows:\n");
4638 long row_count = 0; 4641 long row_count = 0;
4639 while (rs.next()) { 4642 while (rs.next()) {
4640 row_count++; 4643 row_count++;
4641 for (int col = 1; col <= rs_col_count; col++) { 4644 for (int col = 1; col <= rs_col_count; col++) {
4642 if (col > 1) 4645 if (col > 1)
4644 sb.append(rs.getString(col)); 4647 sb.append(rs.getString(col));
4645 } 4648 }
4646 sb.append("\n"); 4649 sb.append("\n");
4647 } 4650 }
4648 rs.close(); 4651 rs.close();
4649 sb.append("Listed ").append(row_count).append(" rows").append("\n"); 4652 sb.append("Listed ").append(row_count).append(" rows\n");
4650 } 4653 }
4651 4654
4652 private void BugSetQueryTimeout_Bug_3357() { 4655 private void BugSetQueryTimeout_Bug_3357() {
4653 sb.setLength(0); // clear the output log buffer 4656 sb.setLength(0); // clear the output log buffer
4654 4657
4697 if (rs != null) 4700 if (rs != null)
4698 rs.close(); 4701 rs.close();
4699 sb.append("getQueryTimeout = ").append(st.getQueryTimeout()).append("\n"); 4702 sb.append("getQueryTimeout = ").append(st.getQueryTimeout()).append("\n");
4700 } 4703 }
4701 4704
4705 /**
4706 * This SQLcopyinto program demonstrates how the MonetDB JDBC driver can facilitate
4707 * in performing COPY INTO ... FROM STDIN sequences.
4708 * It shows how a data stream via MapiSocket to STDIN can be performed.
4709 *
4710 * @author Fabian Groffen, Martin van Dinther
4711 */
4712 private void SQLcopyinto() {
4713 sb.setLength(0); // clear the output log buffer
4714
4715 final String tablenm = "exampleSQLCopyInto";
4716 Statement stmt = null;
4717 ResultSet rs = null;
4718 try {
4719 stmt = con.createStatement();
4720 stmt.execute("CREATE TABLE IF NOT EXISTS " + tablenm + " (id int, val varchar(24))");
4721
4722 fillTableUsingCopyIntoSTDIN(tablenm);
4723
4724 // check content of the table populated via COPY INTO ... FROM STDIN
4725 sb.append("Listing uploaded data:\n");
4726 int row = 0;
4727 rs = stmt.executeQuery("SELECT * FROM " + tablenm);
4728 if (rs != null) {
4729 while (rs.next()) {
4730 row++;
4731 if ((row % 1000) == 0)
4732 sb.append("Row data: ").append(rs.getString(1)).append(", ").append(rs.getString(2)).append("\n");
4733 }
4734 rs.close();
4735 rs = null;
4736 }
4737 } catch (SQLException se) {
4738 sb.append("SQLException: ").append(se.getMessage()).append("\n");
4739 } catch (Exception e) {
4740 sb.append("Exception: ").append(e.getMessage()).append("\n");
4741 }
4742
4743 // cleanup
4744 try {
4745 stmt.execute("DROP TABLE " + tablenm);
4746 sb.append("SQLcopyinto completed\n");
4747 } catch (SQLException se) {
4748 sb.append("SQLException: ").append(se.getMessage()).append("\n");
4749 }
4750 closeStmtResSet(stmt, rs);
4751
4752 compareExpectedOutput("SQLcopyinto()",
4753 "CopyInto STDIN begin\n" +
4754 "Before connecting to MonetDB server via MapiSocket\n" +
4755 "Connected to MonetDB server via MapiSocket\n" +
4756 "Before sending data to STDIN\n" +
4757 "Completed sending data via STDIN\n" +
4758 "CopyInto STDIN end\n" +
4759 "Listing uploaded data:\n" +
4760 "Row data: 999, val_999\n" +
4761 "Row data: 1999, val_1999\n" +
4762 "Row data: 2999, val_2999\n" +
4763 "Row data: 3999, val_3999\n" +
4764 "Row data: 4999, val_4999\n" +
4765 "Row data: 5999, val_5999\n" +
4766 "Row data: 6999, val_6999\n" +
4767 "Row data: 7999, val_7999\n" +
4768 "Row data: 8999, val_8999\n" +
4769 "SQLcopyinto completed\n");
4770 }
4771
4772 private void fillTableUsingCopyIntoSTDIN(String tablenm) throws Exception {
4773 sb.append("CopyInto STDIN begin\n");
4774
4775 org.monetdb.mcl.net.MapiSocket server = new org.monetdb.mcl.net.MapiSocket();
4776 try {
4777 server.setLanguage("sql");
4778
4779 // extract from MonetConnection object the used connection properties
4780 String host = con.getClientInfo("host");
4781 int port = Integer.parseInt(con.getClientInfo("port"));
4782 String login = con.getClientInfo("user");
4783 String passw = con.getClientInfo("password");
4784 // sb.append("host: " + host + " port: " + port + " login: " + login + " passwd: " + passw + "\n");
4785
4786 sb.append("Before connecting to MonetDB server via MapiSocket\n");
4787 List<String> warning = server.connect(host, port, login, passw);
4788 if (warning != null) {
4789 for (Iterator<String> it = warning.iterator(); it.hasNext(); ) {
4790 sb.append("Warning: ").append(it.next().toString()).append("\n");
4791 }
4792 }
4793 sb.append("Connected to MonetDB server via MapiSocket\n");
4794
4795 org.monetdb.mcl.io.BufferedMCLReader mclIn = server.getReader();
4796 org.monetdb.mcl.io.BufferedMCLWriter mclOut = server.getWriter();
4797
4798 String error = mclIn.waitForPrompt();
4799 if (error != null)
4800 sb.append("Received start error: ").append(error).append("\n");
4801
4802 sb.append("Before sending data to STDIN\n");
4803
4804 // the leading 's' is essential, since it is a protocol marker
4805 // that should not be omitted, likewise the trailing semicolon
4806 mclOut.write('s');
4807 mclOut.write("COPY INTO " + tablenm + " FROM STDIN USING DELIMITERS ',',E'\\n';");
4808 mclOut.newLine();
4809 // now write the row data values as csv data lines to the STDIN stream
4810 for (int i = 0; i < 9000; i++) {
4811 mclOut.write("" + i + ",val_" + i);
4812 mclOut.newLine();
4813 }
4814 mclOut.writeLine(""); // need this one for synchronisation over flush()
4815
4816 error = mclIn.waitForPrompt();
4817 if (error != null)
4818 sb.append("Received error: ").append(error).append("\n");
4819
4820 mclOut.writeLine(""); // need this one for synchronisation over flush()
4821
4822 error = mclIn.waitForPrompt();
4823 if (error != null)
4824 sb.append("Received finish error: ").append(error).append("\n");
4825
4826 sb.append("Completed sending data via STDIN\n");
4827 } catch (Exception e) {
4828 sb.append("Mapi Exception: ").append(e.getMessage()).append("\n");
4829 } finally {
4830 // close MAPI connection to MonetDB server
4831 server.close();
4832 }
4833
4834 sb.append("CopyInto STDIN end\n");
4835 }
4836
4702 4837
4703 // some private utility methods for showing table content and params meta data 4838 // some private utility methods for showing table content and params meta data
4704 private void showTblContents(String tblnm) { 4839 private void showTblContents(String tblnm) {
4705 Statement stmt = null; 4840 Statement stmt = null;
4706 ResultSet rs = null; 4841 ResultSet rs = null;
4707 try { 4842 try {
4708 stmt = con.createStatement(); 4843 stmt = con.createStatement();
4709 rs = stmt.executeQuery("SELECT * FROM " + tblnm); 4844 rs = stmt.executeQuery("SELECT * FROM " + tblnm);
4710 if (rs != null) { 4845 if (rs != null) {
4711 ResultSetMetaData rsmd = rs.getMetaData(); 4846 ResultSetMetaData rsmd = rs.getMetaData();
4712 sb.append("Table ").append(tblnm).append(" has ").append(rsmd.getColumnCount()).append(" columns:").append("\n"); 4847 sb.append("Table ").append(tblnm).append(" has ").append(rsmd.getColumnCount()).append(" columns:\n");
4713 for (int col = 1; col <= rsmd.getColumnCount(); col++) { 4848 for (int col = 1; col <= rsmd.getColumnCount(); col++) {
4714 sb.append("\t").append(rsmd.getColumnLabel(col)); 4849 sb.append("\t").append(rsmd.getColumnLabel(col));
4715 } 4850 }
4716 sb.append("\n"); 4851 sb.append("\n");
4717 while (rs.next()) { 4852 while (rs.next()) {