Error in simple todo demo code of Simperium for android - android

I downloaded the demo code.
After running the code :
I am getting this screen. I signed in with same username and id on other device, but nothing is happening.
On entering text, I'm getting the following error :
11-30 18:29:58.731 14566-16417/com.simperium.simpletodo E/SQLiteDatabase﹕ Error inserting bucketName=todo changeVersion=
android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: changeVersions.bucketName (code 2067)
at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:780)
at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788)
at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86)
at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1471)
at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1341)
at com.simperium.android.GhostStore.setChangeVersion(GhostStore.java:98)
at com.simperium.client.Bucket.setChangeVersion(Bucket.java:416)
at com.simperium.client.Bucket.indexComplete(Bucket.java:411)
at com.simperium.client.Channel$IndexProcessor.notifyDone(Channel.java:1126)
at com.simperium.client.Channel$IndexProcessor.next(Channel.java:1039)
at com.simperium.client.Channel$IndexProcessor.addIndexPage(Channel.java:1107)
at com.simperium.client.Channel$IndexProcessor.start(Channel.java:994)
at com.simperium.client.Channel.updateIndex(Channel.java:397)
at com.simperium.client.Channel.access$100(Channel.java:38)
at com.simperium.client.Channel$2.execute(Channel.java:187)
at com.simperium.client.Channel$CommandInvoker.executeCommand(Channel.java:743)
at com.simperium.client.Channel.executeCommand(Channel.java:713)
at com.simperium.client.Channel.receiveMessage(Channel.java:667)
at com.simperium.android.WebSocketManager.onMessage(WebSocketManager.java:420)
at com.simperium.android.WebSocketManager$2.onMessage(WebSocketManager.java:211)
at com.simperium.android.AsyncWebSocketProvider$1$2.onStringAvailable(AsyncWebSocketProvider.java:85)
at com.koushikdutta.async.http.WebSocketImpl$1.onMessage(WebSocketImpl.java:88)
at com.koushikdutta.async.http.HybiParser.emitFrame(HybiParser.java:420)
at com.koushikdutta.async.http.HybiParser.access$800(HybiParser.java:46)
at com.koushikdutta.async.http.HybiParser$5.onDataAvailable(HybiParser.java:197)
at com.koushikdutta.async.DataEmitterReader.handlePendingData(DataEmitterReader.java:24)
at com.koushikdutta.async.DataEmitterReader.onDataAvailable(DataEmitterReader.java:41)
at com.koushikdutta.async.Util.emitAllData(Util.java:22)
at com.koushikdutta.async.AsyncSSLSocketWrapper.onDataAvailable(AsyncSSLSocketWrapper.java:230)
at com.koushikdutta.async.AsyncSSLSocketWrapper$5.onDataAvailable(AsyncSSLSocketWrapper.java:217)
at com.koushikdutta.async.Util.emitAllData(Util.java:22)
at com.koushikdutta.async.AsyncNetworkSocket.onReadable(AsyncNetworkSocket.java:146)
at com.koushikdutta.async.AsyncServer.runLoop(AsyncServer.java:788)
at com.koushikdutta.async.AsyncServer.run(AsyncServer.java:626)
at com.koushikdutta.async.AsyncServer.access$700(AsyncServer.java:41)
at com.koushikdutta.async.AsyncServer$13.run(AsyncServer.java:568)
Please help if anyone knows about it!

The demo app relies on the soft keyboard to add new items, so make sure to have it enabled in your emulator or device.
I'll research the sql error, but it appears to only show in the emulator log and not on a real device.

The error states:
UNIQUE constraint failed: changeVersions.bucketName
bucketName has a UNIQUE constraint, which means that each new inserted value has to be unique.
So you tried to insert an object with a bucketName which already existed in the database.
If you think you can have multiple objects with the same bucketName, remove the constraint.
If you shouldn't, check before inserting if there's already one, and handle it gracefully.

Related

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

get database error code on SQLite exception in android

I use insertOrThrow in my android code to insert rows in to sqlite database. I use try catch to trap SQLiteException. I have set unique constraint in a column other than _id.
In case of errors i get exception message like the following and that is what i wanted.
"column word is not unique (code 19)"
Now, if the error is about duplicate insertion then i get the above error. And i would get messages like that for different errors.
What i need is an error number like in mysql. I was searching for a property of the android DB object which would have an error code but could not. I think in this case i need to parse the error message to get the error code.
The reason to have an error code is to identify the errors. In this case i can find duplicates if the error code is 19. If the entry is a duplicate then i will display 'Data already exists' message else i will display a generic error info like 'Unable to save information'.
Is there any other way to find the error code other than parsing?
Will the error code be consistent?

Get name of constraint which caused SQLiteConstraintException

How do I get the name of the constraint which caused the SQLiteConstraintException.
Calling toString() on the exception just gives me: "error code 19: constraint failed"
And there is no method in the exception to get the cause. This makes it rather difficult to debug my sql.
Beginning with version 3.7.17, SQLite shows the name of the constraint in error messages:
sqlite> create table t(x, constraint x_positive check (x>0));
sqlite> insert into t values(-1);
Error: constraint x_positive failed
However, it will be some time before this version shows up in Android.
In the meantime, you could replace the constraint with a trigger that can use whatever message it likes:
CREATE TRIGGER check_x_positive
BEFORE INSERT ON t -- also UPDATE
FOR EACH ROW
WHEN NEW.x <= 0
BEGIN
SELECT RAISE(ABORT, 'RED ALERT! database on fire because x <= 0');
END;

How to log SQLite commands in Android?

Im getting this error:
10-05 19:36:09.904: WARN/System.err(1039): android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed
Is there a way to the class SQLiteDatabase show queries created in insert and update methods?
Ty
You are probably inserting two items with the same primary key, which is supposed to be unique. There is no way that I know of to get verbose SQL logs, sorry.

Categories

Resources