In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you the "sample analysis of h5 local database", which is easy to understand and clear, hoping to help you solve your doubts. Let the editor lead you to study and learn the article "sample analysis of h5 local database".
In HTML5, in order to reduce the burden on the server and improve the performance of the Web application, the data that must be saved on the server is changed to be saved locally on the client. You can have direct access to the built-in database as easily as accessing local files. There are two local databases built into HTML5, one is SQLLite and the other is indexedDB. This time a simple and simple introduction to SQLLite.
While writing this article, I queried Web SQL Database (SQLLite) and unfortunately saw this.
Screenshot of the official website
This specification is no longer under active maintenance, and the Web Application working Group does not intend to continue to maintain it.
There are three core methods of SQLLite
OpenDatabase: this method is used to create a database object and return an instance
Transaction: this method is used to control transaction commit or rollback
ExecuteSql: this method is used to execute SQL queries (SQLLite can use sql to perform additions, deletions, modifications and queries)
OpenDatabase
For example, you want to create a database
/ / the meaning of the parameter is database name, version, database description, database size var db = openDatabase ("myData", "1.0", "MyDataBase", 1024 * 100)
This allows you to create a local Web SQL Database with the return value "db" as an instance of the database.
Transaction&executeSql
The transaction method is used to handle transactions and roll back the whole thing when a statement fails.
The executeSql method executes the SQL statement and returns the result.
Please look at the code
/ / Open a thing and pass in a method containing transaction content / / use executeSql to execute sql in the transaction to create a table db.transaction (function (tx) {tx.executeSql ("CREATE TABLE IF NOT EXISTS message (name TEXT,content TEXT,time TET)", [], function () {/ / execute a successful callback function (optional or not)} Function (error) {/ / execute a failed callback function (optional or not), / / insert a data tx.executeSql ("INSERT INTO message VALUES (,?)", ["zhong", "web sql database", '2017']) into the table })
Execute the above code to view it in the chrome console
Execution result
Successfully insert a piece of data!
Let's check this data again.
Db.transaction (function (tx) {tx.executeSql ("SELECT * FROM message", [], function (tx, rs) {/ / executes the callback function successfully, returns the execution result rs, and we loop for (var I = 0; I < rs.rows.length) with rs Console.log (rs.rows.item (I))}}, function (eror) {})})
View in the chrome console
The above is all the contents of the article "sample Analysis of h5 Local Database". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.