sql-js / sql-js/sql.js

Exporting database resets pragmas to their default values

オープン
#159 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
JavaScript
スター
13.7k
フォーク
1.1k
PR マージ指標
30日以内にマージされた PR はありません

説明

As of commit 1ee5a18, which fixes issues #9 and #55, the export() function closes the SQLite database (sqlite3_close_v2()) and reopens it (sqlite3_open()). This silently causes any pragmas that have been set since the database was last opened to be reset to their default values. This can have some nasty side-effects - the most obvious (and perhaps most damaging) example of this is with the foreign_keys pragma, which tells SQLite to enforce foreign key constraints on insertions and updates and is OFF by default.

Here's a MWE demonstrating the problem:

var sql = require("./sql.js");
var util = require("util");

var db = new sql.Database();
db.run("pragma foreign_keys = on");
db.run("create table x (xa int, xb char, primary key (xa)) without rowid");
db.run("create table y (ya int, yb int not null references x(xa), primary key (ya)) without rowid");

//db.export();

db.run("insert into x values (1, 'a'), (2, 'b'), (3, 'c')");

db.run("insert into y values (1, 1)");
db.run("insert into y values (999, 999)");

console.log(util.inspect(db.exec("select * from x order by xa"), false, null));
console.log(util.inspect(db.exec("select * from y order by ya"), false, null));

Output:

Error: FOREIGN KEY constraint failed
    at Error (<anonymous>)
    ...

With line 9 uncommented:

[ { columns: [ 'xa', 'xb' ],
    values: [ [ 1, 'a' ], [ 2, 'b' ], [ 3, 'c' ] ] } ]
[ { columns: [ 'ya', 'yb' ], values: [ [ 1, 1 ], [ 999, 999 ] ] } ]

I understand the need for the database to be closed and reopened, but is there any way the non-default pragma values that were set since the database was opened can be restored after it is reopened in the call to export()?

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Start at the export() entry point and inspect the sqlite3_close_v2() and sqlite3_open() sequence described in the issue. Reproduce the provided foreign_keys example, then verify that exporting no longer resets pragma values such as foreign_keys after the database is reopened.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, sqlite
領域
databases
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。