Book Image

Android SQLite Essentials

By : Sunny Kumar Aditya, Vikash Kumar Karn
Book Image

Android SQLite Essentials

By: Sunny Kumar Aditya, Vikash Kumar Karn

Overview of this book

<p>SQLite is an open source relational database management system. Android uses the SQLite database to store and retrieve data persistently. The driving force behind the platform is the database, enabling a myriad of choices for developers making cutting-edge applications.</p> <p>Android SQLite Essentials focuses on the core concepts behind building database-driven applications. This book covers the basic and advanced topics with equivalent simplicity and detail, in order to enable readers to quickly grasp and implement the concepts to build an application database.</p> <p>This book takes a hands-on, example-based approach to help readers understand the core topics of SQLite and Android database-driven applications. This book focuses on providing you with latent as well as widespread knowledge about practices and approaches towards development in an easily understandable manner.</p>
Table of Contents (11 chapters)

General tips and libraries


We will cover some general and not so general workarounds and practices, which can be put to good use depending on the situation. For instance, in some cases, we need to have a prepopulated database of values that we will make use of in our Android application or upgrading a database, which seems trivial but can break our application.

Upgrading a database

In Chapter 2, Connecting the Dots, we used onUpgrade() to show how a database is updated. If we go back to the example, you will notice that it executes a Drop Table command. What will happen here is that the original table will be dropped and a new table will be created by the call, onCreate(). This will lead to a loss of the existing data and hence is not suitable if we need to alter our database. The onUpgrade() function can be defined as follows:

public void onUpgrade(SQLiteDatabase db, int oldVersion,int newVersion)
{
  String DROP_TABLE = "DROP TABLE IF EXISTS " + TABLE_NAME;
  db.execSQL(DROP_TABLE);
  onCreate...