SQLite Class for HTML5 Database

March 15th, 2011 § 11 comments

This is my Javascript Class for HTML5 Databases connection to SQLite. I use this to build mobile application, including iOS, Android, and BlackBerry. I wrote this class to do the instance query to SQLite, and also some function for delete, insert, and update database records and table creation and deletion.

Here is my class:

How To Use It
Database Constructor:

Table Creation:

Drop Table:

Add / Insert Record:

SQLite is not accepting more than 1 line statement, that is the reason why we not able to do more than one statement query, like insertion. If you want to insert more than 1 record at the time, you need to use this function.

Multiline records Insertion:

Or, if you want to combine that two functions, just put if condition:

Delete record:

Update record:

Query:

Just fell free to use it and change it, and don’t forget to ask if you don’t know how to use it, or if there is some bugs. 😀

link of this class on github: https://github.com/helman/jSQLite

Cheers,
Helman

Tagged , , , , , , , , , , , , , , , ,

§ 11 Responses to SQLite Class for HTML5 Database"

  • TC says:

    Just curious, do you still use this for your mobile applications? Im learning and want to use html5, css, and jquery, but, mostly learning html5 currently, doesnt seem too hard, but, trying to learn about data storage, right now, creation of categories, basic storage like list of names, and creating new lists under those names.. sounds simple enough, but if you dont even know how to add, edit, delete, and used to mysql database with php…lol.. little more complicated than I thought..lol… So, do you suggest using this for data or anything else???? Thanks

    • admin says:

      Hi, thanks for your visit.
      Depend on what is your usage, i did catalog app using offline database, because my client want the fast loading of data, so using this, my client only need to update the catalog if there are any changes from website.
      HTML5 database (SQLite) is a little bit different from server database (mySQL). It is faster because of async processing, and because of async, it is quite defferent from php calling mySQL, we need to use Callback function to get the response of our query.
      So, using offline db is very helpfull if you’re considering the loading time. But it is only limited to 5MB only for mobile storage.

      Cheers,
      Helman

  • Martin says:

    I really like this piece of code, but I seem to have some trouble using it. I can write information out to a database, but I can’t seem to query it. I know originally when I was looking at the code I could. I’m not sure what changed. I see it will return an error code, but I’m not sure how to do that.

    Could you show an example of query: function(sql,callback,params,er) using all the fields. For example, show an example using the params and er parameters. I think if I can see the error I can figure out the problem I’m having.

    Thanks,
    Martin

    • admin says:

      Hi Martin,
      Thank you for considering of using this DB Class. This is the simple code for Query:

      Just poke me, if you have any question. 🙂

      Cheers,
      Helman.

  • David says:

    Hello,

    thanks for the lib! I have a little question: The lib always a new DB, why?

  • David says:

    Hello,

    thanks for the lib! I have a little question: The lib add always a new DB, why?

    Grettings David

  • temujin jumlani says:

    Great class!

    Can you give an example on using transactions and getting last inserted row id on a table? Notify me via my email .

    Thanks and good day.

  • Janek says:

    I notice a “zero” from class file at line 75. Is it a bug?

  • nader says:

    What in case more than 5 MB is needed. I am developing an app using HTML5 and javascript with SQL server backend (webservices used), but I need to store data offline for sales entry and then sync it back to server when in offline mode.
    I have seen tutorials for native development with Sqlite but not while using HTML5 & jquery alone. Do you have any suggestions about htis
    Thank you
    Nad

Leave a Reply