Bug 1388584 - Bind ATTACH DATABASE path argument. r=adw, r=markh, a=sledru
authorAndrew Sutherland <asutherland@asutherland.org>
Sat, 12 Aug 2017 02:33:09 -0400
changeset 423516 70f2f3497546cd2fff2e7d4eba9efb9e9805146e
parent 423515 6ea7b3eb8990bb0f7a16119f8545bcf429d88131
child 423517 b65bc1bf7a4179d134b8dc577f1af650a7bddb87
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw, markh, sledru
bugs1388584, 1389660
milestone56.0
Bug 1388584 - Bind ATTACH DATABASE path argument. r=adw, r=markh, a=sledru Tests and a proper fix will land as part of bug 1389660, but that will be a few days.
storage/mozStorageConnection.cpp
toolkit/components/places/Database.cpp
--- a/storage/mozStorageConnection.cpp
+++ b/storage/mozStorageConnection.cpp
@@ -1485,25 +1485,35 @@ Connection::initializeClone(Connection* 
     while (stmt && NS_SUCCEEDED(stmt->ExecuteStep(&hasResult)) && hasResult) {
       nsAutoCString name;
       rv = stmt->GetUTF8String(1, name);
       if (NS_SUCCEEDED(rv) && !name.Equals(NS_LITERAL_CSTRING("main")) &&
                               !name.Equals(NS_LITERAL_CSTRING("temp"))) {
         nsCString path;
         rv = stmt->GetUTF8String(2, path);
         if (NS_SUCCEEDED(rv) && !path.IsEmpty()) {
-          rv = aClone->ExecuteSimpleSQL(NS_LITERAL_CSTRING("ATTACH DATABASE '") +
-            path + NS_LITERAL_CSTRING("' AS ") + name);
+          nsCOMPtr<mozIStorageStatement> attachStmt;
+          rv = aClone->CreateStatement(
+            NS_LITERAL_CSTRING("ATTACH DATABASE :path AS ") + name,
+            getter_AddRefs(attachStmt));
+          MOZ_ASSERT(NS_SUCCEEDED(rv));
+          rv = attachStmt->BindUTF8StringByName(NS_LITERAL_CSTRING("path"),
+                                                path);
+          MOZ_ASSERT(NS_SUCCEEDED(rv));
+          rv = attachStmt->Execute();
           MOZ_ASSERT(NS_SUCCEEDED(rv), "couldn't re-attach database to cloned connection");
         }
       }
     }
   }
 
   // Copy over pragmas from the original connection.
+  // LIMITATION WARNING!  Many of these pragmas are actually scoped to the
+  // schema ("main" and any other attached databases), and this implmentation
+  // fails to propagate them.  This is being addressed on trunk.
   static const char * pragmas[] = {
     "cache_size",
     "temp_store",
     "foreign_keys",
     "journal_size_limit",
     "synchronous",
     "wal_autocheckpoint",
     "busy_timeout"
--- a/toolkit/components/places/Database.cpp
+++ b/toolkit/components/places/Database.cpp
@@ -328,18 +328,24 @@ SetupDurability(nsCOMPtr<mozIStorageConn
   }
   return NS_OK;
 }
 
 nsresult
 AttachDatabase(nsCOMPtr<mozIStorageConnection>& aDBConn,
                const nsACString& aPath,
                const nsACString& aName) {
-  nsresult rv = aDBConn->ExecuteSimpleSQL(
-    NS_LITERAL_CSTRING("ATTACH DATABASE '") + aPath + NS_LITERAL_CSTRING("' AS ") + aName);
+  nsCOMPtr<mozIStorageStatement> stmt;
+  nsresult rv = aDBConn->CreateStatement(
+    NS_LITERAL_CSTRING("ATTACH DATABASE :path AS ") + aName,
+    getter_AddRefs(stmt));
+  NS_ENSURE_SUCCESS(rv, rv);
+  rv = stmt->BindUTF8StringByName(NS_LITERAL_CSTRING("path"), aPath);
+  NS_ENSURE_SUCCESS(rv, rv);
+  rv = stmt->Execute();
   NS_ENSURE_SUCCESS(rv, rv);
 
   // The journal limit must be set apart for each database.
   nsAutoCString journalSizePragma("PRAGMA favicons.journal_size_limit = ");
   journalSizePragma.AppendInt(DATABASE_MAX_WAL_BYTES + DATABASE_JOURNAL_OVERHEAD_BYTES);
   Unused << aDBConn->ExecuteSimpleSQL(journalSizePragma);
 
   return NS_OK;