So after a few updates the QCDBSync library methods now all accept and return data types that can be used in b4a.
The library is a complete working implementation of the java QCDBSync library BUT we do not know how to use it (yet).
We need to put our heads together to figure it all out.
I've not been able to find any java code examples that'd help and the javadoc reference for the java library is pretty brief so not a lot of help.
Here's the b4a library reference:
QCDBSync
Comment: The SynchronizedDB class provides a safe way of keeping a SQLite file on an Android device in sync with a remote server.
Transactions are started and stopped using the SynchronizedDB StartTransaction and EndTransaction methods.
If any error occurs while executing the SQL found within these two transaction method calls then a roll back of the changes made will be executed.
If your database is not going to be used any longer you can use the SynchronizedDB CleanUp method to free the resources.
quickconnectfamily
Version: alpha version
- DataAccessResult
Methods:
- GetColumnNames As String[]
Accessor for the field names of the resultant table of a query.
- GetErrorDescription As String
Accessor for any error that may have occurred as a result of a call to the DataAccessObject GetData or SetData methods.
- GetResults As List
Accessor for the data 'table' that is the result of executing a query against a database.
Returns a List of Lists of Strings.
- IsInitialized As Boolean
- SetColumnNames (ColumnNames() As String)
- SetErrorDescription (ErrorDescription As String)
- SetResults (Results As List)
- SynchronizedDB
Methods:
- CleanUp
This method sends a logout command to the remote HTTP service and closes down the HTTP client on the Android device.
- ClearSync
This is a method that should rarely, if ever, be used.
- EndTransaction
This method is called after the StartTransaction method and any number of SetData calls.
- GetData (SqlKey As String, Parameters() As Object) As DataAccessResult
This method is used to retrieve data from the SQLite database on the device.
- Initialize (DatabaseName As String, RemoteURL As String, Port As Int, Username As String, Password As String, SyncTimeout As Long)
Creates a SynchronizedDB object used to interact with a local database and a remote HTTP service.
- IsInitialized As Boolean
- RegisterSyncStatements (KeySqlMap As Map)
This method is used to associate a series of key - SQL pairs as if they had been registered individually using the RegisterSynchedStatement method.
- RegisterSynchedStatement (SqlKey As String, SQL As String)
This method is used to associate a representative key String with a String containing SQL.
- SetData (SqlKey As String, Parameters() As Object) As DataAccessResult
This method is used to insert data into the SQLite database on the device or do any other type of database modification.
- StartTransaction
This method is called prior to making multiple SetData calls.
- Sync
This method pushes any stored SetData parameters to the HTTP service, waits for any data from the service, and then inserts any data received from the service into the appropriate tables in the local SQLite database.
It's a lovely bright afternoon here in Norfolk, UK so i am going to take a walk.
The library files are attached and also attached is the javadoc reference for the java library.
If anyone wants to make a start trying to use the library then please do and keep this thead updated.
I shall make some time later or tomorrow to put some b4a code together and see what it can do.
Probably best to just get the library basic usage working first, but it may be that it will raise an exception if it can't connect to a script on a server (SynchronizedDB Initialize
RemoteUrl parameter).
Creating an instance of the
SynchronizedDB object and Initializing it is the first thing to do, then we can look at how to make queries, get data and finally sync the device and remote databases.
@Harris Sound like you need some way for your server to push messages to devices to notify them that a update has been made to the online database. I'm not sure how you'd do that, maybe the Google Cloud Messaging service is what you require?
Martin.