Skip to content

Commit 53322ab

Browse files
committed
Removed workaround for numeric parameter types
1 parent f2c8ff9 commit 53322ab

File tree

2 files changed

+2
-51
lines changed

2 files changed

+2
-51
lines changed

plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<clobbers target="OutSystemsSecureSQLiteBundle" />
1919
</js-module>
2020

21-
<dependency id="cordova-sqlcipher-adapter" url="https://github.com/OutSystems/cordova-sqlcipher-adapter.git" commit="0.1.7-os" />
21+
<dependency id="cordova-sqlcipher-adapter" url="https://github.com/OutSystems/cordova-sqlcipher-adapter.git" commit="0.1.7-os.2" />
2222
<dependency id="cordova-plugin-secure-storage" url="https://github.com/Crypho/cordova-plugin-secure-storage.git" commit="v2.4.1" />
2323

2424
</plugin>

www/outsystems-secure-sqlite-init.js

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -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(/(\:qpde\w+\d*)/g, "CAST($1 AS REAL)");
135-
sql = sql.replace(/(\:qp(lo|in)\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

Comments
 (0)