Android - SQLite查询以查找已删除的标志 - 未找到Exception DELETED列

时间:2014-05-29 16:51:43

标签: android sqlite android-contacts

我试图过滤掉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)

修改 导致异常的游标似乎是列表中的第一个游标。

1 个答案:

答案 0 :(得分:0)

我认为你在混淆你正在访问的内容。根据跟踪,您将访问定义为here的联系人表。您认为您正在访问raw contacts

在定义中很明显,联系人表格中没有delete列,您的错误支持该列。