cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ble...@apache.org
Subject [1/2] cassandra git commit: Test bind parameters and unset parameters in InsertUpdateIfConditionTest
Date Mon, 12 Dec 2016 12:47:00 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-3.0 6bd402d12 -> da94781a2


Test bind parameters and unset parameters in InsertUpdateIfConditionTest

patch by Benjamin Lerer; reviewed by Alex Petrov for CASSANDRA-12980


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/9a5aef09
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/9a5aef09
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/9a5aef09

Branch: refs/heads/cassandra-3.0
Commit: 9a5aef09fe51592713d0fa38bfb9e42e21e7644d
Parents: dd41526
Author: Benjamin Lerer <b.lerer@gmail.com>
Authored: Mon Dec 12 12:52:18 2016 +0100
Committer: Benjamin Lerer <b.lerer@gmail.com>
Committed: Mon Dec 12 12:52:18 2016 +0100

----------------------------------------------------------------------
 CHANGES.txt                                     |   1 +
 .../operations/InsertUpdateIfConditionTest.java | 147 ++++++++++++-------
 2 files changed, 91 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/9a5aef09/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 6b2a9c0..134a37d 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.2.9
+ * Test bind parameters and unset parameters in InsertUpdateIfConditionTest (CASSANDRA-12980)
  * Do not specify local address on outgoing connection when listen_on_broadcast_address is
set (CASSANDRA-12673)
  * Use saved tokens when setting local tokens on StorageService.joinRing (CASSANDRA-12935)
  * cqlsh: fix DESC TYPES errors (CASSANDRA-12914)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/9a5aef09/test/unit/org/apache/cassandra/cql3/validation/operations/InsertUpdateIfConditionTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/InsertUpdateIfConditionTest.java
