Zumero PhoneGap Plugin for iOS and Android
This plugin allows applications built on PhoneGap to synchronize with Zumero for SQL Server (ZSS).
Zumero objects
Zumero
You'll need a single Zumero
object, created by requiring the
Zumero module:
var zumero = cordova.require("cordova/plugin/zumero");
Methods:
sync
sync( fullPath,
encryptionKey,
serverURL,
dbFileName,
scheme, user, password,
successCallback, errorCallback)
fullPath
: the full name of the local SQLite databaseencryptionKey
: this db's SQLCipher encryption key, ornull
serverUrl
: the URL of your Zumero instancedbFileName
: the name of the remote dbfilescheme
: the authentication scheme (ornull
)user
: the user name (ornull
)password
: the password (ornull
)successCallback
: function, called when the operation succeedserrorCallback
: function, called when the operation fails (optional)
Example
zumero.sync("/data/data/com.example.myapp/mydb",
"",
"https://zss.example.com",
"mydb",
'{"scheme_type":"table", "table":"users"}',
"user",
"password",
function() {
// success
},
function(result) {
// failure - result.code and result.message will
// contain details
}
);
quarantineSinceLastSync
quarantineSinceLastSync( fullPath,
encryptionKey,
successCallback, errorCallback)
fullPath
: the full name of the local SQLite databaseencryptionKey
: this db's SQLCipher encryption key, ornull
successCallback
: function, called when the operation succeeds. The quarantineID of the newly created quarantine package is sent as the only argument to this function.errorCallback
: function, called when the operation fails (optional)
Example
zumero.quarantineSinceLastSync("/data/data/com.example.myapp/mydb",
"",
function(quarantineID) {
// success
},
function(result) {
// failure - result.code and result.message will
// contain details
}
);
syncQuarantine
syncQuarantine( fullPath,
encryptionKey,
quarantineID,
serverURL,
dbFileName,
scheme, user, password,
successCallback, errorCallback)
fullPath
: the full name of the local SQLite databaseencryptionKey
: this db's SQLCipher encryption key, ornull
quarantineID
: the quarantineID that was returned fromquarantineSinceLastSync
serverUrl
: the URL of your Zumero instancedbFileName
: the name of the remote dbfilescheme
: the authentication scheme (ornull
)user
: the user name (ornull
)password
: the password (ornull
)successCallback
: function, called when the operation succeedserrorCallback
: function, called when the operation fails (optional)
Example
zumero.syncQuarantine("/data/data/com.example.myapp/mydb",
"",
1,
"https://zss.example.com",
"mydb",
'{"scheme_type":"table", "table":"users"}',
"user",
"password",
function() {
// success
},
function(result) {
// failure - result.code and result.message will
// contain details
}
);
deleteQuarantine
deleteQuarantine( fullPath,
encryptionKey,
quarantineID,
successCallback, errorCallback)
fullPath
: the full name of the local SQLite databaseencryptionKey
: this db's SQLCipher encryption key, ornull
quarantineID
: the quarantineID that was returned fromquarantineSinceLastSync
successCallback
: function, called when the operation succeeds.errorCallback
: function, called when the operation fails (optional)
Example
zumero.deleteQuarantine("/data/data/com.example.myapp/mydb",
"",
1,
function() {
// success
},
function(result) {
// failure - result.code and result.message will
// contain details
}
);
References
For more information on authorization schemes, dbfiles, and sync, see the Zumero Client API docs.
Zumero needs the full path to the dbfile being synchronized; you'll either need to know where your SQLite library stores its files (and if it changes their filenames) and add that information to your Zumero calls, or use a SQLite library that exposes the full name of an opened dbfile.
A Zumero-modified fork of the lite4cordova SQLite plugin can be found at
github.com/zumero/Cordova-SQLitePlugin (and is required by this plugin) - it extends the openDatabase
method's "success" handler function, adding a "full path" parameter after the
"message" parameter. This is the path you'd use when synching.
var db = window.sqlitePlugin.openDatabase( {name: dbName, location: 'default'},
function(msg, fullname) {
// save for later
myDbFilename = fullname;
// sync right now
zumero.sync(fullname,
"https://zss.example.com",
dbName,
'{"scheme_type":"table", "table":"users"}',
"syncuser",
"syncpassword",
function() {
// success
},
null
);
}
);