|
-
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);
}
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
|