Blackberry not creating a valid sqlite database -


i have unusual problem.

i'm trying create simple database (6 tables, 4 of have 2 columns). i'm using in-house database library i've used in previous project, , work.

however current project there occasional bugs. database isn't created correctly. added sdcard when access databaseexception.

when access device desktop manager , try open database (with sqlite database browser v2.0b1) "file not sqlite 3 database".

update
found happens when delete database manually off sdcard. since there's no way stop user doing that, there can handle it?

code

public static boolean initialize() {     boolean memory_card_available = applicationinterface.issdcardin();     string application_name = applicationinterface.getapplicationname();     if (memory_card_available == true)     {         file_path = "file:///sdcard/" + application_name + ".db";     }     else     {         file_path = "file:///store/" + application_name + ".db";     }      try     {         uri = uri.create(file_path);         fileclass.hidefile(file_path);     } catch (malformeduriexception mue)     {     }      return create(uri); }  private static boolean create(uri db_file) {     boolean response = false;      try     {         db = databasefactory.create(db_file);         db.close();          response = true;     } catch (exception e)     {     }      return response; } 

since looks problem user deleting database, make sure catch exceptions when open (or access ... wherever you're getting exception):

try {     uri uri = uri.create("file:///sdcard/databases/database1.db");     sqlitedb = databasefactory.open(myuri);     statement st = sqlitedb.createstatement( "create table 'employee' ( " +                                               "'name' text, " +                                               "'age' integer )" );                    st.prepare();     st.execute(); } catch ( databaseexception e ) {              system.out.println( e.getmessage() );      // todo: decide if want create new database here, or      // alert user if sdcard not available } 

note though it's unusual user delete private file app creates, it's normal sdcard unavailable because device connected pc via usb. so, should testing condition (file open error).

see answer regarding checking sdcard availability.

also, read sqlite db storage locations, , make sure review answer michael donohue emmc storage.


update: sqlite corruption

see link describing many ways sqlite databases can corrupted. sounded me maybe .db file deleted, not journal / wal file. if it, try deleting database1* programmatically before create database1.db. but, comments seem suggest else. perhaps file locking failure modes, too.

if desperate, might try changing code use different name (e.g. database2, database3) each time create new db, make sure you're not getting artifacts previous db.


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -