Android Content Provider Query应该为false时返回true

时间:2013-06-10 14:15:50

标签: android sqlite

我对Android开发相当新,我试图使用内容提供程序插入到表中,然后检查表并检索记录是否存在。它继续说它存在,但它不是我正在搜索的记录。

            Cursor c = contentResolver.query(ContentDescriptor.Survey.CONTENT_URI, projection, 
                ContentDescriptor.Survey.Cols.SURVEYNAME + " =?", new String[] {surveyName}, null);
        if((c != null) && (c.moveToFirst())){
            //-----------------------------------------------------------------------------------
            //what if it does exist do something here
            Toast.makeText(getBaseContext(), "Survey Already Exists " + surveyName, Toast.LENGTH_SHORT).show();
            Intent i = new Intent().setClass(CreateSurveyActivity.this, PickSurveyActivity.class);              
        }
        else{
            //does not exist in database
            survey = SurveyRepository.instance().createNewSurvey(context, surveyName);
            Log.i(TAG, "survey did not exist creating survey");
            SurveyRepository.instance().loadContent(context);
        }
        c.close();
    }

1 个答案:

答案 0 :(得分:0)

query方法中,您不会将选择放在您所做的查询中。

因此,忽略SURVEYNAME + " =?"

你需要打电话:

return builder.query(db, projection, selection, selectionArgs, null, null, sortOrder);

将您的参数传递给您的数据库。