Commit c0d58678 authored by Dan Harrington's avatar Dan Harrington Committed by Commit Bot

Fix DCHECK in second call to GetCachedStatement

When an SQL statement has leading or trailing whitespace, the stored
statement doesn't match when performing the DCHECK. Fixed by trimming whitespace
before comparing the statements.

Bug: 894884
Change-Id: If49b06103ed4fa3d49e623f62ce43247b2a27cf3
Reviewed-on: https://chromium-review.googlesource.com/c/1338177Reviewed-by: default avatarChris Mumford <cmumford@chromium.org>
Commit-Queue: Dan H <harringtond@google.com>
Cr-Commit-Position: refs/heads/master@{#608787}
parent ca8475bc
......@@ -1388,8 +1388,9 @@ scoped_refptr<Database::StatementRef> Database::GetCachedStatement(
// one invalidating cached statements, and we remove them from the cache
// when we do that.
DCHECK(it->second->is_valid());
DCHECK_EQ(std::string(sql), std::string(sqlite3_sql(it->second->stmt())))
DCHECK_EQ(base::TrimWhitespaceASCII(sql, base::TRIM_ALL),
base::TrimWhitespaceASCII(sqlite3_sql(it->second->stmt()),
base::TRIM_ALL))
<< "GetCachedStatement used with same ID but different SQL";
// Reset the statement so it can be reused.
......
......@@ -230,7 +230,8 @@ TEST_F(SQLDatabaseTest, ExecuteWithErrorCode) {
TEST_F(SQLDatabaseTest, CachedStatement) {
sql::StatementID id1 = SQL_FROM_HERE;
sql::StatementID id2 = SQL_FROM_HERE;
static const char kId1Sql[] = "SELECT a FROM foo";
// Ensure leading and trailing whitespace doesn't break anything.
static const char kId1Sql[] = "\n SELECT a FROM foo \n";
static const char kId2Sql[] = "SELECT b FROM foo";
ASSERT_TRUE(db().Execute("CREATE TABLE foo (a, b)"));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment