android-sqlite

Delete multiple rows using IDs?

六月ゝ 毕业季﹏ 提交于 2021-02-07 20:27:08
问题 How can I delete multiple rows by a list of IDs in Android SQLite database? I have defined a general delete method in this manner: protected void deleteWhere(String whereClause, String[] whereArgs) { try { databaseHelper.getWritableDatabase().delete( getTableName(), whereClause, whereArgs); } finally { databaseHelper.close(); } } And now I'm trying to call it with a list of IDs: public void deleteAll(Iterable<T> entities) { Iterable<Long> ids = Iterables.transform(entities, getId); String

Synchronize offline SQLite database with online MySQL database

谁都会走 提交于 2021-02-05 10:44:26
问题 I'm creating a Android application that store the data in online backend MySQL and store it in app sqllite . Which means when user is online, data sync with online backend database to sqlite database. When user offline, so he/she can use the sqlite data.is this proper way? Or what I can do to better solution ? 回答1: You should be using Sync Adapters. Checkout how it works in the following link and go further on the documentation for more info. https://developer.android.com/training/sync

How to filter in one to many relationship with android room db

好久不见. 提交于 2021-02-04 21:40:57
问题 I have a User Entity and a Record entity. I want to get a list that shows all users and their record list filtered by record's date. However, I got stuck with not being able to filter the result with conditions. def room_version = "2.2.5" implementation "androidx.room:room-runtime:$room_version" @Entity(tableName = "user_table") public class User { @PrimaryKey public long id; public String name; } @Entity(tableName = "record_table") public class Record { @PrimaryKey @ColumnInfo(name = "record

How do I merge two different tables to a single table?

淺唱寂寞╮ 提交于 2021-01-29 08:33:59
问题 I'm making an android-Base Point of Sale System and I'm straggling of combining two tables , I want The Table Foods and The Table Drinks are combined in the Table Menu. public static final String DATABASE_NAME = "FOODs.db"; //FOODs Tables name public static final String TABLE_FOODS = "table_Food"; public static final String TABLE_DRINKS = "table_drinks"; public static final String TABLE_MENU = "table_data"; //FOODs Table Columns name private static final String COL_1 = "Primary ID"; private

No such column SQLite

烈酒焚心 提交于 2021-01-29 07:06:11
问题 Okay i tried everyting i could, i saw all the posts here about this error and none of them solved my problem: Here is my simple update statement, i would like to increment each itemSlotIndex by 1 at a certain characterName String myQuery = "UPDATE " + theTable.getTableName() + " SET " + theTable.getItemSlotIndex() + " = " + theTable.getItemSlotIndex() + " + 1 WHERE " + theTable.getCharName() + " = "+character.getName(); Log.i("myQuery", myQuery); theDatabase.execSQL(myQuery); If this mumbo

Android - Pre-populated Database, insert or pre-loaded?

ε祈祈猫儿з 提交于 2021-01-27 12:31:32
问题 I am building an application which currently has 11 columns and 120~ rows of text data in one of its few tables. It will likely be the only table which is pre-populated for the user, however, I am trying to figure out what the best method is for populating the data. I see a few different options. Run insert statements during oncreate of the database Create a table in the assets folder which already has the data and copy it over when the application is created. What is the best practice for

How to convert Image into byte[] in Android

泪湿孤枕 提交于 2021-01-22 12:18:28
问题 I want to save image in sqlite. In this method I have got image path into string. My Question is How to convert it into byte[] format. if (resultCode == RESULT_OK) { // we need to update the gallery by starting MediaSanner service. mScanner = new MediaScannerConnection(ImagePreviewActivity.this,new MediaScannerConnection.MediaScannerConnectionClient() { public void onMediaScannerConnected() { mScanner.scanFile(imageUri.getPath(), null ); } public void onScanCompleted(String path, Uri uri) {

How do I select rows from table?

◇◆丶佛笑我妖孽 提交于 2020-12-26 11:24:09
问题 I'm making an app where MainActivity has a RecyclerView that contains the user's lists e.g. grocery list, weekly list, etc. When the user clicks on an item, it'll navigate to products activity also has a RecyclerView. I have 2 different SQLite databases 1:lists 2:products. The logic I used is when a user adds a list, the lists database will record list name and id, also adds list name in products database, and when user add product, I used update() instead of insert() in SQLite because the

onCreate() of RoomDatabase.Callback() was not called after a successful call to .build()

雨燕双飞 提交于 2020-12-11 09:02:33
问题 I have created MovieDatabase using Room Persisdent lib. According to the documentation of onCreate() method in RoomDatabase.Callback, onCreate() to be called after the database is created for the first time, and all the tables were created. What happend after I called buildPersistentDB() is, I received logs from MoviesDatabase class, the class that is annotated with @Database, but the logs from onCreate() in RoomDatabase.Callback were never called despite I called: this.mMovieDatabase = this

onCreate() of RoomDatabase.Callback() was not called after a successful call to .build()

对着背影说爱祢 提交于 2020-12-11 08:59:47
问题 I have created MovieDatabase using Room Persisdent lib. According to the documentation of onCreate() method in RoomDatabase.Callback, onCreate() to be called after the database is created for the first time, and all the tables were created. What happend after I called buildPersistentDB() is, I received logs from MoviesDatabase class, the class that is annotated with @Database, but the logs from onCreate() in RoomDatabase.Callback were never called despite I called: this.mMovieDatabase = this