0

Is it possible to read and write with chrome or ie8 ,9 and 10 a local sqlite file.

I saw this SQLite database in Javascript locally but this code in a javascript section on a html page doesn't seem to create a database.

 <script type="text/javascript">

    //https://stackoverflow.com/questions/5244471/sqlite-database-in-javascript-locally?rq=1

    function createDatabase(){
        try{
            if(window.openDatabase){
                var shortName = 'db_xyz';
                var version = '1.0';
                var displayName = 'Display Information';
                var maxSize = 65536; // in bytes
                db = openDatabase(shortName, version, displayName, maxSize);
            }
        }catch(e){
            alert(e);
        }
    }
Community
  • 1
  • 1
wetlip
  • 133
  • 3
  • 19
  • to all the folks who would answer "no": it is possible. in IE natively with activex and in chrome through an extension. – GottZ Mar 31 '13 at 18:20
  • examining all the online documentation on this subject , a strange thing is happening , w3c will stop using sqlite for storage local, chrome uses it, microsoft will implement it in their new windows 8 apps but doesnt implement it in ie10 for windows 7 , so their will be difference in windows 8 "mobile and desktop". http://diveintohtml5.info/storage.html http://timheuer.com/blog/archive/2012/08/07/updated-how-to-using-sqlite-from-windows-store-apps.aspx – wetlip Apr 01 '13 at 09:53

1 Answers1

0

to achieve this goal you need two things.

  1. you need to read a selected file within the filesystem
  2. you need to implement sqlite in javascript unless the browser supports it (maybe it has been implemented already)

there are optional ways to store data on the clients side:

  1. localStorage
  2. sessionStorage
  3. cookie
  4. file caching

out of theese the most reliable would be the cookie. the bad sideeffect would be that every request to your site forwards the cookies to your http server (within the http request header) besides that, the cookie has a storage quota that is limited to 4kb. so if you store 2 cookies you get 2kb for each or 1kb for the first and 3kb for the second.

localStorage: 2,5 MB for Chrome, 5 MB for Firefox and Opera and 10 MB for Internet Explorer.

the good parts:

  1. it will be stored untill its wiped
  2. it is accessible on a key - value based architecture. localStorage["foo"] = "bar";

the bad part would be that it is only accessible through javascript.

sessionStorage is the same as localStorage however it will be deleted as soon as you close your browser.

file caching is like resource hacking. you could forward a unique file to the user that contains all the data you want to store and let it read from cache each time.

bad parts:

  1. will get deleted as soon as the offline storage quota is reached
  2. will need to be set by your webserver
  3. bad idea unless you srsly can make use of it.

now why did i not mention how to use sql?

for reading a file in IE you simply can use ActiveX components. this requires that the user has set low security settings and that the user actually allows the website to gain file access.

for reading a file in chrome and other browsers or an alternative way for IE with html5 support:

  1. you can read files by draging them into the browser window
  2. you can also read files by selecting them in a file select box
  3. you can read files through plugins

the third way to read files would be the most reliable but it requires that the user has java enabled.

through java you could read files.

now the sqlite part:

  1. you could implement sqlite in javascript. (i would not want to do that)
  2. you could use the obsolete sqlite database for html5. (thats what you are asking for) it has been replaced by localStorage.
  3. you could implement it in java or a browserplugin. (maybe easyer but still i'd prefer localStorage)

maybe this helps you.

GottZ
  • 4,824
  • 1
  • 36
  • 46
  • thank you for the elaborate answer, yes i was trying to establish this with pure javascript. in chrome it works not in ie, i dont like active plugins , the goal was pure javascript sqlite reading and writing local on client side and working in the most used browsers. This isnt possble yet form me. a nice overview using html5 presentation is this one [html5storage](http://html5-demos.appspot.com/static/html5storage/index.html#slide1) – wetlip Apr 01 '13 at 20:56