Using CouchDb on a android phone and mongodb on the server side - android

I have the following scenario.I need to have an embedded database(nosql) on Android and i have a master database on the server which should ideally be nosql database.There needs to be syncing between the two.All queries from the mobile will go to the iternal database.We have differnt options
1)Use couchDB on the mobile side and also use couchdb on the server side
2)Use couchDb on the mobile side and use Mongodb on the server side
3)Use sqlLite on the mobile side and use MongoDb/CouchDb on the server side.
Please give your views in evaluating the best option and the benifits/problems of using these approaches.
Note:Currently MongoDb does not support for an embedded database on Android.Also Mongo does not provide the REST APIS and we need to use third paty like MongoLabs and SleepyMongoose

You don't mention the methodology you would use to sync changes between the databases especially in the cases in which changes conflict (an update on one side, a delete of the matching record on the other side for example), but it seems like your life will be simpler using the same database on each side.

Related

How to connect to a SQL Database on an Android Kotlin app

I am building an Android application with Kotlin. I am not very familiar with Databases and Backend in general, I have only used AWS DynamoDB and S3. I want to try something else and learn SQL. I want to connect my app to a Cloud SQL DB like MySQL or PostreSQL. I can't use SQLite because I want the app to be served remotely and be accessible by all the users. I don't need a server, instead I would like to use a server-less structure where I make queries to the DB on function calls from inside my App. How would I do that? I read online about services like planetscale and raiway.app but I can't find a way to connect to my tables there. Are they perhaps web-only?
If you have a remote back-end you can use retrofit https://square.github.io/retrofit/ otherwise you can use room library https://developer.android.com/training/data-storage/room.
I understand that you aren't going to use a Server but in the case where you have to make queries locally, i.e. you have your database on your PC, you must use retrofit and for doing this you must make a small API that will send you JSON and you can process your queries easily with that. If not, you can use room to connect to sqlite, a small database that is default on android phones.
Some Links :
https://square.github.io/retrofit/,
https://developer.android.com/training/data-storage/room.

Link vb.net /android project with online database

I have a project in vb.net and another in android studio I want to link them with one database (real time connection) what is the best way to do that (sql server-my sql ....other?)
Sql server is pretty easy to link to vb.net. you simply create a connection string with the server name and password, although I am not sure about android, but the process would probably be similar
It looks like you want to communicate between the two applications via SQL server, is that correct? While it is possible to do this it is highly ill-advised as the communication cannot be realtime (you would have to poll a table by selecting from it every ## seconds or use triggers MSSQL / MySQL in a very strange way) and it is likely to be unnecessary.
My suggestion is to consider what data you need to go back and forth and why. It is unusual for an Android app to directly connect to a database across the Internet because of the security risks in exposing a database publicly. Most developers opt to use a web application of some kind that provides an API for the Android app to consume. This prevents direct access to the database and provides you a place to add in all your business/game/other logic.

android auto sync mysql to sqlite [duplicate]

I am developing an android application. I want to update the local SQLite database with MySQL database on server. I am not able to figure out that what is the most appropriate and standardized way to do so?
Create a webservice (REST is probably best) and serialize your SQLite/MySQL data and PUT/POST/GET it to/from your web service. This will give you a nice layer of abstraction in case you decide to switch from MySQL to something else server side.
You may want to take a look at fyrecloud.com/amsler This is source code for a demonstration Android application that implements MySQL replication between a MySQL server and the SQLite db on an Android device.
Amsler rests on two pillars:
It communicates with the MySQL server using the MySQL Client/Server protocol in order to connect to the server for authentication and for receiving replication events as they occur.
It uses the Antlr lex and parse software in order to lex and parse incoming replication events and then to translate the MySQL commands into equivalent SQLite commands.
This is great for one-way replication. You can simulate two-way replication by modifying the MySQL server indirectly via RESTful type methods and then watching while MySQL sends a new replication event back.
Accessing a server via REST is easy enough. However, modifying an existing MySQL installation in order to support serialization presents too many headaches to enumerate here. Amsler takes advantage of pre-existing replication services. REST also depends upon some polling strategy in order to keep the local device reasonably up-to-date. Again, many problems with this approach. Amsler maintains a TCP/IP connection to the server which enables server-push notification of updates.
The most difficult part of Amsler is in figuring out the lexing/parsing. The Syntax between MySQL, SQLite, and the various versions of the same have many subtle differences. So many differences that it's impractical to provide a shrink-wrap translator and instead you must resort to modifying the grammar yourself.
Nevertheless, good, bad, or ugly, here it is. Take a look and maybe the glove fits.
This is probably going to be helpful: sync databases Mysql SQLite
The real answer is that there is no standard or built in magic way to just copy a MySQL database that lives on a server somewhere to a device. You will have to implement either a webservice or somehow convert the MySQL db on the server to the android sqlite implementation and download that file into your app's data directory (not a route I'd recommend taking).
Late to the party, but http://www.symmetricds.org/ is a good solution.
Java, runs on Android too.
LGPL.
Can handle 10,000's of clients.
There is no standard way. Depending on your needs you can e.g. use webservices in REST or SOAP protocols or more binary data exchange.

