@@ -100,53 +100,6 @@ function generateKey() {
100100 } ) . join ( "" ) ;
101101}
102102
103- var alreadyInstalledNumericParamsWorkaround = false ;
104-
105- /**
106- * Instruments SQLiteTransaction.prototype.addStatement to workaround the fact that
107- * numeric query parameters are passed to SQLCipher as Strings, resulting in unexpected
108- * behaviors.
109- *
110- * The current implementation takes advantage of OutSystems-specific parameter name conventions.
111- *
112- * @param {SQLiteDatabase } db An instance of the database class where to install the workaround.
113- */
114- function installNumericParametersWorkaround ( db ) {
115- if ( alreadyInstalledNumericParamsWorkaround ) {
116- // We install the workaround in the prototypes, so there's no need to do it twice
117- return ;
118- }
119-
120- var alreadyInstalledInAddStatement = false ;
121-
122- // Since the plugin's classes are not public, we follow the prototype of our initial DB object
123- // overriding its `addTransaction` method to get a SQLiteTransaction object
124- var dbPrototype = Object . getPrototypeOf ( db ) ;
125- var originalAddTransaction = dbPrototype . addTransaction ;
126-
127- dbPrototype . addTransaction = function ( tx ) {
128- if ( ! alreadyInstalledInAddStatement ) {
129- var txPrototype = Object . getPrototypeOf ( tx ) ;
130- var originalAddStatement = txPrototype . addStatement ;
131-
132- txPrototype . addStatement = function ( sql , values , success , error ) {
133- // Inject an explicit CAST around parameters with numeric types
134- sql = sql . replace ( / ( \: q p d e \w + \d * ) / g, "CAST($1 AS REAL)" ) ;
135- sql = sql . replace ( / ( \: q p ( l o | i n ) \w + \d * ) / g, "CAST($1 AS INTEGER)" ) ;
136-
137- return originalAddStatement . call ( this , sql , values , success , error ) ;
138- } ;
139-
140- alreadyInstalledInAddStatement = true ;
141- console . log ( "Numeric parameters workaround installed successfully." ) ;
142- }
143-
144- return originalAddTransaction . call ( this , tx ) ;
145- } ;
146-
147- alreadyInstalledNumericParamsWorkaround = true ;
148- }
149-
150103/**
151104 * Validates the options passed to a `openDatabase` call are correctly set.
152105 *
@@ -184,9 +137,7 @@ window.sqlitePlugin.openDatabase = function(options, successCallback, errorCallb
184137
185138 // Validate the options and call the original openDatabase
186139 validateDbOptions ( newOptions ) ;
187- var db = originalOpenDatabase . call ( window . sqlitePlugin , newOptions , successCallback , errorCallback ) ;
188- installNumericParametersWorkaround ( db ) ;
189- return db ;
140+ return originalOpenDatabase . call ( window . sqlitePlugin , newOptions , successCallback , errorCallback ) ;
190141 } ,
191142 errorCallback ) ;
192143} ;
0 commit comments