React-Native: Async Storage no such table - android

At the opening of my app I'm trying to get some preferences via AsyncStorage.multiGet or AsyncStorage.getItem. Unfortunately the very first time I open the app, the SQLite table used by AsyncStorage in Android, doesn't exist. And so the app crashes. How should I handle the error to avoid having a red death screen.
FYI the exception thrown is :
no such table: catalystLocalStorage (code 1): , while compiling: INSERT OR REPLACE INTO catalystLocalStorage VALUES (?, ?);
Thanks

Related

Syntax Error using Vacuum Into on Android

I'm trying to make a backup of a database in an Android application, and I was pointed to the VACUUM INTO query. However, when I try to call it, I get a syntax error around "INTO":
Caused by: android.database.sqlite.SQLiteException: near "INTO": syntax error (code 1 SQLITE_ERROR): , while compiling: VACUUM INTO 'Test'
The String itself:
String query = "VACUUM INTO 'Test'";
I've tried using double quotes, single quotes, different path names, .db, no file type, including and excluding the database name - always the same error.
Is INTO not supported on Android's implementation of SQLite?

Error in studio SQLiteException: json_each

I have json Array in my column and i want to extract json array as separate values I am using sqlite query
SELECT
json_extract(t2.value, '$.time') as time
FROM
json_each((SELECT column_name
FROM tbl_name)) AS t2
My column looks like this
[{"time":0,"value":0},{"time":2,"value":0},{"time":0,"value":0}]
It works fine in sqlite browser but I get an error in Android studio.
SQLiteException: no such table: json_each (code 1):
Update: I am using room database and it works fine for other queries
json_each and json_extract would need JSON1 extension. It's not available on Android. You need to do your json mapping in code.

Error with query in SQLite

My SQLLite query is not working properly. See below:
UUID i=UUID.randomUUID();
String Beregero ="INSERT INTO
contacts(id,uuid,name,phone,email,street,city,state,zip) " +
" VALUES(3,"+"'"+i.toString()+"'"+",'Patrice
Beregeron','978-555-1212','pBeregero#BostonBruins.com'," +
"'1 causeway street','Boston','Mass','01236');";
db.execSQL(Beregero);
I am receiving the following error in my log:
(table contacts has no column named uuid (code 1): , while
compiling: INSERT INTO contacts(id,uuid,name,phone,email,
street,city,state,zip) VALUES(3,'12ee5bbf-dabb-4d95-bfe7-6e6f14702add',
'Patrice Beregeron','978-555-1212','pBeregero#BostonBruins.com',
'1 causeway street','Boston','Mass','01236');)
#################################################################
The exception says it all, your table has no column name uuid created. So uninstall the app, then run it again. This error occurs only if the column is not generated.
The error message in you log clearly states the problem. The contacts table does not have a column uuid. You now could do the following:
Check if you have got right lower case vs. upper case. The column in question might be UUID instead of uuid (I don't know SQLite, but case matters in many database systems).
If the column really is not in the table yet, then add it (either by code or by hand). Read SQLite's documentation to learn how to that (I can't help you here because I don't know SQLite).
Uninstalling and re-installing the app would help only if the app would generate the database upon installing or during the first run. Since we don't know anything about the app, this might or might not be the case.
You have not added the column "uuid" in the create table "contacts" query like this :
String createTableContacts = "create table contacts ( ' uuid text ')";

Deleting large sqlite table

I'm stuck in unique situation. In my app, I have local database. Somehow one of the tables got filled with junk data and database grew massively large. By the time I came to know, size was over 1 gb. So I kept getting database locked exception as reading that junk rows on that table was very very slow. After debugging, I figured out which table it was and now I want to delete it (either drop whole table or delete all rows) but whenever I perform any operation on that table, database gets locked and ANR happens. So I'm not sure how to get rid of that table. I can't uninstall app.
Note that I'm using GreenDao in my android app.
I've tried following things
1) DROP TABLE mytable;
2) DELETE FROM mytable;
3) DaoSession.getMyDao().deleteAll(); // this is a greedao method but it internally performs 2nd query I mentioned I think
In all the cases. It is just producing ANR.and app database gets locked.
Edit: I tried it in separate thread also, It just avoided ANR but did not drop table and database was still locked.
After lock I get this whenever other thread tried to write to db which is obvious.
E/SQLiteDatabase: Failed to open database '/data/user/0/myapp/databases/mydb.db'.
android.database.sqlite.SQLiteDatabaseLockedException: database is locked (code 5): , while compiling: PRAGMA journal_mode
#################################################################
Error Code : 5 (SQLITE_BUSY)
Caused By : The database file is locked.
(database is locked (code 5): , while compiling: PRAGMA journal_mode)
#################################################################
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1000)
at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:704)
at android.database.sqlite.SQLiteConnection.setJournalMode(SQLiteConnection.java:385)
at android.database.sqlite.SQLiteConnection.setWalModeFromConfiguration(SQLiteConnection.java:359)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:248)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:199)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:514)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:206)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:178)
at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:934)
at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:895)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:708)
at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:646)
at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:283)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:223)
at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:187)
at com.intouchapp.database.IntouchDb.getNewReadableDaoSesssion(IntouchDb.java:80)
at com.intouchapp.models.ActivityLogsDb.getCursorOfAllResults(ActivityLogsDb.java:298)
at com.intouchapp.services.ActivityLogsDbInsertionService.onHandleIntent(ActivityLogsDbInsertionService.java:73)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:66)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.os.HandlerThread.run(HandlerThread.java:61)
Also I get this too,
The connection pool for database '+data+user+0+myapp+databases+mydb' has been unable to grant a connection to thread 2262 (SyncAdapterThread-1) with flags 0x2 for 12.0060005 seconds.
Connections: 1 active, 0 idle, 0 available.
Requests in progress:
executeForChangedRowCount started 12645ms ago - running, sql="DELETE FROM 'mytable'"
This clearly states that It is not able to execute "DELETE FROM 'mytable'" this particular query hence the lock.
SQLite locks database when it is used to write operation.
You should take care about some points regarding this :-
DataBase operation should use in another Thread not in UI Thread.
Make a single instance of SQLiteOpenHelper class
close all the instances of database after finishing task
always use endTransaction()
close all instance of database in finally block

Android Studio Database SQLite Error

i want to build a database system with android studio, so i follow a step on someone blog.
When i start to save a data that i have inputted from my phone, the data cannot saved to the database.
Here is the log cat when i run my app
05-27 17:01:26.579 10597-10597/com.example.opec.menuprototype E/SQLiteLog: (1) table MenuTable has no column named menu_name
05-27 17:01:26.594 10597-10597/com.example.opec.menuprototype E/SQLiteDatabase: Error inserting menu_name=migor menu_id=1st menu_desc=mie menu_price=12000
android.database.sqlite.SQLiteException: table MenuTable has no column named menu_name (code 1): , while compiling: INSERT INTO MenuTable(menu_name,menu_id,menu_desc,menu_price) VALUES (?,?,?,?)
#################################################################
Error Code : 1 (SQLITE_ERROR)
Caused By : SQL(query) error or missing database.
(table MenuTable has no column named menu_name (code 1): , while compiling: INSERT INTO MenuTable(menu_name,menu_id,menu_desc,menu_price) VALUES (?,?,?,?))
Which part of the code you need to look up ? i will get it for you.
Replace this line
Context context = View.getRootView.getContext();
With this line
Context context = v.getRootView().getContext();

Categories

Resources