avoiding the implicit creation of the oid primary key to avoid sqlite backwards bug compatible quirks

This commit is contained in:
Cheng 2023-08-03 01:44:08 -07:00
parent c344a597a2
commit 529cc368c9
No known key found for this signature in database
GPG Key ID: 571C3A9C3B9E6FCA
2 changed files with 10 additions and 3 deletions

2
mpir

@ -1 +1 @@
Subproject commit bc42eee0b5d04b508b196231165a567db9f8f4b6 Subproject commit dda9307f16da43d1da8f003734f465ae9cf7fa9e

View File

@ -242,21 +242,28 @@ void Frame::NewWallet(wxFileName& filename, ristretto255::hash<256>& secret) {
// Disk operations to create wallet, which may throw. // Disk operations to create wallet, which may throw.
// This try/catch block exists to catch disk io issues. // This try/catch block exists to catch disk io issues.
db.reset(Sqlite3_create(filename.GetFullPath().ToUTF8())); db.reset(Sqlite3_create(filename.GetFullPath().ToUTF8()));
// To avoid legacy quirks and backward bug compatibility, every sqlite3 table needs an INTEGER PRIMARY KEY or a WITHOUT ROWID.
// if you want a non integer primary key and do not want to use sqlite3's complicated backward bug compatibility special feature,
// instead use a CREATE INDEX rather than making the thing a primary key.
db->exec(R"|( db->exec(R"|(
PRAGMA journal_mode = WAL; PRAGMA journal_mode = WAL;
PRAGMA synchronous = 1; PRAGMA synchronous = 1;
BEGIN IMMEDIATE TRANSACTION; BEGIN IMMEDIATE TRANSACTION;
CREATE TABLE "Keys"( CREATE TABLE "Keys"(
"pubkey" BLOB NOT NULL UNIQUE PRIMARY KEY, "oid" INTEGER PRIMARY KEY,
"pubkey" BLOB NOT NULL UNIQUE,
"id" integer NOT NULL, "id" integer NOT NULL,
"use" INTEGER NOT NULL); "use" INTEGER NOT NULL);
CREATE UNIQUE INDEX i_pubkey ON Keys (pubkey);
CREATE TABLE "Names"( CREATE TABLE "Names"(
"oid" INTEGER PRIMARY KEY,
"name" TEXT NOT NULL UNIQUE "name" TEXT NOT NULL UNIQUE
); );
CREATE TABLE "Misc"( CREATE TABLE "Misc"(
"index" INTEGER NOT NULL UNIQUE PRIMARY KEY, "index" INTEGER PRIMARY KEY,
"m" BLOB "m" BLOB
); );
COMMIT;)|"); COMMIT;)|");