Momo1199
Momo1199
采纳率90.9%
2013-04-25 07:29 阅读 4.0k

Android SQLite查询报错

在运行查询语句时,报错语法错误:

inal 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): Caused by: android.database.sqlite.SQLiteException: near "AS": syntax error (code 1): , while compiling: SELECT CASE WHEN createduser = 112 THEN (createdplayerpts AS you AND connectedplayerpts AS them) ELSE (connectedplayerpts AS you AND createdplayerpts AS them) FROM game WHERE (turn = ?)
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    baimy1985 balmy 2013-04-25 11:28

    类似这种SQL语法错误可以把你的语句先放到sql工具中执行下,首先确保sql语句本身没错,再检查你的代码有没有笔误,类似缺少逗号,括号不匹配这些。

    点赞 1 评论 复制链接分享
  • Kakalapa1986 Kakalapa1986 2013-04-25 08:17
    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 = ?)
    
    点赞 评论 复制链接分享

相关推荐