mirror of
https://github.com/moparisthebest/PhoneGap-SQLitePlugin-Android
synced 2024-11-14 04:55:04 -05:00
Cordova-iOS version in subdirectory, keep legacy PhoneGap (iPhone) version in its own subdirectory
This commit is contained in:
parent
08b113a959
commit
ae073173f4
100
README.md
100
README.md
@ -3,9 +3,9 @@ Cordova SQLitePlugin
|
||||
|
||||
DISCLAIMER:
|
||||
|
||||
Created by @Joenoon:
|
||||
Created by @Joenoon:
|
||||
|
||||
Adapted to 1.5 by coomsie
|
||||
Adapted to 1.5 by @coomsie
|
||||
|
||||
|
||||
DISCLAIMER:
|
||||
@ -15,9 +15,41 @@ We are brand new to objective-c, so there could be problems with our code!
|
||||
Installing
|
||||
==========
|
||||
|
||||
Cordova (PhoneGap) 1.5.0
|
||||
**NOTE:** There are now 2 trees: `Cordova-iOS` for Cordova 1.5(+) and `Legacy-PhoneGap-iPhone` for PhoneGap (tested 1.3 and earlier). I am planning to add an Android version in another tree, hopefully in the near future.
|
||||
|
||||
|
||||
PhoneGap 1.3.0
|
||||
--------------
|
||||
|
||||
For installing with PhoneGap 1.3.0:
|
||||
in PGSQLitePlugin.h file change for PhoneGaps JSONKit.h implementation.
|
||||
|
||||
#ifdef PHONEGAP_FRAMEWORK
|
||||
#import <PhoneGap/PGPlugin.h>
|
||||
#import <PhoneGap/JSONKit.h>
|
||||
#import <PhoneGap/PhoneGapDelegate.h>
|
||||
#import <PhoneGap/File.h>
|
||||
#import<PhoneGap/FileTransfer.h>
|
||||
#else
|
||||
#import "PGPlugin.h"
|
||||
#import "JSON.h"
|
||||
#import "PhoneGapDelegate.h"
|
||||
#import "File.h"
|
||||
#endif
|
||||
|
||||
and in PGSQLitePlugin.m JSONRepresentation must be changed to JSONString:
|
||||
|
||||
--- a/Plugins/PGSQLitePlugin.m
|
||||
+++ b/Plugins/PGSQLitePlugin.m
|
||||
@@ -219,7 +219,7 @@
|
||||
if (hasInsertId) {
|
||||
[resultSet setObject:insertId forKey:@"insertId"];
|
||||
}
|
||||
- [self respond:callback withString:[resultSet JSONRepresentation] withType:@"success"];
|
||||
+ [self respond:callback withString:[resultSet JSONString] withType:@"success"];
|
||||
}
|
||||
}
|
||||
|
||||
SQLite library
|
||||
--------------
|
||||
|
||||
@ -36,7 +68,7 @@ file in src/ to javascript WITH the top-level function wrapper option (default).
|
||||
|
||||
Use the resulting javascript file in your HTML.
|
||||
|
||||
Look for the following to your project's PhoneGap.plist:
|
||||
Look for the following to your project's Cordova.plist or PhoneGap.plist:
|
||||
|
||||
<key>Plugins</key>
|
||||
<dict>
|
||||
@ -48,9 +80,16 @@ Insert this in there:
|
||||
<key>SQLitePlugin</key>
|
||||
<string>SQLitePlugin</string>
|
||||
|
||||
**NOTE:** for `Legacy-PhoneGap-iPhone` the plugin name is still `PGSQLitePlugin`, expected to be fixed in the near future.
|
||||
|
||||
General Usage
|
||||
=============
|
||||
|
||||
**NOTE:** in this fork the API is undergoing changes to be closer to the HTML5 Web SQL API.
|
||||
|
||||
Cordova iOS
|
||||
-----------
|
||||
|
||||
## Coffee Script
|
||||
|
||||
db = new SQLitePlugin("test_native.sqlite3")
|
||||
@ -98,14 +137,63 @@ General Usage
|
||||
});
|
||||
|
||||
|
||||
Legacy PhoneGap (old version)
|
||||
-----------------------------
|
||||
|
||||
## Coffee Script
|
||||
|
||||
db = new PGSQLitePlugin("test_native.sqlite3")
|
||||
db.executeSql('DROP TABLE IF EXISTS test_table')
|
||||
db.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data text, data_num integer)')
|
||||
|
||||
db.transaction (tx) ->
|
||||
|
||||
tx.executeSql [ "INSERT INTO test_table (data, data_num) VALUES (?,?)", "test", 100], (res) ->
|
||||
|
||||
# success callback
|
||||
|
||||
console.log "insertId: #{res.insertId} -- probably 1"
|
||||
console.log "rowsAffected: #{res.rowsAffected} -- should be 1"
|
||||
|
||||
# check the count (not a part of the transaction)
|
||||
db.executeSql "select count(id) as cnt from test_table;", (res) ->
|
||||
console.log "rows.length: #{res.rows.length} -- should be 1"
|
||||
console.log "rows[0].cnt: #{res.rows[0].cnt} -- should be 1"
|
||||
|
||||
, (e) ->
|
||||
|
||||
# error callback
|
||||
|
||||
console.log "ERROR: #{e.message}"
|
||||
|
||||
## Plain Javascript
|
||||
|
||||
var db;
|
||||
db = new PGSQLitePlugin("test_native.sqlite3");
|
||||
db.executeSql('DROP TABLE IF EXISTS test_table');
|
||||
db.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data text, data_num integer)');
|
||||
db.transaction(function(tx) {
|
||||
return tx.executeSql(["INSERT INTO test_table (data, data_num) VALUES (?,?)", "test", 100], function(res) {
|
||||
console.log("insertId: " + res.insertId + " -- probably 1");
|
||||
console.log("rowsAffected: " + res.rowsAffected + " -- should be 1");
|
||||
return db.executeSql("select count(id) as cnt from test_table;", function(res) {
|
||||
console.log("rows.length: " + res.rows.length + " -- should be 1");
|
||||
return console.log("rows[0].cnt: " + res.rows[0].cnt + " -- should be 1");
|
||||
});
|
||||
}, function(e) {
|
||||
return console.log("ERROR: " + e.message);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Lawnchair Adapter Usage
|
||||
=======================
|
||||
|
||||
Include the following js files in your html:
|
||||
|
||||
- lawnchair.js (you provide)
|
||||
- sqlite_plugin.js
|
||||
- lawnchair_sqlite_plugin_adapter.js (must come after sqlite_plugin.js)
|
||||
- sqlite_plugin.js [pgsqlite_plugin.js in Legacy-PhoneGap-iPhone]
|
||||
- lawnchair_sqlite_plugin_adapter.js [lawnchair_pgsqlite_plugin_adapter.js] (must come after sqlite_plugin.js [pgsqlite_plugin.js in Legacy-PhoneGap-iPhone])
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user