CouchBase sync_gateway + web application?

By using couchbase sync_gateway for mobile sync(android,ios) you can still use the database from custom server side app?
My application needs to run on both mobile and web. I have angularjs for browsers and nodejs/express for server side.
If I will update the database form browser->node->couchbase ... mobile clients will get db update?! I think this is with no revisions so?!
if you are using the Node.js smart client for Couchbase Server, you can still co-exist with Couchbase Lite mobile clients using a workflow we call "bucket shadowing". For more information on this, check out: https://github.com/couchbase/sync_gateway/wiki/Bucket-Shadowing
Alternatively, you could use a Node.js library that interfaces directly with the Sync Gateway instead. For example, cradle: https://github.com/flatiron/cradle
But, for most use cases, I would recommend the bucket shadowing method instead.
I've attempted to approach it from a similar direction in PHP.
Sync_gateway is based on CouchDB API but has some changes and missing features in it's architecture when compared to a normal Couchbase or CouchDB instance.
Sync/Admin REST API:
Attachments aren't supported: Sync_gateway runs in memory passing JSON documents to clients and isn't designed to store larger binary files.
Views aren't supported (except for a few special sync_gateway views): A sync_gateway pipes documents through channels to the authenticated users instance of Couchbase Lite. View design documents are passed also then ran on the client to analyse the documents they have locally. Structurally views otherwise have no ability to change their contents based on which user is authenticated, as they are pre-computed indexes.
Get/store docs, adding/removing users, channels, roles, DB compact, registering new databases as sync_gateway and a few other handy features are exposed.
So depending on your needs it is possible to connect a web-app to sync_gateway and retrieve documents, however "bucket shadowing" with separate ACL system for the web-app is likely the solution for most applications.
Alternatively you could compile Couchbase Lite for the server node and have the web-app connect to it, however this Couchbase Lite instance will only represent a single user and contain only their channel's documents.
PHP Client for Sync Gateway: https://github.com/mryellow/PHP-on-CouchSync/
Update: Nowadays probably the best way to go is with PouchDB for the web side. You can monitor changes with AngularJS and make responsive interfaces that will automatically react to your data changes in the browser.

how can I two way sync data between android device and webserver?

My project setup is like this
Server side
I have webserver with PHP,MySQL database apache
On android device side
I have sqlite database
I want to sync data between these two databases of device side and server side whenever there is any update in any side of database. Does android has any package to do this? Or do I need to take care of this by myself using php scripts and HttpClient api of android?
If you write this yourself these are some of the points to keep in mind
Proper authentication between the device and the Sync Server
A sync protocol between the device and the server. It will usually go in 3 phases, authentication, data exchange, status exchange (which operations worked and which failed)
Pick your payload format. I suggest SyncML based XML mixed with JSON based format to represent the actual data. So SyncML for the protocol, and JSON for the actual data being exchanged
Keeping track of data changes on both client and server. You can maintain a changelog of ids that change and pick them up during a sync session. Also, clear the changelog as the objects are successfully synchronized
Need to have a way to communicate from the server to the device to start a sync session as data changes on the server. You can use C2DM or write your own persistent tcp based communication. The tcp approach is a lot seamless
A way to replicate data changes across multiple devices
And last but not the least, a way to detect and handle conflicts
Hope this helps as a good starting point
For the Above Purpose, you need to create web services in PHP. You can call these web services from Android side for sync purpose.

Categories

Resources