Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 database storage (SQL lite) - few questions

Tags:

html

database

Hy there,

I can't find enough beginner resources on the web about HTML5 database storage usage examples (CRUD)

I'm opening(creating) my DB like this:

var db;  $(document).ready(function()  {      try     {       if (!window.openDatabase) {             alert('Not Supported -> Please try with a WebKit Browser');       } else {           var shortName = 'mydatab';           var version = '1.0';           var displayName = 'User Settings Database';           var maxSize = 3072*1024; //  = 3MB            in bytes 65536           db = openDatabase(shortName, version, displayName, maxSize);                 }     }      catch(e)      {       if (e == 2) {            alert("Invalid database version.");       } else {           alert("Unknown error "+e+".");       }return;     } }); 

QUESTION 1: How many databases can i create and use on one domain? QUESTION 2. How to delete (drop) a database. -> i have not figured this out yet.

To create sql queries you use transaction:

function nullDataHandler(transaction, results) { } function createTables(db) {   db.transaction(function (transaction)   {     //first query causes the transaction to (intentionally) fail if the table exists.     transaction.executeSql('CREATE TABLE people(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL DEFAULT "John Doe", shirt TEXT NOT NULL DEFAULT "Purple");', [], nullDataHandler, errorHandler);   }); } 

QUESTION 3: How so is the above transaciton failed if a table exists? Is the nullDataHandler involved to do this? Where on the web is there documentation explaining the executeSql API? Arguments?

thx

like image 357
PathOfNeo Avatar asked Apr 22 '10 10:04

PathOfNeo


People also ask

What is HTML5 database?

Advertisements. The Web SQL Database API isn't actually part of the HTML5 specification but it is a separate specification which introduces a set of APIs to manipulate client-side databases using SQL.

Does HTML5 have SQL support?

One of the HTML 5 specifications, Web SQL database, enables offline data storage by defining an API for storing structured data within the client. Yuvarani Meiyappan introduces the new Web SQL database feature in HTML5 and its API, and then dives into using Web SQL database with a demo for implementing a shopping cart.


1 Answers

The spec you're looking for is Web SQL Database. A quick reading suggests:

  1. There is no limit, although once your databases increase beyond a certain size (5MB seems to be the default), the browser will prompt the user to allow for more space.
  2. There is no way, in the current spec, to delete databases.
  3. The executeSql() function takes an optional error callback argument.

HTML5 Doctor also has a good introduction.

Going forward, though, I'd recommend looking at Indexed DB. Web SQL has essentially been abandoned since there is no standard for SQL / SQLite. Even Microsoft has endorsed Indexed DB. See Consensus emerges for key Web app standard.

like image 134
Jeffery To Avatar answered Sep 23 '22 14:09

Jeffery To