No credentials needed for Sqlite database? - android

I am not quite getting the idea of sqlite database. I am developing a hybrid mobile app using Ionic Framework and backend with PHP.
I referrred to this article for using the sqlite https://blog.nraboy.com/2014/11/use-sqlite-instead-local-storage-ionic-framework/
I have a few questions now,
1) So, anybody can create a table,insert and do any kind of operations? Is'nt there any need of a security method to access the DB like mysql?
2) Is a separate instance of Sqlite created for each application? Coz if not,I can make a guess for a tablename created by any other application and delete it all together,isn't it? I just dont get it?

1) SQLite is a file database so if you have access to file you have access to database and can do anything with it. What is the purpose of restricting access to db when you can just delete whole file? SQLite db file should be created in app private storage so no one have access to it only your app.
2) the answear is above. just create file in right place and everything will be fine :)

1) So, anybody can create a table,insert and do any kind of operations? Is'nt there any need of a security method to access the DB like mysql?
By default, each app db will store in their private folder(data/data/your_package_name/database and only that app or system app can access to it.
But if you choose to store your db in sdcard, anybody can mess up your db if they know the path to db file and have right to access it.
Other case is if your device is root, other apps can access your db too.
2) Is a separate instance of Sqlite created for each application? Coz if not,I can make a guess for a tablename created by any other application and delete it all together,isn't it? I just dont get it?
Like above, each app can choose where to store their db file, so basically, they a separate instance.
You can also create multi db file for one app if you like.

Related

reusing Room or SQLite database in the app?

I'm trying to figure out an android app that stores user's data in a database on sdcard.
But I don't know if it's possible to have these too:
even if the user deletes the app, the db remains and the user can access it.
So later they can re-install and give the app the path to the db file. The app uses that file as a database again.
Something like WhatsApp db, but the user must have the database as a file on their phone so they can transfer and store it anywhere. The data is large so it's not a good idea to get a backup file.
Is it possible to create it with Room or SQLite? and reuse it again?

How to alert users on new update to local database?

I'd like to receive some advice from all of you.
What is the best way for me to alert users on an update to my app? My app is a very knowledge-based & it works like a dictionary, so there will always be updates to it.
The database I have used is by DB Browser for SQLite, and they are all local database where it is uploaded into the assets folder in Android Studio.
Currently, the limitations are that:
1) it's obviously not real-time because it's stored locally;
2) every update I make to the database structure, I am required to upload the new database into the assets folder again, followed by uninstalling the old app on my phone, then run the app to install in my phone again so that the new database is overwritten.
I have read (How can I regularly update a database of content on an Android app?) & some others, and it seemed like I have to have a server, a cloud-based database & live app in market, to solve the limitations?
Is there really no way for me to overcome the limitations if I want to stick to a local database? At the same time, I kinda wish to avoid setting up a server because I am not intending to make the app live on market, and also this is just a school project I am working on and as such, I have very limited skill sets & knowledge about it and would like to make it on a school-project-based level.
Thanks in advance.
One way to do it is to connect to your local DB through local network instead of assets folder. Therefore, you can update the information by querying the local DB.
As for syncing the information between DB and your application, you should create a trigger or watcher that notify your application when the DB is updated. Therefore, your application can know when to query the DB for the updates. Another way is to just query the database periodically.
Bonus: you could move your database to a cloud-based database. Usually there are several providers that provide free database hosting up to a certain size, which should be enough for your project.

Where is SQLite database located on android

