How to use MAC address as primary key for my sqlite database: I can easily populate the database, and select *.
The problem is that I defined the MAC address to be CHAR(17) in order to get all characters and the collins
private static final String SQL_CREATE_TABLE_DEVICE = "CREATE TABLE " + TABLE_DEVICE + "("
+ COLUMN_DEVICE_MAC + " CHAR(17) PRIMARY KEY, "
+ COLUMN_DEVICE_LAST_TIME_DETECTION + " NUMERIC, "
+ COLUMN_DEVICE_LAST_TIME_RANGE + " REAL, "
+ COLUMN_DEVICE_DETECTION_FREQUENCY + " INTEGER, "
+ COLUMN_DEVICE_CUMULATIVE_DETECTION_DURATION + " REAL, "
+ COLUMN_DEVICE_PHONE_NUMBER + " VARCHAR(50), "
+ COLUMN_DEVICE_DESCRIPTIVE_NAME + " TEXT "
+");";
But, then when fetching a row based on the primary key, I am having an issue since i am passing the MAC from the MAIN activity as string and also i am confusing how to use the quotations:
public Cursor getDatabyMAC(String MAC)
{
SQLiteDatabase db =this.getWritableDatabase();
Cursor result = db.rawQuery("select * from "+TABLE_DEVICE+" where _Did =? ",new String[]{MAC});
return result;
}
or
public Cursor getDatabyMAC(String MAC)
{
SQLiteDatabase db =this.getWritableDatabase();
Cursor result = db.rawQuery("select * from "+TABLE_DEVICE+" where _Did = '"+device_ID+"'",null);
return result;
}
Neither works by the way.
(Below is the main call)
public void onbtnclick2(View view) {
Cursor result2 = myDb.getDatabyMAC("01:53:45:67:87:AE");
txt_ReadSpecific.setText(result2.getCount());
}
Aucun commentaire:
Enregistrer un commentaire