Skip to content

Commit

Permalink
Bug 1388584 - Part 1: Bind ATTACH DATABASE path argument. r=adw r=mar…
Browse files Browse the repository at this point in the history
…kh a=Aryx

This is for the trunk/nightly landing only, and approval was explicitly
requested from #sheriffs to land without tests as a preliminary stop-gap.

Tests and a proper fix will land as part of bug 1389660, but that will be a few
days.
  • Loading branch information
asutherland committed Aug 12, 2017
1 parent b51eee8 commit ffaf2a1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
14 changes: 12 additions & 2 deletions storage/mozStorageConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1490,15 +1490,25 @@ Connection::initializeClone(Connection* aClone, bool aReadOnly)
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",
Expand Down
10 changes: 8 additions & 2 deletions toolkit/components/places/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,14 @@ 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.
Expand Down

0 comments on commit ffaf2a1

Please sign in to comment.