sql: Restore strict DCHECK of cached statements SQL.

https://crrev.com/c/1338177 relaxed the DCHECKs for
sql::Database::GetCachedStatment by allowing the SQL statement argument
to have leading and trailing whitespace when compared with the SQL
statement reported by SQLite.

This CL reverts the relaxed restriction. Instead, GetCachedStatement
will also DCHECK that the SQL statement argument matches the SQL
statement reported by SQLite when preparing the statement. This will
help developers discover non-canonical statements on first use.

Bug: 894884
Change-Id: I166f8cda8d5a3980d9858a26507f778bc87ee6cc
Reviewed-on: https://chromium-review.googlesource.com/c/1341493
Commit-Queue: Victor Costan <[email protected]>
Reviewed-by: Joshua Bell <[email protected]>
Cr-Commit-Position: refs/heads/master@{#609605}
diff --git a/sql/database.cc b/sql/database.cc
index 8d3bf081..b1a7cdc5 100644
--- a/sql/database.cc
+++ b/sql/database.cc
@@ -1384,13 +1384,11 @@
     const char* sql) {
   auto it = statement_cache_.find(id);
   if (it != statement_cache_.end()) {
-    // Statement is in the cache. It should still be active. We're the only
-    // one invalidating cached statements, and we remove them from the cache
+    // Statement is in the cache. It should still be valid. We're the only
+    // entity invalidating cached statements, and we remove them from the cache
     // when we do that.
     DCHECK(it->second->is_valid());
-    DCHECK_EQ(base::TrimWhitespaceASCII(sql, base::TRIM_ALL),
-              base::TrimWhitespaceASCII(sqlite3_sql(it->second->stmt()),
-                                        base::TRIM_ALL))
+    DCHECK_EQ(std::string(sqlite3_sql(it->second->stmt())), std::string(sql))
         << "GetCachedStatement used with same ID but different SQL";
 
     // Reset the statement so it can be reused.
@@ -1399,8 +1397,11 @@
   }
 
   scoped_refptr<StatementRef> statement = GetUniqueStatement(sql);
-  if (statement->is_valid())
+  if (statement->is_valid()) {
     statement_cache_[id] = statement;  // Only cache valid statements.
+    DCHECK_EQ(std::string(sqlite3_sql(statement->stmt())), std::string(sql))
+        << "Input SQL does not match SQLite's normalized version";
+  }
   return statement;
 }