annotate tests/BugExecuteUpdate_Bug_3350.java @ 261:d4baf8a4b43a

Update Copyright year to 2019
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Thu, 03 Jan 2019 14:43:44 +0100 (2019-01-03)
parents c38d4eaf5479
children 54137aeb1f92
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
1 /*
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
2 * This Source Code Form is subject to the terms of the Mozilla Public
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
5 *
261
d4baf8a4b43a Update Copyright year to 2019
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V.
21
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
7 */
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
8
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
9 import java.sql.*;
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
10
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
11 public class BugExecuteUpdate_Bug_3350 {
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
12 public static void main(String[] args) throws Exception {
27
04fbf3655452 Disable Class.forName("nl.cwi.monetdb.jdbc.MonetDriver"); code
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 21
diff changeset
13 // Class.forName("nl.cwi.monetdb.jdbc.MonetDriver"); // not needed anymore for self registering JDBC drivers
21
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
14 final Connection con = DriverManager.getConnection(args[0]);
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
15 con.setAutoCommit(false); // disable auto commit, so we can roll back the transaction
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
16
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
17 final Statement stmt = con.createStatement();
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
18 try {
129
f9ba2b04db7b Changed ExecuteUpdate test to not work on sys.keywords table (which became readonly in Jul2017 branch) but use its own created table t3350.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
19 stmt.execute("CREATE TABLE t3350 (keyword VARCHAR(30) PRIMARY KEY)");
f9ba2b04db7b Changed ExecuteUpdate test to not work on sys.keywords table (which became readonly in Jul2017 branch) but use its own created table t3350.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
20 con.commit();
f9ba2b04db7b Changed ExecuteUpdate test to not work on sys.keywords table (which became readonly in Jul2017 branch) but use its own created table t3350.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
21
f9ba2b04db7b Changed ExecuteUpdate test to not work on sys.keywords table (which became readonly in Jul2017 branch) but use its own created table t3350.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
22 executeDML(stmt, "INSERT INTO t3350 VALUES ('Bug_3350')"); // should insert 1 row
f9ba2b04db7b Changed ExecuteUpdate test to not work on sys.keywords table (which became readonly in Jul2017 branch) but use its own created table t3350.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
23 executeDML(stmt, "INSERT INTO t3350 VALUES ('Bug_3350')"); // this will result in an SQLException due to PK uniqueness violation
21
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
24 con.rollback();
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
25
129
f9ba2b04db7b Changed ExecuteUpdate test to not work on sys.keywords table (which became readonly in Jul2017 branch) but use its own created table t3350.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
26 executeDML(stmt, "INSERT INTO t3350 VALUES ('Bug_3350')"); // should insert 1 row
f9ba2b04db7b Changed ExecuteUpdate test to not work on sys.keywords table (which became readonly in Jul2017 branch) but use its own created table t3350.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
27 executeDML(stmt, "INSERT INTO t3350 VALUES ('1'), ('x'), ('3'), ('y')"); // should insert 4 rows
f9ba2b04db7b Changed ExecuteUpdate test to not work on sys.keywords table (which became readonly in Jul2017 branch) but use its own created table t3350.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
28 executeDML(stmt, "DELETE FROM t3350 WHERE \"keyword\" = 'Bug_3350'"); // should delete 1 row
f9ba2b04db7b Changed ExecuteUpdate test to not work on sys.keywords table (which became readonly in Jul2017 branch) but use its own created table t3350.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
29 executeDML(stmt, "DELETE FROM t3350 WHERE \"keyword\" = 'Bug_3350'"); // should delete 0 rows
f9ba2b04db7b Changed ExecuteUpdate test to not work on sys.keywords table (which became readonly in Jul2017 branch) but use its own created table t3350.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
30 executeDML(stmt, "UPDATE t3350 set \"keyword\" = keyword||'_ext'"); // should update 4 rows
f9ba2b04db7b Changed ExecuteUpdate test to not work on sys.keywords table (which became readonly in Jul2017 branch) but use its own created table t3350.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
31 executeDML(stmt, "DELETE FROM t3350"); // should delete 4 rows
f9ba2b04db7b Changed ExecuteUpdate test to not work on sys.keywords table (which became readonly in Jul2017 branch) but use its own created table t3350.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
32 con.commit();
21
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
33
129
f9ba2b04db7b Changed ExecuteUpdate test to not work on sys.keywords table (which became readonly in Jul2017 branch) but use its own created table t3350.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
34 stmt.execute("DROP TABLE t3350");
f9ba2b04db7b Changed ExecuteUpdate test to not work on sys.keywords table (which became readonly in Jul2017 branch) but use its own created table t3350.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
35 con.commit();
21
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
36 } catch (SQLException se) {
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
37 System.out.println(se.getMessage());
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
38 } finally {
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
39 stmt.close();
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
40 }
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
41 con.close();
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
42 }
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
43
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
44 private static void executeDML(Statement st, String sql) {
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
45 try {
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
46 int upd_count = st.executeUpdate(sql);
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
47 System.out.println("executeUpdate(" + sql.substring(0, 6) + " ...) returned: " + upd_count);
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
48 } catch (SQLException se) {
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
49 System.out.println(se.getMessage());
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
50 }
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
51
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
52 try {
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
53 System.out.println("getUpdateCount() returned: " + st.getUpdateCount());
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
54 } catch (SQLException se) {
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
55 System.out.println(se.getMessage());
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
56 }
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
57 }
3fa84d6924a6 Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
58 }