2011-06-10 84 views
1

我有兩個表:Android上的SQLite查詢?

CREATE TABLE APTable (id_Ap INTEGER PRIMARY KEY AUTOINCREMENT, 
SSID TEXT, 
BSSID TEXT, 
Id_APtest INTEGER NOT NULL, 
FOREIGN KEY (Id_APtest) REFERENCES Tests (id_test) ON DELETE CASCADE) 

CREATE TABLE APmeasure (id_APmeasure INTEGER PRIMARY KEY AUTOINCREMENT, 
RSSI TEXT, 
TimeOfMeasure DATETIME, 
BSSID TEXT, 
id_APm INTEGER NOT NULL, 
FOREIGN KEY (id_APm) REFERENCES APTable (id_Ap) ON DELETE CASCADE) 

我想檢查是否存在APTable其中BSSID = xid_Aptest=y一個id_Ap,並返回id_Ap值。

我該如何在Android API查詢中做到這一點?

回答

0
// pass in x and y (must be strings or converted to strings) as query 
// parameters to the database query. 
Cursor cursor = db.query("APTable", 
    new String[] { "id_Ap" }, 
    "BSSID = ? AND ip_Aptest = ?", 
    new String[] { x, y }, 
    null, 
    null, 
    null, 
    null); 

// get the value of id_Ap 
int id = cursor.getInt(0);