microsoft / cordova-plugin-websql

Cordova WebSQL Plugin
Other
61 stars 40 forks source link

Error occured while executing sql in Windows (Phone) 8.1 #19

Open mareksip opened 9 years ago

mareksip commented 9 years ago

I am debugging Apache Cordova application in Visual Studio 2013.4. The application works fine in Ripple and Android emulator, however, when I try to debug on Windows x64 or Windows Phone (device) I get following error:

On this line: https://github.com/MSOpenTech/cordova-plugin-websql/blob/17015eb938d902eeb6018c03e438658103b28c17/www/windows/SqlTransaction.js#L105

Unhandled exception at line 105, column 9 in ms-appx://io.cordova.myapp.../www/plugins/com.msopentech.websql/www/windows/SqlTransaction.js

0x800a139e - JavaScript - runtime error [object Object]

Here is my code inside index.html in onDeviceReady function:

<script type="text/javascript">
    document.addEventListener("deviceready", onDeviceReady, false);

    var db = null;

    function onDeviceReady() {

        var dbSize = 5 * 1024 * 1024;
        // 5MB

        db = window.openDatabase("lilka", "1.0", "Lilka hybrid db", dbSize)
        if (db) {
            populateDatabase();
        }

    }

    function populateDatabase() {

        db.transaction(function(tx) {
                tx.executeSql("CREATE TABLE IF NOT EXISTS Product (Id INTEGER, Name TEXT)", [], onSuccess, onError);
                tx.executeSql("INSERT INTO Product(Id, Name) values (1, 'testvalue')", [], onSuccess, onError);

                tx.executeSql('SELECT * FROM Product', [], function(tx, results) {
                    var len = results.rows.length,
                        i;
                    for (i = 0; i < len; i++) {
                        alert(results.rows.item(i).Name);
                    }
                });
            )
        };
    }
</script>

I have found out that it fails while executing the CREATE TABLE IF NOT EXISTS.

daserge commented 9 years ago

Hi @mareksip,

Here are the possible reasons of this issue:

mareksip commented 9 years ago

@daserge thank you for taking your time to investigate this issue.

daserge commented 9 years ago

@mareksip can you please add window.__webSqlDebugModeOn = true; before this line?

db = window.openDatabase("lilka", "1.0", "Lilka hybrid db", dbSize);

Probably some error details will arise.

mareksip commented 9 years ago

@daserge added the line as suggested but no detailed exception arised.

From Output tab:

Exception was thrown at line 105, column 9 in ms-appx://io.cordova.myapp8724a31325644ec29a8d2d88682b7987/www/plugins/com.msopentech.websql/www/windows/SqlTransaction.js
0x800a139e - JavaScript – runtime error: [object Object]

Unhandled exception at line 105, column 9 in ms-appx://io.cordova.myapp8724a31325644ec29a8d2d88682b7987/www/plugins/com.msopentech.websql/www/windows/SqlTransaction.js
0x800a139e - JavaScript – runtime error: [object Object]

I have found out that it fails while executing the CREATE TABLE IF NOT EXISTS.

I am confused why it does work with Android emulator, any idea? - Because the plugin only covers Windows platform. Cordova has its own implementation of SQLite to iOS and Android.

daserge commented 9 years ago

@mareksip can you please take a look into JavaScript console? In Visual Studio it is in Debug -> Wndows -> JavaScript console

PS: I think it works in Android and iOS as WebSql is supported natively in Chrome and Safari.

mareksip commented 9 years ago

@daserge sorry, here is the output from JavaScript Console:

File: index.html
adding proxy for WebSql
openDatabase: name = lilka
[Database] name: lilka, lastTransactionId: 0. | new Database(); name = lilka
[Database] name: lilka, lastTransactionId: 0. | transaction
[SqlTransaction] id: 1, connectionId: 1. | Error occured while executing sql: SAVEPOINT trx1. Error: [object Object]
[Database] name: lilka, lastTransactionId: 1. | transaction.run callback error, lastTransactionId = 1; error: [object Object]
[SqlTransaction] id: 1, connectionId: 1. | Error occured while executing sql: ROLLBACK TO trx1. Error:[object Object]

SCRIPT5022: Unhandled exception at line 105, column 9 in ms-appx://io.cordova.myapp8724a31325644ec29a8d2d88682b7987/www/plugins/com.msopentech.websql/www/windows/SqlTransaction.js 0x800a139e - JavaScript – runtime error : [object Object]
File: SqlTransaction.js, Line: 105, Column: 9

I have found out that the exception is thrown on the line for CREATE TABLE

daserge commented 9 years ago

@mareksip could you please also set a breakpoint on /www/plugins/com.msopentech.websql/www/windows/SqlTransaction.js Line 105 and copy the error details?

mareksip commented 9 years ago

@daserge Code 14: unable to open database file

daserge commented 9 years ago

@mareksip thanks for the details! I will investigate this issue later.

One more question regarding your setup - can you please check if the sample app works for you? Here are the steps to test it:

Or in one command:

git clone https://github.com/MSOpenTech/cordova-plugin-websql && cordova create sample --copy-from="cordova-plugin-websql\test" && cd sample && cordova platform add windows && cordova plugin add ..\cordova-plugin-websql && cordova run windows

Additionally can you please send the entire solution if possible?

mareksip commented 9 years ago

@daserge the test sample works well. I have tested all possible functions. I will try to follow the sample for now to find out if there are any differences in my code. Please note that I have installed version 0.5 as it is suggested by default in plugins of Visual Studio. Thank you.

mareksip commented 9 years ago

Hi @daserge, have you had a spare time to look into this issue, please? I would be really glad to use this plugin in my app.

daserge commented 9 years ago

Hi @mareksip, I would take a look if I could reproduce the issue - can you please upload the project code somewhere so that I can investigate?