只需尝试将整数设置为我的sql数据库中某列中行的大小。
int x = db.execSQL("SELECT COUNT"+ COL_2);
不确定最简单的方法是什么。感谢
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});
}
}
我的计划是获取COL_2行的大小然后 - >将ID设置为该大小。我的问题是,当我删除我的数据时,我需要有行数,以便我可以按大小或行的比例设置ID。
也许我可以创建一个简单的getter方法,在从另一个类调用时返回它?