When my app runs it first checks for the existence of the db. The first time it runs the db should not exist and if that's the case it will create the dB's tables, then it will populate specific tables with various support data. So, in testing this works fine. So I then delete the db through adb shell. Then I rerun the app and it determines that the db still exists!! I have 2 different methods that checks existence, or not,and both behave in the same aberrant way.
Method 1 simply tries to open the db as a Java file and then uses the exists method to check. Method 2 is a bit more elaborate using the db path and name as args to thedb.open database method.
Both methods fail to determine that the db does not exist, after I delete it in adb shell.
I can provide the code if needed, but thought I'd see if there are some ideas for this behavior. I have cycled the genymotion emulator but this did not fix it.
Thanks for any suggestions.
No. I stop the app, delete the db, then restart (All in Android Studio). By the way. Do you know why the db path, as reported by Gene motion, is not the same as my apps db path? Both tho do point to the same db, as shown in adb.
Related
I am trying to set up a Tasker task that will delete all alarms in the clock. I had it setup and working great on my old phone. What I did was made a copy of the alarms database when there were no alarms. When I want to delete the alarms that are currently set, Tasker runs a shell command to delete the current database with the alarms in it. Then Tasker runs a shell command to copy the empty database and rename it. Then some commands to change permissions and owner.
When I tried to move this all over to my new phone is when I ran into some trouble. The new phone is a One Plus 3 for what it's worth. So I copied everything thing over and the only thing that looked like it needed to be changed was the package name for the shell commands. I changed that and tried the Tasker task. No luck. The clock app froze up. I restored everything from my backups. I decided to do some testing to see where the issue is.
I used the Root Explorer app to copy the alarms database. When I tried to open the copied database I got the following error message:
An error occurred while opening the database. Attempt to invoke
virtual method 'android.database.Cursor
android.database.sqlite.SQLiteDatabase.query(java.lang.String,
java.lang.String[], java.lang.String, java.lang.String[],
java.lang.String, java.lang.String, java.lang.String)' on a null
object reference
I can still open the original database just fine. But it appears something is happening when I make a copy of it. Any insight would be a big help. Thanks
Problem as I understand it:
You say "When I copy a database I get an error", if it's in the copy process then it's trivial, if you don't mean that, then say that. Moving on...
You have copied an sqlite database from somewhere, to some where (you don't say where, it may matter), and you don't permission to open it [maybe you do, then say so, give ALL permissions] (but you can open the original). File Permissions comes to mind (user permissions on the file).
This method works on an old phone but now does NOT work a new one (API versions would be useful, these methods have changed a LOT).
The error is about Cursor queries.
see my answer about Cursor's, and cursor management
Do not assume your original code was perfect because it worked. More detail required.
Post some minimal code the is involved in the error. We are not trying to steal your code, we cannot answer your question, without seeing the code that makes it fall over, how can we do that ?. ALSO include the catlog. You never know, we might give you code that works ;O)
At the moment, I have a little JavaFX app that generates reports and statistics from the data on a remote MySQL-Server. I use EclipseLink for persistence. Since the access is read-only and the data doesn´t always need to be fresh, I thought I could speed things up by using an embedded DB (H2) that can be synchronized to the remote server when and if the user wishes to. The problem is, I don´t have a clue how to go about it.
What I came up with so far, is to execute mysqldump, make a dump of the remote server and execute the resulting SQL script locally. This is surely far from elegant, so: Is there a patent solution for this task?
Well, 50 tables possible have a considerable amount of relations, this can be tricky... As far as I know there is nothing that automate this for you or something like that. Very possible that you will have to create your own logic to that. When I did something like what are you trying to do I used the logic of "last update", like, the local data have the timestamp of the time it was last synced with the remote, and the remote data have the timestamp of the last time the data was updated there (himself on the table, or even a relation to it like a One-To-One). Having that data, every time the local user enter a part of the system that can be outdated, the client connect to the server and check if the last update timestamp is bigger that the local synced timestamp, if so, it updates the full object and relation. I consumed some time to develop but at the end worked like a charm. There may be some other way to do it, but this was the way I found at the time. Hope it helps you with your problem.
I am developing a web application to migrate images from CVS to Adobe CQ. There is a requirement to maintain versioning for the images in a database table. The flow is as follows:
Check Out files from CVS -- returns a list of all files checked out, but does not tell whether a file was updated or newly added to CVS! (Due to the files being binary file, it seems it is not able to detect updates and all files are treated as additions)
Check if this is application's first run, if yes, then treat all files as additions. If not, for every file, check database for presence of record corresponding to this file. If record present, treat as update, else insert
... Carry on with other operations
For every insert, add an entry in the database
I have to detect if the application is running for the first time, or has been run previously. This also needs to support future tasks such as resetting everything and starting the application from scratch.
What would be a good way to do this? The application is hosted in WebSphere in Linux. I have thought of two ways:
a. creating an entry in a file with a flag set to true, which I will have to reset to false after the first run - difficult for a user to reset later
b. creating a .firstrun or similar file in the app folder somewhere and check presence of this file to determine first run, easier to reset for any user
Which of this is a better way? Or is there any other way to do it better?
You mentioned database. Why not to store in db, in even more extended way: when what version, # of runs, etc.
I have an application, which is behaving weird at the moment. It's using an SQLite database, and it worked pretty well before I wanted to improve some parts of it. Now comes the problem: How could I "explore" my database while the application is running on my phone?
Like you can watch variables, and check them if you break the debug session at some point.
But with the SQLite database. (The application of course got a "Main" status where it's idle, where I could check the database.)
Try
adb shell
sqlite3 /data/data/com.app.name/databases/DatabaseName.db
which will take you to the SQLite command line. From there, you can perform SQLite queries/data dumps on your database to see the data inside. If you want to do this with a real device (i.e. not the emulator), then you will need to root your device first.
Note:
If your device doesn't let you execute the sqlite3 binary (or the binary doesn't exist in the device's path... or it just doesn't exist all together, etc.), you can install sqlite3 on your local machine and then do
adb pull /data/data/com.app.name/databases/DatabaseName.db .
sqlite3 DatabaseName.db
which will copy the database to your local directory and then execute the sqlite3 binary on your local machine. This happened to me once when I rooted my Motorola Xoom... but the first suggestion works fine on most devices (at least in my experience).
It seems like SQLite (1-st impression) stores it`s data temporary, while executing SQLiteOpenHelper and creating tables there, and inserting rows within onCreate method.
The Q is: Is there an ability to store data permanently and do not create DB and Tables every time the app is start-up? As I understand the data kills, when user exit the app?
Sorry for my English and a lame question - I'm new to Android =)
Thanks in advance.
Your initial impression is incorrect. SQLite tables are persistent in Android - they exist as files in a particular directory based on your application's package id.
The idea of the SQLiteOpenHelper is to encapsulate database creation AND database upgrade in one place, so that the rest of your database-using code doesn't have to worry about such things - it just called the helper and when the helper returns, the database is exactly as it should be.
That's why the helper has an 'onCreate' method (which is used when the database doesn't already exist) and an 'onUpdate' method (which is used when the database already exists, but has a different version number).
The data base is created only if it does not exist. That is the only time that the onCreate method is called. Once created, the data base will remain in existence until you explicitly delete it or until the app is uninstalled.
if you are using SQLiteOpenHelper to create your database it will be create the first time you use the SQLiteOpenHelper object and it will be permanent
Please check by running application on real device. You may be using it on Emulator.
When you start application in emulator the database is created and when you close emulator the temporary environment created by emulator is destroyed thus you will not be able to get it back. Whether running on actual device may store database permanently on your device. So next time when you open your application, it will connect to existing database and you can do operations on it.
You have not provided information regarding whether you are using real device or emulator, please describe that.
Let me know if there is anything more -Thanks.