SQLite的更新表导致“LIKE或GLOB模式过于复杂(代码1)”错误

时间:2015-07-19 08:02:37

标签: android sqlite bitmap

我正在尝试在SQLite数据库中保存位图字符串,但是当我尝试更新数据库时出现以下错误:LIKE or GLOB pattern too complex (code 1)

我从我的ImageView cropImageView获取了位图并将其转换为位图>字符串如下:

 UserDatabase db = new UserDatabase(getApplicationContext());
 HashMap<String, String> user = db.getUserDetails();

 Bitmap bitmap = ((BitmapDrawable) cropImageView.getDrawable()).getBitmap();
 String stringBitmap = bitMapToString(bitmap);
 db.updateUsers(user.get("image"), user.get("email"), user.get("username"), stringBitmap);

以下是我的UserDatabase代码:

    public class UserDatabase extends SQLiteOpenHelper {
    private static final int DATABASE_VERSION = 1;
    private static final String DATABASE_NAME = "login_database";
    private static final String TABLE_LOGIN = "login_table";

    // Column items
    private static final String KEY_IMAGE = "image";
    private static final String KEY_EMAIL = "email";
    private static final String KEY_USERNAME = "username";

    public UserDatabase(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    // Creating Tables
    @Override
    public void onCreate(SQLiteDatabase db) {
        String CREATE_TABLE = "CREATE TABLE " + TABLE_LOGIN + "("
                + KEY_IMAGE + " TEXT, "
                + KEY_EMAIL + " TEXT,"
                + KEY_USERNAME + " TEXT " + ");";

       db.execSQL(CREATE_TABLE);
    }

    // This method stores user details in database.
    public void addUser(String image, String email, String username) {
        SQLiteDatabase db = this.getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put(KEY_IMAGE, image); // Image
        values.put(KEY_EMAIL, email); // Email
        values.put(KEY_USERNAME, username); // Username

        // Inserting Row
        long id = db.insert(TABLE_LOGIN, null, values);
        db.close(); // Closing database connection

        Log.d(TAG, "New user inserted into sqlite: " + id);
    }

    // This method updates user information.
    public void updateUsers(String image, String email, String username, String latest_image) {
        String selection = KEY_IMAGE + " LIKE ? AND " + KEY_EMAIL + " LIKE ? AND " + KEY_USERNAME + " LIKE ? ";
        String[] args = { image, email, username };

        ContentValues values = new ContentValues();
        values.put(KEY_IMAGE, latest_image);

        SQLiteDatabase sqLiteDatabase = this.getWritableDatabase();
        sqLiteDatabase.update(TABLE_LOGIN, values, selection, args);
    }

}

1 个答案:

答案 0 :(得分:2)

documentation说:

  

LIKE或GLOB模式的长度限制为SQLITE_MAX_LIKE_PATTERN_LENGTH个字节。此限制的默认值为50000。

无论如何,不​​需要按图像内容搜索用户记录。只需使用主键即可。