Android - 用于查找已删除标志的 SQLite 查询 - 未找到异常 DELETED 列
Posted
技术标签:
【中文标题】Android - 用于查找已删除标志的 SQLite 查询 - 未找到异常 DELETED 列【英文标题】:Android - SQLite query to look for the deleted flag - Exception DELETED column not found 【发布时间】:2014-07-19 06:28:44 【问题描述】:我正在尝试从 android 的联系人存储数据库中过滤掉联系人和数据。为此,我使用了 DELETED 过滤器。
来自here,它说可以使用Data.DELETED
访问它,但要么我做错了我无法弄清楚它在哪里,要么文档似乎有问题。
我对每个查询都使用了一个游标,但我不知道是哪一个导致了异常。 这是我的光标:
final Cursor cursorPhoneNumber = contentResolver.query(Phone.CONTENT_URI, projectionPhoneNumber, Data.MIMETYPE + " =? AND " + Phone.DELETED + " != 1", new String[]Phone.CONTENT_ITEM_TYPE, phoneQueryOrder);
final Cursor cursorStructuredName = contentResolver.query(Data.CONTENT_URI, projectionStructuredName, Data.MIMETYPE + " =? AND " + Data.DELETED + " != 1", new String[]StructuredName.CONTENT_ITEM_TYPE, null);
final Cursor cursor = contentResolver.query(Data.CONTENT_URI, projectionEmail, Data.MIMETYPE + " =? AND " + Data.DELETED + " != 1", new String[]Email.CONTENT_ITEM_TYPE, null);
final Cursor cursor = contentResolver.query(Data.CONTENT_URI, projectionStructuredPostal, Data.MIMETYPE + " =? AND " + Data.DELETED + " != 1", new String[]StructuredPostal.CONTENT_ITEM_TYPE, null);
final Cursor cursor = contentResolver.query(Data.CONTENT_URI, projectionOrganization, Data.MIMETYPE + " =? AND " + Data.DELETED + " != 1", new String[]Organization.CONTENT_ITEM_TYPE, null);
final Cursor cursor = contentResolver.query(Data.CONTENT_URI, projectionInstantMessaging, Data.MIMETYPE + " =? AND " + Data.DELETED + " != 1", new String[]Im.CONTENT_ITEM_TYPE, null);
final Cursor cursor = contentResolver.query(Data.CONTENT_URI, projectionNickname, Data.MIMETYPE + " =? AND " + Data.DELETED + " != 1", new String[]Nickname.CONTENT_ITEM_TYPE, null);
final Cursor cursor = contentResolver.query(Data.CONTENT_URI, projectionNote, Data.MIMETYPE + " =? AND " + Data.DELETED + " != 1", new String[]Note.CONTENT_ITEM_TYPE, null);
final Cursor cursor = contentResolver.query(Data.CONTENT_URI, projectionPhoto, Data.MIMETYPE + " =? AND " + Data.DELETED + " != 1",
new String[]android.provider.ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE,
null);
final Cursor cursor = contentResolver.query(Data.CONTENT_URI, projectionWebsites, Data.MIMETYPE + " =? AND " + Data.DELETED + " != 1", new String[]Website.CONTENT_ITEM_TYPE, null);
final Cursor cursor = contentResolver.query(Data.CONTENT_URI, projectionEvents, Data.MIMETYPE + " =? AND " + Data.DELETED + " != 1", new String[]Event.CONTENT_ITEM_TYPE, null);
我的预测,不认为它们在这里是相关的,但如果它们真的是:
// Phone numbers
private static final String[] projectionPhoneNumber = new String[]
Phone.CONTACT_ID, // 0
Phone.RAW_CONTACT_ID, // 1
Phone.TYPE, // 2
Phone.LABEL, // 3
Phone.NUMBER // 4
;
// Structured Name
private static final String[] projectionStructuredName = new String[]
StructuredName.CONTACT_ID, // 0
StructuredName.RAW_CONTACT_ID, // 1
StructuredName.DISPLAY_NAME, // 2
StructuredName.GIVEN_NAME, // 3
StructuredName.FAMILY_NAME, // 4
StructuredName.PREFIX, // 5
StructuredName.MIDDLE_NAME, // 6
StructuredName.SUFFIX // 7
;
// Email
private static final String[] projectionEmail = new String[]
Email.CONTACT_ID, // 0
Email.RAW_CONTACT_ID, // 1
Email.ADDRESS, // 2
Email.TYPE, // 3
Email.LABEL // 4
;
// Structured Postal
private static final String[] projectionStructuredPostal = new String[]
StructuredPostal.CONTACT_ID, // 0
StructuredPostal.RAW_CONTACT_ID, // 1
StructuredPostal.FORMATTED_ADDRESS, // 2
StructuredPostal.TYPE, // 3
StructuredPostal.LABEL, // 4
StructuredPostal.STREET, // 5
StructuredPostal.POBOX, // 6
StructuredPostal.NEIGHBORHOOD, // 7
StructuredPostal.CITY, // 8
StructuredPostal.REGION, // 9
StructuredPostal.POSTCODE, // 10
StructuredPostal.COUNTRY // 11
;
// Organization
private static final String[] projectionOrganization = new String[]
Organization.CONTACT_ID, // 0
Organization.RAW_CONTACT_ID, // 1
Organization.COMPANY, // 2
Organization.DEPARTMENT, // 3
Organization.JOB_DESCRIPTION, // 4
Organization.OFFICE_LOCATION // 5
;
// InstantMessaging
private static final String[] projectionInstantMessaging = new String[]
Im.CONTACT_ID, // 0
Im.RAW_CONTACT_ID, // 1
Im.PROTOCOL, // 2
Im.CUSTOM_PROTOCOL // 3
;
// Nickname
private static final String[] projectionNickname = new String[]
Nickname.CONTACT_ID, // 0
Nickname.RAW_CONTACT_ID, // 1
Nickname.NAME // 2
;
// Note
private static final String[] projectionNote = new String[]
Note.CONTACT_ID, // 0
Note.RAW_CONTACT_ID, // 1
Note.NOTE // 2
;
// Photo
private final String[] projectionPhoto = new String[]
android.provider.ContactsContract.CommonDataKinds.Photo.CONTACT_ID,
android.provider.ContactsContract.CommonDataKinds.Photo.RAW_CONTACT_ID
;
// Websites
private final String[] projectionWebsites = new String[]
Website.CONTACT_ID,
Website.RAW_CONTACT_ID,
Website.URL,
Website.TYPE
;
// Events
private final String[] projectionEvents = new String[]
Event.CONTACT_ID,
Event.RAW_CONTACT_ID,
Event.START_DATE,
Event.TYPE
;
这是一个例外:
05-29 05:41:32.607: E/SQLiteLog(1561): (1) no such column: deleted
05-29 05:41:32.611: E/DatabaseUtils(1561): Writing exception to parcel
05-29 05:41:32.611: E/DatabaseUtils(1561): android.database.sqlite.SQLiteException: no such column: deleted (code 1): , while compiling: SELECT contact_id, raw_contact_id, data2, data3, data1 FROM view_data data LEFT OUTER JOIN (SELECT data_usage_stat.data_id, SUM(data_usage_stat.times_used) as times_used, MAX(data_usage_stat.last_time_used) as last_time_used FROM data_usage_stat GROUP BY data_id) as data_usage_stat ON (data_usage_stat.data_id=data._id) WHERE (1 AND mimetype_id=5) AND ((mimetype =? AND deleted != 1)) ORDER BY contact_id ASC
05-29 05:41:32.611: E/DatabaseUtils(1561): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
05-29 05:41:32.611: E/DatabaseUtils(1561): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
05-29 05:41:32.611: E/DatabaseUtils(1561): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
05-29 05:41:32.611: E/DatabaseUtils(1561): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
05-29 05:41:32.611: E/DatabaseUtils(1561): at android.database.sqlite.SQLiteQueryBuilder.validateQuerySql(SQLiteQueryBuilder.java:412)
05-29 05:41:32.611: E/DatabaseUtils(1561): at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:389)
05-29 05:41:32.611: E/DatabaseUtils(1561): at com.android.providers.contacts.ContactsProvider2.query(ContactsProvider2.java:6438)
05-29 05:41:32.611: E/DatabaseUtils(1561): at com.android.providers.contacts.ContactsProvider2.queryLocal(ContactsProvider2.java:6386)
05-29 05:41:32.611: E/DatabaseUtils(1561): at com.android.providers.contacts.ContactsProvider2.query(ContactsProvider2.java:4999)
05-29 05:41:32.611: E/DatabaseUtils(1561): at android.content.ContentProvider$Transport.query(ContentProvider.java:200)
05-29 05:41:32.611: E/DatabaseUtils(1561): at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:112)
05-29 05:41:32.611: E/DatabaseUtils(1561): at android.os.Binder.execTransact(Binder.java:404)
05-29 05:41:32.611: E/DatabaseUtils(1561): at dalvik.system.NativeStart.run(Native Method)
编辑 导致异常的光标似乎是列表中的第一个光标。
【问题讨论】:
你的表定义显示了什么?请你把那个贴出来好吗?异常很明显,它没有找到该列。 这是Android的联系人存储数据库,Android存储联系人的地方。 DELETED 字段是一个整数。我回答你的问题了吗? @AndroidAddict 我在联系人数据库中找不到名为deleted
的列:developer.android.com/reference/android/provider/…
【参考方案1】:
我认为您对正在访问的内容感到困惑。根据跟踪,您正在访问定义为here 的联系人表。你认为你正在访问raw contacts。
在定义中很明显,联系人表中没有delete
列,您的错误支持这一点。
【讨论】:
以上是关于Android - 用于查找已删除标志的 SQLite 查询 - 未找到异常 DELETED 列的主要内容,如果未能解决你的问题,请参考以下文章