Android SQLite查询ContentProvider Case Statement语法

时间:2013-04-25 03:01:51

标签: android sqlite case

我在运行此查询时收到错误,任何线索我的语法错误是什么?

final Cursor c = getContentResolver().query(
Provider.GAME_URI, new String[]{"CASE WHEN " +DBHelper.COLUMN_CRE_USER + " = " + preferences.getInt(LoginScreen.ID, 0) + " THEN (" + DBHelper.COLUMN_CRE_PTS + " AS you AND " + DBHelper.COLUMN_CON_PTS + " AS them) ELSE (" + DBHelper.COLUMN_CON_PTS + " AS you AND " + DBHelper.COLUMN_CRE_PTS + " AS them)"},"turn = ?",
new String[] { preferences.getInt(LoginScreen.ID, 0) + ""}, null);
  

04-24 19:57:48.345:E / AndroidRuntime(18775):引起:android.database.sqlite.SQLiteException:near“AS”:语法错误(代码1):,编译时:SELECT CASE WHEN createduser = 112然后(创建的播放器,你和他们连接的播放器)ELSE(你和他们创建的播放器是连接的播放器)来自游戏WHERE(转=?)

1 个答案:

答案 0 :(得分:1)

试试这个。

SELECT 
    CASE WHEN createduser = 112 THEN createdplayerpts ELSE connectedplayerpts END AS you,
    CASE WHEN createduser = 112 THEN connectedplayerpts ELSE createdplayerpts END AS them
FROM 
    game WHERE (turn = ?)