HTML5 Web SQL database file location in chrome
Asked Answered
F

2

5

I want to use HTML Web SQL for my next web application project, so I did a quick search to find a tutorial and wrote the following code:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Web SQL Test</title>
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script type="text/javascript">
    $(function() {
        var db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
        db.transaction(function (tx) {
           tx.executeSql('CREATE TABLE IF NOT EXISTS LOGS (id unique, log)');
           tx.executeSql('INSERT INTO LOGS (id, log) VALUES (1, "foobar")');
           tx.executeSql('INSERT INTO LOGS (id, log) VALUES (2, "logmsg")');
        });
        db.transaction(function (tx) {
           tx.executeSql('SELECT * FROM LOGS', [], function (tx, results) {
           var len = results.rows.length, i;
           msg = "<p>Found rows: " + len + "</p>";
           document.querySelector('#status').innerHTML +=  msg;
           for (i = 0; i < len; i++){
              alert(results.rows.item(i).log );
           }
         }, null);
        });
    });
    </script>
</head>
<body id="status">
</body>
</html>

I ran the code above in chrome via WAMP (http://localhost/web_sql.html) and I can see the expected output in browser: Found rows: 2

Now I am trying to find the sqlite file that was created by this operation on my PC and after searching around, everyone is pointing to this particular folder for the db files:

C:\Users\USERNAME\AppData\Local\Google\Chrome\User Data\Default\databases

When I go to that location, it's empty.

On other note, the database changes doesn't seems to be persisting. If I refresh the page, it still says Found rows: 2 (surely it should say 4).

Is this why I can't find the file locally on my PC?

Fotina answered 24/4, 2015 at 8:34 Comment(0)
H
16

Navigate your Chrome to chrome://version url and check the Profile Path value. Your sqlite db should be inside it, in 'databases' folder.

And your particular problem with 2 found rows (rather than 4) is probably caused by inserting rows with same ids. id column is unique, so additional inserts are failing.

Handler answered 24/4, 2015 at 15:20 Comment(2)
I'm running Win7 and I created a script that create/modify sqlite DB under name WebSqlDB, but I found data saved in location: C:\Users\home\AppData\Local\Google\Chrome\User Data\Default\databases\http_www.respon.edu_0, under name: 38, without extension! Strange stuff, weird... I lost 22 hours to figure out where data are, even I was able to see DB inside GC console under real name, location provided me to change manualy table contents with the help of handsome DB Browser for SQLite, hope this will help to someone too.Sterner
I'm running Apache Cordova project with Microsoft Visual Studio 2017 and the path is: C:\Users\my_username\AppData\Roaming\Microsoft\VisualStudio\MDA\SIM_UserData\Default\databases\http_localhost_4400. The path is different from the one you start Chrome or Visual Studio starts chrome.Stir
T
3

Open chrome. Press F12 and then go to application in the first row (you may use >> symbol). Go to storage->websql and see your database :)

Twirp answered 9/6, 2017 at 9:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.