What is Fastest way to query a database android? - android

I have a database that contains 35000 records, and can easily get up to about 60000 records,
What is the best way to query these data? Will ORMLite or GreenDAO be usefull? Or should i just stick with Cursor?

That depends on what you mean by "best".
Fastest, most flexible, best integration with Android library functions: Stick with Cursor. Since ORMs are just wrappers around the native Android cursors, they are unlikely to be faster than direct access. In many cases, the Android UI library classes are optimized for Cursors (e.g. SimpleCursorAdapter, which allows you to bind a cursor to a UI list).
Most readable, most maintainable: An ORM might help here, but that depends on a lot of factors, including your project complexity, your application architecture, etc.
See the following programmers.se question for more information:
Does it make sense to use ORM in Android development?

Related

Is it a good idea to use an ORM for Android apps?

Is it a good idea to use an ORM (Object Relational Mapper) like:
ORMLite
ActiveAndroid
for Android apps.
The abstraction layer this technique adds has itself calculation and memory overhead. Since, those resources and the battery lifetime are mostly very limited I would think 'no', but on the other hand it makes the code much cleaner, because one almost never has to write raw queries.
What are the pros and cons?
What is recommended?
If it is recommended, which one should I use?
As of May 18, 2017, Google introduced Room at I/O '17 as replacement for raw SQLite queries. So, at least this ORM is now officially recommended.
OrmLite use SQLite database underneath. It just generates database schema using annotation processor. It is a good idea if your project allows using third- party opensource libraries. However, you should incapsulate all implementation - dependent features - 'Dao' pattern. By doing so, you'll be able to switch between database implementations. BE careful with Realm though. It is a very powerful database, but if you use it incorrectly, it can ruin your architecture. Always specify Dao interface before implementing database itself.

Union clause in android sqlite?

How can we perform Union operation on multiple tables in android sqlite using SQLiteQueryBuilder class?
Perhaps you can use buildUnionQuery(). From the documentation, it looks pretty straightforward, you just need to construct the individual SELECT statements yourself.
There is also this method buildUnionSubQuery(), but i have absolutely no idea how to use it and the documentation is not very helpful...
I actually prefer a library called SquiDB, which has much better query building capabilities with an API that is more clear. (There are other libraries out there with good APIs as well. The point is you aren't stuck with using Android's SQLiteQueryBuilder, whose API is somewhat lacking in my opinion.)

Alternative to core data in android?

I am building a social media application which requires local storage of table data entities. This data must also be connected to a server to retrieve and update information to and from users. Our team has built an iOS client using core data, though we are looking for storage options in android. Is using SQLite the way to go? Any thoughts would be greatly appreciated.
You should take a look at Realm, it has clients for Objective-C, Swift and Android.
Description from their GitHub repository:
Features
Mobile-first: Realm is the first database built from the ground up to run directly inside phones, tablets and wearables.
Simple: Data is directly exposed as objects and queryable by code, removing the need for ORM's riddled with performance & maintenance issues. Plus, we've worked hard to keep our API down to very few classes: most of our users pick it up intuitively, getting simple apps up & running in minutes.
Modern: Realm supports easy thread-safety, relationships & encryption.
Fast: Realm is faster than even raw SQLite on common operations, while maintaining an extremely rich feature set.
If you're familiar with RxJava, you will probably want to check SQLBrite, wich is Square's solution for this.
Yes, Sqlite is a default storage solution for android. Howevere there is a wrap around it called ContentProvider. ContentProvider can be used with Loaders and provide async data loading. ContentProvider may be used to modify contats and merge accounts, see this guide. However ContentProvider may seem tricky and if you prefer ORMs you can use ORMLite or GreenDAO which are using sqlite as well.

Android database framework for complex queries and comfortable engineering

I've been using the native Android SQLite library in the last time, but I am not pleased with the re-usability and readability. There are some ORM database libraries I found for Android, but I wonder whether those are useful as I got a whole bunch of complex select and delete operations I have to be able to run.
Can you suggest me any appropriate library?
Tried this once. Pretty good I must say.
http://ormlite.com/

