我已经检查了NotesDbAdapter示例,我注意到这仅适用于单个表.(笔记)
1)我想知道如何为多个表做这个?例如,我现在有3个表.我如何处理这三个表中的所有升级,获取,删除?
2)我看到表列的已定义属性
public static final String KEY_TITLE = "title"; public static final String KEY_BODY = "body"; public static final String KEY_ROWID = "_id";
您如何定义多表情况的列?
对于我的应用程序,我创建了一个类来定义数据库:
public final class MyApplicationDb { public static String DATABASE_NAME = "my_application_db"; public static int DATABASE_VERSION = 1; public static final class Table1 { public static String TABLE_NAME = "table1"; public static String ID = "_id"; public static String DAY = "day"; public static String NAME = "name"; public static String SOURCE = "source"; public static String[] COLUMNS = { ID, DAY, NAME, SOURCE }; } public static final class Table2 { public static String TABLE_NAME = "table2"; public static String ID = "_id"; public static String CONTACT_ID = "contactId"; public static String CONTACT_NAME = "contactName"; public static String LAST_WISH_DATE = "lastWishDate"; public static String[] COLUMNS = { ID, CONTACT_ID, CONTACT_NAME, LAST_WISH_DATE }; } }
和2个sql脚本,用于创建和更新数据库res/raw/db_create.sql
和res/raw/db_update.sql
/* db_create.sql */ create table table1( _id integer primary key autoincrement, day char(5) not null, name varchar(64) not null, source varchar(64) not null); create table table2( _id integer primary key autoincrement, contactId integer not null, contactName text not null, lastWishDate char(10) null); /* db_update.sql */ DROP TABLE IF EXISTS table1; DROP TABLE IF EXISTS table2
另一个用于创建/更新/访问数据库的类,NotesDbAdapter
除了它使用sql脚本创建/更新数据库而不是常量之外.(看这里看看怎么做)