Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
查询ContactsContract数据库,比较空字段和空字符串-Android_Android_Sqlite_Android Contentprovider_Android Contacts_Contactscontract - Fatal编程技术网

查询ContactsContract数据库,比较空字段和空字符串-Android

查询ContactsContract数据库,比较空字段和空字符串-Android,android,sqlite,android-contentprovider,android-contacts,contactscontract,Android,Sqlite,Android Contentprovider,Android Contacts,Contactscontract,我正在创建编辑联系人字段的方法。 在编辑之前,我要确保这些字段确实存在,并且与我要编辑的公司相对应,因此我选择并查找if(cursor.moveToFirst()),但由于某种原因,它不会进入if中。我只知道问题出在我的空字符串上如果我删除了它们,代码工作正常 我已经下载了电话联系人数据库,所以我确切地知道联系人数据库中有什么。这就是我硬编码变量的原因 这是我的密码: public Boolean editRawContactOrganization(String rawContactId, S

我正在创建编辑联系人字段的方法。 在编辑之前,我要确保这些字段确实存在,并且与我要编辑的公司相对应,因此我选择并查找
if(cursor.moveToFirst())
,但由于某种原因,它不会进入
if
中。我只知道问题出在我的空
字符串上
如果我删除了它们,代码工作正常

我已经下载了电话联系人数据库,所以我确切地知道联系人数据库中有什么。这就是我硬编码变量的原因

这是我的密码:

public Boolean editRawContactOrganization(String rawContactId, String oldCompany, String oldType, String oldLabel, String oldTitle, 
        String oldDepartment, String oldJobDescription, String oldSymbol, String oldPhoneticName, String oldLocation,
        String newCompany, String newType, String newLabel, String newTitle, String newDepartment, String newJobDescription, 
        String newSymbol, String newPhoneticName, String newOfficeLocation)
{
    final ContentValues cv = new ContentValues();

    final String filter = Organization.RAW_CONTACT_ID + "=? AND " 
            + Organization.COMPANY + "=? AND "
            + Organization.TYPE_WORK + "=? AND "
            + Organization.LABEL + "=? AND "
            + Organization.TITLE + "=? AND "
            + Organization.DEPARTMENT + "=? AND "
            + Organization.JOB_DESCRIPTION + "=? AND "
            + Organization.SYMBOL + "=? AND "
            + Organization.PHONETIC_NAME + "=? AND "
            + Organization.OFFICE_LOCATION + "=? AND "
            + Data.MIMETYPE + "=?";

    oldCompany = "Tone Inc.";
    oldType = "2";
    oldLabel = "";
    oldTitle = "The Big Boss";
    oldDepartment = "";
    oldJobDescription = "";
    oldSymbol = "";
    oldPhoneticName = "";
    oldLocation = "";


    final String[] selectionArgs = new String[] {rawContactId, oldCompany, oldType, oldLabel, oldTitle, oldDepartment, oldJobDescription,
            oldSymbol, oldPhoneticName, oldLocation, Organization.CONTENT_ITEM_TYPE};

    final String[] projection = new String[] { Organization._ID };

    final Cursor cursor = contentResolver.query(Data.CONTENT_URI, 
            projection, 
            filter, 
            selectionArgs, 
            null);

    if(cursor.moveToFirst())
    {
        Log.d(TAG, "SUCCESS: Organization found! ID: " + cursor.getString(0));
        cursor.close();
    }
    else
    {
        Log.d(TAG, "ERROR: Organization not found...");
        cursor.close();
        return false;
    }

    return false;
}
如您所见,这些变量是用我刚从手机下载的联系人数据库中看到的相应值硬编码的

oldCompany = "Tone Inc.";
oldType = "2";
oldLabel = "";
oldTitle = "The Big Boss";
oldDepartment = "";
oldJobDescription = "";
oldSymbol = "";
oldPhoneticName = "";
oldLocation = "";
但是我总是在
logcat上得到
错误:找不到组织…
输出 有人能告诉我错误在哪里吗

这里是一个工作示例,如果我取消注释注释注释的代码,我将得到未找到的输出(与上面的问题相同)。与上面的模式相同,注释的列内部没有值。即使在发送空字符串时,为什么不将空与空匹配?

public Boolean editRawContactWebsite(String rawContactId, String oldWebsite, String oldType, String oldLabel, 
        String newWebsite, String newType, String newLabel)
{
    final ContentValues cv = new ContentValues();

    final String filter = Website.RAW_CONTACT_ID + "=? AND " 
            + Website.URL + "=? AND "
            + Website.TYPE + "=? AND "
            //+ Website.LABEL + "=? AND "
            + Data.MIMETYPE + "=?";

    oldWebsite = "www.sitr.com";
    oldType = "7";
    oldLabel = "";


    final String[] selectionArgs = new String[] {rawContactId, oldWebsite, oldType, /*oldLabel,*/ Website.CONTENT_ITEM_TYPE};

    final String[] projection = new String[] { Website._ID };

    final Cursor cursor = contentResolver.query(Data.CONTENT_URI, 
            projection, 
            filter, 
            selectionArgs, 
            null);

    if(cursor.moveToFirst())
    {
        Log.d(TAG, "SUCCESS: website found! ID: " + cursor.getString(0));
        cursor.close();
    }
    else
    {
        Log.d(TAG, "ERROR: website not found...");
        cursor.close();
        return false;
    }
    return false;
}

我通过在contacts数据库中传递一个与我要编辑的行对应的ID来修复这个问题