weird error comming from Android SQLite - android

I'm getting a weird error in DDMS, it appears just after the innocent "Finalizing a Cursor that has not been deactivated or closed", comming from my own DataAdapter (about that in next question)
Error:
"Finalizing a Cursor that has not been deactivated or closed. database = /data/data/net.toload.main/databases/lime, table = null, query = SELECT _id, code, code3r, word, score FROM mapping WHERE code3r = '0' AND code ='HTT' ORDER BY cod"
I didn't create any tables with such columns in my app! And my localdatabase isn't stored there... /databases/lime, but this error seems to come just after my real error from my own DataAdapter. I tried to pull the lime.db file to read the contents of the database but the pulled file is always of 0 bytes, though on DDMS-FileExplorer is much more, now 26624bytes.
So ... im thinking that maybe android/google is tracking my every move!! and the app doesnt run in a isolated process...
Anyway can you explain this error?

Your project must be using this Lime IME (Lightweight Input Method Editor):
http://code.google.com/p/limeime/

Related

Unable to find SQLite on Android

I have this android application that I am developing in Unity. I am using SQLite to save and access my data.
When I run my code on Unity editor it works fine. But when I tried it in my android device after some changes in the database, it did not work. So I undid those changes and use Android Device Monitor to check what was happening. I found out that, even though it looked to be working, it was throwing a Unity error: Unable to find SQLite.
I just can't understand what is going on. It works on Unity editor, and, before changes in my database, it also worked (or that was what it seemed) on android device.
This is the code I use to connect to database:
private void conecta()
{
if (Application.platform != RuntimePlatform.Android)
{
dbFile = Application.dataPath + "/StreamingAssets/" + databasefile;
}
else
{
dbFile = Application.persistentDataPath + "/" + databasefile;
if (!File.Exists(dbFile))
{
WWW load = new WWW("jar:file://" + Application.dataPath + "!/assets/" + databasefile);
while (!load.isDone)
{
}
File.WriteAllBytes(dbFile, load.bytes);
}
}
print("aaaaaaaaaaaaaaa");
connection = new SqliteConnection("URI=file:" + dbFile);
print("bbbbbbbbbbbbbb");
}
On my project, I have some dll in my Plugins folder.
And I have libsqlite3.so in my Android folder that can be seen in the picture.
I don't understand what's going on, because when I run the app it accesses the database data and stores more data, but apparently it also throws this error. Can anyone please help me?
If this information is not enough, please let me know. I will complete my question.
UPDATE
I now know the exact line of code that is giving the error. I use the code above to establish a connection with the SQLite database in some scripts. But in this specific script, which is attached to the first screen of the application, the error is coming from this line:
connection = new SqliteConnection("URI=file:" + dbFile);
I don't know why. I use that code as a method and use it some times in this script. I have some buttons that only become interactable if I have data in my database. And when I run it on my device they became interactable. That's why I did not see the error until yesterday when I changed the database file. Below you can see the error when accessing the new column and the table structure in database.
I added one column in two tables, and when I try to access one of those columns it throws an error saying that the table does not have a column with that name.
NEW UPDATE
I got tired of this error and deleted my database file. After that I did a new one, with columns I addes before. What happened was that the Unable to find SQLite continues. After taht it keeps saying that my table does not have the especific column I added in the other file. I don't understant what's going on. That new database had the column from the very begining.
I still don't know what was the problem with the app. But I did a new database file with a different name and it is now working.

SQLiteDatabase locked after any insert "SQLiteCantOpenDatabaseException: unable to open database file (code 14)"

As I changed the android version and the path from externalized to the default database-folder, I don't know where the error come from.
I found that the reason might be problems accessing the journal file is locked (it is created by the program).
the "test" is reading data and if it exists it updates and if not it inserts. This is done in a loop while reading lines from a file. For testing purpose i simplified it but the error is the same.
package ...;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
public class test {
public test(SQLiteDatabase MyDB)
{
MyDB.execSQL("CREATE TABLE IF NOT EXISTS testtable (mytext TEXT, number INT PRIMARY KEY)", new String[] {});
for (int i = 1; i < 5; i++)
{
String[] ColArray = { "any text", String.valueOf(i) };
Cursor readCursor = MyDB.rawQuery("SELECT mytext FROM testtable WHERE number=?", new String[] { String.valueOf(i) });
if (!readCursor.moveToNext()) // Error when executing moveToNext
/*
In the 2nd time it runs over this point an Error occurs:
android.database.sqlite.SQLiteCantOpenDatabaseException: unable to open database file (code 14)
I need to remove the journal file to be able to connect to the database it again - the change made by the Insert/Update is successfully saved!
*/ {
readCursor.close();
MyDB.execSQL("INSERT INTO testtable (mytext, number) VALUES(?, ?)", ColArray);
}
else {
readCursor.close();
MyDB.execSQL("UPDATE testtable SET mytext=? WHERE number=?", ColArray);
}
}
}
}
MyDB is a valid DB-Connection.
1) The Table is created
2) The Table is READ but Line 1 is not found
2a) READ again is possible until now if the read is closed.
3) Line 1 is INSERTED
4) when trying to READ again (the line 2 would not be found, too), moving the cursor fails.
The journalfile need to be deleted manually or the app will fail to start again when trying to connect.
Please Help! Thank you.
Maybe you should use the specialized insert and update methods.
In the documentation of the SQLiteDatabase it says for execSQL:
Execute a single SQL statement that is NOT a SELECT/INSERT/UPDATE/DELETE.
There are specialized methods for insert and update with similar names. I guess, that there is some problem generated, when the unspecific "execSQL" statement is used.
i solved it after hours of testing.
possibly the sqlite version is different in the old and new system... i changed the rom again - for some reason, this time i didn't copy the databasefile into the data-folder. Instead i let the program create a empty database and imported the data from text by the program itself from a csv-export.
I currently don't know if the problem was within the rom or (what seem to be the reason in my opinion) i created the problem by using the origin database which might be read and writeable but has problems when the journalfile should get processed. if somebody has an equal problem, he should try to create a new empty database in the new system.

