How can I view the DB in IntelliJ to view its content and perform operations on it. Now I have created my tables etc but i have no idea what data is on the DB and I do not want to create queries in java to check it. seems like a slow workflow so ill wait til I know how to access the db that resides on the Android emulator im using.
Is it possible?
You can also use Stetho. A nice debugging tool from Facebook.
Just simple to use, initialize it in your Application class and access your sqlite and even shared preferences from Google Chrome's developer console.
You can create a database file outside of Android and use any tool to create and read it.
Then, you place it in the assets folder and setup your code to read the database from there instead of private app data. Caveat here is that a copy will be made from the assets folder to the app data, so any updates within the app won't be mirrored to the database file in the assets folder.
I believe you can access the DDMS window in Intellij/Android Studio and there is a Database Explorer there
see #alexsimo's answer.
Without root you cannot access your database on your device, unless the file is created with a+r permissions.
Since that is something that is unrelated to the issue, you can just search in plugin.jetbrains.com for sqlite and get a variety of plugins.
Related
I wondered If it is possible to push db files into databases folder of an Android application either programatically or using any tool.
Thanks in advance!
Yes you can but not directly.
Typically a pre-built database would be included as an asset and copied to the databases folder for the package when the App is first run after installation.
If using this method then you should consider using SQLiteAssethelper, as using this simplifies the process.
In one of my App's I introduced a back-restore that backed-up the database and could restore from the downloads folder. If need be I can copy a database from elsewhere into the downloads folder and restore from that within the App. However obviously such a database has to have the correct structure/schema to not result in errors. So that is another way but would be at the user's discretion to do.
Obviously data/data//databases is protected so that imposes restrictions on "Pushing" data directly into the folder.
My proble is I created a device in sqlite database browser and its work fine in emulator.
but when a try my application to my device it cause force close.
and when I remove the database and create a new one using eclipse it works fine even in my device. But inserting a lot of data in database 1 by 1 realy freakin me out so anyone know a sqlite database browser that also work for device??!
check out this tutorial for using database file in application.
Remember one thing that it only copy you DB file in application that's it.
On real device you don't have permissions to sqlite database. That's why you won't be able to browse database like you can on a emulator.
See this for a work around.
Tool to see android database, tables and data
If you want to create a pre-loaded DB outside of your app and use it in your app later, you will have to put it in your assets directory and then copy it to your apps storage space the first time your app is started.
This is due to the fact that as a security measure, on real (unrooted) devices nothing but your own app is allowed access to that apps databases directory (and certain other ones as well).
There is a good tutorial for creating/copying your own DB outside of the app and copying it to the apps databases directory here.
I have finished the notepad tutorial on the android site. I did this because i want to create a DB for my app. Once i finished i found out where the data is located in the DDMS. Then..
I downloaded the SQLite browser database i created a mini DB. Know i am trying to put this data into my project.
Can i put this new saved database file(i made with browser)into the notepad database file & and delete the old one. So when the emulator loads it will load my data.
Because i made a database with android notepad with all the code etc. with this SQLite browser i am thinking the code is done for me(table, columns,)
I guess am asking you is can i just make a full database with sql browser and just input it so how in my project.
Your database class needs to be specifc to your database, so you cannot just change databases on the back end and expect the handler class you wrote for the notepad tutorial on the front end to work properly with it.
That being said, you can create a handler to run your custom db. It's rather round-a-bout though. After you get the helper class created, you have to put your db into the assets folder. In your db helper you need code to copy the file out of assets to it's proper home in your applications data directory.
You can find instructions on how to set up your database so the Android framework can use it properly as well as code for copying it out of assets to your data directory here.
I have adopted Rhodes recently & I was wondering how to debug a Rhodes application. For example in Ruby we can see the line-by-line execution of code using irb. Also after creating the models in a Rhodes application, I want to see the database structure because I prefer to use the SQLite Manager as a Firefox plugin for my Rails apps.
I need to really see how the models look in the databases and how the attributes are stored.
Thanks
Using RhoStudio (built on top of Eclipse), you can set breakpoints and step through the Ruby controllers and models (source)
To see the database structure, you can access the file system and get the database's path, and save the SQLite database off in a web service or some other means (maybe to the SD card?) to view in your Firefox plugin, the following being an example of how to get the path to the database.
db_path = Rho::RhoFSConnector::get_db_fullpathname('app') # can be app, user, or local
EDIT
Or, if you build to RhoSimulator from within RhoStudio, you can navigate to the "bin" directory for RhoSimulator and inspect the SQLite files there.
/path/to/app/rhosimulator/db
I am working with SQLite in an App. It writes to the database, etc., with no problem. However, I can not find this new database. I have tried changing the directory with cd /data/data/packageName/databases, but it says "no such file or directory". Also, this database is not found when I click on the File Explorer in eclipse. My logging tells me the database was created and that it is being written to. I think I need to set the path in the shell or something to that effect using adb, but I have no idea how to do that. Can anyone give me some instruction? Also, I am using my phone for development. The database also does not show up when using the emulator.
Thanks very much.
Matt
Matt,
This thread gives a good explanation on why you might not be able to access the data folder on your phone.
Can't access data folder in the File Explorer of DDMS using a Nexus One!
You can still test the Sqlite code though. Just boot up an emulator. The emulator will have no access restrictions. Once it's booted up you can use the ddms tool (located in the tools directory under your android SDK install folder). It has a File Explorer and you can download the files from the /data folder.
Also, I am using my phone for development.
You cannot access the database on a standard Android device except via your own application code.
Your options are:
Do this sort of testing on an emulator, in which case you can access the directory that you are failing to access on the device
Add a database backup feature to your app, that copies the (closed) database to external storage, so you can examine it
Root your phone (leastways, I am under the impression this can help get you to this directory -- haven't done it myself)
The database also does not show up when using the emulator.
Try harder. If you can store data in the database and read data out of it using SQLiteDatabase, then the database file is there.