tags:

views:

65

answers:

2

Hello all, i have come into quite a funny hole here. i can't seem to be able to create a 2nd database table to my existing one. i basically want them to be of the same structure and the same of columns, in other words a copy of my existing table. my goal is to copy the values from my first table to the second table. The first table i created works cos i have used it already.

i have tried everything i know, unistalled and reinstalled the app to clear the database, changed the name of the tables, version..etc but i keep getting a "table not found exception". please any ideas what could be causing this and how to go about it?.. thanks

here is the creation for both of them:

/* tables variable*/
public static final String DATABASE_TABLE = "Memo";
    public static final String ROUTE = "Route";

 public static final String KEY_ID = "_id";
public static final String NAME = "Title";
public static final String DATE = "date";
public static final String TIME = "time";
public static final String VENUE = "venue";
public static final String CATEGORY = "category";
    public static final String PRIORITY = "priority";
    public static final String NOTES = "notes";

  private static final String DATABASE_CREATE = "create table Memo (_id integer primary key autoincrement," 
    + "Title text, date text, time text,"
    + "venue text, category text,"
     + "priority text, notes text);";

  private static final String DATABASE_CREATE_ROUTE = "create table Route (_id integer primary key autoincrement," 
    + "Title text, date text, time text,"
    + "venue text, category text,"
     + "priority text, notes text);";


public void onCreate(SQLiteDatabase db) {
        db.execSQL(DATABASE_CREATE);
        Log.d(TAG, "created Memo table");

        db.execSQL(DATABASE_CREATE_ROUTE );
        Log.d(TAG, "created Route table");

    }
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.w(TAG,"upgrading Database from version"+ oldVersion+ "to"
                +newVersion+ "which old data will be lost");
        db.execSQL("DROP TABLE IF EXITS Memo");
        db.execSQL("DROP TABLE IF EXITS Route");

        onCreate(db);
    }
}


public void copyData(long rowId){

db.execSQL("insert into ROUTE select * from DATABASE_TABLE WHERE KEY_ID = rowId");
}

Logcat Exception is:

10-22 15:47:17.326: ERROR/Database(807): Failure 1 (no such table: ROUTE) on 0x1d7f20 when preparing 'insert into ROUTE select * from DATABASE_TABLE WHERE KEY_ID = rowId'.

10-22 15:47:17.356: ERROR/AndroidRuntime(807): Uncaught handler: thread main exiting due to uncaught exception

10-22 15:47:17.526: ERROR/AndroidRuntime(807): android.database.sqlite.SQLiteException: no such table: ROUTE: insert into ROUTE select * from DATABASE_TABLE WHERE KEY_ID = rowId

10-22 15:47:17.526: ERROR/AndroidRuntime(807):     at android.database.sqlite.SQLiteDatabase.native_execSQL(Native Method)

10-22 15:47:17.526: ERROR/AndroidRuntime(807):     at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1496)

10-22 15:47:17.526: ERROR/AndroidRuntime(807):     at com.MemoManager.DBAdapter.copyData(DBAdapter.java:265)
+1  A: 

I think you are missing a paren in your DATABASE_CREATE and DATABASE_CREATE_ROUTE

private static final String DATABASE_CREATE = "create table Memo (_id integer primary key autoincrement," 
    + "Title text, date text, time text,"
    + "venue text, category text,"
    + "priority text, notes text;";
                                ^ (HERE?)
Aaron H.
oh sorry about that. its not the problem. i had it in my code, i did not realise i did not copy it when i was posting the question.
sparrow
any more ideas please?..
sparrow
Mind to post the logcat log of that exception?
Tseng
ok. i have added the logcat exception.
sparrow
and i can't think of anything else. i don't know what else i can chage. since i have tried the changing the names and version. i once read somewhere in a post about the problem linking to the onUpgrade() method in the sqlite database, but sadly no solution was shown. does anybody know anything about that please? i have added how i did my onUpgrade method.
sparrow
+2  A: 

Could it be referring to your DATABASE_TABLE in the insert string? I assume it needs to be "insert into ROUTE select * from " + DATABASE_TABLE + " WHERE KEY_ID = rowId"

EDIT: I think Aaron might correct too/instead.

raybritton
well am not sure.. will give it a try, but i would have thought it would refer to a "syntax error" more of, than a "table not found exception" and besides, it explicitly says "ROUTE" in the exception.
sparrow
@sparrow then I'm probably wrong, and Aaron is most likely correct.
raybritton
Also ROUTE is being referred to in the string. Should be: "insert into " + ROUTE + " select * from " + DATABASE_TABLE + " WHERE KEY_ID = rowId". And is KEY_ID the proper column name? It looks like you called it "_id". Not sure if SQLite appends something or not. But you definitely have to refer to column and table names in the proper case here.
AndrewKS
well.. you might have a point there. because i created static constants for that, but i would have thought it gets used in both cases. will add it now. and yeah, i have that syntax error corrected in the method, its still the same. i would edit my question to include the constants i have there. don't know what else to do :(
sparrow
Am trying not to make the code too long, so it doesn't become distressful for you guys. thats why i try to keep it short as possible.
sparrow
Yeah, raybritton is right too I think. You should have: db.execSQL("insert into ROUTE select * from " + DATABASE_TABLE + " WHERE KEY_ID = rowId"); -- Could it also be that ROUTE is case sensitive? Sqlite on my machine isn't, but I don't know about your platform, you're creating table "Route" but referencing "ROUTE"...
Aaron H.
hmmm.. never heard about sql being case sensitive on different platform.. well am not too experienced with it anyway. will try what you suggested but i felt it would give a syntax error if that was the case.
sparrow
hmmm.. funny, its now giving me a: "android.database.sqlite.SQLiteException: no such column: KEY_ID: insert into ROUTE select * from Memo WHERE KEY_ID = rowId"but as i say, the first row is working. or does that mean i have to use a different KEY_ID for the 2nd database table?..
sparrow
i don't know why its giving an exception " no such column: KEY_ID" because i am already using the first database table and its working. yeah, i know this is tiresome, am sorry about that. but anyone have a link i can check or something?.. thanks
sparrow
Because there is no KEY_ID column, you have the columns: _id, Title, date, time, venue, category, priority, and notes
raybritton
oh gosh am sorry about this.. Thanks! i did something earlier and did not realise about that. it works now! Thank you guys very much for all the input!. seems i have to brush up on my sql, but first, i need some sleep!! have a great weekend. :)
sparrow
Can you mark either of the replies as an answer please.
raybritton
oh.. sorry about that. will do it now
sparrow
No problem, thank you
raybritton