Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 Web SQL database file location in chrome

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?

like image 913
Latheesan Avatar asked Apr 24 '15 08:04

Latheesan


People also ask

How do I view SQL database in Chrome?

Click the Sources tab to open the Application panel. Expand the Web SQL section to view databases and tables.

Where does Chrome save its SQLite database to?

The location of the sqlite folder in Chrome is: ~/Library/Application Support/Google/Chrome/Default/databases/chrome-extension...

How do I open a SQL database in my browser?

To start SQL Server Browser ServiceOn the Start menu, in the Search Programs and Files box, type SQL, and then choose SQL Server Configuration Manager.

What is Websql in Chrome?

The Web SQL Database API, which allows you to store data in a structured manner on the user's computer (internally based on the SQLite database engine), was introduced in April 2009 and abandoned in November 2010.


1 Answers

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.

like image 80
M Kowalski Avatar answered Sep 20 '22 06:09

M Kowalski