Questions tagged [android-database]

General programmatic usage of databases on Android

Databases and tools related with persistence supported by the Android operating system.

584 questions
8
votes
2 answers

Define one-to-many relationship among Room entities for Chat model

I started using Room database and went through several docs to create room entities. These are my relations. A Chat Channel can have Many Conversations. So this goes as one-to-many relationship. Hence i created entities as below. Channel…
8
votes
2 answers

How can I update a TypeConverted column of an entity in Room Dao function

I have an @Entity which holds a variable(list of custom object) along with other fields for the table. I am able to insert, fetch and delete from this entity. But I am facing an issue in updating the entity: I want to update that particular field…
skygeek
  • 1,548
  • 11
  • 24
8
votes
1 answer

Insert an object inside an object using android room persistence library

Directory @Entity(tableName = "directory") class Directory(@PrimaryKey(autoGenerate = false) var id: Int? = null, @ColumnInfo(name = DIR_NAME) var dirName: String? = null, @Ignore var dirImages: List? =…
8
votes
1 answer

Sugar ORM listAll() not showing any data

I'm trying to get data from databse in a listview as shown below. long count = UserTableSugar.count(UserTableSugar.class); if(count>0) { UserTableSugar.listAll(UserTableSugar.class); List userTable =…
Aakash Joshi
  • 147
  • 8
8
votes
1 answer

How to store the audio/Video file to SQLite database in android.?

Am new to developing, am successfully store the images to database by converting the images in to bytes array and store it to SQLite database in BLOB (find below code). But am not getting how to store audio's/video's into DB any one help me PLZ... …
7
votes
1 answer

Android Room Relations with multiple parentColumn and entityColumn

Let's say that you have a Room database with two tables (entities) that are related using foreign key. (This is just a simplified example, so no need to propose a new data structure :) ) @Entity(tableName = "Streets", primaryKeys = {"Country",…
Raz
  • 458
  • 4
  • 11
7
votes
3 answers

Android - When does insertOrThrow() throw an exception?

Before reading the documentation, I would have expected SQLiteDatabase's insertOrThrow() method to have thrown an exception if the insert wasn't successful. However, the documentation says that the insertOrThrow() method returns the row ID of the…
ban-geoengineering
  • 18,324
  • 27
  • 171
  • 253
6
votes
0 answers

Why Room.databaseBuilder function requires context as the parameter in a Room database?

companion object { @Volatile private lateinit var instance: ExampleDatabase fun getInstance(context: Context): ExampleDatabase { synchronized(this) { if(!::instance.isInitialized) { …
goodonion
  • 1,401
  • 13
  • 25
6
votes
7 answers

Map new POJO class with lesser fields to an existing Room table

Currently, we have the following Dao and model class. NoteDao @Query("SELECT * FROM note") public abstract LiveData> getAllNotes(); Note class @Entity( tableName = "note" ) public class Note { @ColumnInfo(name = "title") …
Cheok Yan Cheng
  • 47,586
  • 132
  • 466
  • 875
6
votes
0 answers

Room TypeConverter transform multiple DB columns into one field?

Is there a way to have one Room TypeConverter that will take multiple table fields and combine them into some object? As an example, let's assume I have a table Foo that has columns INT numerator, INT denominator (together representing a fraction),…
user1713450
  • 1,307
  • 7
  • 18
6
votes
5 answers

Room Database distinct value

I am trying to integrate the room database in my android application. Now I want to query distinct result from DB but I am getting this error: error: The columns returned by the query does not have the fields [id] in com.abc.def.model.User even…
Harsh Shah
  • 2,162
  • 2
  • 19
  • 39
6
votes
5 answers

SQLite: No Such Table Error Android P problem

Until Android P everything worked fine with my code but now in Android P I'm having a lot of problems working with databases. I have .db SQLite database files stored on assets folder. I was importing them into the database space of Android and it…
6
votes
1 answer

Joining tables in a ROOM database

This is my first ROOM implementation. I have a User class which has a list of Pets as one of its member variables. public class User { String id; String name; List pets; } Public class Pets { String id; String type; } How…
6
votes
0 answers

Failed to change locale for db '/data/data/com.scoreup/databases/scoreUp' to 'en_GB'

I have recently updated one of my application and I get the above error in very rare cases. This error occurs only when the user tries to update the app over the existing one. This doesn't happen every time and on every device. I have found a…
Anudeep
  • 1,520
  • 1
  • 19
  • 38
6
votes
2 answers

IllegalArgumentException: Unknown URL content:// CONTENT

IllegalArgumentException: Unknown URL content:// ^ Having a nightmare with the above. I've checked my variables and paths but can't see what the issue is? Greatly appreciate any pointers! Here's my trace. java.lang.IllegalArgumentException: Unknown…
1
2
3
38 39