android-sqlite

Using Loaders with sqlite query that returns object

老子叫甜甜 提交于 2020-01-05 04:04:25
问题 Here's what I've been doing all this while to get data from my database - my fragment will call a dbhelper which will run the query and pass the resulting data in an object. I should have used a loader so that the querying is not done in the UI thread, but previously I didn't bother since my app's database is very small. Moving forward, this was a bad idea since my app has grown larger and so do the database. So now I'm reading all I can about Loaders including CursorLoader and custom loaders

Don't have database lock! in android

情到浓时终转凉″ 提交于 2020-01-04 16:53:32
问题 I've been getting this error recently I know the cause but i don't know how to fix it. here is the error from the logcat: 10-05 02:34:00.177: E/SQLiteDatabase(1111): close() was never explicitly called on database '/data/data/standard.internet.marketing.mymovingfriend/databases/mymovingfriend' 10-05 02:34:00.177: E/SQLiteDatabase(1111): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here 10-05 02:34:00.177: E

Don't have database lock! in android

好久不见. 提交于 2020-01-04 16:52:49
问题 I've been getting this error recently I know the cause but i don't know how to fix it. here is the error from the logcat: 10-05 02:34:00.177: E/SQLiteDatabase(1111): close() was never explicitly called on database '/data/data/standard.internet.marketing.mymovingfriend/databases/mymovingfriend' 10-05 02:34:00.177: E/SQLiteDatabase(1111): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here 10-05 02:34:00.177: E

Room Migration Alter Table not adding new column & migrate getting called again and again

故事扮演 提交于 2020-01-03 18:46:20
问题 So basically i am using room and trying to add migration from database version 1 to 2 but my alter command is not working My current implementation is below : void init() { db = Room.databaseBuilder(Global.getInstance(), AppDatabase.class, "feed").addMigrations(MIGRATION_1_2).build(); } Migration property : static final Migration MIGRATION_1_2 = new Migration(1,2) { @Override public void migrate(SupportSQLiteDatabase database) { database.execSQL("ALTER TABLE 'post' ADD COLUMN 'age' INTEGER

Room Migration Alter Table not adding new column & migrate getting called again and again

假装没事ソ 提交于 2020-01-03 18:46:10
问题 So basically i am using room and trying to add migration from database version 1 to 2 but my alter command is not working My current implementation is below : void init() { db = Room.databaseBuilder(Global.getInstance(), AppDatabase.class, "feed").addMigrations(MIGRATION_1_2).build(); } Migration property : static final Migration MIGRATION_1_2 = new Migration(1,2) { @Override public void migrate(SupportSQLiteDatabase database) { database.execSQL("ALTER TABLE 'post' ADD COLUMN 'age' INTEGER

SQLite group by/count hours, days, weeks, year

徘徊边缘 提交于 2020-01-03 01:47:29
问题 Assume that we have a simple Android application that has only one button. Click on that button record the date and time of that click (in sqlite). I wondering what is the best format for that records keep a long or a string of that date-time. The purpose is to make reports that show: 1. sum of clicks that made for chosen day grouped by hours. 2. sum of clicks that made for chosen week grouped by days. 3. sum of clicks that made for chosen month grouped by weeks. 4. sum of clicks that made

No Such table in API 2.2

我与影子孤独终老i 提交于 2020-01-02 13:45:28
问题 Everything goes successful in my app in higher versions, but in the lower versions like 2.2 the app crashes while fetching data from database with this error 07-17 21:46:36.361: I/Database(520): sqlite returned: error code = 1, msg = no such table: Schedules 07-17 21:46:36.371: W/System.err(520): android.database.sqlite.SQLiteException: no such table: Schedules: , while compiling: SELECT DISTINCT * FROM Schedules 07-17 21:46:36.391: W/System.err(520): at android.database.sqlite

IllegalStateException: database already closed (using ViewPager)

蹲街弑〆低调 提交于 2020-01-02 04:44:09
问题 I'm stumped as to what is causing this error, as I have made sure that I am closing my database adapter properly (at least I think I am). Here's what LogCat's saying (the tag for all of them is AndroidRuntime): FATAL EXCEPTION: main java.lang.IllegalStateException: database /data/data/com.acedit.assignamo/databases/data.db (conn# 0) already closed at android.database.sqlite.SQLiteDatabase.verifyDbIsOpen(SQLiteDatabase.java:2082) at android.database.sqlite.SQLiteDatabase.lock(SQLiteDatabase

GreenDAO support multiple relations between tables

孤人 提交于 2020-01-02 00:59:47
问题 I've been trying to create a DB model using GreenDAO. the problem started when I tried to create more than one relationship between a different tables. basically, I have a Message table, a Conversation table and a User table. the User has a list of messages, and the message has a parent conversation. I tried writing this code for creating the DB: private static void addUser(Schema schema) { user = schema.addEntity("User"); userId = user.addIdProperty().getProperty(); user.addStringProperty(

Get the SQLite path within the Assets Folder

邮差的信 提交于 2020-01-01 15:45:29
问题 I'm developing an application and I've run into two problems here: How can I open an SQLite database which is stored in the assets folder? What path do I use to access the assets folder in my application? Here's what I have so far: path = "file:///asset_folder/database.dat"; SQLiteDatabase db = null; db = SQLiteDatabase.openDatabase(path, null, SQLiteDatabase.OPEN_READONLY); How can I copy a file to the internal memory ( /data/data/... ) during the installation of my application or during the