How is android.database different from android.database.sqlite? - android

I am trying to develop this android application whose database is not stored in the device but on a server. To use sqlite database I need to use android.database.sqlite; and I haven't made much use of android.database package. I went through the documentation site but it did not state clearly if it's possible can store my sqlite database file on server and invoke methods to access it from there. What should I do?

SQLite is not an ideal database to use on a server. The andriod.database.sqlite package is going to have resources for dealing with sqlite specifically, where the android.database package is going to have generic database resources, not specific to sqlite.
For using sqlite on a server, first bear in mind that concurrent connections are a big no-no... sqlite is not designed to handle them.
If I still felt I had to do this, I'd probably look at creating an adapter on the server which would accept requests from the application, then use the android.database.sqlite package on the server, as it's local per the scope there (as sqlite is designed for).
https://www.sqlite.org/serverless.html

Related

How Can I Create a Database Accessed By windows and Android

I have been looking and searching for this whole day, so i want to create a database which can be accessed by both computer and smartphone, is there a way to do it, and how ?
Sorry For Beginner Question, Thanks in Advance
Ok, the first thing you should do is to define the type of database
that you want. You can build SQL or No-SQL database. For the most
part I would suggest no-sql so something like MongoDB could do, but you can always do mySQL. As
for accessing that db with anything actually, you need application
layer around it. You see, database acts as just a huge data
container thus it should not be used for any other logic.
Now, lets talk about application layer. To be more precise - about posting/updating/retrieving data from db. You should research something about RESTApi or GraphQL concepts as they are used to make communication between your app and your db which is hosted on a server (I deliberately did not talk about how you can build an app because I assumed you already know this one).
THE POINT: The most important concept to wrap your head around is how you can access the db you make not the type or tech used to build it. (Even though this is important too)
Good luck!
The better way to do this its creating a web service, so your app will talk to this web service, the web service will talk to your database and retrieve the results to your app (this can be done using HTTP protocol's APIs like Volley for android) and its a secure way to do it.
You can connect your application direct to your database granting external access, but this is a specif configuration according to your database (mysql, ms sql, etc.) and its not recommended.
You can think in the same way to the computer(s) that will access your database, except if this computer(s) is in the same network which the computer that your database is hosted in, in this last case, the program in this computer (which will access the database) can access it directly (you need to setup the database to permit this and this setting is diferent according to your database).

Use my own SQLite database vs Import data from csv file

I'm currently trying to import ~300.000 lines saved in a file.sql.
After reading few forums, few posts stackoverflow, I found two main solutions :
Use my own database with android (https://blog.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications)
Use a csv file or sql file and import it with a transaction
How to populate a large sqlite database on first run
https://www.sqlite.org/cvstrac/wiki?p=ImportingFiles
Inserting large amount of data into android sqlite database?
What is the best solution, considering the performance aspect, the evolvment aspect (volumetry), the best practises on Android...?
In the perfect case, can I have a example ?
I'm using ORMlite libray, and classic DatabaseHelper methods like :
onCreate => to import my data
onUpgrade => to do my migrations scripts (https://riggaroo.co.za/android-sqlite-database-use-onupgrade-correctly/)
Edit : The database is used for the operations of read-write, and is synchronized with a primary server, in order to obtain and send the changes (using Flatbuffer).
The reason for which I need to import these data is because the synchronization dating of a timestamp 0 (all the lines contained in the base of data of the backend server) is too long at the level of the time.
What is the best solution, considering the performance aspect
Shipping a database in assets, and using SQLiteAssetHelper to install it as needed, should be much faster than anything involving executing database transactions.
volumetric evolution about data. the amount of my line (in file.sql), will grow.
Shipping a database in assets will be faster for deploying the app to a new user.
For existing users, neither of your approaches works, and you will need to craft your own code to blend:
Your new data that you want to ship with the app
The old data that you already shipped and have on the user's device
The data that is on the user's device that shipped with neither the original nor the updated app (e.g., data from a server, data entered by the user)

Storing simple data in android app

I'm making a simple GPA android app. The user can input their grades and class names for each semester. How would I then store each of these semesters so that they can always be pulled up in the app? I might also need to store random variables that are alone.
I've briefly looked at options such as Shared Preferences, Internal Storage, and others. What option is the best for my needs? Please explain why. Thanks!
Here is Explanation...
Shared preferences are good for storing ... an application's preferences, and other small bits of data. It's a just really simple persistent string key store for a few data types: boolean, float, int, long and string. So for instance if my app had a login, I might consider storing the session key as string within SharedPreferences.
Internal storage is good for storing application data that the user doesn't need access to, because the user cannot easily access internal storage. Possibly good for caching, logs, other things. Anything that only the app intends to Create Read Update or Delete.
External storage. Great for the opposite of what I just said. The dropbox app probably uses external storage to store the user's dropbox folder, so that the user has easy access to these files outside the dropbox application, for instance, using the file manager.
SQLite databases are great whenever you a lot of structured data and a relatively rigid schema for managing it. Put in layman's terms, SQLite is like MySQL or PostgreSQL except instead of the database acting as a server daemon which then takes queries from the CGI scripts like php, it is simply stored in a .db file, and accessed and queried through a simple library within the application. While SQLite cannot scale nearly as big as the dedicated databases, it is very quick and convenient for smaller applications, like Android apps. I would use an SQLite db if I were making an app for aggregating and downloading recipes, since that kind of data is relatively structured and a database would allow for it to scale well. Databases are nice because writing all of your data to a file, then parsing it back in your own proprietary format it no fun. Then again, storing data in XML or JSON wouldn't be so bad.
Network connection refers to storing data on the cloud. HTTP or FTP file and content transfers through the java.net.* packages makes this happen.
Considering this i suggest you to use Sqlite especially in your case.
Best luck
it depends on your need, some times you use all options in the same app,
for example : the best way to store grades and classes is using database, in android SqlLite database.
and for storing some variables values like username and password you just need to use shared preferences.... at least this is my policy in my apps.
SQLite will be the best for your scenario.
As you can create well formatted Tables with desired columns. Either you can use pre-developed database or you can create tables on the go.

approach for synching android app database with server db?

I'm developing an Android app as a "proof of concept" for our company. If they like it and think it's worth investing, then we'll move on to bigger things. I'm trying to figure out the best/most practical approach for this.....the basics of the app will connect to our DB and display information regarding a specific customer. For now, let's say we will only pull data from 3-4 tables (but there could be 10+ in the future). If the app doesn't have an internet connection then it should use the local DB. What is the best approach for this? Here's what I was thinking and would like some input/suggestions if possible:
1.) app runs checks internet connection. If exists, check db version (how, through a web service?)..if server db is newer, get latest data. If no internet, use local db.
2.) app parses data and displays it.
If this is correct, then there could be no modifications to the web service that would add fields to a result without changing the app as well. Is there a way for an app to parse fields regardless of how many fields there are?
I've read and walked through the tutorial on google with databases and such (Notepad tutorial) but it seems like the column names are all hard-coded in the parsing class, which I was hoping to avoid.
Sorry if this is confusing but I know I need my app to use a local db to read data, I also know that the app must get data from the server when it can (via onCreate or a refresh button) and copy it locally....Copying it locally is the part I'm having trouble understanding I guess....is there no way of saying "go out and get this result and display it", knowing that those results could mean 5 fields the first time or 1 the next.
Any help/guidance is greatly appreciated!
You probably want to use a SQLLite DB to store your data locally, a ContentProvider to provide CRUD access to the db, and a SyncAdapter to sync with your server when possible. The Sync Adapter also writes to the DB via the ContentProvider. See the SampleSyncAdapter sample in the SDK for an example of how this works. You will be implementing your own ContentProvider, but the sample just uses Android's supplied Contacts ContentProvider.
http://developer.android.com/resources/samples/SampleSyncAdapter/index.html

Android - reading/writing to online mysql database

I've just written a short Android app which stores userdata in the phone-side sqlite database.
What I'd like to be able to do is to add this to an online database (I currently have a mysql database with my webhosts, but if there's any easier way then I'm open to suggestions), but it'll be subject to condition (Such as if a certain value doesn't already exist). I'd also like to be able to get data from this online database too to be added to the sqlite database on the phone.
I've had a look around and people seem to suggest using php as a go-between for that, but is that the easiest way? there aren't any mysql helper classes that could just interface directly or anything?
Newbie question I know, but the project was to teach myself how Android works so getting stuck in is the way to go..
Cheers!
Yes; using PHP is an example of an easier way to go. You need to create web services which allow you to interact between the android phone and a MySQL database. To my knowledge you can't go directly to a database hook; as you need to have something that can hook in. Also it would be a security issue if you put on each and all of your phones the connection information for your database.
Think if you had to change the host of your DB as your traffic grew large that you needed to upgrade; this would be a new update in the store and all clients would need to update this; otherwise you would be maintaining two code bases.
By using PHP you are able to create that middle level and easily interact with the DB.
Here is a quick article on creating REST PHP Web Service. Tutorial
Good Luck!

Categories

Resources