I'm new to programing for android and i'm still learning. So I have a question about the location of the SQLite database. Is it stored in the same file system as the application ?
And also i'm not sure can the database be created before the app is installed(can it come with the app) or can the database only be created from inside the app ?
And what if i wanted my app to come with a database that already has tables and records which is local and not on a server. Would that be possible ?
SQLite is available on every Android device. Using an SQLite database in Android does not require any database setup or administration.
You only have to define the SQL statements for creating and updating the database. Afterwards the database is automatically managed for you by the Android platform.
Access to an SQLite database involves accessing the filesystem. This can be slow. Therefore it is recommended to perform database operations asynchronously, for example inside the AsyncTask class.
If your application creates a database, this database is by default saved in the directory DATA/data/APP_NAME/databases/FILENAME.
The parts of the above directory are constructed based on the following rules. DATA is the path which the Environment.getDataDirectory() method returns. APP_NAME is your application name. FILENAME is the name you specify in your application code for the database.
You can also follow this tutorial for further understanding.
http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/
Database is created after the app installation or after the db changes. The db is stored in /data/data/your_package/databases/

android: is it possible to check if db is created in other app

Is it possible to check if a db is created in other app? I have to have a common db for two app. If one app is already created the db then the second one should use the first apps' db (I mean should not create new one). For this,Is there a way to check whether that particular common db is created or not? Please help me on this.
This is not as easy as you may think. Even If you would definetly know, that your other app has created the db already, there is still difficulty in querying it. As any Db belongs to the app which created it, only this app usually gets access to it.
Good news is that there is is a mechanism for that, called ContentProvider. With it you are able to share the db-infos between apps, but it takes some effort to implement this.
The database is stored under /data/data/your.applications.package/databases. Normally this location could only be access by the user the Android OS created for the app. No other user is able to access this location unless the device is rooted. Then any user can access any location on the phone and manipulate the data.
so you can check the whether the db is present in this location or not
you can directly check this Android Access Another App's Database
The best thing for you is to use the sdcard (or some other user accessible area, without root)
Look at this thread
I know it's unsecure, but it's the best thing for this kind of problem. One application (the first one installed) creates the db on sdcard. The other one, just check's if the file (db) allready exists and reads from the existing db.
You should use SQLiteOpenHelper to control versioning of your database as described in database tutorial.
Unfortunately SQLiteOpenHelper only works in local app-directory but you can tell it to use a different directory on sd-card as described in sqliteopenhelper-with-fully-qualified-db-path-name
Try the following code
DB_PATH = "/data/data/THE_PACKAGE_NAME/databases/";
DB_NAME="YOUR_DB_NAME";
File dbFile = new File(DB_PATH + DB_NAME);
if(dbFile.exists()){
/* YOUR CODE HERE*/
}
Do the above check in both of your application with the PACKAGE NAME before creating the db.
:)

Android: SQLite Database. Do we need to create it?

I've been going through some tutorials on working with sqlite databases and they all seem to create a new database, tables, etc on the first run of the application. Is this necessary? What if I already have a pre-built database sitting in the assets folder when the application is installed? Can I not simply just open the connection to said database and start using its information or is there a specific reason everyone wants to create it using sql on first launch?
This question comes up frequently. Try this tutorial to use an existing database on Android:
http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
You can't use database file which sits in assets folder directly as SQLite database, since this file would not be usual file located in common filesystem. E.g. you can have only readonly access to it. So the only your option is to copy those database from assets folder to device's filesystem.
To handle database creation for the first time and accessing it there's special helper class SQLiteOpenHelper. Read about it here. Specifically look in SQLiteOpenHelper.onCreate() - where should sit database creation (or copying from assets folder as in your case)
It's been quite sometime since I last worked with SQLite databases (in Android) but I believe that when they write CREATE statements, they always do so with the IF NOT EXISTS condition (i.e., CREATE (DATABASE|TABLE) IF NOT EXISTS...).
I don't know what you'll use SQLite for but I believe they do that in Android "just to make sure". That is, if it's the user's first time to run the app, the DB/Tables must be created first else app goes bonkers. Otherwise, they are (probably) created already and this case will be handled by the IF NOT EXISTS clause and they just go ahead and create a connection with the existing DB. Win-win.
(If, for some reason, it is not the user's first time to use the app and the DB isn't there, it will just be created again. But that's obvious isn't it? ;) )
If you just link with preexisting database it wont bind to your system. So there may be failures. Creating db at first run is the most appropriate way to work with db.

Categories

Resources