b/test/unit/org/apache/cassandra/cql3/validation/operations/InsertUpdateIfConditionTest.java
index fc6cc2e..4a209e6 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/operations/InsertUpdateIfConditionTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/InsertUpdateIfConditionTest.java
@@ -41,8 +41,8 @@ public class InsertUpdateIfConditionTest extends CQLTester
         {
             execute("INSERT INTO %s (tkn, consumed) VALUES (?, FALSE)", i);
 
-            assertRows(execute("UPDATE %s SET consumed = TRUE WHERE tkn = ? IF consumed =
FALSE", i), row(true));
-            assertRows(execute("UPDATE %s SET consumed = TRUE WHERE tkn = ? IF consumed =
FALSE", i), row(false, true));
+            assertRows(execute("UPDATE %s SET consumed = TRUE WHERE tkn = ? IF consumed =
?", i, false), row(true));
+            assertRows(execute("UPDATE %s SET consumed = TRUE WHERE tkn = ? IF consumed =
?", i, false), row(false, true));
         }
     }
 
@@ -54,8 +54,11 @@ public class InsertUpdateIfConditionTest extends CQLTester
     {
         createTable(" CREATE TABLE %s (k int PRIMARY KEY, v1 int, v2 text, v3 int)");
 
+        assertInvalidMessage("Invalid 'unset' value in condition",
+                             "UPDATE %s SET v1 = 3, v2 = 'bar' WHERE k = 0 IF v1 = ?", unset());
+
         // Shouldn't apply
-        assertRows(execute("UPDATE %s SET v1 = 3, v2 = 'bar' WHERE k = 0 IF v1 = 4"), row(false));
+        assertRows(execute("UPDATE %s SET v1 = 3, v2 = 'bar' WHERE k = 0 IF v1 = ?", 4),
row(false));
         assertRows(execute("UPDATE %s SET v1 = 3, v2 = 'bar' WHERE k = 0 IF EXISTS"), row(false));
 
         // Should apply
@@ -66,50 +69,50 @@ public class InsertUpdateIfConditionTest extends CQLTester
         assertRows(execute("SELECT * FROM %s"), row(0, 2, "foo", null));
 
         // Shouldn't apply
-        assertRows(execute("UPDATE %s SET v1 = 3, v2 = 'bar' WHERE k = 0 IF v1 = 4"), row(false,
2));
+        assertRows(execute("UPDATE %s SET v1 = 3, v2 = 'bar' WHERE k = 0 IF v1 = ?", 4),
row(false, 2));
         assertRows(execute("SELECT * FROM %s"), row(0, 2, "foo", null));
 
         // Should apply (note: we want v2 before v1 in the statement order to exercise #5786)
-        assertRows(execute("UPDATE %s SET v2 = 'bar', v1 = 3 WHERE k = 0 IF v1 = 2"), row(true));
+        assertRows(execute("UPDATE %s SET v2 = 'bar', v1 = 3 WHERE k = 0 IF v1 = ?", 2),
row(true));
         assertRows(execute("UPDATE %s SET v2 = 'bar', v1 = 3 WHERE k = 0 IF EXISTS"), row(true));
         assertRows(execute("SELECT * FROM %s"), row(0, 3, "bar", null));
 
         // Shouldn't apply, only one condition is ok
-        assertRows(execute("UPDATE %s SET v1 = 5, v2 = 'foobar' WHERE k = 0 IF v1 = 3 AND
v2 = 'foo'"), row(false, 3, "bar"));
+        assertRows(execute("UPDATE %s SET v1 = 5, v2 = 'foobar' WHERE k = 0 IF v1 = ? AND
v2 = ?", 3, "foo"), row(false, 3, "bar"));
         assertRows(execute("SELECT * FROM %s"), row(0, 3, "bar", null));
 
         // Should apply
-        assertRows(execute("UPDATE %s SET v1 = 5, v2 = 'foobar' WHERE k = 0 IF v1 = 3 AND
v2 = 'bar'"), row(true));
+        assertRows(execute("UPDATE %s SET v1 = 5, v2 = 'foobar' WHERE k = 0 IF v1 = ? AND
v2 = ?", 3, "bar"), row(true));
         assertRows(execute("SELECT * FROM %s"), row(0, 5, "foobar", null));
 
         // Shouldn't apply
-        assertRows(execute("DELETE v2 FROM %s WHERE k = 0 IF v1 = 3"), row(false, 5));
+        assertRows(execute("DELETE v2 FROM %s WHERE k = 0 IF v1 = ?", 3), row(false, 5));
         assertRows(execute("SELECT * FROM %s"), row(0, 5, "foobar", null));
 
         // Shouldn't apply
-        assertRows(execute("DELETE v2 FROM %s WHERE k = 0 IF v1 = null"), row(false, 5));
+        assertRows(execute("DELETE v2 FROM %s WHERE k = 0 IF v1 = ?", (Integer) null), row(false,
5));
         assertRows(execute("SELECT * FROM %s"), row(0, 5, "foobar", null));
 
         // Should apply
-        assertRows(execute("DELETE v2 FROM %s WHERE k = 0 IF v1 = 5"), row(true));
+        assertRows(execute("DELETE v2 FROM %s WHERE k = 0 IF v1 = ?", 5), row(true));
         assertRows(execute("SELECT * FROM %s"), row(0, 5, null, null));
 
         // Shouln't apply
-        assertRows(execute("DELETE v1 FROM %s WHERE k = 0 IF v3 = 4"), row(false, null));
+        assertRows(execute("DELETE v1 FROM %s WHERE k = 0 IF v3 = ?", 4), row(false, null));
 
         // Should apply
-        assertRows(execute("DELETE v1 FROM %s WHERE k = 0 IF v3 = null"), row(true));
+        assertRows(execute("DELETE v1 FROM %s WHERE k = 0 IF v3 = ?", (Integer) null), row(true));
         assertRows(execute("SELECT * FROM %s"), row(0, null, null, null));
 
         // Should apply
-        assertRows(execute("DELETE FROM %s WHERE k = 0 IF v1 = null"), row(true));
+        assertRows(execute("DELETE FROM %s WHERE k = 0 IF v1 = ?", (Integer) null), row(true));
         assertEmpty(execute("SELECT * FROM %s"));
 
         // Shouldn't apply
         assertRows(execute("UPDATE %s SET v1 = 3, v2 = 'bar' WHERE k = 0 IF EXISTS"), row(false));
 
         // Should apply
-        assertRows(execute("DELETE FROM %s WHERE k = 0 IF v1 IN (null)"), row(true));
+        assertRows(execute("DELETE FROM %s WHERE k = 0 IF v1 IN (?)", (Integer) null), row(true));
     }
 
     /**
@@ -123,15 +126,28 @@ public class InsertUpdateIfConditionTest extends CQLTester
         // non-EQ conditions
         execute("INSERT INTO %s (k, v1, v2) VALUES (0, 2, 'foo')");
 
-        assertRows(execute("UPDATE %s SET v2 = 'bar' WHERE k = 0 IF v1 < 3"), row(true));
-        assertRows(execute("UPDATE %s SET v2 = 'bar' WHERE k = 0 IF v1 <= 3"), row(true));
-        assertRows(execute("UPDATE %s SET v2 = 'bar' WHERE k = 0 IF v1 > 1"), row(true));
-        assertRows(execute("UPDATE %s SET v2 = 'bar' WHERE k = 0 IF v1 >= 1"), row(true));
-        assertRows(execute("UPDATE %s SET v2 = 'bar' WHERE k = 0 IF v1 != 1"), row(true));
-        assertRows(execute("UPDATE %s SET v2 = 'bar' WHERE k = 0 IF v1 != 2"), row(false,
2));
-        assertRows(execute("UPDATE %s SET v2 = 'bar' WHERE k = 0 IF v1 IN (0, 1, 2)"), row(true));
-        assertRows(execute("UPDATE %s SET v2 = 'bar' WHERE k = 0 IF v1 IN (142, 276)"), row(false,
2));
+        assertRows(execute("UPDATE %s SET v2 = 'bar' WHERE k = 0 IF v1 < ?", 3), row(true));
+        assertRows(execute("UPDATE %s SET v2 = 'bar' WHERE k = 0 IF v1 <= ?", 3), row(true));
+        assertRows(execute("UPDATE %s SET v2 = 'bar' WHERE k = 0 IF v1 > ?", 1), row(true));
+        assertRows(execute("UPDATE %s SET v2 = 'bar' WHERE k = 0 IF v1 >= ?", 1), row(true));
+        assertRows(execute("UPDATE %s SET v2 = 'bar' WHERE k = 0 IF v1 != ?", 1), row(true));
+        assertRows(execute("UPDATE %s SET v2 = 'bar' WHERE k = 0 IF v1 != ?", 2), row(false,
2));
+        assertRows(execute("UPDATE %s SET v2 = 'bar' WHERE k = 0 IF v1 IN (?, ?, ?)", 0,
1, 2), row(true));
+        assertRows(execute("UPDATE %s SET v2 = 'bar' WHERE k = 0 IF v1 IN ?", list(142, 276)),
row(false, 2));
         assertRows(execute("UPDATE %s SET v2 = 'bar' WHERE k = 0 IF v1 IN ()"), row(false,
2));
+
+        assertInvalidMessage("Invalid 'unset' value in condition",
+                             "UPDATE %s SET v1 = 3, v2 = 'bar' WHERE k = 0 IF v1 < ?",
unset());
+        assertInvalidMessage("Invalid 'unset' value in condition",
+                             "UPDATE %s SET v1 = 3, v2 = 'bar' WHERE k = 0 IF v1 <= ?",
unset());
+        assertInvalidMessage("Invalid 'unset' value in condition",
+                             "UPDATE %s SET v1 = 3, v2 = 'bar' WHERE k = 0 IF v1 > ?",
unset());
+        assertInvalidMessage("Invalid 'unset' value in condition",
+                             "UPDATE %s SET v1 = 3, v2 = 'bar' WHERE k = 0 IF v1 >= ?",
unset());
+        assertInvalidMessage("Invalid 'unset' value in condition",
+                             "UPDATE %s SET v1 = 3, v2 = 'bar' WHERE k = 0 IF v1 != ?", unset());
+        assertInvalidMessage("Invalid 'unset' value in condition",
+                             "UPDATE %s SET v1 = 3, v2 = 'bar' WHERE k = 0 IF v1 IN (?, ?)",
unset(), 1);
     }
 
     /**
@@ -175,20 +191,31 @@ public class InsertUpdateIfConditionTest extends CQLTester
         assertRows(execute("DELETE FROM %s WHERE k='k' AND i=0 IF EXISTS"), row(false));
 
         // CASSANDRA-6430
-        assertInvalid("DELETE FROM %s WHERE k = 'k' IF EXISTS");
-        assertInvalid("DELETE FROM %s WHERE k = 'k' IF v = 'foo'");
-        assertInvalid("DELETE FROM %s WHERE i = 0 IF EXISTS");
-        assertInvalid("DELETE FROM %s WHERE k = 0 AND i > 0 IF EXISTS");
-        assertInvalid("DELETE FROM %s WHERE k = 0 AND i > 0 IF v = 'foo'");
+        assertInvalidMessage("DELETE statements must restrict all PRIMARY KEY columns with
equality relations in order to use IF conditions, but column 'i' is not restricted",
+                             "DELETE FROM %s WHERE k = 'k' IF EXISTS");
+        assertInvalidMessage("DELETE statements must restrict all PRIMARY KEY columns with
equality relations in order to use IF conditions, but column 'i' is not restricted",
+                             "DELETE FROM %s WHERE k = 'k' IF v = ?", "foo");
+        assertInvalidMessage("DELETE statements must restrict all PRIMARY KEY columns with
equality relations in order to use IF conditions, but column 'k' is not restricted",
+                             "DELETE FROM %s WHERE i = 0 IF EXISTS");
+        assertInvalidMessage("Invalid INTEGER constant (0) for \"k\" of type text",
+                             "DELETE FROM %s WHERE k = 0 AND i > 0 IF EXISTS");
+
+        assertInvalidMessage("Invalid operator > for PRIMARY KEY part i",
+                             "DELETE FROM %s WHERE k = 'k' AND i > 0 IF EXISTS");
+        assertInvalidMessage("Invalid operator > for PRIMARY KEY part i",
+                             "DELETE FROM %s WHERE k = 'k' AND i > 0 IF v = ?", "foo");
+
+        assertInvalidMessage("Invalid 'unset' value in condition",
+                             "DELETE FROM %s WHERE k = 'k' AND i = 0 IF v = ?", unset());
 
         createTable("CREATE TABLE %s(k int, s int static, i int, v text, PRIMARY KEY(k, i))");
         execute("INSERT INTO %s (k, s, i, v) VALUES ( 1, 1, 2, '1')");
-        assertRows(execute("DELETE v FROM %s WHERE k = 1 AND i = 2 IF s != 1"), row(false,
1));
-        assertRows(execute("DELETE v FROM %s WHERE k = 1 AND i = 2 IF s = 1"), row(true));
+        assertRows(execute("DELETE v FROM %s WHERE k = 1 AND i = 2 IF s != ?", 1), row(false,
1));
+        assertRows(execute("DELETE v FROM %s WHERE k = 1 AND i = 2 IF s = ?", 1), row(true));
         assertRows(execute("SELECT * FROM %s WHERE k = 1 AND i = 2"), row(1, 2, 1, null));
 
-        assertRows(execute("DELETE FROM %s WHERE  k = 1 AND i = 2 IF s != 1"), row(false,
1));
-        assertRows(execute("DELETE FROM %s WHERE k = 1 AND i = 2 IF s = 1"), row(true));
+        assertRows(execute("DELETE FROM %s WHERE  k = 1 AND i = 2 IF s != ?", 1), row(false,
1));
+        assertRows(execute("DELETE FROM %s WHERE k = 1 AND i = 2 IF s = ?", 1), row(true));
         assertEmpty(execute("SELECT * FROM %s WHERE k = 1 AND i = 2"));
         assertRows(execute("SELECT * FROM %s WHERE k = 1"), row(1, null, 1, null));
     }
@@ -211,13 +238,13 @@ public class InsertUpdateIfConditionTest extends CQLTester
 
         execute("INSERT INTO %s(id, version) VALUES (0, 0)");
 
-        assertRows(execute("UPDATE %s SET v='foo', version=1 WHERE id=0 AND k='k1' IF version
= 0"), row(true));
+        assertRows(execute("UPDATE %s SET v='foo', version=1 WHERE id=0 AND k='k1' IF version
= ?", 0), row(true));
         assertRows(execute("SELECT * FROM %s"), row(0, "k1", 1, "foo"));
 
-        assertRows(execute("UPDATE %s SET v='bar', version=1 WHERE id=0 AND k='k2' IF version
= 0"), row(false, 1));
+        assertRows(execute("UPDATE %s SET v='bar', version=1 WHERE id=0 AND k='k2' IF version
= ?", 0), row(false, 1));
         assertRows(execute("SELECT * FROM %s"), row(0, "k1", 1, "foo"));
 
-        assertRows(execute("UPDATE %s SET v='bar', version=2 WHERE id=0 AND k='k2' IF version
= 1"), row(true));
+        assertRows(execute("UPDATE %s SET v='bar', version=2 WHERE id=0 AND k='k2' IF version
= ?", 1), row(true));
         assertRows(execute("SELECT * FROM %s"), row(0, "k1", 2, "foo"), row(0, "k2", 2, "bar"));
 
         // Testing batches
@@ -559,14 +586,16 @@ public class InsertUpdateIfConditionTest extends CQLTester
 
             execute("INSERT INTO %s(k, l) VALUES (0, ['foo', 'bar', 'foobar'])");
 
-            assertInvalid("DELETE FROM %s WHERE k=0 IF l[null] = 'foobar'");
-            assertInvalid("DELETE FROM %s WHERE k=0 IF l[-2] = 'foobar'");
+            assertInvalidMessage("Invalid null value for list element access",
+                                 "DELETE FROM %s WHERE k=0 IF l[?] = ?", null, "foobar");
+            assertInvalidMessage("Invalid negative list index -2",
+                                 "DELETE FROM %s WHERE k=0 IF l[?] = ?", -2, "foobar");
 
-            assertRows(execute("DELETE FROM %s WHERE k=0 IF l[1] = null"), row(false, list("foo",
"bar", "foobar")));
-            assertRows(execute("DELETE FROM %s WHERE k=0 IF l[1] = 'foobar'"), row(false,
list("foo", "bar", "foobar")));
+            assertRows(execute("DELETE FROM %s WHERE k=0 IF l[?] = ?", 1, null), row(false,
list("foo", "bar", "foobar")));
+            assertRows(execute("DELETE FROM %s WHERE k=0 IF l[?] = ?", 1, "foobar"), row(false,
list("foo", "bar", "foobar")));
             assertRows(execute("SELECT * FROM %s"), row(0, list("foo", "bar", "foobar")));
 
-            assertRows(execute("DELETE FROM %s WHERE k=0 IF l[1] = 'bar'"), row(true));
+            assertRows(execute("DELETE FROM %s WHERE k=0 IF l[?] = ?", 1, "bar"), row(true));
             assertEmpty(execute("SELECT * FROM %s"));
         }
     }
@@ -766,19 +795,21 @@ public class InsertUpdateIfConditionTest extends CQLTester
                                       : "map<text, text>"));
 
             execute("INSERT INTO %s (k, m) VALUES (0, {'foo' : 'bar'})");
-            assertInvalid("DELETE FROM %s WHERE k=0 IF m[null] = 'foo'");
-            assertRows(execute("DELETE FROM %s WHERE k=0 IF m['foo'] = 'foo'"), row(false,
map("foo", "bar")));
-            assertRows(execute("DELETE FROM %s WHERE k=0 IF m['foo'] = null"), row(false,
map("foo", "bar")));
+            assertInvalidMessage("Invalid null value for map element access",
+                                 "DELETE FROM %s WHERE k=0 IF m[?] = ?", null, "foo");
+            assertRows(execute("DELETE FROM %s WHERE k=0 IF m[?] = ?", "foo", "foo"), row(false,
map("foo", "bar")));
+            assertRows(execute("DELETE FROM %s WHERE k=0 IF m[?] = ?", "foo", null), row(false,
map("foo", "bar")));
             assertRows(execute("SELECT * FROM %s"), row(0, map("foo", "bar")));
 
-            assertRows(execute("DELETE FROM %s WHERE k=0 IF m['foo'] = 'bar'"), row(true));
+            assertRows(execute("DELETE FROM %s WHERE k=0 IF m[?] = ?", "foo", "bar"), row(true));
             assertEmpty(execute("SELECT * FROM %s"));
 
             execute("INSERT INTO %s(k, m) VALUES (1, null)");
             if (frozen)
-                assertInvalid("UPDATE %s set m['foo'] = 'bar', m['bar'] = 'foo' WHERE k =
1 IF m['foo'] IN ('blah', null)");
+                assertInvalidMessage("Invalid operation (m['foo'] = 'bar') for frozen collection
column m",
+                                     "UPDATE %s set m['foo'] = 'bar', m['bar'] = 'foo' WHERE
k = 1 IF m[?] IN (?, ?)", "foo", "blah", null);
             else
-                assertRows(execute("UPDATE %s set m['foo'] = 'bar', m['bar'] = 'foo' WHERE
k = 1 IF m['foo'] IN ('blah', null)"), row(true));
+                assertRows(execute("UPDATE %s set m['foo'] = 'bar', m['bar'] = 'foo' WHERE
k = 1 IF m[?] IN (?, ?)", "foo", "blah", null), row(true));
         }
     }
 
@@ -987,6 +1018,8 @@ public class InsertUpdateIfConditionTest extends CQLTester
     {
         createTable("CREATE TABLE %s (a int, b int, s int static, d text, PRIMARY KEY (a,
b))");
 
+        assertInvalidMessage("Invalid 'unset' value in condition", "UPDATE %s SET s = 6 WHERE
a = 6 IF s = ?", unset());
+
         // pre-existing row
         execute("INSERT INTO %s (a, b, s, d) values (6, 6, 100, 'a')");
         assertRows(execute("UPDATE %s SET s = 6 WHERE a = 6 IF s = 100"),
@@ -1021,7 +1054,7 @@ public class InsertUpdateIfConditionTest extends CQLTester
         conditionalUpdatesWithNonExistingOrNullValues();
 
         // rejected: IN doesn't contain null
-        assertRows(execute("UPDATE %s SET s = 30 WHERE a = 3 IF s IN (10,20,30)"),
+        assertRows(execute("UPDATE %s SET s = 30 WHERE a = 3 IF s IN ?", list(10,20,30)),
                    row(false));
         assertRows(execute("SELECT * FROM %s WHERE a = 3"),
                    row(3, 3, null, null));
@@ -1029,7 +1062,7 @@ public class InsertUpdateIfConditionTest extends CQLTester
         // rejected: comparing number with NULL always returns false
         for (String operator: new String[] { ">", "<", ">=", "<=", "="})
         {
-            assertRows(execute("UPDATE %s SET s = 50 WHERE a = 5 IF s " + operator + " 3"),
+            assertRows(execute("UPDATE %s SET s = 50 WHERE a = 5 IF s " + operator + " ?",
3),
                        row(false));
             assertRows(execute("SELECT * FROM %s WHERE a = 5"),
                        row(5, 5, null, null));
@@ -1045,14 +1078,14 @@ public class InsertUpdateIfConditionTest extends CQLTester
         conditionalUpdatesWithNonExistingOrNullValues();
 
         // rejected: IN doesn't contain null
-        assertRows(execute("UPDATE %s SET s = 3 WHERE a = 3 IF s IN (10,20,30)"),
+        assertRows(execute("UPDATE %s SET s = 3 WHERE a = 3 IF s IN ?", list(10,20,30)),
                    row(false));
         assertEmpty(execute("SELECT a, s, d FROM %s WHERE a = 3"));
 
         // rejected: comparing number with NULL always returns false
         for (String operator : new String[]{ ">", "<", ">=", "<=", "=" })
         {
-            assertRows(execute("UPDATE %s SET s = 50 WHERE a = 5 IF s " + operator + " 3"),
+            assertRows(execute("UPDATE %s SET s = 50 WHERE a = 5 IF s " + operator + " ?",
3),
                        row(false));
             assertEmpty(execute("SELECT * FROM %s WHERE a = 5"));
         }
@@ -1060,17 +1093,17 @@ public class InsertUpdateIfConditionTest extends CQLTester
 
     private void conditionalUpdatesWithNonExistingOrNullValues() throws Throwable
     {
-        assertRows(execute("UPDATE %s SET s = 1 WHERE a = 1 IF s = NULL"),
+        assertRows(execute("UPDATE %s SET s = 1 WHERE a = 1 IF s = ?", (Integer) null),
                    row(true));
         assertRows(execute("SELECT a, s, d FROM %s WHERE a = 1"),
                    row(1, 1, null));
 
-        assertRows(execute("UPDATE %s SET s = 2 WHERE a = 2 IF s IN (10,20,NULL)"),
+        assertRows(execute("UPDATE %s SET s = 2 WHERE a = 2 IF s IN (?, ?, ?)", 10,20,null),
                    row(true));
         assertRows(execute("SELECT a, s, d FROM %s WHERE a = 2"),
                    row(2, 2, null));
 
-        assertRows(execute("UPDATE %s SET s = 4 WHERE a = 4 IF s != 4"),
+        assertRows(execute("UPDATE %s SET s = 4 WHERE a = 4 IF s != ?", 4 ),
                    row(true));
         assertRows(execute("SELECT a, s, d FROM %s WHERE a = 4"),
                    row(4, 4, null));
@@ -1182,23 +1215,23 @@ public class InsertUpdateIfConditionTest extends CQLTester
         for (int i = 1; i <= 5; i++)
             execute("INSERT INTO %s (a, b, s1, s2, v) VALUES (?, ?, ?, ?, ?)", i, i, i, null,
i);
 
-        assertRows(execute("DELETE s1 FROM %s WHERE a = 1 IF s2 = NULL"),
+        assertRows(execute("DELETE s1 FROM %s WHERE a = 1 IF s2 = ?", (Integer) null),
                    row(true));
         assertRows(execute("SELECT * FROM %s WHERE a = 1"),
                    row(1, 1, null, null, 1));
 
         // rejected: IN doesn't contain null
-        assertRows(execute("DELETE s1 FROM %s WHERE a = 2 IF s2 IN (10,20,30)"),
+        assertRows(execute("DELETE s1 FROM %s WHERE a = 2 IF s2 IN ?", list(10,20,30)),
                    row(false, null));
         assertRows(execute("SELECT * FROM %s WHERE a = 2"),
                    row(2, 2, 2, null, 2));
 
-        assertRows(execute("DELETE s1 FROM %s WHERE a = 3 IF s2 IN (NULL,20,30)"),
+        assertRows(execute("DELETE s1 FROM %s WHERE a = 3 IF s2 IN (?, ?, ?)", null, 20,
30),
                    row(true));
         assertRows(execute("SELECT * FROM %s WHERE a = 3"),
                    row(3, 3, null, null, 3));
 
-        assertRows(execute("DELETE s1 FROM %s WHERE a = 4 IF s2 != 4"),
+        assertRows(execute("DELETE s1 FROM %s WHERE a = 4 IF s2 != ?", 4),
                    row(true));
         assertRows(execute("SELECT * FROM %s WHERE a = 4"),
                    row(4, 4, null, null, 4));
@@ -1206,7 +1239,7 @@ public class InsertUpdateIfConditionTest extends CQLTester
         // rejected: comparing number with NULL always returns false
         for (String operator : new String[]{ ">", "<", ">=", "<=", "=" })
         {
-            assertRows(execute("DELETE s1 FROM %s WHERE a = 5 IF s2 " + operator + " 3"),
+            assertRows(execute("DELETE s1 FROM %s WHERE a = 5 IF s2 " + operator + " ?",
3),
                        row(false, null));
             assertRows(execute("SELECT * FROM %s WHERE a = 5"),
                        row(5, 5, 5, null, 5));


Mime
View raw message