![]() To do this, we will start a transaction in db and execute the SQL query asynchronously:ĭb.transaction(createTable, sqlErrH, getTaskList) The next step is to create a table for our records. The openDatabase function requires four parameters: the name of the dabase, the version of the database, the display name of the database, and the size (in bytes) of the database.Ģ. The first thing we need to do when using Cordova is to get a reference to our database using the openDatabase function:ĭb = window.openDatabase(“TaskDB”, “1.0″, “Simple Tasks”, 1000000) Once you have the source code, open the TodoListPhoneGap project with Eclipse, preferrably Eclipse Indigo.ġ. You can obtain the source code through SVN by issuing the following command in a terminal: Its functionality is limited to adding new tasks if you want to add other functions (such as updating and deleting tasks), you can write them yourself. My demo application is called TodoListPhoneGap. Note that WebSQL is not supported on Firefox and IE, and that the Web SQL spec was deprecated in Nov. It is also fast and heavy-duty because SQLite’s storage capacity is much bigger compared to LocalStorage. Web SQL offers a useful interface for storing structured data it works well if you have a remote server that uses SQL databases, and you want to mirror the structure of your data between platforms. Web SQL is a thin, asynchronous wrapper around an SQLite database it is currently well-implemented on first-class mobile devices (iOS, Android, and BlackBerry OS 6.0). ![]() Since LocalStorage relies on key-value pairs instead of SQL, I used Web SQL for the demo application in this tutorial. The W3C docs help fill in some things that the Cordova documentation doesn’t cover, such as error-handling and labels for SQLError.Ĭordova provides two options for persisting your applications data: Web SQL and LocalStorage. In this tutorial, we will briefly cover using Web SQL on Cordova for storage on mobile devices.īefore proceeding, please carefully read Cordova’s Storage documentation along with the W3C spec for Web SQL Database support. This tutorial will focus on storage options provided by Apache Cordova to store structured data in a database.Īpache Cordova (aka PhoneGap) is an HTML5 application platform that allows you to author native applications with web technologies and get access to APIs and app stores.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |