Tag: sqlite

Get generated id after insert

I’m using the SQLite with Android, and I want to know the best way to get the generated id of the row I inserted. A solution I think makes a search after include, but it doesn’t look the best way.

How to delete SQLite database from Android programmatically

I would like to delete the database file from the Android file system programatically? Can I have a shell script launch adb which in turns runs a shell script in the Android space to do the database deletion? Can I get this done from within a JUnit test case (with a system() call)? How do […]

SQLiteDatabase.query method

I am using the query method of SQLiteDatabase. How do I use the query method? I tried this: Cursor cursor = sqLiteDatabase.query( tableName, tableColumns, whereClause, whereArgs, groupBy, having, orderBy); tableColumns – columns parameter is constructed as follows. String[] columns = new String[]{KEY_ID, KEY_CONTENT}; If we need to get all the fields, how should the column […]

Pros and Cons of SQLite and Shared Preferences

What is the good mechanism to store information among SQLite database and Shared Preferences? Why use shared preferences? Why use sqlite? I tried to find the difference between them, and which is the better mechanism for data storing, but I am unable to find the appropriate answer on Google. Please help me with example and […]

Get boolean from database using Android and SQLite

How can I obtain the value of a boolean field in an SQLite database on Android? I usually use getString(), getInt(), etc. to get the values of my fields, but there does not seem to be a getBoolean() method.

When is SQLiteOpenHelper onCreate() / onUpgrade() run?

I create my tables in my SQLiteOpenHelper onCreate() but receive SQLiteException: no such table or SQLiteException: no such column errors. Why? NOTE: (This is the amalgamated summary of tens of similar questions every week. Attempting to provide a “canonical” community wiki question/answer here so that all those questions can be directed to a good reference.)

Android search with Fragments

Does somebody know of a tutorial or an example of how to implement the standard Android search interface with Fragments? In other words, is it possible to put a standard search with a SearchManager in a Fragment?

Best way to work with dates in Android SQLite

I’m having some trouble working with dates on my Android application that uses SQLite. I have a couple questions: What type should I use to store dates in SQLite (text, integer, …)? Given the best way to store dates how do I store It properly using ContentValues? What’s the best way to retrieve the date […]

What are the best practices for SQLite on Android?

What would be considered the best practices when executing queries on an SQLite database within an Android app? Is it safe to run inserts, deletes and select queries from an AsyncTask’s doInBackground? Or should I use the UI Thread? I suppose that database queries can be “heavy” and should not use the UI thread as […]

Version of SQLite used in Android?

What is the version of SQLite used in Android? Reason: I’m wondering how to handle schema migrations. The newer SQLite versions support an “ALTER TABLE” SQL command which would save me having to copy data, drop the table, recreate table and re-insert data.

Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.