Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Unified Diff: sql/sqlite_features_unittest.cc

Issue 2440653002: [sql] Verify regexp not cached with prepared statement. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sql/sqlite_features_unittest.cc
diff --git a/sql/sqlite_features_unittest.cc b/sql/sqlite_features_unittest.cc
index b84a80d69c0d597ba1c38d7ca6dc666473a23c01..199d9446c73b14ba452297f1c9b317ddcd1565c1 100644
--- a/sql/sqlite_features_unittest.cc
+++ b/sql/sqlite_features_unittest.cc
@@ -270,4 +270,37 @@ TEST_F(SQLiteFeaturesTest, Mmap) {
}
#endif
+// Verify that http://crbug.com/248608 is fixed. In this bug, the
+// compiled regular expression is effectively cached with the prepared
+// statement, causing errors if the regular expression is rebound.
+TEST_F(SQLiteFeaturesTest, CachedRegexp) {
+ ASSERT_TRUE(db().Execute("CREATE TABLE r (id INTEGER UNIQUE, x TEXT)"));
+ ASSERT_TRUE(db().Execute("INSERT INTO r VALUES (1, 'this is a test')"));
+ ASSERT_TRUE(db().Execute("INSERT INTO r VALUES (2, 'that was a test')"));
+ ASSERT_TRUE(db().Execute("INSERT INTO r VALUES (3, 'this is a stickup')"));
+ ASSERT_TRUE(db().Execute("INSERT INTO r VALUES (4, 'that sucks')"));
+
+ const char* kSimpleSql = "SELECT SUM(id) FROM r WHERE x REGEXP ?";
+ sql::Statement s(db().GetCachedStatement(SQL_FROM_HERE, kSimpleSql));
+
+ s.BindString(0, "this.*");
+ ASSERT_TRUE(s.Step());
+ EXPECT_EQ(4, s.ColumnInt(0));
+
+ s.Reset(true);
+ s.BindString(0, "that.*");
+ ASSERT_TRUE(s.Step());
+ EXPECT_EQ(6, s.ColumnInt(0));
+
+ s.Reset(true);
+ s.BindString(0, ".*test");
+ ASSERT_TRUE(s.Step());
+ EXPECT_EQ(3, s.ColumnInt(0));
+
+ s.Reset(true);
+ s.BindString(0, ".* s[a-z]+");
+ ASSERT_TRUE(s.Step());
+ EXPECT_EQ(7, s.ColumnInt(0));
+}
+
} // namespace
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698