What is the real use of Sqliteopenhelper on Android?

Asked

Viewed 1,890 times

2

I was watching a course online devmedia explaining about Sqlite on Android, in the example of the course was made a basic crud, were created 1 bank and 2 tables. In the example, I was creating two classes that extended to Sqliteopenhelper, and each class manipulated a table, i.e., the example was using Sqliteopenhelper to manage the database and table data!!

After searching on the outside, I saw that when creating the database, the sqlite generates its cache, which could generate a big problem in this case of the example. And I saw an example of a website that used a separate class to manipulate the tables!

  • So I’m confused, Sqliteopenhelper only serves to create the bank?

  • You should not manipulate table data by it (creating several classes of Sqliteopenhelper, for each table)?

  • If it only serves to manage the bank (without the tables), would I have to create all tables in the same Sqliteopenhelper class? In this case, if a user removes some table, how would it return?

I have no way to send the devmedia link, because the access is only for subscribers.

Example managing tables outside the helper: http://pplware.sapo.pt/smartphones-tablets/android/tutorial-utilizao-do-sqlite-no-android-parte-i/

  • 1

    I do not know the use of Sqlite on Android but I know the history of courses and articles from Devmedia. Many are cool, help even. But I’ve seen some bullshit too. And the laity (most of whom read, obviously) think it is good what it is not. Nothing against saying about this course, just a general warning. Well, actually anyone can write bullshit, I can do this, so the alert is wider.

  • I’ve been noticing this after noticing a bunch of silly things, which I didn’t realize until I Googled. At least my question serves as a warning to pay attention before signing something.

  • I have been researching, and it seems that really the function of Sqliteopenhelper. is only to facilitate the creation of the bank by the methods onCreate and onUpdate. But still I am in doubt about the table creations, whether they should all be created in Sqliteopenhelper, and manipulated in another class

  • I think the main idea of SQLiteOpenHelper is the initial configuration of the application (either in the first installation, where the tables have not yet been created) or for evolution (upgrade and downgrade of the database version). It should not be used directly for consultations. In the documentation it is clear this ("A helper class to Manage database Creation and version management"). I believe that for bank appointments it should not be used, the best thing to do is to use ContentProvider's, Cursor's or at most a SQLiteDatabase for quick queries, if it is something asynchronous use a CursorLoader.

  • @Wakim if you can answer, so I can accept... I don’t think there will be any answer

1 answer

2


I think the main idea of Sqliteopenhelper is the initial configuration of the application (whether in the first installation, where the tables have not yet been created) as for evolution (upgrade and downgrade of database version).

In the documentation it’s clear that:

A helper class to Manage database Creation and version management.

One should not use it directly for queries, because there are better ways to be doing this.

The best thing to do is to use Contentprovider’s/Contentresolver’s, Cursor’s or at most a Sqlitedatabase for quick queries. If the idea is to make asynchronous queries, use a Cursorloader.

In the worst case, even a ORM is valid. Examples: Ormlite, greenDAO, Sugar ORM and the Active Android.

Personal opinion: I use to CursorLoader, ContentProvider's and Cursor. I have an app that uses Active Android, but if I had time to redo, I would wear a suit CursorLoader even.

I will not put examples of codes because otherwise you will run too far from the scope of the question.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.