Hi Tim,
Thanks very much for your reply.
As I was waiting for a reply I was thinking that I probably didn't do a very good job of explaining my problem, so I'm going to elaborate.
I am working exclusively in Eclipse currently as I don't have a phone.
I would like to use a SQLite look-up table in my app.
There is a database example in the Hello, Android book (starts on p. 170 as I recall).
It creates a sqlite db from within the app. That is interesting and I will use that technique in the future on some app I'm sure.
Although it doesn't seem to work exactly as advertised. It creates the db and tbl the first time thru but doesn't drop the tbl when it run it again. It just keeps adding
records to the table. Here is the relevant db code:
Here is the Constants interface -
package com.example.events;
import android.provider.BaseColumns;
public interface Constants extends BaseColumns{
public static final String TABLE_NAME = "events";
// define the Columns in the Events database
public static final String TIME = "time";
public static final String TITLE = "title";
}
Here is the class that extends SQLiteOpenHelper -
package com.example.events;
import static android.provider.BaseColumns._ID;
import static com.example.events.Constants.TABLE_NAME;
import static com.example.events.Constants.TIME;
import static com.example.events.Constants.TITLE;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class EventsData extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "events.db";
private static final int DATABASE_VERSION = 1;
// create a helper object for the Events database
public EventsData(Context ctx) {
super(ctx, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + TABLE_NAME + " (" + _ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + TIME
+ " INTEGER," + TITLE + " TEXT NOT NULL);");
}
@Override
public void onUpgrade(SQLiteDatabase db, int OldVersion,
int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
}
* The tbl is never being dropped. I have set debuggable to try in my manifest file and set a breakpoint in this method to see if it is being invoked but it doesn't stop at that breakpoint or any other breakpoint I set in the app. I don't understand why?
I have looked all over for the events.db file but can't find it anywhere.
In actuality, I would like to have it be created under the "assets" folder in the Eclipse project structure for my Android project, but don't know how to tell to do that.
Would you be able to help me understand how to do that?
Once I understand that I can go onto my next little learning app where I put a look-up db into that same place and open it from there. Not exactly sure how to do an open on an existing db but will try and figure that out once this problem is solved.
Thanks again for your assistance as I am looking forward to hearing back from you.
-Chris