Simply trying to set an integer to be the size of the rows in one of my columns in my sql database.
int x = db.execSQL("SELECT COUNT"+ COL_2);
Not sure what the easiest way to do this would be. Thanks
public class DatabaseSQL extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "simpleNotes.db";
private static final String TABLE_NAME = "titles_notes";
private static final String COL_1 = "ID";
private static final String COL_2 = "TITLES";
private static final String COL_3 = "NOTES";
public DatabaseSQL(Context context) {
super(context, DATABASE_NAME,null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
//creates table...
db.execSQL("CREATE TABLE " + TABLE_NAME + " (ID INTEGER PRIMARY KEY, TITLES TEXT, NOTES TEXT )");
}
@Override
public void onUpgrade(SQLiteDatabase db, int i, int i1) {
db.execSQL("DROP TABLE IF EXISTS" + TABLE_NAME);
onCreate(db);
}
public boolean insertData(int key, String title, String notes){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL_1,key);
contentValues.put(COL_2,title);
contentValues.put(COL_3,notes);
long result = db.insert(TABLE_NAME,null,contentValues);
if(result == -1){
return false;
}else{
return true;
}
}
public Cursor getAllData(){
SQLiteDatabase db = this.getWritableDatabase();
Cursor res = db.rawQuery("select * from "+ TABLE_NAME,null);
return res;
}
public Integer deleteData (String id) {
SQLiteDatabase db = this.getWritableDatabase();
return db.delete(TABLE_NAME, "ID = ?",new String[] {id});
}
}
My plan is to get the size of the row of COL_2 then ->set the ID to be that size. My problem is that when I delete my data I need to have the number of rows so that I can set the ID in proportion to the size or rows.
Perhaps I can create a simple getter method to return this when called from another class?