在我的Android程序中,我正在尝试使用带有选择参数的managedQuery,但是我得到了一个Sql异常。
07-26 19:30:44.364: INFO/Database(1163):
sqlite returned: error code = 1, msg = near ".": syntax error
这是我的示例代码
String[] proj = { MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.DATA, MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.ARTIST, MediaStore.Audio.Media.ALBUM_ID,
MediaStore.Audio.Media.IS_MUSIC };
// Example without selection, works
String selection = null;
Cursor musiccursor = managedQuery(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, proj, selection, null,
null);
// Example with selection, does not work
selection = "MediaStore.Audio.Media._ID = 1";
musiccursor = managedQuery(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, proj, selection, null,
null);
谢谢,Niclas
答案 0 :(得分:1)
选择应该像这样初始化:
selection = MediaStore.Audio.Media._ID +“= 1”;
如果在引号中包含MediaStore.Audio.Media._ID,则将常量名称发送给SQLite以评估而不是实际的列名_id。