简体   繁体   English

在Android中管理非本地sqlite数据库

[英]manage non local sqlite database in android

I have started working with databases lately, I was able to create a local database and manage it in my Android app. 我最近开始使用数据库,我能够创建本地数据库并在我的Android应用程序中对其进行管理。 Now I want to move to higher level with it but I don't know how to do it. 现在我想将其推向更高的层次,但是我不知道该怎么做。

The users in my app need to be able to modify the database, for example insert new data in it. 我的应用程序中的用户需要能够修改数据库,例如在数据库中插入新数据。 When a user insert new data in the database I want other users to see this change in their copy of the database. 当用户在数据库中插入新数据时,我希望其他用户在其数据库副本中看到此更改。

I understand that I will need to store that database on a server or something and synchronize it with the users. 我了解我将需要将该数据库存储在服务器或其他设备上,并与用户进行同步。

Can anyone tell me the steps to do so? 谁能告诉我这样做的步骤?

You should perfom this task in steps. 您应该逐步执行此任务。

First, make the local database, and use a system to know when/what changed. 首先,建立本地数据库,并使用系统来了解何时/更改了什么。 I usually work with triggers myself, but any "mark" is enough to synchronize. 我通常自己使用触发器,但是任何“标记”都足以同步。

Then, you must make a replica of that database somewhere else. 然后,您必须在其他位置复制该数据库。 Realise that maintaining the databases is a process, any change in the structure of one database must be performed in all other as well. 意识到维护数据库是一个过程,一个数据库结构的任何更改也必须在所有其他数据库中执行。

Finally, you must implement a method to transfer the data. 最后,您必须实现一种传输数据的方法。

So, for an example: 因此,例如:

db_local the database in the device. db_local设备中的数据库。 db_outside the database in the internet. db_outsidedb_outside的数据库。

db_local.trigger -> onInsert

On the applications, check for internet, then connect to your server, then upload the same command to db_outside and run it... 在应用程序上,检查互联网,然后连接到服务器,然后将同一命令上传到db_outside并运行它。

In this step, you must handle connection issues, and if the SQL command was succesfully executed, you have replicated the database content. 在此步骤中,您必须处理连接问题,并且如果成功执行了SQL命令,则您已经复制了数据库内容。

Once you have the replicated database, inform a system (like google cloud messaging), that the database was changed, and have the other users pull the info. 复制数据库后,请通知系统(例如google cloud消息传递)数据库已更改,并让其他用户提取信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM