@@ -37,22 +37,26 @@ class WaSqliteConnection extends BaseSqliteConnection {
37
37
async query ( sql : string , params ?: any [ ] | undefined ) : QueryReturn {
38
38
const rows : any [ ] = [ ]
39
39
const str = this . sqlite . str_new ( this . db , sql )
40
- const prepared = await this . sqlite . prepare_v2 ( this . db , this . sqlite . str_value ( str ) )
40
+ try {
41
+ const prepared = await this . sqlite . prepare_v2 ( this . db , this . sqlite . str_value ( str ) )
41
42
42
- if ( prepared ) {
43
- const stmt = prepared . stmt
44
- try {
45
- params ?. length && this . sqlite . bind_collection ( stmt , params as [ ] )
43
+ if ( prepared ) {
44
+ const stmt = prepared . stmt
45
+ try {
46
+ params ?. length && this . sqlite . bind_collection ( stmt , params as [ ] )
46
47
47
- const cols = this . sqlite . column_names ( stmt )
48
+ const cols = this . sqlite . column_names ( stmt )
48
49
49
- while ( ( await this . sqlite . step ( stmt ) ) === 100 /* SQLITE_ROW */ ) {
50
- const row = this . sqlite . row ( stmt )
51
- rows . push ( Object . fromEntries ( cols . map ( ( key , i ) => [ key , row [ i ] ] ) ) )
50
+ while ( ( await this . sqlite . step ( stmt ) ) === 100 /* SQLITE_ROW */ ) {
51
+ const row = this . sqlite . row ( stmt )
52
+ rows . push ( Object . fromEntries ( cols . map ( ( key , i ) => [ key , row [ i ] ] ) ) )
53
+ }
54
+ } finally {
55
+ await this . sqlite . finalize ( stmt )
52
56
}
53
- } finally {
54
- await this . sqlite . finalize ( stmt )
55
57
}
58
+ } finally {
59
+ this . sqlite . str_finish ( str )
56
60
}
57
61
return rows
58
62
}
0 commit comments