What is Web SQL?
Web SQL Database is a web page used for storing or managing the data in the database. The API is supported by Google Chrome, Opera and Android browsers.
The Web SQL API is not a part of the HTML5 specification, but is a separate specification. It addresses a set of APIs to manipulate the client-side database.
Open databases, transactions, are the basic methods to execute.
The W3C web application is working on the specification in November 2010. It was specifying a lack of independent implementations because the specification cannot proceed to become a W3C recommendation.
Mozilla Corporation was one of the key behind the standard at the same time being the prime mover behind IndexDB, is an alternative storage standard.
The Web API is not the part of HTML5 specification. It is a separate specification which specifies a set of APIs to manipulate the client-side database.
The web SQL database works in the newest version of Safari, Chrome and Opera.
Methods of Web SQL:
There are three methods -
The Open Database method opening the database if it already exists. Use the code below to create and open the database-
The above method took the below five parameters -
In the last and 5th arguments, the creation call-back will be called if the database is being created.
We use the database.transaction () to execute a query. It has a single argument, that executing the query as below:
The above code generates a table named LOGS in 'mydb' database.
To create entries in the table, we execute a SQL query, as follows:
We can pass dynamic values while creating entering as follows -
e_id and e_log are the external variables here, and executes every item in the array.
To read already existing records we use a callback to capture the results as follows -
Let us keep this example in a full-fledged HTML5 document as follows and try to run it with the Safari browser.
The above code produces the following result:
Log message created and row inserted. Found rows: 2 foobar logmsg