0

私はアンドロイド開発にかなり慣れていません。コンテンツプロバイダーを使用してテーブルに挿入し、テーブルをチェックして、存在する場合はレコードを取得しようとしています。存在すると言い続けていますが、私が探していたレコードではありません。

            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 に答える