A (175)

(Tuis.) #1

508 CHAPTER 14: Android Content Providers: Providing Data to Applications


Each row is a database record, and a database record will usually contain all sorts of different data
types across the different data table columns. The classifications of data fields that a data record
may contain usually spans names (text), numbers, and references (addresses) to things like emails,
websites, social media profiles, passwords, and the like.


Caution Once the record structure and data fields that define your record structure are set up, don’t change
this record structure later, if you are designing your own databases. This is because currently loaded records
(the fields) may not fit into the new data structure definition correctly! It is best to design your database
structures up-front. The database design process is especially critical to the success of your RDBMS project
over time.

One of the most popular database programming languages in the world is called SQL, which
stands for Structured Query Language. You will be learning about SQL, as used in SQLite, later on
in this chapter.


The structured part comes from the structured tabular format of a relational database, and the
query part comes from the fact that these tables of data are designed to be searched through using
a certain data value. The language part comes from the fact that SQL has evolved over time into a
database programming language, which is so complex and involved, that there are probably more
books regarding SQL RDBMS topics than there are on database programming for the Android OS.


If you have a massive amount of data fields (columns) in the database table, you will probably want
to optimize your database using more than one table of data. In real-world database design, the
theory of which is largely beyond the scope of an introductory book, you will want to have more than
one database table for search and access performance, as well as for organization reasons. In fact
the Android OS uses more than one database table for its end-user information storage and access,
as you will soon see later in the chapter when you get into the Contacts database tables structure,
which is quite complex, spanning quite a number of database tables.


The way to create multiple database tables that act together as one massive unified database is to
have a unique key (unique index) for each record in each of the tables. That way, information for a
single data record can span more than one database table using the unique key. In Android, this key
is called an ID and is always designated using a system database constant _ID in Android’s SQLite
databases. For instance, if a key or _ID value is 154, your email information and phone information
could be contained in two different tables, but stored under that same key (index) value, and thus
accurately associated with your Android user account even though it spans across multiple tables.


SQLite: The Open Source Database Engine


As you know, the SQL in SQLite stands for Structured Query Language. The “Lite” part denotes that
this is a “lightweight” version of a DBMS, intended for embedded use in consumer electronics
devices, and not a full-blown DBMS, as would be used on an advanced computer system such as a
database server. It is also interesting to note that SQLite is also included in all the HTML5 browsers!
All you really need to know about SQLite is that it is a part of the Android OS, and that you can use it
for data storage.

Free download pdf