-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Multiple query enhanced feedback #429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lovasoa
merged 13 commits into
sql-js:master
from
cpainterwakefield:multiple_query_enhanced_feedback
Oct 19, 2020
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6eaa5c2
Initial working version of statement iteration.
cpainterwakefield 3bbb200
Tests written and running green.
cpainterwakefield f61862c
Merge branch 'master' into multiple_query_enhanced_feedback
cpainterwakefield be2c531
Resolved linter issues.
cpainterwakefield 0b4db07
Modified approach based on PR feedback; simple testing works, automat…
cpainterwakefield 022d165
Testing and documentation written.
cpainterwakefield 2adbaa3
Undid prior commit (accidentally committed change from sql-wasm.js to…
cpainterwakefield b8588d2
Applied all suggested modifications.
cpainterwakefield 710f679
Documentation fixes.
cpainterwakefield f829a87
Improve the documentation of db#iterateStatements
lovasoa 2d7902e
Add @implements annotations for StatementIterator
lovasoa d9392c1
Reformat test code
lovasoa dbc9edc
Fix the type definition of StatementIterator.StatementIteratorResult
lovasoa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,4 +31,4 @@ | |
document.getElementById('error').innerHTML = error; | ||
}; | ||
</script> | ||
</body> | ||
</body> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ | |
"cwrap", | ||
"stackAlloc", | ||
"stackSave", | ||
"stackRestore" | ||
"stackRestore", | ||
"UTF8ToString" | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
exports.test = function (SQL, assert) { | ||
// Create a database | ||
var db = new SQL.Database(); | ||
|
||
// Multiline SQL | ||
var sqlstr = "CREATE TABLE test (x text, y integer);\n" | ||
+ "INSERT INTO test\n" | ||
+ "VALUES ('hello', 42), ('goodbye', 17);\n" | ||
+ "SELECT * FROM test;\n" | ||
cpainterwakefield marked this conversation as resolved.
Show resolved
Hide resolved
|
||
+ " -- nothing here"; | ||
var sqlstart = "CREATE TABLE test (x text, y integer);" | ||
|
||
// Manual iteration | ||
// Get an iterator | ||
var it = db.iterateStatements(sqlstr); | ||
|
||
// Get first item | ||
var x = it.next(); | ||
assert.equal(x.done, false, "Valid iterator object produced"); | ||
assert.equal(x.value.getSQL(), sqlstart, "Statement is for first query only"); | ||
assert.equal(it.getRemainingSQL(), sqlstr.slice(sqlstart.length), "Remaining sql retrievable"); | ||
|
||
// execute the first query | ||
x.value.step(); | ||
|
||
// get and execute the second query | ||
x = it.next(); | ||
assert.equal(x.done, false, "Second query found"); | ||
x.value.step(); | ||
|
||
// get and execute the third query | ||
x = it.next(); | ||
assert.equal(x.done, false, "Third query found"); | ||
x.value.step(); | ||
assert.deepEqual(x.value.getColumnNames(), ['x', 'y'], "Third query is SELECT"); | ||
|
||
// check for additional queries | ||
x = it.next(); | ||
assert.deepEqual(x, { done: true }, "Done reported after last query"); | ||
|
||
// additional iteration does nothing | ||
x = it.next(); | ||
assert.deepEqual(x, { done: true }, "Done reported when iterating past completion"); | ||
|
||
db.run("DROP TABLE test;"); | ||
|
||
// for...of | ||
var count = 0; | ||
for (let statement of db.iterateStatements(sqlstr)) { | ||
statement.step(); | ||
count = count + 1; | ||
} | ||
assert.equal(count, 3, "For loop iterates correctly"); | ||
|
||
var badsql = "SELECT 1 as x;garbage in, garbage out"; | ||
|
||
// bad sql will stop iteration | ||
it = db.iterateStatements(badsql); | ||
x = it.next(); | ||
x.value.step(); | ||
assert.deepEqual(x.value.getAsObject(), { x: 1 }, "SQL before bad statement executes successfully"); | ||
assert.throws(function () { it.next() }, /syntax error/, "Bad SQL stops iteration with exception"); | ||
assert.deepEqual(it.next(), { done: true }, "Done reported when iterating after exception"); | ||
|
||
// valid SQL executes, remaining SQL accessible after exception | ||
it = db.iterateStatements(badsql); | ||
var remains = ''; | ||
try { | ||
for (let statement of it) { | ||
statement.step(); | ||
} | ||
} catch { | ||
remains = it.getRemainingSQL(); | ||
} | ||
assert.equal(remains, "garbage in, garbage out", "Remaining SQL accessible after exception"); | ||
|
||
// From the doc example on the iterateStatements method | ||
const results = []; | ||
const sql_queries = "SELECT 1 AS x; SELECT '2' as y"; | ||
for (const statement of db.iterateStatements(sql_queries)) { | ||
statement.step(); // Fetch one line of result from the statement | ||
const sql = statement.getSQL(); | ||
const result = statement.getAsObject(); | ||
results.push({ sql, result }); | ||
} | ||
console.log(results); | ||
assert.deepEqual(results, [ | ||
{ sql: 'SELECT 1 AS x;', result: { x: 1 } }, | ||
{ sql: " SELECT '2' as y", result: { y: '2' } } | ||
], "The code example from the documentation works"); | ||
}; | ||
|
||
if (module == require.main) { | ||
const target_file = process.argv[2]; | ||
const sql_loader = require('./load_sql_lib'); | ||
sql_loader(target_file).then((sql) => { | ||
require('test').run({ | ||
'test statement iterator': function (assert) { | ||
exports.test(sql, assert); | ||
} | ||
}); | ||
}) | ||
.catch((e) => { | ||
console.error(e); | ||
assert.fail(e); | ||
}); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.