HTML5 Web SQL database file location in chrome

Latheesan picture Latheesan · Apr 24, 2015 · Viewed 13.8k times · Source

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?

Answer

M Kowalski picture M Kowalski · Apr 24, 2015

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.