NotesDbAdapter example for a single table, what about multiple tables?

I checked the NoteDbAdapter example, and I noticed that this is for only one table. (notes)

1) I am wondering how to do this for multiple tables? For example, now I have 3 tables. How can I handle all updates, selections, deletions from these three tables?

2) I see certain properties for table columns

public static final String KEY_TITLE = "title";
public static final String KEY_BODY = "body";
public static final String KEY_ROWID = "_id";

How do you define columns for a multi-table situation?

+5
source share
1 answer

For my application, I created a class to define the database:

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 };
    }
}

And 2 sql scripts to create and update db res/raw/db_create.sqlandres/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 script / . ( , , )

+6

All Articles