I am trying to insert rows in a SQLite database within Android. To put a record in my DB, a call looks like this: DataHelper.insertChild (reference, kid) My goal is to wrap the functionality in statically called functions that handle all knightly grunts. First of all, I share my code
I am doing this through static methods:
Private static SQLiteDatabase readyChildDatabase (reference reference) {Log.d ( TAG, "DB: Ready Chald Database"); OpenHelper openHelper = new OpenHelper (reference); Return openHelper.getWritableDatabase (); } Then I make my entry:
Public Stable Long Contained Child (Reference Reference, Child Children) {Log D. (Tag, "db: insert hair"); SQLiteDatabase db = readyChildDatabase (reference); SQLiteStatement insertStmt = db.compileStatement (INSERT); InsertStmt.bindLong (1, child.getBirthday (.) GetTime ()); // These are optional if (child.getName ()! = Null) {insertStmt.bindString (2, child.getName ()); } And {insertStmt.bindNull (2); } If (child.getPhoto ()! = Null) {string photo urai = hair.jetphoto (). ToString (); InsertStmt.bindString (3, PhotoURI); } And {insertStmt.bindNull (3); } Last long id = insertStmt.executeInsert (); // insertStmt.clearBindings (); // Not sure that it is required; insertStmt.close (); Db.close (); Return id; } For reference, my OpenHelper is here:
OpenHelper spreads Private Static class {OpenHelper {Reference reference} {Super (Reference, Database_Name, Null, DATABASE_VERSION); } @ Override Public Wide on Crate (SQLiteDatabase db) {Log D. (Tag, "db: openhalper: on creature:" + CREATE_CHILDREN_TABLE); Db.execSQL (CREATE_CHILDREN_TABLE); } @Override Public Zero onUpgrade (SQLiteDatabase db, integer oldVersion, integer NewVersion) {db.execSQL ("drop table if present" + TABLE_NAME); OnCreate (database); }} And finally, the variable, description and table:
private static last string table_name = "children"; Private static last string COL_NAME = "name"; Private static last string COL_BDAY = "birthday"; Private static final string COL_PHOTO = "photo"; Private static last string insert = "insert" + TABLE_NAME + "(" + COL_BDAY + "," + COL_NAME + "," + COL_PHOTO + ") values (" ??) "; Private Static Last String Update = "Update" + TABLE_NAME + "Set" + COL_BDAY + "=?" + COL_NAME + "=?" + COL_PHOTO + "=) Where?" + BaseColumns._ID + "=?"; Private static last string CREATE_CHILDREN_TABLE = "CREATE TABLE" + TABLE_NAME + "(" + BaseColumns._ID + "integer primary key autoincrement," + COL_BDAY + "no whole number NULL," + COL_NAME + "lesson lesson," + COL_PHOTO + "lesson Zero)"; What is happening is that for the first time I call all this works just fine, insert work, data exists, and I can export DB from my device to SQL Server I am The inserting post (...) does not work in breaking open the DB (...) that SQLiteBrowser does not display any tables or rows and it shows some things that opens inside the text editor; My guess is that DB is corrupt. No more rows are being added and I can not read it. Do not throw any errors. I'm guessing one of the two things here. First of all, my handles are not opening / closing correctly and some references are being bored by subsequent calls. Second, my understanding of prepared statements is faulty. The thing is that I look at the code and it looks fine. Open a database, be bound by a ready statement, execute, close statement, close database.
Anyone willing to help me out of this? I am entering, searching for exceptions, and trying to do things, but nothing is working. I think that I can remember a bit of detail that he or I am going crazy.
Thank you,
Update I changed my focus to the thread because the problem does not reproduce on my emulator. View link:
You always have it The Hrurt should always connection open or open it before you insert all before closing it.
Comments
Post a Comment