This is cool,do you think so?
So you've probably heard a lot about the new HTML, HTML5. This is tutorial is about one of my favorite new specifications from it, client-side databases. This new specification will be popular, web-apps are now changing the web and portability it the key. People don't have the internet everywhere (yet) so this is where client-side functionality comes in, these databases allow for storage offline and when connection is available, update online.
Creating the database
We use the openDatabase to create and open a database. This function which has a few specific parameters.
* shortName - This is basically the name you will use to reference the database. Keep it simple and distinguishable.
* version - This is a string, so anything is generally accepted i.e using the alpha (α) or beta (β) symbols
* displayName - Just for readability, has no real effect on the database.
* maxSize - An integer which states the maximum size of the database in bytes
Querying the database
The transaction function is basically the wrapper for the executeSql function. ExecuteSql is the vital function for querying the database. The parameters for executeSql is just the SQL query.
Getting the data
The key to retrieving the data is to send it to a function to parse and use/display it. As in the example above, I use a function called retriveData. The data is sent as a parameter in the function.
To access the data, we need to use the results parameter. The data is a bit different from accessing normal Javascript variables as it needs the keywords rows and item(). Item(int) needs an integer to select a specific row, it does not return every row. This will return a Javascript object with the data in that row. After we have our row selected, we select a column we want the data returned from, so we add our column name after item() e.g item(2)['foo'] This is exactly the same as if you were retrieve data in a normal JS Object.