mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Use getters and setters for database schema version. b=386369, p=sdwilsh, r=dwitte, sr=biesi.
This commit is contained in:
parent
62b499b0ed
commit
88b3d4896c
@ -446,34 +446,22 @@ nsCookieService::InitDB()
|
|||||||
} else {
|
} else {
|
||||||
// table already exists; check the schema version before reading
|
// table already exists; check the schema version before reading
|
||||||
PRInt32 dbSchemaVersion;
|
PRInt32 dbSchemaVersion;
|
||||||
{
|
rv = mDBConn->GetSchemaVersion(&dbSchemaVersion);
|
||||||
// scope the statement, so the write lock is released when finished
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
nsCOMPtr<mozIStorageStatement> stmt;
|
|
||||||
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING("PRAGMA user_version"),
|
if (dbSchemaVersion == 0) {
|
||||||
getter_AddRefs(stmt));
|
NS_WARNING("couldn't get schema version!");
|
||||||
|
|
||||||
|
// the table may be usable; someone might've just clobbered the schema
|
||||||
|
// version. we can treat this case like a downgrade using the codepath
|
||||||
|
// below, by verifying the columns we care about are all there. for now,
|
||||||
|
// re-set the schema version in the db, in case the checks succeed (if
|
||||||
|
// they don't, we're dropping the table anyway).
|
||||||
|
rv = mDBConn->SetSchemaVersion(COOKIES_SCHEMA_VERSION);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
PRBool hasResult;
|
// set this to a large number, to force the downgrade codepath
|
||||||
rv = stmt->ExecuteStep(&hasResult);
|
dbSchemaVersion = PR_INT32_MAX;
|
||||||
if (NS_SUCCEEDED(rv) && hasResult) {
|
|
||||||
dbSchemaVersion = stmt->AsInt32(0);
|
|
||||||
} else {
|
|
||||||
NS_WARNING("couldn't get schema version!");
|
|
||||||
stmt = nsnull;
|
|
||||||
|
|
||||||
// the table may be usable; someone might've just clobbered the schema
|
|
||||||
// version. we can treat this case like a downgrade using the codepath
|
|
||||||
// below, by verifying the columns we care about are all there. for now,
|
|
||||||
// re-set the schema version in the db, in case the checks succeed (if
|
|
||||||
// they don't, we're dropping the table anyway).
|
|
||||||
nsCAutoString stmtString(NS_LITERAL_CSTRING("PRAGMA user_version="));
|
|
||||||
stmtString.AppendInt(COOKIES_SCHEMA_VERSION);
|
|
||||||
rv = mDBConn->ExecuteSimpleSQL(stmtString);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
|
|
||||||
// set this to a large number, to force the downgrade codepath
|
|
||||||
dbSchemaVersion = PR_INT32_MAX;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dbSchemaVersion != COOKIES_SCHEMA_VERSION) {
|
if (dbSchemaVersion != COOKIES_SCHEMA_VERSION) {
|
||||||
@ -542,9 +530,7 @@ nsresult
|
|||||||
nsCookieService::CreateTable()
|
nsCookieService::CreateTable()
|
||||||
{
|
{
|
||||||
// set the schema version, before creating the table
|
// set the schema version, before creating the table
|
||||||
nsCAutoString stmtString(NS_LITERAL_CSTRING("PRAGMA user_version="));
|
nsresult rv = mDBConn->SetSchemaVersion(COOKIES_SCHEMA_VERSION);
|
||||||
stmtString.AppendInt(COOKIES_SCHEMA_VERSION);
|
|
||||||
nsresult rv = mDBConn->ExecuteSimpleSQL(stmtString);
|
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
// create the table
|
// create the table
|
||||||
|
Loading…
Reference in New Issue
Block a user