Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7d45baf

Browse files
authored
Permit JS booleans to be bound to queries, as integer 0/1 values (#272)
* Permit boolean values to be bound to statements, as 0/1* Add test for boolean binding
1 parentfa72fb0 commit7d45baf

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

‎src/sqlite-api.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ export function Factory(Module) {
118118
}
119119
case'string':
120120
returnsqlite3.bind_text(stmt,i,value);
121+
case"boolean":
122+
returnsqlite3.bind_int(stmt,i,value ?1 :0);
121123
default:
122124
if(valueinstanceofUint8Array||Array.isArray(value)){
123125
returnsqlite3.bind_blob(stmt,i,value);

‎test/api_statements.js‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,27 @@ export function api_statements(context) {
238238
}
239239
});
240240

241+
it('should bind boolean',asyncfunction(){
242+
letrc;
243+
constsql='SELECT ?';
244+
conststoreValue=true;
245+
constexpectedRetrievedValue=1;
246+
247+
forawait(conststmtofi(sqlite3.statements(db,sql))){
248+
// Comlink intercepts the 'bind' property so use an alias.
249+
rc=awaitsqlite3.bind$(stmt,1,storeValue);
250+
expect(rc).toEqual(SQLite.SQLITE_OK);
251+
252+
while((rc=awaitsqlite3.step(stmt))!==SQLite.SQLITE_DONE){
253+
expect(rc).toEqual(SQLite.SQLITE_ROW);
254+
255+
expect(awaitsqlite3.column_count(stmt)).toEqual(1);
256+
expect(awaitsqlite3.column_type(stmt,0)).toEqual(SQLite.SQLITE_INTEGER);
257+
expect(awaitsqlite3.column_int(stmt,0)).toEqual(expectedRetrievedValue);
258+
}
259+
}
260+
});
261+
241262
it('should bind collection array',asyncfunction(){
242263
letrc;
243264
constsql='VALUES (?, ?, ?, ?, ?)';

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp