@@ -315,12 +315,11 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
315315 @throws {String } SQLite Error
316316 */
317317 Statement . prototype [ "step" ] = function step ( ) {
318- var ret ;
319318 if ( ! this . stmt ) {
320319 throw "Statement closed" ;
321320 }
322321 this . pos = 1 ;
323- ret = sqlite3_step ( this . stmt ) ;
322+ var ret = sqlite3_step ( this . stmt ) ;
324323 switch ( ret ) {
325324 case SQLITE_ROW :
326325 return true ;
@@ -352,18 +351,14 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
352351 } ;
353352
354353 Statement . prototype . getBlob = function getBlob ( pos ) {
355- var i ;
356- var ptr ;
357- var result ;
358- var size ;
359354 if ( pos == null ) {
360355 pos = this . pos ;
361356 this . pos += 1 ;
362357 }
363- size = sqlite3_column_bytes ( this . stmt , pos ) ;
364- ptr = sqlite3_column_blob ( this . stmt , pos ) ;
365- result = new Uint8Array ( size ) ;
366- i = 0 ;
358+ var size = sqlite3_column_bytes ( this . stmt , pos ) ;
359+ var ptr = sqlite3_column_blob ( this . stmt , pos ) ;
360+ var result = new Uint8Array ( size ) ;
361+ var i = 0 ;
367362 while ( i < size ) {
368363 result [ i ] = HEAP8 [ ptr + i ] ;
369364 i += 1 ;
@@ -383,15 +378,12 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
383378 while (stmt.step()) console.log(stmt.get());
384379 */
385380 Statement . prototype [ "get" ] = function get ( params ) {
386- var field ;
387- var ref ;
388- var results1 ;
389381 if ( params != null && this [ "bind" ] ( params ) ) {
390382 this [ "step" ] ( ) ;
391383 }
392- results1 = [ ] ;
393- field = 0 ;
394- ref = sqlite3_data_count ( this . stmt ) ;
384+ var results1 = [ ] ;
385+ var field = 0 ;
386+ var ref = sqlite3_data_count ( this . stmt ) ;
395387 while ( field < ref ) {
396388 switch ( sqlite3_column_type ( this . stmt , field ) ) {
397389 case SQLITE_INTEGER :
@@ -423,12 +415,9 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
423415 // Will print ['nbr','data','null_value']
424416 */
425417 Statement . prototype [ "getColumnNames" ] = function getColumnNames ( ) {
426- var i ;
427- var ref ;
428- var results1 ;
429- results1 = [ ] ;
430- i = 0 ;
431- ref = sqlite3_column_count ( this . stmt ) ;
418+ var results1 = [ ] ;
419+ var i = 0 ;
420+ var ref = sqlite3_column_count ( this . stmt ) ;
432421 while ( i < ref ) {
433422 results1 . push ( sqlite3_column_name ( this . stmt , i ) ) ;
434423 i += 1 ;
@@ -453,19 +442,13 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
453442 // Will print {nbr:5, data: Uint8Array([1,2,3]), null_value:null}
454443 */
455444 Statement . prototype [ "getAsObject" ] = function getAsObject ( params ) {
456- var i ;
457- var len ;
458- var name ;
459- var names ;
460- var rowObject ;
461- var values ;
462- values = this [ "get" ] ( params ) ;
463- names = this [ "getColumnNames" ] ( ) ;
464- rowObject = { } ;
465- i = 0 ;
466- len = names . length ;
445+ var values = this [ "get" ] ( params ) ;
446+ var names = this [ "getColumnNames" ] ( ) ;
447+ var rowObject = { } ;
448+ var i = 0 ;
449+ var len = names . length ;
467450 while ( i < len ) {
468- name = names [ i ] ;
451+ var name = names [ i ] ;
469452 rowObject [ name ] = values [ i ] ;
470453 i += 1 ;
471454 }
@@ -486,14 +469,12 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
486469 } ;
487470
488471 Statement . prototype . bindString = function bindString ( string , pos ) {
489- var bytes ;
490- var strptr ;
491472 if ( pos == null ) {
492473 pos = this . pos ;
493474 this . pos += 1 ;
494475 }
495- bytes = intArrayFromString ( string ) ;
496- strptr = allocate ( bytes , "i8" , ALLOC_NORMAL ) ;
476+ var bytes = intArrayFromString ( string ) ;
477+ var strptr = allocate ( bytes , "i8" , ALLOC_NORMAL ) ;
497478 this . allocatedmem . push ( strptr ) ;
498479 this . db . handleError ( sqlite3_bind_text (
499480 this . stmt ,
@@ -506,12 +487,11 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
506487 } ;
507488
508489 Statement . prototype . bindBlob = function bindBlob ( array , pos ) {
509- var blobptr ;
510490 if ( pos == null ) {
511491 pos = this . pos ;
512492 this . pos += 1 ;
513493 }
514- blobptr = allocate ( array , "i8" , ALLOC_NORMAL ) ;
494+ var blobptr = allocate ( array , "i8" , ALLOC_NORMAL ) ;
515495 this . allocatedmem . push ( blobptr ) ;
516496 this . db . handleError ( sqlite3_bind_blob (
517497 this . stmt ,
@@ -583,8 +563,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
583563 Statement . prototype . bindFromObject = function bindFromObject ( valuesObj ) {
584564 var that = this ;
585565 Object . keys ( valuesObj ) . forEach ( function each ( name ) {
586- var num ;
587- num = sqlite3_bind_parameter_index ( that . stmt , name ) ;
566+ var num = sqlite3_bind_parameter_index ( that . stmt , name ) ;
588567 if ( num !== 0 ) {
589568 that . bindValue ( valuesObj [ name ] , num ) ;
590569 }
@@ -598,8 +577,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
598577 @nodoc
599578 */
600579 Statement . prototype . bindFromArray = function bindFromArray ( values ) {
601- var num ;
602- num = 0 ;
580+ var num = 0 ;
603581 while ( num < values . length ) {
604582 this . bindValue ( values [ num ] , num + 1 ) ;
605583 num += 1 ;
@@ -639,7 +617,6 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
639617 return res ;
640618 } ;
641619
642-
643620 /** @classdesc
644621 * Represents an SQLite database
645622 * @constructs Database
@@ -681,12 +658,11 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
681658 @return {Database } The database object (useful for method chaining)
682659 */
683660 Database . prototype [ "run" ] = function run ( sql , params ) {
684- var stmt ;
685661 if ( ! this . db ) {
686662 throw "Database closed" ;
687663 }
688664 if ( params ) {
689- stmt = this [ "prepare" ] ( sql , params ) ;
665+ var stmt = this [ "prepare" ] ( sql , params ) ;
690666 try {
691667 stmt [ "step" ] ( ) ;
692668 } finally {
@@ -765,12 +741,11 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
765741 * @return {Database.QueryExecResult[] } The results of each statement
766742 */
767743 Database . prototype [ "exec" ] = function exec ( sql , params ) {
768- var curresult ;
769- var stmt ;
770744 if ( ! this . db ) {
771745 throw "Database closed" ;
772746 }
773747 var stack = stackSave ( ) ;
748+ var stmt = null ;
774749 try {
775750 var nextSqlPtr = allocateUTF8OnStack ( sql ) ;
776751 var pzTail = stackAlloc ( 4 ) ;
@@ -790,7 +765,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
790765 nextSqlPtr = getValue ( pzTail , "i32" ) ;
791766 // Empty statement
792767 if ( pStmt !== NULL ) {
793- curresult = null ;
768+ var curresult = null ;
794769 stmt = new Statement ( pStmt , this ) ;
795770 if ( params != null ) {
796771 stmt . bind ( params ) ;
@@ -810,9 +785,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
810785 }
811786 return results ;
812787 } catch ( errCaught ) {
813- if ( stmt ) {
814- stmt [ "free" ] ( ) ;
815- }
788+ if ( stmt ) stmt [ "free" ] ( ) ;
816789 throw errCaught ;
817790 } finally {
818791 stackRestore ( stack ) ;
@@ -868,16 +841,14 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
868841 @throws {String } SQLite error
869842 */
870843 Database . prototype [ "prepare" ] = function prepare ( sql , params ) {
871- var pStmt ;
872- var stmt ;
873844 setValue ( apiTemp , 0 , "i32" ) ;
874845 this . handleError ( sqlite3_prepare_v2 ( this . db , sql , - 1 , apiTemp , NULL ) ) ;
875846 // pointer to a statement, or null
876- pStmt = getValue ( apiTemp , "i32" ) ;
847+ var pStmt = getValue ( apiTemp , "i32" ) ;
877848 if ( pStmt === NULL ) {
878849 throw "Nothing to prepare" ;
879850 }
880- stmt = new Statement ( pStmt , this ) ;
851+ var stmt = new Statement ( pStmt , this ) ;
881852 if ( params != null ) {
882853 stmt . bind ( params ) ;
883854 }
@@ -889,14 +860,13 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
889860 @return {Uint8Array } An array of bytes of the SQLite3 database file
890861 */
891862 Database . prototype [ "export" ] = function exportDatabase ( ) {
892- var binaryDb ;
893863 Object . values ( this . statements ) . forEach ( function each ( stmt ) {
894864 stmt [ "free" ] ( ) ;
895865 } ) ;
896866 Object . values ( this . functions ) . forEach ( removeFunction ) ;
897867 this . functions = { } ;
898868 this . handleError ( sqlite3_close_v2 ( this . db ) ) ;
899- binaryDb = FS . readFile ( this . filename , { encoding : "binary" } ) ;
869+ var binaryDb = FS . readFile ( this . filename , { encoding : "binary" } ) ;
900870 this . handleError ( sqlite3_open ( this . filename , apiTemp ) ) ;
901871 this . db = getValue ( apiTemp , "i32" ) ;
902872 return binaryDb ;
@@ -965,7 +935,6 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
965935 name ,
966936 func
967937 ) {
968- var func_ptr ;
969938 function wrapped_func ( cx , argc , argv ) {
970939 var result ;
971940 function extract_blob ( ptr ) {
@@ -1034,7 +1003,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
10341003 }
10351004 // The signature of the wrapped function is :
10361005 // void wrapped(sqlite3_context *db, int argc, sqlite3_value **argv)
1037- func_ptr = addFunction ( wrapped_func , "viii" ) ;
1006+ var func_ptr = addFunction ( wrapped_func , "viii" ) ;
10381007 this . functions [ name ] = func_ptr ;
10391008 this . handleError ( sqlite3_create_function_v2 (
10401009 this . db ,
@@ -1050,7 +1019,6 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
10501019 return this ;
10511020 } ;
10521021
1053-
10541022 // export Database to Module
10551023 Module . Database = Database ;
10561024} ;
0 commit comments