changeset 21:3fa84d6924a6

Add test program for Bug 3350
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Thu, 13 Oct 2016 19:30:29 +0200 (2016-10-13)
parents dbb8e7c2dbbf
children 07530c9a099e
files tests/BugExecuteUpdate_Bug_3350.java tests/build.xml
diffstat 2 files changed, 57 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
new file mode 100644
--- /dev/null
+++ b/tests/BugExecuteUpdate_Bug_3350.java
@@ -0,0 +1,50 @@
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0.  If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * Copyright 1997 - July 2008 CWI, August 2008 - 2016 MonetDB B.V.
+ */
+
+import java.sql.*;
+
+public class BugExecuteUpdate_Bug_3350 {
+	public static void main(String[] args) throws Exception {
+		// Class.forName("nl.cwi.monetdb.jdbc.MonetDriver");
+		final Connection con = DriverManager.getConnection(args[0]);
+		con.setAutoCommit(false);	// disable auto commit, so we can roll back the transaction
+
+		final Statement stmt = con.createStatement();
+		try {
+			executeDML(stmt, "INSERT INTO sys.keywords VALUES ('Bug_3350')"); // should insert 1 row
+			executeDML(stmt, "INSERT INTO sys.keywords VALUES ('Bug_3350')"); // this will result in an SQLException due to PK uniqueness violation
+			con.rollback();
+
+			executeDML(stmt, "INSERT INTO sys.keywords VALUES ('Bug_3350')"); // should insert 1 row
+			executeDML(stmt, "DELETE FROM sys.keywords WHERE \"keyword\" = 'Bug_3350'"); // should delete 1 row
+			executeDML(stmt, "DELETE FROM sys.keywords WHERE \"keyword\" = 'Bug_3350'"); // should delete 0 rows
+
+			con.rollback();
+		} catch (SQLException se) {
+			System.out.println(se.getMessage());
+		} finally {
+			stmt.close();
+		}
+		con.close();
+	}
+
+	private static void executeDML(Statement st, String sql) {
+		try {
+			int upd_count = st.executeUpdate(sql);
+			System.out.println("executeUpdate(" + sql.substring(0, 6) + " ...) returned: " + upd_count);
+		} catch (SQLException se) {
+			System.out.println(se.getMessage());
+		}
+
+		try {
+			System.out.println("getUpdateCount() returned: " + st.getUpdateCount());
+		} catch (SQLException se) {
+			System.out.println(se.getMessage());
+		}
+	}
+}
--- a/tests/build.xml
+++ b/tests/build.xml
@@ -128,6 +128,7 @@ Copyright 1997 - July 2008 CWI, August 2
     <antcall target="Test_Wrapper" />
     <antcall target="BugConcurrent_clients_SF_1504657" />
     <antcall target="BugConcurrent_sequences" />
+    <antcall target="BugExecuteUpdate_Bug_3350" />
     <antcall target="BugDatabaseMetaData_Bug_3356" />
     <antcall target="BugSetQueryTimeout_Bug_3357" />
     <antcall target="BugDecimalRound_Bug_3561" />
@@ -344,6 +345,12 @@ Copyright 1997 - July 2008 CWI, August 2
     </antcall>
   </target>
 
+  <target name="BugExecuteUpdate_Bug_3350">
+    <antcall target="test_class">
+      <param name="test.class" value="BugExecuteUpdate_Bug_3350" />
+    </antcall>
+  </target>
+
   <target name="BugDatabaseMetaData_Bug_3356">
     <antcall target="test_class">
       <param name="test.class" value="BugDatabaseMetaData_Bug_3356" />