0

我对 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();
    }
4

1 回答 1

0

在您的query方法中,您没有将选择放入您所做的查询中。

因此,SURVEYNAME + " =?"被忽略。

你需要调用类似的东西:

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

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

于 2013-06-10T14:30:28.330 回答