582 CHAPTER 16 Offline web applications
Lesson 1: Working with Web SQL
Web SQL is arguably one of the most powerful options available to you. It provides a full rela-
tional database that includes many of the features you’ve come to enjoy from the server-side
database offerings.
Most current implementations are built on SQLite, which is one of the most widely
used lightweight database engines. It’s an open-source solution with a vibrant community
backing it.
After this lesson, you will be able to:
■■Describe the use of Web SQL.
■■Implement transactions using Web SQL.
Estimated lesson time: 20 minutes
Considering the questionable longevity of Web SQL
Before starting with Web SQL, be aware that the World Wide Web Consortium (W3C) has
stated that Web SQL is no longer on its recommendation track. In 2010, the W3C Web
Applications Working Group announced that it does not intend to maintain the specification.
NOTE DISCONTINUED SUPPORT
For further details regarding the W3C’s decision to discontinue support of the Web SQL
specifications, please see its explanation at http://dev.w3.org/html5/webdatabase/.
What this means for Web SQL depends on the browser you’re targeting. Although the
specification is no longer being maintained, some browsers have continued their support.
(See Chapter 15 for a complete list.) Therefore, Web SQL might be a viable option if you’re
building specifically for a platform such as iOS for iPad or iPhone. Another common use is in
Google Chrome extensions. If you’re building a browser-agnostic application, consider one of
the other offline storage solutions.
If you do plan on developing with Web SQL, it might be a good idea to remember what
alternatives are available (such as IndexedDB) and what level of effort might be needed if
other browser vendors decide to move away from it in the future.
Creating and opening the database
In the following sections, examine the syntax used to create or open a database, start a trans-
action, and execute a SQL command. Most of these commands should look very familiar if
you’ve used other relational databases.