views:

87

answers:

3

Hello everyone, I have a problem with a deadline. And that deadline is tomorrow :S Luckily it doesn't have to be the best solution; not even a good one. I only need one part working which I will describe shortly. What I want you to know is that I looking for the quickest and dirtiest solution right so my idea maybe sound really bad.

So, for the past couple of days I've been trying to synchronize a database located in a Windows Mobile device with a MySQL database located to a central linux server. Microsoft's walkthrough contains a web service which I am not sure how to handle (I have very limited knowledge in this area). As far as I understand, there is a service which should be located in the server side, but this is not possible for various reasons (including the fact that it is a linux machine). Furthermore, I have yet to figure out how to make a mysql sync provider.

My solution, and this is an ugly one mind you, is to create a Java web service on the server that is responsible for tracking each Windows Mobiles' sync requests and respond appropriately. Here is how I think it will go:

Each Windows Mobile device will contain a local database (SQL Compact). When there is an active internet connection, it will send a request to the web service to sync their database sending along their username and password. The web service will look for the last sync request from these credentials (which is a dump of the database at the time of the request) and compare it with the current database state. The service will only send the changes as a response. Once the response is sent, it will store the current database state as the user's last sync request for the next one. All the Windows Mobile device has to do is follow the response (simple CRUD statements).

So, my question, finally, is: How can I store the database state in order to later compare it with a future state?

Of course, needless to say, if there is a better solution that can be done quickly, I can discard this whole idea.

For this case, here is what you need to know: the server is running linux. The database on it is MySQL and I cannot modify the schema. I can however install software on the server, like a webservice. Finally, the Windows Mobile devices are currently running SQL Compact. And of course, this should not cost anything since it will not be the final solution (which will use the Microsoft Sync Framework once I get to figure out some things).

Thank you very very much. I'd also like you to know that this is not a "give me code" question, I am mainly looking for any type of feedback (comments/ideas/suggestions/rants/etc).

+1  A: 

You could create a snapshot of the data.

Ardman
Could you elaborate a little? How do I do that and how do I compare the snapshots?
pek
If you take a look here : http://msdn.microsoft.com/en-us/library/ms175876.aspx
Ardman
+1  A: 

Here is a random (and possibly stupid and unworkable) way to address it. If I understand correctly, you are synchronizing in only one direction (from the MySQL database to the mobile device). If it is two-way sync, then this will not work at all.

Set up replication on the database to replicate to a slave copy of the data. In that slave database, put triggers on the tables involved and for each modification (delete, update, insert), write the necessary information to generate your CRUD statements to some file/table. Then during the sync, just replay those statements to the device and then delete/clear the file. The next sync would then replay the next set of statements that were accumulated.

Mark Wilkins
I am not sure if it is a one direction thing. The devices make changes in their local database and push them to the central. Logically, these changes must be propagated to all the other devices to update their own local db. So both the device and the central have changes that need to be pushed to one another. Since I liked your idea (although I will have to learn about trigger and slaves), can it still be done?
pek
@pek: In theory, it could be done. But it gets a lot more difficult. For example, I suspect that the local store on the mobile device has no concept of replication. But if you control the data modification on the device, then you could build up a set of replay changes (same type of CRUD statements). Then replay those back to the server. However, two-way synchronization is very difficult particularly when it comes to conflict detection and resolution. In this simple scenario I have described there is no talk about handling the case where a record is modified on both sides "concurrently".
Mark Wilkins
@Mark well, I actually don't care about conflicts right now. I'll just give priority to the mobile devices. I only need to make a simple version of this and then take care about good sync practices.
pek
@pek: In that case, it seems like it could work if it is possible for you to generate the update statements with each update on the device. I'm not very familiar with that area, though, so I don't know what kinds of tools would be available to help with that.
Mark Wilkins
+1  A: 

Why not simply create an MD5 key for all the data in the database and store that? This will not let you see what changes took place but at least you will know that a change has been made.

Savvas Dalkitsis
Yeah, well, in this case I would have to download all the database since I don't know what changed. This would be fine for a desktop application, but in a PDA it would require a reliable and fast wireless connection which is rarely true. But then again, this is a quick and dirty solution so maybe I will try this if everything else fails.
pek
You can make the md5 table specific and pinpoint which table was changed. This way you won't have to download the whole db just one (or as many as have changed) tables. You will need to maintain more md5s though for comparison.
Savvas Dalkitsis