Mercurial > hg > monetdb-java
annotate tests/BugExecuteUpdate_Bug_3350.java @ 391:f523727db392
Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
This naming complies to the Java Package Naming convention as MonetDB's main website is www.monetdb.org.
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Thu, 12 Nov 2020 22:02:01 +0100 (2020-11-12) |
parents | 54137aeb1f92 |
children | bf9f6b6ecf40 |
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 * |
350
54137aeb1f92
Update Copyright year.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
261
diff
changeset
|
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2020 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 { |
3fa84d6924a6
Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
13 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
|
14 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
|
15 |
3fa84d6924a6
Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
16 final Statement stmt = con.createStatement(); |
3fa84d6924a6
Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
17 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
|
18 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
|
19 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
|
20 |
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 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
|
22 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
|
23 con.rollback(); |
3fa84d6924a6
Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
24 |
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
|
25 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
|
26 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
|
27 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
|
28 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
|
29 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
|
30 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
|
31 con.commit(); |
21
3fa84d6924a6
Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
32 |
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
|
33 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
|
34 con.commit(); |
21
3fa84d6924a6
Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
35 } catch (SQLException se) { |
3fa84d6924a6
Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
36 System.out.println(se.getMessage()); |
3fa84d6924a6
Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
37 } finally { |
3fa84d6924a6
Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
38 stmt.close(); |
3fa84d6924a6
Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
39 } |
3fa84d6924a6
Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
40 con.close(); |
3fa84d6924a6
Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
41 } |
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 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
|
44 try { |
3fa84d6924a6
Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
45 int upd_count = st.executeUpdate(sql); |
3fa84d6924a6
Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
46 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
|
47 } catch (SQLException se) { |
3fa84d6924a6
Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
48 System.out.println(se.getMessage()); |
3fa84d6924a6
Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
49 } |
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 try { |
3fa84d6924a6
Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
52 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
|
53 } catch (SQLException se) { |
3fa84d6924a6
Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
54 System.out.println(se.getMessage()); |
3fa84d6924a6
Add test program for Bug 3350
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
55 } |
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 } |