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
在Android中通过SQLiteDatabase.delete()中的限制1_Android_Sqlite_Android Contentprovider - Fatal编程技术网

在Android中通过SQLiteDatabase.delete()中的限制1

在Android中通过SQLiteDatabase.delete()中的限制1,android,sqlite,android-contentprovider,Android,Sqlite,Android Contentprovider,//在内容提供商中 public int delete(Uri uri, String selection, String[] selectionArgs) { int uriType = sURIMatcher.match(uri); SQLiteDatabase sqlDB = myDB.getWritableDatabase(); int rowsDeleted = 0; switch (u

//在内容提供商中

public int delete(Uri uri, String selection, String[] selectionArgs) {

            int uriType = sURIMatcher.match(uri);
            SQLiteDatabase sqlDB = myDB.getWritableDatabase();
            int rowsDeleted = 0;

            switch (uriType) {
            case STUDENTS:
    //          rowsDeleted = sqlDB.delete(MyDBHandler.TABLE_STUDENTS, selection,  selectionArgs);
                rowsDeleted = sqlDB.delete(MyDBHandler.TABLE_STUDENTS, selection + " ?",  new String [] {"limit 1"});


                break;
default:
            throw new IllegalArgumentException("Unknown URI: " + uri);
        }
        getContext().getContentResolver().notifyChange(uri, null);
        return rowsDeleted;
    }
内容内解析器

    private ContentProviderClient myCR;
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/"+ STUDENT_TABLE);

        public MyDBHandler(Context context, String name, CursorFactory factory, int version) {
            super(context, DATABASE_NAME, factory, DATABASE_VERSION);
            myCR = 

context.getContentResolver().acquireContentProviderClient(CONTENT_URI);
        public boolean deleteStudent(String studentName) {  
    String selection = "sName = " + studentName +  " LIMIT 1";
        rowsDeleted = myCR.delete(CONTENT_URI, selection,null);

//also tried this
String selection = "sName = " + studentName ;
rowsDeleted = myCR.delete(CONTENT_URI.buildUpon().encodedQuery("limit 1").build(), selection,null);

有一个student表,我正在根据名称从中删除条目,由于可能有许多同名的学生,我想限制delete函数仅删除第一个条目。请不要告诉我使用学生注册号删除。

编译到Android中的SQLite不允许使用
限制
子句来删除
语句

您必须使用
限制1执行
选择
(或仅读取第一条返回的记录),并使用学生注册号使用返回的ID进行删除