SQLITE与Android(用于建立数据库最好的方法) [英] SQLITE with Android (best methodology for setting up a database)

查看:227
本文介绍了SQLITE与Android(用于建立数据库最好的方法)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了你可以使用SQLite作为数据库为您的应用程序几种不同的方式。它们如下:

I have seen a few different ways that you can utilize SQLite as the database for your app. They are as follows:

  • 在数据库中创建和数据通过一个XML文件中导入。
  • 使用一个SQLite GUI(SQLite数据库浏览器)
  • 通过数据库辅助类
  • 在直数据库创建。
  • Database is created and data is imported via an XML file.
  • Use of a SQLite GUI (SQLite Database Browser)
  • Straight Database creation via a Database helper class.

什么是每个人的利益?我倾向于使用SQLite数据库浏览器加载了几桌,我需要为我的应用程序。我也会有用户输入。

What are the benefits of each one? I'm leaning towards using SQLite Database browser to load a few tables I will need for my app. I will also have user input.

你认为我有一个额外的表征求他们的意见和联盟,或者允许用户输入表我已经提供了。在一个问题我预见是对应用程序的升级(通过市场),我不希望他们已经输入的用户数据丢失。

Do you suggest that I have an additional table for their input and Union, or allow the user to input into table I have provided. The one issue I foresee is on upgrade of the app (via the Market), I do not want the user to lose data that they have entered.

谢谢!

推荐答案

这是我做了一个选择:

  • 在资源存储每个架构和数据文件的人口为脚本
  • 在创建运行这些脚本从资源的包装类
  • 一个资源文件的一个是公知的(通过名称)清单,它具有脚本列表于其中的顺序运行。
  • 我在其中存储有什么运行过的最后一个脚本数据库中的poperties表。

这意味着:

  • 在创建(第一次运行) - 它运行在继承的所有脚本
  • 在当前的应​​用程序是更新 - 它运行那些尚未运行的所有脚本。更新进行资源多个脚本。

脚本更新模式和修改/ munge现有的客户数据 - 当然,不会丢失数据

The scripts update schema and modify/munge existing customer data - of course without data loss.

顺便说一句,我这样做是对的iOS与Android的,winphone和其他平台之间共享这些源码脚本的意图。你只需要在每次运行序列平台上的包装类。

BTW, I did this on iOS with the intent of sharing those sqlite scripts between android, winphone and other platforms. You just need the wrapper class on each platform that runs the sequences.

这也意味着我可以为了从CMDLINE如果需要运行脚本来创建一个数据库...

It also means I can run the scripts in order from the cmdline to create a db if needed ...

编辑:

例如,在我的示例应用程序,Update1.sql是作为资源添加的文件。它有它两个SQL批处理。我打开包装清单文件,得到是的运行脚本列表,查询数据库,看看最后的剧本跑,然后创建的脚本运行的阵列。当它运行Update1.sql这是在列表中,我的包装类将执行作为资源嵌入的文件,这就是所有的语句。例如,这里是我的Update1.sql

For example, in my sample app, Update1.sql is a file added as a resource. It has two sql batches in it. My wrapper opens the manifest file, get's the list of scripts to run, queries the database to see the last script ran, then creates an array of scripts to run. When it runs Update1.sql which is in the list, my wrapper class executes all the statements in that file thats embedded as a resource. For example, here's my Update1.sql

alter table messages add column user text;

create table log
(
    id integer primary key autoincrement, 
    information text    
);

现在,让我们说创造了新的表需要在它的一些数据。 (在我的情况下,日志表没有)。该脚本可以在创建表之后包含一系列插入到语句。

Now, let's say the new table created needs some data in it. (in my case a log table doesn't). That scripts could contain a series of insert into statements right after the create table.

在脚本执行多个批次需要使用尾部参数在prepare的。我有C / Objective-C的code,如果你想看到它,但我不写了android包装尚未...

Executing multiple batches in a script requires the use of the tail argument in prepare. I have C/objective-c code if you would like to see it but I haven't written the android wrapper yet ...

这篇关于SQLITE与Android(用于建立数据库最好的方法)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