Original address: http://www.cnblogs.com/xumingxiang/archive/2012/03/25/2416418.html
Web SQL database (detail URL:http://www.w3.org/TR/2008/WD-html5-20080610/structured.html )
Web SQLdatabase: Databases API(IE and Firefox not supported)
HTML5 Database API:
OpenDatabase : Create a Database object using an existing database or creating a new database.
Transaction : Allows the user to control the transaction commit or rollback, depending on the situation.
ExecuteSQL : used to perform a real SQL query.
There are two necessary steps to writing a sqllite database using javascript scripting :
Creates an object that accesses the database.
Use transaction processing.
1. Create or open a database opendatabase
Use the opendatabase method to create an object that accesses the database.
Database OpenDatabase (in domstring name,in domstring version,in domstring displayname,in unsigned long estimatedsize,in o Ptional databasecallback Creationcallback)
OpenDatabase () method: You can open a database that already exists and create it if it does not exist.
Five parameters: Database name, version number, description, database size, and create callback.
Note: To detect whether the connection was successful.
2. Accessing and manipulating Databases transaction
Db.transction (Function (TX) {})
Transaction.executesql (Sqlquery,[],datahandler,errorhandler)
extension: After executing executesql , There is a parameter resultin the DataHandler callback function.
Result: The data set that is queried. Its data type is sqlresultset .
The SqlResultSet is defined as:
Interface SqlResultSet {
readonly attribute long Insertid;
readonly attribute long rowsaffected;
readonly attribute sqlresultsetrowlist rows;
};
Insertid: is an insert operation that represents the first number of data inserted into a table, when inserting multiple data, returns the ordinal of the last data corresponding
Rowsaffected: Represents the number of rows affected, for example, performing an update operation and updating a data, then it is 1
rows: Returns a sqlresultsetrowlist type of data
Interface Sqlresultsetrowlist {
ReadOnly attribute unsigned long length;
[Indexgetter] Domobject item (in unsigned long index);
};
result.rows.length: Returns the number of items per line
result.rows.item (0) ["id"] or result.rows.item (0). ID; : Returns each item
HTML5 Web SQL