@@ -237,12 +237,19 @@ class Database
237
237
# Open a new database either by creating a new one or opening an existing one,
238
238
# stored in the byte array passed in first argument
239
239
# @param data [Array<Integer>] An array of bytes representing an SQLite database file
240
- constructor : (data ) ->
240
+ # @param initialDbSize [Integer] Size to which the database node will be expanded
241
+ constructor : (data , initialDbSize ) ->
241
242
@filename = ' dbfile_' + (0xffffffff * Math .random ()>>> 0 )
242
243
if data? then FS .createDataFile ' /' , @filename , data, true , true
243
244
@ handleError sqlite3_open @filename , apiTemp
244
245
@db = getValue (apiTemp, ' i32' )
245
246
RegisterExtensionFunctions (@db )
247
+ if initialDbSize?
248
+ @ run ' VACUUM' # Called so the node will have the correct database structure
249
+ parent = FS .lookupPath ' /'
250
+ parentNode = parent .node
251
+ dbNode = FS .lookupNode parentNode, @filename
252
+ MEMFS .expandFileStorage dbNode, initialDbSize
246
253
@statements = {} # A list of all prepared statements of the database
247
254
@functions = {} # A list of all user function of the database (created by create_function call)
248
255
@@ -315,7 +322,7 @@ class Database
315
322
316
323
# Store the SQL string in memory. The string will be consumed, one statement
317
324
# at a time, by sqlite3_prepare_v2_sqlptr.
318
- # Note that if we want to allocate as much memory as could _possibly_ be used, we can
325
+ # Note that if we want to allocate as much memory as could _possibly_ be used, we can
319
326
# we allocate bytes equal to 4* the number of chars in the sql string.
320
327
# It would be faster, but this is probably a premature optimization
321
328
nextSqlPtr = allocateUTF8OnStack (sql)
@@ -480,7 +487,7 @@ class Database
480
487
sqlite3_result_error (cx,error,- 1 )
481
488
return
482
489
483
- # Return the result of the user defined function to SQLite
490
+ # Return the result of the user defined function to SQLite
484
491
switch typeof (result)
485
492
when ' boolean' then sqlite3_result_int (cx,if result then 1 else 0 )
486
493
when ' number' then sqlite3_result_double (cx, result)
0 commit comments