I have begun to programming in Android with Eclipse a little application who has a tiny sqlite database. As you know, sqlite is really easy to use. I have been using sqlite for many years, but now I have found somethig unusual and disappointing:
when I try to update manually my database (e.g. using SQLiteman or another SQLite GUI), changes are reflected when I make a simple SELECT * FROM... in SQLiteman. But when I execute my application and make another simple SELECT * FROM... the new row is absent! I doesn't appear!
-I have cleaned my solution and I have tried to update many times with "Import..." without any result.
-I suspect that it may be something related to an internal index not updated, but I'm not sure.
My code is minimal, as you will see:
String query = "Select _id, name FROM mytable";
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(query, null);
int totalRows=cursor.getCount(); //<---- This only shows the older total!
What's wrong with this?
Addendum:
I'm not using an emulator and my device is already rooted. But I can't see my database when I go to the DDMS in Eclipse (but this is another question).
I'm editing the database in my PC and then I import it to Eclipse. I have edited too directly in Eclipse, but without no luck.
Thank you
I guess you must be running the older version of your database. Just try to uninstall the old application from the emulator or device and install the new updated version.
I am sure it will reflect.
Whenever you change your database explicitly at that time to get it reflected into application you need to upgrade the version of your database otherwise it will not affect your database. Or you need to uninstall the old version of your application and install updated application that will reflect the SQLite.
Most likely, you are not doing a "COMMIT" on the new data, so it isn't persisting in the database in Android
Related
Technologies used for the app: Ionic, Capacitor, Angular and SQLite
The requirement is to use a prepopulated SQLite database in the app. The methods that I found over the internet across various blogs and forums mentioned running a SQL script to initialize the DB as a pre-population step, but this brings about an unwanted overhead time to start querying the DB. As in the user needs to wait for a minute or so for the SQL Script to run completely every time, even if the app exists.
This issue became a roadblock because when the need became to port a large-sized database, it was no longer feasible to write SQL scripts as the overhead time increased drastically. Also, a bigger problem is, in Android studio, Java started throwing Heap Memory exceeded error.
A solution that I tried was to port the database directly as an asset of the app so that it can be shipped along with the app. But, while placing the database file in src/assets/, every build of the app generates www/ to create a web app that can be wrapped in a native view. The builder and compiler delete all the contents of the previous build in the www/ folder, we must understand that the capacitor looks for the database file at www/ and not in www/assets/, but we can't place the database file at www/ as it gets deleted on every build.
Link to existing issue on using the sqlite extension
maybe my experience can help you
RULES FOR DEVELOPMENT
1
database1 of bundle ( Android APK) from /assets must be static and not for update. because they can be changed when the application will be reinstalled on you version
2
you must to create new database2 - local , on the device , programmatically - to store a user's data. you can affill this database2 with data from database1
3
when you will install new version of application: database1 one may be changed, but the database2 becomes constant
the same situation is in browser: programmatically created database not disappear from session to session.
I check - it works in my application...
I am not new to Android or Java but very new to Databases. I have been practicing with SQLite in Android and have now become completely stuck.
I want to completely remove the current database that I have been using in my app and create a new one with more columns, different types of columns, and etc...
I have tried "context.deleteDatabase()" which appears to delete the database but then after that I uninstall the app and re-install it with the myDatabaseHandler java class file having all the new columns and changed added to the file.
The code compiles and runs fine until I try to add info to the database, I receive an error cannot find columns, the error refers specifically to the columns that I added.
Why does it seem that I cannot start over completely. It seems like the structure or schema of the database won't change.
So how do I eliminate any evidence of the databases that I was practicing and messing around with, and just start completely new? After all, thats what practice is, you don't know what you are doing and you learn by making mistakes. So now I need to completely wipe away the mistakes, not upgrade just to make alterations.
Upgrading the database seems to provide an avenue for achieving close to what I want, but ultimately is way more involved and confusing for what I need when I just need to start over with a freshly created databases that has more columns.
The SQLiteOpenHelper class goes to great care to keep the old database to allow you to upgrade it in place.
If you're not interested in the old data, just change the file name. Then it is guaranteed that there is no old version. (You still have to call deleteDatabase() to get rid of the old file, but now that call cannot conflict with any accesses to the new file.)
Using the ADB tools from the SDK/platform-tools folder can help to remove all data (including the database schema)
./adb.exe -s shell pm clear <your app's package name>
will remove all the data associated with your app. Then you install the new version of the app, it will use the new database schema.
When i modify the database and upgrade the existing app in my Phone, the DB is not getting overwritten which makes my application crash.
How to tell phone to delete the DB and add fresh one during installation of APK file?
Did you try to increase the version number you pass to the the SQLiteOpenHelper constructor.
http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html
Some of my users are reporting that they cannot correctly open sqlite databases created in Android using sqlite jdbc or other tools like sqlite browser (http://sourceforge.net/projects/sqlitebrowser/).
Here is an example database with the problem:
http://pocket-for-android.1047292.n5.nabble.com/Desktop-Version-Screenshots-Work-In-Progress-tp4383220p4456017.html
This sqlite db was created on a HTC Sensation, running Android 2.3.3 and Sense 3.0.
The exact problem is that if you look at the file in a text editor you can see a bunch of tables being created but if you try and run "select * from groups;" you will get an SQLException: file is encrypted or is not a database.
I have tried using "select sqlite_version;" to see if it is a versioning issue - the sqlite browser says 3.6.18.but different tools give me different version numbers... not sure what is going on with that.
I should also point out that my app copies the db directly from the device (/data/data/com.citc.wallet/databases/wallet.db) onto Dropbox.
Any help would be really appreciated.
The solution was that the zentus project is not working with the latest versions of SQLite.
Fortunately someone is keeping a fork maintained here: http://www.xerial.org/trac/Xerial/wiki/SQLiteJDBC
All I had to do was replace the jar with the xerial one and it all worked. Xerial sqlite jdbc is in my opinion the best way of connecting to SQLite in Java (I tried several of the libs).
I am also getting the same problem.
But once I have changed the database name it resolved.
So, just try it by creating new database
I apologize if this is a stupid question, nevertheless I need to ask. I am new to Android development and have gone through every single tutorial and reference provided. I have been doing great, with the exception of one stupid problem; I cannot find where the databases for some apps are stored.
For example I would like to build my own app that includes thousands of pre-made records from an established SQLite Database. As a reference I tried to use the "Searchable Dictionary" app from the provided programs in the Android SDK, but cannot find it.
I read that all databases are stored in /data/data//databases on the device, but I cannot find this location. So how would I access the database in Eclipse or anywhere else for that matter to set up my pre-configured database?
Thanks so much!
not directly in eclipse, but sqlite db browser is petty nice http://sqlitebrowser.sourceforge.net/
Assuming your package for your app is com.example.androidapp and the database name is db you can do the following:
adb shell
and then in the command line shell
cd /data/data/com.example.androidapp/databases
sqlite3 db
and then in the sqlite3 interface e.g.
.schema
or
SELECT * FROM tablename;
and so on.