I'm trying to save bitmap string in SQLite database, but instead I get the following error when I tried updating my database: LIKE or GLOB pattern too complex (code 1)
I've gotten the bitmap from my ImageView cropImageView
and converted it into bitmap > string as follows:
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);
Here is my code for 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);
}
}
Aucun commentaire:
Enregistrer un commentaire