| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent af52410 commit c010131
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2865,12 +2865,16 @@ MaybeLocal<Value> StatementExecutionHelper::All(Environment* env, | |||
| 2865 | 2865 | Isolate* isolate = env->isolate(); | |
| 2866 | 2866 | EscapableHandleScope scope(isolate); | |
| 2867 | 2867 | int r; | |
| 2868 | - int num_cols = sqlite3_column_count(stmt); | ||
| 2868 | + int num_cols = 0; | ||
| 2869 | 2869 | LocalVector<Value> rows(isolate); | |
| 2870 | 2870 | LocalVector<Value> row_values(isolate); | |
| 2871 | 2871 | LocalVector<Name> row_keys(isolate); | |
| 2872 | 2872 | ||
| 2873 | 2873 | while ((r = sqlite3_step(stmt)) == SQLITE_ROW) { | |
| 2874 | + if (num_cols == 0) { | ||
| 2875 | + num_cols = sqlite3_column_count(stmt); | ||
| 2876 | + } | ||
| 2877 | + | ||
| 2874 | 2878 | if (ExtractRowValues(env, stmt, num_cols, use_big_ints, &row_values) | |
| 2875 | 2879 | .IsNothing()) { | |
| 2876 | 2880 | return MaybeLocal<Value>(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -53,6 +53,29 @@ suite('StatementSync.prototype.get()', () => { | |||
| 53 | 53 | const stmt = db.prepare('SELECT 1 as __proto__, 2 as constructor, 3 as toString'); | |
| 54 | 54 | t.assert.deepStrictEqual(stmt.get(), { __proto__: null, ['__proto__']: 1, constructor: 2, toString: 3 }); | |
| 55 | 55 | }); | |
| 56 | + | ||
| 57 | + test('reflects an added column after the schema changes', (t) => { | ||
| 58 | + using db = new DatabaseSync(':memory:'); | ||
| 59 | + db.exec('CREATE TABLE storage(key TEXT, val TEXT)'); | ||
| 60 | + db.prepare('INSERT INTO storage (key, val) VALUES (?, ?)').run('key1', 'val1'); | ||
| 61 | + const stmt = db.prepare('SELECT * FROM storage ORDER BY key'); | ||
| 62 | + db.exec("ALTER TABLE storage ADD COLUMN extra TEXT DEFAULT 'def'"); | ||
| 63 | + t.assert.deepStrictEqual(stmt.get(), { | ||
| 64 | + __proto__: null, key: 'key1', val: 'val1', extra: 'def', | ||
| 65 | + }); | ||
| 66 | + }); | ||
| 67 | + | ||
| 68 | + test('reflects a dropped column after the schema changes', (t) => { | ||
| 69 | + using db = new DatabaseSync(':memory:'); | ||
| 70 | + db.exec('CREATE TABLE storage(key TEXT, val TEXT, extra TEXT)'); | ||
| 71 | + db.prepare('INSERT INTO storage (key, val, extra) VALUES (?, ?, ?)') | ||
| 72 | + .run('key1', 'val1', 'x'); | ||
| 73 | + const stmt = db.prepare('SELECT * FROM storage ORDER BY key'); | ||
| 74 | + db.exec('ALTER TABLE storage DROP COLUMN extra'); | ||
| 75 | + t.assert.deepStrictEqual(stmt.get(), { | ||
| 76 | + __proto__: null, key: 'key1', val: 'val1', | ||
| 77 | + }); | ||
| 78 | + }); | ||
| 56 | 79 | }); | |
| 57 | 80 | ||
| 58 | 81 | suite('StatementSync.prototype.all()', () => { | |
@@ -83,6 +106,29 @@ suite('StatementSync.prototype.all()', () => { | |||
| 83 | 106 | { __proto__: null, key: 'key2', val: 'val2' }, | |
| 84 | 107 | ]); | |
| 85 | 108 | }); | |
| 109 | + | ||
| 110 | + test('reflects an added column after the schema changes', (t) => { | ||
| 111 | + using db = new DatabaseSync(':memory:'); | ||
| 112 | + db.exec('CREATE TABLE storage(key TEXT, val TEXT)'); | ||
| 113 | + db.prepare('INSERT INTO storage (key, val) VALUES (?, ?)').run('key1', 'val1'); | ||
| 114 | + const stmt = db.prepare('SELECT * FROM storage ORDER BY key'); | ||
| 115 | + db.exec("ALTER TABLE storage ADD COLUMN extra TEXT DEFAULT 'def'"); | ||
| 116 | + t.assert.deepStrictEqual(stmt.all(), [ | ||
| 117 | + { __proto__: null, key: 'key1', val: 'val1', extra: 'def' }, | ||
| 118 | + ]); | ||
| 119 | + }); | ||
| 120 | + | ||
| 121 | + test('reflects a dropped column after the schema changes', (t) => { | ||
| 122 | + using db = new DatabaseSync(':memory:'); | ||
| 123 | + db.exec('CREATE TABLE storage(key TEXT, val TEXT, extra TEXT)'); | ||
| 124 | + db.prepare('INSERT INTO storage (key, val, extra) VALUES (?, ?, ?)') | ||
| 125 | + .run('key1', 'val1', 'x'); | ||
| 126 | + const stmt = db.prepare('SELECT * FROM storage ORDER BY key'); | ||
| 127 | + db.exec('ALTER TABLE storage DROP COLUMN extra'); | ||
| 128 | + t.assert.deepStrictEqual(stmt.all(), [ | ||
| 129 | + { __proto__: null, key: 'key1', val: 'val1' }, | ||
| 130 | + ]); | ||
| 131 | + }); | ||
| 86 | 132 | }); | |
| 87 | 133 | ||
| 88 | 134 | suite('StatementSync.prototype.iterate()', () => { | |
@@ -125,6 +171,29 @@ suite('StatementSync.prototype.iterate()', () => { | |||
| 125 | 171 | } | |
| 126 | 172 | }); | |
| 127 | 173 | ||
| 174 | + test('reflects an added column after the schema changes', (t) => { | ||
| 175 | + using db = new DatabaseSync(':memory:'); | ||
| 176 | + db.exec('CREATE TABLE storage(key TEXT, val TEXT)'); | ||
| 177 | + db.prepare('INSERT INTO storage (key, val) VALUES (?, ?)').run('key1', 'val1'); | ||
| 178 | + const stmt = db.prepare('SELECT * FROM storage ORDER BY key'); | ||
| 179 | + db.exec("ALTER TABLE storage ADD COLUMN extra TEXT DEFAULT 'def'"); | ||
| 180 | + t.assert.deepStrictEqual(stmt.iterate().toArray(), [ | ||
| 181 | + { __proto__: null, key: 'key1', val: 'val1', extra: 'def' }, | ||
| 182 | + ]); | ||
| 183 | + }); | ||
| 184 | + | ||
| 185 | + test('reflects a dropped column after the schema changes', (t) => { | ||
| 186 | + using db = new DatabaseSync(':memory:'); | ||
| 187 | + db.exec('CREATE TABLE storage(key TEXT, val TEXT, extra TEXT)'); | ||
| 188 | + db.prepare('INSERT INTO storage (key, val, extra) VALUES (?, ?, ?)') | ||
| 189 | + .run('key1', 'val1', 'x'); | ||
| 190 | + const stmt = db.prepare('SELECT * FROM storage ORDER BY key'); | ||
| 191 | + db.exec('ALTER TABLE storage DROP COLUMN extra'); | ||
| 192 | + t.assert.deepStrictEqual(stmt.iterate().toArray(), [ | ||
| 193 | + { __proto__: null, key: 'key1', val: 'val1' }, | ||
| 194 | + ]); | ||
| 195 | + }); | ||
| 196 | + | ||
| 128 | 197 | test('iterator keeps the prepared statement from being collected', (t) => { | |
| 129 | 198 | const db = new DatabaseSync(':memory:'); | |
| 130 | 199 | db.exec(` | |
| Back | FazBrowse Home | New Git URL |
0 commit comments