Skip to content

Commit

Permalink
Fix memory error with long sql strings (#566)
Browse files Browse the repository at this point in the history
* add a test for #561

* fix memory issue with long sql strings

fixes #561

thanks @kripken for the fix: #561 (comment)

* include the new stack size on all targets

* remove debig log
  • Loading branch information
lovasoa committed Jan 20, 2024
1 parent 53335a9 commit 19cbe48
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ EMFLAGS = \
-s EXPORTED_RUNTIME_METHODS=@src/exported_runtime_methods.json \
-s SINGLE_FILE=0 \
-s NODEJS_CATCH_EXIT=0 \
-s NODEJS_CATCH_REJECTION=0
-s NODEJS_CATCH_REJECTION=0 \
-s STACK_SIZE=5MB

EMFLAGS_ASM = \
-s WASM=0
Expand All @@ -56,7 +57,7 @@ EMFLAGS_OPTIMIZED= \
--closure 1

EMFLAGS_DEBUG = \
-s ASSERTIONS=1 \
-s ASSERTIONS=2 \
-O1

BITCODE_FILES = out/sqlite3.bc out/extension-functions.bc
Expand Down
34 changes: 34 additions & 0 deletions test/test_long_sql_statement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// test for https://github.com/sql-js/sql.js/issues/561
exports.test = function (sql, assert) {
// Create a database
var db = new sql.Database();
var len = 70000;
var many_a = "";
for (var i = 0; i < len; i++) many_a += 'a';

var res = db.exec("select length('" + many_a + "') as len");
var expectedResult = [
{
columns: ['len'],
values: [
[len]
]
}
];
assert.deepEqual(res, expectedResult, "length of long string");
};

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 long sql string (issue 561)': function (assert) {
exports.test(sql, assert);
}
});
}).catch((e) => {
console.error(e);
assert.fail(e);
});
}

0 comments on commit 19cbe48

Please sign in to comment.