summaryrefslogtreecommitdiffstats
path: root/sql/connection_unittest.cc
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-12 23:50:59 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-12 23:50:59 +0000
commiteff1fa525ce9cf8965cf187c9e7aef8c2db39bf9 (patch)
tree11404979e9dfe31379468712d8b3acf5c552b345 /sql/connection_unittest.cc
parentd2528e607d9f876b4db237ebf37a57dcd45a4dbf (diff)
downloadchromium_src-eff1fa525ce9cf8965cf187c9e7aef8c2db39bf9.zip
chromium_src-eff1fa525ce9cf8965cf187c9e7aef8c2db39bf9.tar.gz
chromium_src-eff1fa525ce9cf8965cf187c9e7aef8c2db39bf9.tar.bz2
Put debugging assertions into sql::Statement.
Pulls out the core of gbillock's http://codereview.chromium.org/8283002/ - Move NOTREACHED and similar checks into the sql:: implementation code. - Add malformed SQL checks to Connection::Execute. - Add SQL-checking convenience methods to Connection. The general idea is that the sql:: framework assumes valid statements, rather than having client code contain scattered ad-hoc (and thus inconsistent) checks. This version puts back Statement operator overloading and loosy-goosy Execute() calls to allow other code to be updated in small batches. R=gbillock@chromium.org,jhawkins@chromium.org,dhollowa@chromium.org BUG=none TEST=sql_unittests,unit_tests:*Table*.* Review URL: http://codereview.chromium.org/8899012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114118 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sql/connection_unittest.cc')
-rw-r--r--sql/connection_unittest.cc24
1 files changed, 20 insertions, 4 deletions
diff --git a/sql/connection_unittest.cc b/sql/connection_unittest.cc
index e99bff7..9718ce0 100644
--- a/sql/connection_unittest.cc
+++ b/sql/connection_unittest.cc
@@ -35,10 +35,21 @@ TEST_F(SQLConnectionTest, Execute) {
EXPECT_EQ(SQLITE_OK, db().GetErrorCode());
// Invalid statement should fail.
- ASSERT_FALSE(db().Execute("CREATE TAB foo (a, b"));
+ ASSERT_EQ(SQLITE_ERROR,
+ db().ExecuteAndReturnErrorCode("CREATE TAB foo (a, b"));
EXPECT_EQ(SQLITE_ERROR, db().GetErrorCode());
}
+TEST_F(SQLConnectionTest, ExecuteWithErrorCode) {
+ ASSERT_EQ(SQLITE_OK,
+ db().ExecuteAndReturnErrorCode("CREATE TABLE foo (a, b)"));
+ ASSERT_EQ(SQLITE_ERROR,
+ db().ExecuteAndReturnErrorCode("CREATE TABLE TABLE"));
+ ASSERT_EQ(SQLITE_ERROR,
+ db().ExecuteAndReturnErrorCode(
+ "INSERT INTO foo(a, b) VALUES (1, 2, 3, 4)"));
+}
+
TEST_F(SQLConnectionTest, CachedStatement) {
sql::StatementID id1("foo", 12);
@@ -48,7 +59,7 @@ TEST_F(SQLConnectionTest, CachedStatement) {
// Create a new cached statement.
{
sql::Statement s(db().GetCachedStatement(id1, "SELECT a FROM foo"));
- ASSERT_FALSE(!s); // Test ! operator for validity.
+ ASSERT_TRUE(s.is_valid());
ASSERT_TRUE(s.Step());
EXPECT_EQ(12, s.ColumnInt(0));
@@ -61,7 +72,7 @@ TEST_F(SQLConnectionTest, CachedStatement) {
// Get the same statement using different SQL. This should ignore our
// SQL and use the cached one (so it will be valid).
sql::Statement s(db().GetCachedStatement(id1, "something invalid("));
- ASSERT_FALSE(!s); // Test ! operator for validity.
+ ASSERT_TRUE(s.is_valid());
ASSERT_TRUE(s.Step());
EXPECT_EQ(12, s.ColumnInt(0));
@@ -71,6 +82,12 @@ TEST_F(SQLConnectionTest, CachedStatement) {
EXPECT_FALSE(db().HasCachedStatement(SQL_FROM_HERE));
}
+TEST_F(SQLConnectionTest, IsSQLValidTest) {
+ ASSERT_TRUE(db().Execute("CREATE TABLE foo (a, b)"));
+ ASSERT_TRUE(db().IsSQLValid("SELECT a FROM foo"));
+ ASSERT_FALSE(db().IsSQLValid("SELECT no_exist FROM foo"));
+}
+
TEST_F(SQLConnectionTest, DoesStuffExist) {
// Test DoesTableExist.
EXPECT_FALSE(db().DoesTableExist("foo"));
@@ -103,4 +120,3 @@ TEST_F(SQLConnectionTest, GetLastInsertRowId) {
ASSERT_TRUE(s.Step());
EXPECT_EQ(12, s.ColumnInt(0));
}
-