AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Jquery mobile sqlite tutorial3/1/2024 JavaScript code to execute if the query failed Transaction.executeSql (sql, / undefined, From the db object recovered earlier, your SQL commands are executed in a transaction. The principle of data management is simple. We have here indicated a starting size of 65,535 bytes, which may be exceeded if the database grows. Creating the databaseįirst, create an access to the database, which creates the empty database if it is the first call: But it is possible to use SQL database locally via JavaScript, thanks to HTML5. Permanent storage and temporary storage as we have seen, do not allow facilities such as those found in the databases using SQL. SessionStorage.fname = "Eric" Using a database SessionStorage allows storage in the session.įor example, storing a first and last name in one of these objects is done by: To enable this, two JavaScript objects will be used: localStorage and sessionStorage: This means that all the pages of our site (and a fortiori all windows) can access information stored in the session, but this until the end of end of our application. In session storage, the information is stored only in the context of the session. We see that it is really a permanent storage. In permanent storage, information is saved permanently until you erase them, even if the application is closed (and even if the phone is restarted). The difference between permanent storage of information and its storage in the session, held in the storage period. Less restrictive than the previous form of storage, it is also simpler to implement, but can store less information. Storage through localStorage and sessionStorage objects, to store information made up of strings. We will use this type of storage when we will have a lot of information to store. Storage via a database containing the tables described in SQL. HTML5 offers two types of data storage on the client: We will have the opportunity, in a JavaScript program written with jQuery Mobile to access data stored in a local database, without accessing a server. The complementarity of these notions with jQuery Mobile is obvious. This version of HTML is becoming more present in browsers (in their latest version), and smartphones as well as graphics tablets naturally use it. Indeed, the concepts presented here are directly related to HTML5. Tx.This chapter is not about the direct use of the jQuery Mobile possibilities. To read already existing records we use a callback to capture the results as follows − Here e_id and e_log are external variables, and executeSql maps each item in the array argument to the "?"s. Tx.executeSql('INSERT INTO LOGS (id,log) VALUES (?, ?'), We can pass dynamic values while creating entering as follows − Tx.executeSql('INSERT INTO LOGS (id, log) VALUES (2, "logmsg")') Tx.executeSql('INSERT INTO LOGS (id, log) VALUES (1, "foobar")') To create enteries into the table we add simple SQL query in the above example as follows − The above query will create a table called LOGS in 'mydb' database. Tx.executeSql('CREATE TABLE IF NOT EXISTS LOGS (id unique, log)') This function needs a single argument, which is a function that takes care of actually executing the query as follows − To execute a query you use the ansaction() function. Without this feature, however, the databases are still being created on the fly and correctly versioned. The last and 5th argument, creation callback will be called if the database is being created. The above method took the following five parameters − To create and open a database, use the following code − The openDatabase method takes care of opening a database if it already exists, this method will create it if it already does not exist. Transaction − This method gives us the ability to control a transaction and performing either commit or rollback based on the situation.ĮxecuteSql − This method is used to execute actual SQL query. OpenDatabase − This method creates the database object either using existing database or creating new one. There are following three core methods defined in the spec that I am going to cover in this tutorial − Web SQL Database will work in latest version of Safari, Chrome and Opera. If you still want to have a session with SQL then, you can go through our SQL Tutorial. I'm assuming you are a great web developer and if that is the case then no doubt, you would be well aware of SQL and RDBMS concepts. 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.
0 Comments
Read More
Leave a Reply. |