Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
cordova-plugin-sqlite-fts
Advanced tools
Cordova SQLite Plugin with built-in support for full-text search.
Native interface to sqlite in a Cordova/PhoneGap plugin for Android, iOS, Windows Universal (8.1), Amazon Fire-OS, and WP(7/8) with API similar to HTML5/Web SQL API.
License for Android, Windows Universal (8.1), Amazon Fire-OS, and WP(7/8) versions: MIT or Apache 2.0
License for iOS version: MIT only
3.8.7
embedded)3.8.9
embeddedplugin.xml
- NOT TESTED-DSQLITE_TEMP_STORE=3
CFLAG to support UPDATE properly;openDatabase
and deleteDatabase
location
option to select database location (iOS only) and disable iCloud backupwindow.openDatabase()
--> sqlitePlugin.openDatabase()
\u2028
) is currently not supported and known to be broken in iOS version.\u0000
(same as \0
) character not working in Windows (8.1) or WP(7/8) versionsThe idea is to emulate the HTML5/Web SQL API as closely as possible. The only major change is to use window.sqlitePlugin.openDatabase()
(or sqlitePlugin.openDatabase()
) instead of window.openDatabase()
. If you see any other major change please report it, it is probably a bug.
There are two options to open a database:
var db = window.sqlitePlugin.openDatabase({name: "my.db", location: 1});
var db = window.sqlitePlugin.openDatabase("myDatabase.db", "1.0", "Demo", -1);
The new location
option is used to select the database subdirectory location (iOS only) with the following choices:
0
(default): Documents
- visible to iTunes and backed up by iCloud1
: Library
- backed up by iCloud, NOT visible to iTunes2
: Library/LocalDatabase
- NOT visible to iTunes and NOT backed up by iCloudIMPORTANT: Please wait for the "deviceready" event, as in the following example:
// Wait for Cordova to load
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
function onDeviceReady() {
var db = window.sqlitePlugin.openDatabase({name: "my.db"});
// ...
}
NOTE: The database file name should include the extension, if desired.
For Android, iOS, and Amazon Fire-OS (only): put the database file in the www
directory and open the database like:
var db = window.sqlitePlugin.openDatabase({name: "my.db", createFromLocation: 1});
or to disable iCloud backup:
db = sqlitePlugin.openDatabase({name: "my.db", location: 2, createFromLocation: 1});
IMPORTANT NOTES:
www
subdirectory. This should work well with using the Cordova CLI to support both Android & iOS versions.openDatabase
. The automatic extension has been completely eliminated.TIP: If you don't see the data from the pre-populated database file, completely remove your app and try it again!
By default, this plugin uses sqlite4java which is more efficient than the built-in Android database classes. The sqlite4java library consists of a Java part and a NDK part.
Unfortunately some app developers have encountered problems using sqlite4java with Ionic and Crosswalk. To use the built-in Android database classes instead:
var db = window.sqlitePlugin.openDatabase({name: "my.db", androidDatabaseImplementation: 2});
Issue #193 was reported (as observed by several app developers) that on some newer versions of the Android database classes, if the app is stopped or aborted without closing the database then:
This issue is suspected to be caused by this Android sqlite commit, which references and includes the sqlite commit at: http://www.sqlite.org/src/info/6c4c2b7dba
There is an optional workaround that simply closes and reopens the database file at the end of every transaction that is committed. The workaround is enabled by opening the database with options as follows:
var db = window.sqlitePlugin.openDatabase({name: "my.db", androidDatabaseImplementation: 2, androidLockWorkaround: 1});
This option is ignored if androidDatabaseImplementation: 2
is not specified.
IMPORTANT NOTE: This workaround is only applied when using db.transaction()
or db.readTransaction()
, not applied when running executeSql()
on the database object.
The threading model depends on which version is used:
This is a pretty strong test: first we create a table and add a single entry, then query the count to check if the item was inserted as expected. Note that a new transaction is created in the middle of the first callback.
// Wait for Cordova to load
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
function onDeviceReady() {
var db = window.sqlitePlugin.openDatabase({name: "my.db"});
db.transaction(function(tx) {
tx.executeSql('DROP TABLE IF EXISTS test_table');
tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data text, data_num integer)');
// demonstrate PRAGMA:
db.executeSql("pragma table_info (test_table);", [], function(res) {
console.log("PRAGMA res: " + JSON.stringify(res));
});
tx.executeSql("INSERT INTO test_table (data, data_num) VALUES (?,?)", ["test", 100], function(tx, res) {
console.log("insertId: " + res.insertId + " -- probably 1");
console.log("rowsAffected: " + res.rowsAffected + " -- should be 1");
db.transaction(function(tx) {
tx.executeSql("select count(id) as cnt from test_table;", [], function(tx, res) {
console.log("res.rows.length: " + res.rows.length + " -- should be 1");
console.log("res.rows.item(0).cnt: " + res.rows.item(0).cnt + " -- should be 1");
});
});
}, function(e) {
console.log("ERROR: " + e.message);
});
});
}
In this case, the same transaction in the first executeSql() callback is being reused to run executeSql() again.
// Wait for Cordova to load
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
function onDeviceReady() {
var db = window.sqlitePlugin.openDatabase("Database", "1.0", "Demo", -1);
db.transaction(function(tx) {
tx.executeSql('DROP TABLE IF EXISTS test_table');
tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data text, data_num integer)');
tx.executeSql("INSERT INTO test_table (data, data_num) VALUES (?,?)", ["test", 100], function(tx, res) {
console.log("insertId: " + res.insertId + " -- probably 1");
console.log("rowsAffected: " + res.rowsAffected + " -- should be 1");
tx.executeSql("select count(id) as cnt from test_table;", [], function(tx, res) {
console.log("res.rows.length: " + res.rows.length + " -- should be 1");
console.log("res.rows.item(0).cnt: " + res.rows.item(0).cnt + " -- should be 1");
});
}, function(e) {
console.log("ERROR: " + e.message);
});
});
}
This case will also works with Safari (WebKit), assuming you replace window.sqlitePlugin.openDatabase
with window.openDatabase
.
window.sqlitePlugin.deleteDatabase({name: "my.db", location: 1}, successcb, errorcb);
location
as described above for openDatabase
(iOS only)
NOTE: not implemented for Windows Universal (8.1) version.
WARNING: This is still in pre/alpha state. Please read and follow these items very carefully.
npm update -g cordova cordova-windows
cordova create MyProjectFolder com.my.project MyProject
(and then cd
into your project directory)cordova plugin add https://github.com/litehelpers/Cordova-sqlite-storage
cordova platform add windows
Make a clone of this project and in your clone, remove (or comment out) the items that include the SQLite3.Windows.vcxproj
and SQLite3.WindowsPhone.vcxproj
framework projects:
--- a/plugin.xml
+++ b/plugin.xml
@@ -75,8 +75,6 @@
</js-module>
<!-- Thanks to AllJoyn-Cordova / cordova-plugin-alljoyn: -->
- <framework src="src/windows/SQLite3-WinRT/SQLite3/SQLite3.Windows.vcxproj" custom="true" type="projectReference" target="windows" />
- <framework src="src/windows/SQLite3-WinRT/SQLite3/SQLite3.WindowsPhone.vcxproj" custom="true" type="projectReference" target="phone" />
<!-- old:
<framework src="src/windows/SQLite3-WinRT/SQLite3/SQLite3-Windows8.1.vcxproj" custom="true" type="projectReference" target="windows" />
-->
Then:
windows
target;SQLite3.Windows.vcxproj
and SQLite3.WindowsPhone.vcxproj
projects (located in path.to.plugin/src/windows/SQLite3-WinRT/SQLite3
) to your app solution project, and add the references in your solution explorer.plugman install --platform MYPLATFORM --project path.to.my.project.folder --plugin https://github.com/litehelpers/Cordova-sqlite-storage
where MYPLATFORM is android
, ios
, or wp8
.
A posting how to get started developing on Windows host without the Cordova CLI tool (for Android target only) is available here.
NOTE: Automatic installation for the Windows target platform is not properly supported by the plugman
tool.
npm install -g cordova # if you don't have cordova
cordova create MyProjectFolder com.my.project MyProject && cd MyProjectFolder # if you are just starting
cordova plugin add https://github.com/litehelpers/Cordova-sqlite-storage
You can find more details at this writeup.
WARNING: for Windows target platform please read the section above.
IMPORTANT: sometimes you have to update the version for a platform before you can build, like: cordova prepare ios
NOTE: If you cannot build for a platform after cordova prepare
, you may have to remove the platform and add it again, such as:
cordova platform rm ios
cordova platform add ios
SQLitePlugin.coffee.md
: platform-independent (Literate coffee-script, can be read by recent coffee-script compiler)www
: SQLitePlugin.js
platform-independent Javascript as generated from SQLitePlugin.coffee.md
(and checked in!)src
: platform-specific source code:
android
- Java plugin code for Android (along with sqlite4java library);android-classic
- Java plugin code for Amazon Fire-OSios
- Objective-C plugin code for iOS;windows
- Javascript proxy code and SQLite3-WinRT project for Windows Universal;wp
- C-sharp code for WP(7/8)spec
: test suite using Jasmine (2.2.0), ported from QUnit test-www
test suite, working on all platformsLawnchair-adapter
: Lawnchair adaptor, based on the version from the Lawnchair repository, with the basic Lawnchair test suite in test-www
subdirectoryThese installation instructions are based on the Android example project from Cordova/PhoneGap 2.7.0, using the lib/android/example
subdirectory from the PhoneGap 2.7 zipball.
SQLitePlugin.js
from www
into assets/www
SQLiteAndroidDatabase.java
and SQLitePlugin.java
from src/android/io/liteglue
into src/io/liteglue
subdirectorylibs
subtree from src/android/sqlite4java/libs
into your Android project<plugin name="SQLitePlugin" value="io.liteglue.SQLitePlugin"/>
to res/xml/config.xml
Sample change to res/xml/config.xml
for Cordova/PhoneGap 2.x:
--- config.xml.orig 2015-04-14 14:03:05.000000000 +0200
+++ res/xml/config.xml 2015-04-14 14:08:08.000000000 +0200
@@ -36,6 +36,7 @@
<preference name="useBrowserHistory" value="true" />
<preference name="exit-on-suspend" value="false" />
<plugins>
+ <plugin name="SQLitePlugin" value="io.liteglue.SQLitePlugin"/>
<plugin name="App" value="org.apache.cordova.App"/>
<plugin name="Geolocation" value="org.apache.cordova.GeoBroker"/>
<plugin name="Device" value="org.apache.cordova.Device"/>
Before building for the first time, you have to update the project with the desired version of the Android SDK with a command like:
android update project --path $(pwd) --target android-19
(assuming Android SDK 19, use the correct desired Android SDK number here)
NOTE: using this plugin on Cordova pre-3.0 requires the following changes to SQLiteAndroidDatabase.java
and SQLitePlugin.java
:
--- Cordova-sqlite-storage/src/android/io/liteglue/SQLiteAndroidDatabase.java 2015-04-14 14:05:01.000000000 +0200
+++ src/io/liteglue/SQLiteAndroidDatabase.java 2015-04-14 14:15:23.000000000 +0200
@@ -24,7 +24,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.apache.cordova.CallbackContext;
+import org.apache.cordova.api.CallbackContext;
import org.json.JSONArray;
import org.json.JSONException;
diff -u Cordova-sqlite-storage/src/android/io/liteglue/SQLitePlugin.java src/io/liteglue/SQLitePlugin.java
--- Cordova-sqlite-storage/src/android/io/liteglue/SQLitePlugin.java 2015-04-14 14:05:01.000000000 +0200
+++ src/io/liteglue/SQLitePlugin.java 2015-04-14 14:10:44.000000000 +0200
@@ -22,8 +22,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.apache.cordova.CallbackContext;
-import org.apache.cordova.CordovaPlugin;
+import org.apache.cordova.api.CallbackContext;
+import org.apache.cordova.api.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;
In the Project "Build Phases" tab, select the first "Link Binary with Libraries" dropdown menu and add the library libsqlite3.dylib
or libsqlite3.0.dylib
.
NOTE: In the "Build Phases" there can be multiple "Link Binary with Libraries" dropdown menus. Please select the first one otherwise it will not work.
SQLitePlugin.[hm]
from src/ios
into your project Plugins folder and add them in XCode (I always just have "Create references" as the option selected).SQLitePlugin.js
from www
into your project www
folderconfig.xml
Sample change to config.xml
for Cordova/PhoneGap 2.x:
--- config.xml.old 2013-05-17 13:18:39.000000000 +0200
+++ config.xml 2013-05-17 13:18:49.000000000 +0200
@@ -39,6 +39,7 @@
<content src="index.html" />
<plugins>
+ <plugin name="SQLitePlugin" value="SQLitePlugin" />
<plugin name="Device" value="CDVDevice" />
<plugin name="Logger" value="CDVLogger" />
<plugin name="Compass" value="CDVLocation" />
Described above.
TODO
Make a change like this to index.html (or use the sample code) verify proper installation:
--- index.html.old 2012-08-04 14:40:07.000000000 +0200
+++ assets/www/index.html 2012-08-04 14:36:05.000000000 +0200
@@ -24,7 +24,35 @@
<title>PhoneGap</title>
<link rel="stylesheet" href="master.css" type="text/css" media="screen" title="no title">
<script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>
- <script type="text/javascript" charset="utf-8" src="main.js"></script>
+ <script type="text/javascript" charset="utf-8" src="SQLitePlugin.js"></script>
+
+
+ <script type="text/javascript" charset="utf-8">
+ document.addEventListener("deviceready", onDeviceReady, false);
+ function onDeviceReady() {
+ var db = window.sqlitePlugin.openDatabase("Database", "1.0", "Demo", -1);
+
+ db.transaction(function(tx) {
+ tx.executeSql('DROP TABLE IF EXISTS test_table');
+ tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data text, data_num integer)');
+
+ tx.executeSql("INSERT INTO test_table (data, data_num) VALUES (?,?)", ["test", 100], function(tx, res) {
+ console.log("insertId: " + res.insertId + " -- probably 1"); // check #18/#38 is fixed
+ alert("insertId: " + res.insertId + " -- should be valid");
+
+ db.transaction(function(tx) {
+ tx.executeSql("SELECT data_num from test_table;", [], function(tx, res) {
+ console.log("res.rows.length: " + res.rows.length + " -- should be 1");
+ alert("res.rows.item(0).data_num: " + res.rows.item(0).data_num + " -- should be 100");
+ });
+ });
+
+ }, function(e) {
+ console.log("ERROR: " + e.message);
+ });
+ });
+ }
+ </script>
</head>
<body onload="init();" id="stage" class="theme">
sqlitePlugin
object name starts with "sql" in small letters.If you have an issue with the plugin please check the following first:
config.xml
.If you still cannot get something to work:
Then you can raise the new issue.
If you have any questions about the plugin please post them to the new discussion forum at Ost.io / @litehelpers / Cordova-sqlite-storage.
Professional support is available, please contact info@litehelpers.net.
Unit testing is done in spec
.
To run the tests from *nix shell, simply do either:
./bin/test.sh ios
or for Android:
./bin/test.sh android
To run then from a windows powershell do either
.\bin\test.ps1 android
or for Windows (8.1):
.\bin\test.ps1 windows
or for Windows Phone (7/8):
.\bin\test.ps1 wp8
Please look at the Lawnchair-adapter
tree that contains a common adapter, which should also work with the Android version, along with a test-www directory.
Include the following Javascript files in your HTML:
cordova.js
(don't forget!)lawnchair.js
(you provide)SQLitePlugin.js
(in case of Cordova pre-3.0)Lawnchair-sqlitePlugin.js
(must come after SQLitePlugin.js
in case of Cordova pre-3.0)The name
option determines the sqlite database filename, with no extension automatically added. Optionally, you can change the db filename using the db
option.
In this example, you would be using/creating a database with filename kvstore
:
kvstore = new Lawnchair({name: "kvstore"}, function() {
// do stuff
);
Using the db
option you can specify the filename with the desired extension and be able to create multiple stores in the same database file. (There will be one table per store.)
recipes = new Lawnchair({db: "cookbook", name: "recipes", ...}, myCallback());
ingredients = new Lawnchair({db: "cookbook", name: "ingredients", ...}, myCallback());
KNOWN ISSUE: the new db options are not supported by the Lawnchair adapter. The workaround is to first open the database file using sqlitePlugin.openDatabase()
.
The adapter is now part of PouchDB thanks to @nolanlawson, see PouchDB FAQ.
WARNING: Please do NOT propose changes from your master
branch. In general, contributions are rebased using git rebase
or git cherry-pick
and not merged.
git mv
to move files & directories;@brodybits (Chris Brody) and others contribute their valuable time and expertise to maintain this project for the benefit of the mobile app community. Small consulting relationships can help strengthen the business viability of this project (see contact below).
common-src
- source for Android (not using sqlite4java), iOS, Windows (8.1), and Amazon Fire-OS versions (shared with litehelpers / Cordova-sqlcipher-adapter)new-common-src
- source for Android (using sqlite4java), iOS, Windows (8.1), and Amazon Fire-OS versionsnew-common-rc
- pre-release version for Android/iOS/Windows (8.1), including library dependencies for Android and Windows (8.1)wp-src
- source for Android (not using sqlite4java), iOS, WP(7/8), and Amazon Fire-OS versionswp-master-rc
- pre-release version for Android(not using sqlite4java)/iOS/WP(7/8), including source for CSharp-SQLite (C#) library classesmaster-rc
- pre-release version for all supported platforms, including library dependencies for Android, Windows (8.1), and WP(7/8)master
- version for release, to be included in PhoneGap build.FAQs
Cordova SQLite Plugin with built-in support for full-text search.
The npm package cordova-plugin-sqlite-fts receives a total of 1 weekly downloads. As such, cordova-plugin-sqlite-fts popularity was classified as not popular.
We found that cordova-plugin-sqlite-fts demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.