Higher level database layer for Android?

Are there any good database abstraction layers/object relational mappers/ActiveRecord implementations/whatever they are called for Android? I'm aware that db4o is officially supported, but it has quite a large footprint and I'd rather use a more conventional database (SQLite).
I am the main author of ORMLite which was designed to be small[ish] but still provide higher level functionality. ORMLite makes calls to the native Android OS database APIs to support its ORM functionality. See the following for general information
http://ormlite.com/sqlite_java_android_orm.shtml
Here are some Android example applications:
http://ormlite.com/docs/android-examples
I tried the Sugar ORM, which is very basic (and easy to use) but it worked for my needs.
Sugar website
There is an 'android-active-record' project which provides ActiveRecord abstraction for accessing Android SQLite database.
It's available here: http://code.google.com/p/android-active-record
It allows to eliminate most of boilerplate coding when performing CRUD operations on database entities and also minimizes efforts for creating/maintaining a database structure
Try ActiveAndroid. It is free and open source (Apache Version 2.0).
From the website:
ActiveAndroid is an active record style ORM (object relational
mapper). [...] ActiveAndroid allows you
to save and retrieve SQLite database records without ever writing a
single SQL statement. Each database record is wrapped neatly into a
class with methods like save() and delete().
[...] Accessing the database is a hassle, to say the least, in Android.
ActiveAndroid takes care of all the setup and messy stuff, and all
with just a few simple steps of configuration.
If performance and size matter, you should have a look at our open source ORM tool greenDAO. We wrote it because we did not want to compromise on speed. Other tools heavily rely on reflection, which is very slow on Android. Despite the tiny size (<100k), it supports relations, query builders, etc.
Shameless plug, but I've been working on a new open source Android framework called Infinitum. One of its main features is an ORM which has a criteria API similar to Hibernate and a few other nifty features (associations, lazy loading, etc.). It's still in its early stages, but I think it's coming along pretty nicely.
I have written a new ORM, for android, that's aimed and being as easy as possible to implement. It support lists and SQL free migration a couple things which I always found had an overhead in other libraries.
http://www.rushorm.com/
I faced the same problem and looked at both android-active-record and ActiveAndroid. I found android-active-record didn't handle the things I cared about (relationships for example), and ActiveAndroid isn't free. Therefore, I decided to write my own library. It's called AndroidRecord and it's hosted on GitHub and you're free to do with it what you want (I think I'm going to go with the MIT license). I use this every day and I'm content with it, but I'd love to get feedback.
If you need to know how to use it, I'm working on the documentation. If you need it right away, you can check out this lame example project which should be enough to dip your toes in. You can also email me of course.
There's also Neodatis and Perst (Lite).
I've toyed with Perst a year ago and concluded it's not worth it.
After all, a) Android runs on a rather restricted device with ~16mb of heap space per app and b) You customers would really appreciate performance and low power consumption.
So my advice is to go with SQLite and hand-written SQL. It's not hard at all and the wrappers provided by Android SDK are really nice.
EDIT: In 2012 the advice would be to use the ORM component of DroidParts (which is my project).
I was comparing basics of ormlite and greendao some time ago. You might want to take a look there. I plan to write some follow up with more advanced stuff in the near future but for now it's only a basic stuff. In my own project I'm using GreenDAO.
Have a look at Androrm. It is open source and well documented (see here). If you ever worked with django, you will notice, that the syntax is very similar.
Androrm also supports abstraction classes for the most common field types, plus relational fields. This way it enables you to query for your data in an very easy manner with only very little effort on your side.
SQLite is explicitly part of Android:
http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html
However you might have to create your own abstraction layer (query builder for simple queries), or otherwise deal with SQL.
Maybe http://developer.android.com/reference/android/database/sqlite/SQLiteQueryBuilder.html is what you need?

Categories

Resources