2013-05-09 57 views
0

我有以下表列的Android sqlight與多個地方

public static final String SHOWID = "show_id"; 
    public static final String SHOWNAME = "show_name"; 
    public static final String SHOWSEASON = "season_name"; 
    public static final String EPISODENAME = "episode_name"; 
    public static final String EPISODESTATUS = "episode_status"; 

我想要做下面的查詢

SELECT episode_name , episode_status FROM tv_show WHERE show_name='aName' AND season_name='aSeason'"; 

如何做到這一點?

我不想使用db.rawQuery(...)

我想用這樣的

db.query(
       true, 
       DBTABLE, 
       new String[] {SHOWSEASON}, 
       SHOWNAME + " like ?", 
       new String[] { String.valueOf(shName) }, 
       null, null, null, null 
       ); 

回答

1

這是基本的SQL,快速搜索,你會發現解決方案:

SELECT episode_name , episode_status FROM tv_show WHERE show_name='aName' AND season_name='aSeason'"; 

你必須使用AND,不&

你可以做類似的事情,如果需要的話用'LIKE'代替'=':

Cursor cursor = db.query(TVSHOW_TABLE, new String[] { EPOSIDENAME, EPISODESTATUS }, SHOWNAME + "='" + aName + "' AND " + SEASONNAME + "='" + aSeason + "'", null, null, null, null); 
+0

請看我編輯的問題。併爲那個愚蠢的錯誤感到抱歉 – LynAs 2013-05-09 14:04:04

+0

感謝它的工作。和FYI有一個(')失蹤之前AND – LynAs 2013-05-09 14:33:26

+1

不客氣,我修復並添加了缺少的報價。 – 2013-05-09 14:35:22