|
-
November 23rd, 2010, 11:51 AM
#1
Android SQLite Database problems
I'm having issues getting my SQLite database in Android to work. It previously worked fine, except now whenever I add something a -1 is returned as the RowId. The only thing I changed was how the database is initially created so I suspect I may have screwed up something there, I'm just not sure what. Here's my code, thanks in advance for the help and let me know if you have any more questions.
private static final String DATABASE_NAME = "data";
private static final String DATABASE_TABLE = "info";
private static final int DATABASE_VERSION = 2;
public static final String KEY_BODY = "body";
public static final String KEY_ROWID = "id";
private final Context myCtxt;
private DatabaseHelper DataHelper;
private static SQLiteDatabase database;
private static final String DATABASE_CREATE =
"create table info (id integer primary key autoincrement, "
+ "body text not null);";
private static class DatabaseHelper extends SQLiteOpenHelper
{
DatabaseHelper(Context context)
{
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db)
{
db.execSQL(DATABASE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS notes");
onCreate(db);
}
}
public MedicalInfo(Context ctxt) {
this.myCtxt = ctxt;
}
public MedicalInfo open() throws SQLException {
DataHelper = new DatabaseHelper(myCtxt);
database = DataHelper.getWritableDatabase();
return this;
}
public long addInfo(String body)
{
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_BODY, body);
return database.insert(DATABASE_TABLE, null, initialValues);
}
-
November 23rd, 2010, 04:58 PM
#2
Re: Android SQLite Database problems
Since you said the problem may be independent of your java code, and instead be caused by the way you recreated the database and/or tables, why don't you trying doing the update without using java, and seeing what is being returned for the rowid. That way you will get a better idea of where the problem is.
-
July 3rd, 2012, 07:18 AM
#3
Re: Android SQLite Database problems
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|