Android: SqliteDatabase's lastModified() is giving wrong value

I am using sqlcipher database. I am tracking the lastModified time of my database. According to my understanding long value returned by lastModified() function will change only if we update or add a value to the database we refer. I am using a query to fetch (not modifying) a value from the database, for this i am using the below code
mDatabaseFileObj = mContext.getDatabasePath("xxx.db");
Log.i(""," "+mDatabaseFileObj.lastModified());
mSQLiteDatabase = net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(...)
Log.i(""," "+mDatabaseFileObj.lastModified());
mCursor = mSQLiteDatabase.rawQuery(query, null);
do{
....
}while(..)
In this i had printed two logs. First log before creation of mSQLiteDatabase obj and another log after that.According to the doc for lastModified() both the values printed by the logs should be same as i just quering not modifying the database. But the value is changing.
I couldnt sort out this problem.Give your thoughts on this.
An addtional info is, i had placed this code snippet in a function and i am calling that function 5 times and strangely for the first time alone the log is printing different values but for the rest 4 times the log printed values are same..
Thanks in Advance
Deepak,
openOrCreateDatabase is not a read only operation. In particular the wrapping library, which is based on the Android sqlite library, manipulates a table called android_metadata when the database is open. This could cause the timestamp to change, because the database is actually modified during open.
mDatabaseFileObj this is reference to your File object from OS don't confuse this with database in SQLITE database are implemented on top of file system only, so in first line you are printing when this file was last modified,
while second line you are trying to alter the file, and third line again printing time, so as per me and going with file systemn behaviour you will get a different time stamp, this doesn't mean if content inside this file was modified or not.
Just imagine it like this, open a txt file in windows and save it again without changing it notice time before and after they will be different.
Hope this help.

SQLite Error Code 17

One of my tables in my SQLite database is returning this error code below:
sqlite returned: error code = 17, msg = prepared statement aborts at
32[sql statement]
As far as I know, the data was successfully inserted. Is this something I should be concerned about? Or is it just a false error? Based on this post, it says:
The database schema changed
What exactly does it mean? Any suggestions?
Try insetting more elements it seems false error, once you inserted values your database schema recognized and stops giving this false error..
I'm getting the same error. Are you dropping your database and then re-populating it? This "warning" appears when I wipe out my database and then insert about 200 rows again ... but all works fine. It's strange. There is a thread in the sqlite forum about this.

rawQuery on "count(*)" return no row

I'm trying to fix a DB issue I had in Ankidroid. The following statement was executed:
SELECT count(*) FROM cards c WHERE type = 1 AND combinedDue <
1335153600.000000
It was generated there. The code executed is the following (github link):
cursor = mDatabase.rawQuery(query, null);
if (!cursor.moveToNext()) {
throw new SQLException("No result for query: " + query);
}
I can't understand how I can get no record, I should get either 1 or 0. The call stack in the log was the following:
at com.ichi2.anki.Deck.rebuildRevCount(Deck.java:1351)
Caused by: android.database.SQLException: No result for query: ……
at com.ichi2.anki.AnkiDb.queryScalar(AnkiDb.java:129)
at com.ichi2.anki.Deck._rebuildRevCount(Deck.java:1621)
Any idea?
In fact, I was more looking at a similar case. We have a table «Stats» with a column "global", in which there can be one global record and many daily records. If we don't find (a simple select) the global record, we create it. On my phone, it seems that sometime the global record is not found, so we create an additional one, which break things.
It really look like the case I showed above.
Edit:
I found why. In another thread, an AsyncTask closes the DB at the same time the query is being made (because a lot of processing triggered by the GUI is done asynchronously). And it returns a cursor with no record.
I saw that by adding traces to a file.
Try if (cursor.moveToFirst == false) instead of using the ! operator. I think that the way you are currently doing it is always going to.pass you into the body of the if. And the cursor isn' t properly initialized.without a.moveToFirst.

Categories

Resources