You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cordova.apache.org by "Wayne Fisher (Created) (JIRA)" <ji...@apache.org> on 2012/04/12 03:46:16 UTC

[jira] [Created] (CB-482) window.openDatabase on Android doesn't handle the version parameter very well.

window.openDatabase on Android doesn't handle the version parameter very well.
------------------------------------------------------------------------------

                 Key: CB-482
                 URL: https://issues.apache.org/jira/browse/CB-482
             Project: Apache Callback
          Issue Type: Bug
          Components: Android
    Affects Versions: 1.4.0, 1.3.0, 1.2.0
            Reporter: Wayne Fisher
            Assignee: Joe Bowser


In the database code for Android, near the very bottom of the phonegap.js file, we find the following code:

{code}
    if (typeof window.openDatabase === "undefined") {
        setupDroidDB();
    } else {
        window.openDatabase_orig = window.openDatabase;
        window.openDatabase = function(name, version, desc, size){
            // Some versions of Android will throw a SECURITY_ERR so we need 
            // to catch the exception and seutp our own DB handling.
            var db = null;
            try {
                db = window.openDatabase_orig(name, version, desc, size);
            } 
            catch (ex) {
                db = null;
            }

            if (db == null) {
                setupDroidDB();
                return DroidDB_openDatabase(name, version, desc, size);
            }
            else {
                return db;
            }
        };
    }
{code}

The comment makes reference to a SECURITY_ERR exception that appears to occur on some versions of Android. The following try/catch block will catch the SECURITY_ERR exception and proceed to setup the DroidDB.

However, the try/catch block does not take into account that other exceptions can occur. In particular, from w3.org the following specifies an exception that should be raised if the specified version does not match the actual database version:

{quote}
If the database version provided is not the empty string, and the database already exists but has a different version, or no version, then the method must raise an INVALID_STATE_ERR exception.
{quote}

It would appear to me that the above code should be modified to be more selective about the handling of exceptions. If an INVALID_STATE_ERR exception is raised, it should not setup the DroidDB but instead allow it to propagate to the caller.

I came across this issue when attempting to update a database to a new version due to a requirement for additional columns. My code attempted to open the new database version and if it failed (due to exception) it would fallback and attempt to open and upgrade the previous version. What happened was that it was never able to find the previous version since the INVALID_STATE_ERR exception was being thrown which was caught by the PhoneGap code which would then proceed to setup the DroidDB. There was no way to get to the original database.

The above code appears the same in PhoneGap v1.2, 1.3, and 1.4. I didn't check 1.5. In 1.5 the code moved to be much earlier in the file and changed slightly but is effectively the same:

{code}
        // First patch WebSQL if necessary
        if (typeof window.openDatabase == 'undefined') {
            // Not defined, create an openDatabase function for all to use!
            window.openDatabase = storage.openDatabase;
        } else {
            // Defined, but some Android devices will throw a SECURITY_ERR -
            // so we wrap the whole thing in a try-catch and shim in our own
            // if the device has Android bug 16175.
            var originalOpenDatabase = window.openDatabase;
            window.openDatabase = function(name, version, desc, size) {
                var db = null;
                try {
                    db = originalOpenDatabase(name, version, desc, size);
                } 
                catch (ex) {
                    db = null;
                }

                if (db === null) {
                    return storage.openDatabase(name, version, desc, size);
                }
                else {
                    return db;
                }
            };
        }
{code}


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Assigned] (CB-482) window.openDatabase on Android doesn't handle the version parameter very well.

Posted by "Joe Bowser (Assigned) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CB-482?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Joe Bowser reassigned CB-482:
-----------------------------

    Assignee: Simon MacDonald  (was: Joe Bowser)

It looks good, but it's your call.
                
> window.openDatabase on Android doesn't handle the version parameter very well.
> ------------------------------------------------------------------------------
>
>                 Key: CB-482
>                 URL: https://issues.apache.org/jira/browse/CB-482
>             Project: Apache Callback
>          Issue Type: Bug
>          Components: Android
>    Affects Versions: 1.2.0, 1.3.0, 1.4.0, 1.5.0, 1.6.0
>            Reporter: Wayne Fisher
>            Assignee: Simon MacDonald
>             Fix For: 1.6.1
>
>
> In the database code for Android, near the very bottom of the phonegap.js file, we find the following code:
> {code}
>     if (typeof window.openDatabase === "undefined") {
>         setupDroidDB();
>     } else {
>         window.openDatabase_orig = window.openDatabase;
>         window.openDatabase = function(name, version, desc, size){
>             // Some versions of Android will throw a SECURITY_ERR so we need 
>             // to catch the exception and seutp our own DB handling.
>             var db = null;
>             try {
>                 db = window.openDatabase_orig(name, version, desc, size);
>             } 
>             catch (ex) {
>                 db = null;
>             }
>             if (db == null) {
>                 setupDroidDB();
>                 return DroidDB_openDatabase(name, version, desc, size);
>             }
>             else {
>                 return db;
>             }
>         };
>     }
> {code}
> The comment makes reference to a SECURITY_ERR exception that appears to occur on some versions of Android. The following try/catch block will catch the SECURITY_ERR exception and proceed to setup the DroidDB.
> However, the try/catch block does not take into account that other exceptions can occur. In particular, from w3.org the following specifies an exception that should be raised if the specified version does not match the actual database version:
> {quote}
> If the database version provided is not the empty string, and the database already exists but has a different version, or no version, then the method must raise an INVALID_STATE_ERR exception.
> {quote}
> It would appear to me that the above code should be modified to be more selective about the handling of exceptions. If an INVALID_STATE_ERR exception is raised, it should not setup the DroidDB but instead allow it to propagate to the caller.
> I came across this issue when attempting to update a database to a new version due to a requirement for additional columns. My code attempted to open the new database version and if it failed (due to exception) it would fallback and attempt to open and upgrade the previous version. What happened was that it was never able to find the previous version since the INVALID_STATE_ERR exception was being thrown which was caught by the PhoneGap code which would then proceed to setup the DroidDB. There was no way to get to the original database.
> The above code appears the same in PhoneGap v1.2, 1.3, and 1.4. I didn't check 1.5. In 1.5 the code moved to be much earlier in the file and changed slightly but is effectively the same:
> {code}
>         // First patch WebSQL if necessary
>         if (typeof window.openDatabase == 'undefined') {
>             // Not defined, create an openDatabase function for all to use!
>             window.openDatabase = storage.openDatabase;
>         } else {
>             // Defined, but some Android devices will throw a SECURITY_ERR -
>             // so we wrap the whole thing in a try-catch and shim in our own
>             // if the device has Android bug 16175.
>             var originalOpenDatabase = window.openDatabase;
>             window.openDatabase = function(name, version, desc, size) {
>                 var db = null;
>                 try {
>                     db = originalOpenDatabase(name, version, desc, size);
>                 } 
>                 catch (ex) {
>                     db = null;
>                 }
>                 if (db === null) {
>                     return storage.openDatabase(name, version, desc, size);
>                 }
>                 else {
>                     return db;
>                 }
>             };
>         }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CB-482) window.openDatabase on Android doesn't handle the version parameter very well.

Posted by "Filip Maj (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-482?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13255063#comment-13255063 ] 

Filip Maj commented on CB-482:
------------------------------

As Master Exploder, I approve of this change!
                
> window.openDatabase on Android doesn't handle the version parameter very well.
> ------------------------------------------------------------------------------
>
>                 Key: CB-482
>                 URL: https://issues.apache.org/jira/browse/CB-482
>             Project: Apache Callback
>          Issue Type: Bug
>          Components: Android
>    Affects Versions: 1.2.0, 1.3.0, 1.4.0, 1.5.0, 1.6.0
>            Reporter: Wayne Fisher
>            Assignee: Filip Maj
>             Fix For: 1.6.1
>
>
> In the database code for Android, near the very bottom of the phonegap.js file, we find the following code:
> {code}
>     if (typeof window.openDatabase === "undefined") {
>         setupDroidDB();
>     } else {
>         window.openDatabase_orig = window.openDatabase;
>         window.openDatabase = function(name, version, desc, size){
>             // Some versions of Android will throw a SECURITY_ERR so we need 
>             // to catch the exception and seutp our own DB handling.
>             var db = null;
>             try {
>                 db = window.openDatabase_orig(name, version, desc, size);
>             } 
>             catch (ex) {
>                 db = null;
>             }
>             if (db == null) {
>                 setupDroidDB();
>                 return DroidDB_openDatabase(name, version, desc, size);
>             }
>             else {
>                 return db;
>             }
>         };
>     }
> {code}
> The comment makes reference to a SECURITY_ERR exception that appears to occur on some versions of Android. The following try/catch block will catch the SECURITY_ERR exception and proceed to setup the DroidDB.
> However, the try/catch block does not take into account that other exceptions can occur. In particular, from w3.org the following specifies an exception that should be raised if the specified version does not match the actual database version:
> {quote}
> If the database version provided is not the empty string, and the database already exists but has a different version, or no version, then the method must raise an INVALID_STATE_ERR exception.
> {quote}
> It would appear to me that the above code should be modified to be more selective about the handling of exceptions. If an INVALID_STATE_ERR exception is raised, it should not setup the DroidDB but instead allow it to propagate to the caller.
> I came across this issue when attempting to update a database to a new version due to a requirement for additional columns. My code attempted to open the new database version and if it failed (due to exception) it would fallback and attempt to open and upgrade the previous version. What happened was that it was never able to find the previous version since the INVALID_STATE_ERR exception was being thrown which was caught by the PhoneGap code which would then proceed to setup the DroidDB. There was no way to get to the original database.
> The above code appears the same in PhoneGap v1.2, 1.3, and 1.4. I didn't check 1.5. In 1.5 the code moved to be much earlier in the file and changed slightly but is effectively the same:
> {code}
>         // First patch WebSQL if necessary
>         if (typeof window.openDatabase == 'undefined') {
>             // Not defined, create an openDatabase function for all to use!
>             window.openDatabase = storage.openDatabase;
>         } else {
>             // Defined, but some Android devices will throw a SECURITY_ERR -
>             // so we wrap the whole thing in a try-catch and shim in our own
>             // if the device has Android bug 16175.
>             var originalOpenDatabase = window.openDatabase;
>             window.openDatabase = function(name, version, desc, size) {
>                 var db = null;
>                 try {
>                     db = originalOpenDatabase(name, version, desc, size);
>                 } 
>                 catch (ex) {
>                     db = null;
>                 }
>                 if (db === null) {
>                     return storage.openDatabase(name, version, desc, size);
>                 }
>                 else {
>                     return db;
>                 }
>             };
>         }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Resolved] (CB-482) window.openDatabase on Android doesn't handle the version parameter very well.

Posted by "Filip Maj (Resolved) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CB-482?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Filip Maj resolved CB-482.
--------------------------

    Resolution: Fixed

Fixed in:

[JS - b2de4b|http://git-wip-us.apache.org/repos/asf?p=incubator-cordova-js.git;a=commit;h=b2de4baa76a94ecb916619a536339ffee9ef6843]

[Specs - bfe48c|http://git-wip-us.apache.org/repos/asf?p=incubator-cordova-mobile-spec.git;a=commit;h=bfe48ce6c2c7fd3bebb8415ab4748f985852079d]
                
> window.openDatabase on Android doesn't handle the version parameter very well.
> ------------------------------------------------------------------------------
>
>                 Key: CB-482
>                 URL: https://issues.apache.org/jira/browse/CB-482
>             Project: Apache Callback
>          Issue Type: Bug
>          Components: Android
>    Affects Versions: 1.2.0, 1.3.0, 1.4.0, 1.5.0, 1.6.0
>            Reporter: Wayne Fisher
>            Assignee: Filip Maj
>             Fix For: 1.6.1
>
>
> In the database code for Android, near the very bottom of the phonegap.js file, we find the following code:
> {code}
>     if (typeof window.openDatabase === "undefined") {
>         setupDroidDB();
>     } else {
>         window.openDatabase_orig = window.openDatabase;
>         window.openDatabase = function(name, version, desc, size){
>             // Some versions of Android will throw a SECURITY_ERR so we need 
>             // to catch the exception and seutp our own DB handling.
>             var db = null;
>             try {
>                 db = window.openDatabase_orig(name, version, desc, size);
>             } 
>             catch (ex) {
>                 db = null;
>             }
>             if (db == null) {
>                 setupDroidDB();
>                 return DroidDB_openDatabase(name, version, desc, size);
>             }
>             else {
>                 return db;
>             }
>         };
>     }
> {code}
> The comment makes reference to a SECURITY_ERR exception that appears to occur on some versions of Android. The following try/catch block will catch the SECURITY_ERR exception and proceed to setup the DroidDB.
> However, the try/catch block does not take into account that other exceptions can occur. In particular, from w3.org the following specifies an exception that should be raised if the specified version does not match the actual database version:
> {quote}
> If the database version provided is not the empty string, and the database already exists but has a different version, or no version, then the method must raise an INVALID_STATE_ERR exception.
> {quote}
> It would appear to me that the above code should be modified to be more selective about the handling of exceptions. If an INVALID_STATE_ERR exception is raised, it should not setup the DroidDB but instead allow it to propagate to the caller.
> I came across this issue when attempting to update a database to a new version due to a requirement for additional columns. My code attempted to open the new database version and if it failed (due to exception) it would fallback and attempt to open and upgrade the previous version. What happened was that it was never able to find the previous version since the INVALID_STATE_ERR exception was being thrown which was caught by the PhoneGap code which would then proceed to setup the DroidDB. There was no way to get to the original database.
> The above code appears the same in PhoneGap v1.2, 1.3, and 1.4. I didn't check 1.5. In 1.5 the code moved to be much earlier in the file and changed slightly but is effectively the same:
> {code}
>         // First patch WebSQL if necessary
>         if (typeof window.openDatabase == 'undefined') {
>             // Not defined, create an openDatabase function for all to use!
>             window.openDatabase = storage.openDatabase;
>         } else {
>             // Defined, but some Android devices will throw a SECURITY_ERR -
>             // so we wrap the whole thing in a try-catch and shim in our own
>             // if the device has Android bug 16175.
>             var originalOpenDatabase = window.openDatabase;
>             window.openDatabase = function(name, version, desc, size) {
>                 var db = null;
>                 try {
>                     db = originalOpenDatabase(name, version, desc, size);
>                 } 
>                 catch (ex) {
>                     db = null;
>                 }
>                 if (db === null) {
>                     return storage.openDatabase(name, version, desc, size);
>                 }
>                 else {
>                     return db;
>                 }
>             };
>         }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CB-482) window.openDatabase on Android doesn't handle the version parameter very well.

Posted by "Simon MacDonald (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-482?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13252543#comment-13252543 ] 

Simon MacDonald commented on CB-482:
------------------------------------

I'm pretty sure I have a fix and test case for this but I need a device that produces the security_err in order to be sure. If I'm not mistaken the error code is 18 but help.

Test: https://github.com/macdonst/incubator-cordova-mobile-spec/commit/bfe48ce6c2c7fd3bebb8415ab4748f985852079d
Fix: https://github.com/macdonst/callback-js/commit/1242c3208c8f62da6fea238929ff564823c8cc8f
                
> window.openDatabase on Android doesn't handle the version parameter very well.
> ------------------------------------------------------------------------------
>
>                 Key: CB-482
>                 URL: https://issues.apache.org/jira/browse/CB-482
>             Project: Apache Callback
>          Issue Type: Bug
>          Components: Android
>    Affects Versions: 1.2.0, 1.3.0, 1.4.0, 1.5.0, 1.6.0
>            Reporter: Wayne Fisher
>            Assignee: Joe Bowser
>
> In the database code for Android, near the very bottom of the phonegap.js file, we find the following code:
> {code}
>     if (typeof window.openDatabase === "undefined") {
>         setupDroidDB();
>     } else {
>         window.openDatabase_orig = window.openDatabase;
>         window.openDatabase = function(name, version, desc, size){
>             // Some versions of Android will throw a SECURITY_ERR so we need 
>             // to catch the exception and seutp our own DB handling.
>             var db = null;
>             try {
>                 db = window.openDatabase_orig(name, version, desc, size);
>             } 
>             catch (ex) {
>                 db = null;
>             }
>             if (db == null) {
>                 setupDroidDB();
>                 return DroidDB_openDatabase(name, version, desc, size);
>             }
>             else {
>                 return db;
>             }
>         };
>     }
> {code}
> The comment makes reference to a SECURITY_ERR exception that appears to occur on some versions of Android. The following try/catch block will catch the SECURITY_ERR exception and proceed to setup the DroidDB.
> However, the try/catch block does not take into account that other exceptions can occur. In particular, from w3.org the following specifies an exception that should be raised if the specified version does not match the actual database version:
> {quote}
> If the database version provided is not the empty string, and the database already exists but has a different version, or no version, then the method must raise an INVALID_STATE_ERR exception.
> {quote}
> It would appear to me that the above code should be modified to be more selective about the handling of exceptions. If an INVALID_STATE_ERR exception is raised, it should not setup the DroidDB but instead allow it to propagate to the caller.
> I came across this issue when attempting to update a database to a new version due to a requirement for additional columns. My code attempted to open the new database version and if it failed (due to exception) it would fallback and attempt to open and upgrade the previous version. What happened was that it was never able to find the previous version since the INVALID_STATE_ERR exception was being thrown which was caught by the PhoneGap code which would then proceed to setup the DroidDB. There was no way to get to the original database.
> The above code appears the same in PhoneGap v1.2, 1.3, and 1.4. I didn't check 1.5. In 1.5 the code moved to be much earlier in the file and changed slightly but is effectively the same:
> {code}
>         // First patch WebSQL if necessary
>         if (typeof window.openDatabase == 'undefined') {
>             // Not defined, create an openDatabase function for all to use!
>             window.openDatabase = storage.openDatabase;
>         } else {
>             // Defined, but some Android devices will throw a SECURITY_ERR -
>             // so we wrap the whole thing in a try-catch and shim in our own
>             // if the device has Android bug 16175.
>             var originalOpenDatabase = window.openDatabase;
>             window.openDatabase = function(name, version, desc, size) {
>                 var db = null;
>                 try {
>                     db = originalOpenDatabase(name, version, desc, size);
>                 } 
>                 catch (ex) {
>                     db = null;
>                 }
>                 if (db === null) {
>                     return storage.openDatabase(name, version, desc, size);
>                 }
>                 else {
>                     return db;
>                 }
>             };
>         }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (CB-482) window.openDatabase on Android doesn't handle the version parameter very well.

Posted by "Joe Bowser (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CB-482?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Joe Bowser updated CB-482:
--------------------------

    Fix Version/s: 1.6.1
    
> window.openDatabase on Android doesn't handle the version parameter very well.
> ------------------------------------------------------------------------------
>
>                 Key: CB-482
>                 URL: https://issues.apache.org/jira/browse/CB-482
>             Project: Apache Callback
>          Issue Type: Bug
>          Components: Android
>    Affects Versions: 1.2.0, 1.3.0, 1.4.0, 1.5.0, 1.6.0
>            Reporter: Wayne Fisher
>            Assignee: Joe Bowser
>             Fix For: 1.6.1
>
>
> In the database code for Android, near the very bottom of the phonegap.js file, we find the following code:
> {code}
>     if (typeof window.openDatabase === "undefined") {
>         setupDroidDB();
>     } else {
>         window.openDatabase_orig = window.openDatabase;
>         window.openDatabase = function(name, version, desc, size){
>             // Some versions of Android will throw a SECURITY_ERR so we need 
>             // to catch the exception and seutp our own DB handling.
>             var db = null;
>             try {
>                 db = window.openDatabase_orig(name, version, desc, size);
>             } 
>             catch (ex) {
>                 db = null;
>             }
>             if (db == null) {
>                 setupDroidDB();
>                 return DroidDB_openDatabase(name, version, desc, size);
>             }
>             else {
>                 return db;
>             }
>         };
>     }
> {code}
> The comment makes reference to a SECURITY_ERR exception that appears to occur on some versions of Android. The following try/catch block will catch the SECURITY_ERR exception and proceed to setup the DroidDB.
> However, the try/catch block does not take into account that other exceptions can occur. In particular, from w3.org the following specifies an exception that should be raised if the specified version does not match the actual database version:
> {quote}
> If the database version provided is not the empty string, and the database already exists but has a different version, or no version, then the method must raise an INVALID_STATE_ERR exception.
> {quote}
> It would appear to me that the above code should be modified to be more selective about the handling of exceptions. If an INVALID_STATE_ERR exception is raised, it should not setup the DroidDB but instead allow it to propagate to the caller.
> I came across this issue when attempting to update a database to a new version due to a requirement for additional columns. My code attempted to open the new database version and if it failed (due to exception) it would fallback and attempt to open and upgrade the previous version. What happened was that it was never able to find the previous version since the INVALID_STATE_ERR exception was being thrown which was caught by the PhoneGap code which would then proceed to setup the DroidDB. There was no way to get to the original database.
> The above code appears the same in PhoneGap v1.2, 1.3, and 1.4. I didn't check 1.5. In 1.5 the code moved to be much earlier in the file and changed slightly but is effectively the same:
> {code}
>         // First patch WebSQL if necessary
>         if (typeof window.openDatabase == 'undefined') {
>             // Not defined, create an openDatabase function for all to use!
>             window.openDatabase = storage.openDatabase;
>         } else {
>             // Defined, but some Android devices will throw a SECURITY_ERR -
>             // so we wrap the whole thing in a try-catch and shim in our own
>             // if the device has Android bug 16175.
>             var originalOpenDatabase = window.openDatabase;
>             window.openDatabase = function(name, version, desc, size) {
>                 var db = null;
>                 try {
>                     db = originalOpenDatabase(name, version, desc, size);
>                 } 
>                 catch (ex) {
>                     db = null;
>                 }
>                 if (db === null) {
>                     return storage.openDatabase(name, version, desc, size);
>                 }
>                 else {
>                     return db;
>                 }
>             };
>         }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CB-482) window.openDatabase on Android doesn't handle the version parameter very well.

Posted by "Wayne Fisher (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-482?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13252573#comment-13252573 ] 

Wayne Fisher commented on CB-482:
---------------------------------

I have looked at your fix and the test code and it looks good to me. Unfortunately, I don't have a device that is affected by the SECURITY_ERR exception to be able to help to test that.

                
> window.openDatabase on Android doesn't handle the version parameter very well.
> ------------------------------------------------------------------------------
>
>                 Key: CB-482
>                 URL: https://issues.apache.org/jira/browse/CB-482
>             Project: Apache Callback
>          Issue Type: Bug
>          Components: Android
>    Affects Versions: 1.2.0, 1.3.0, 1.4.0, 1.5.0, 1.6.0
>            Reporter: Wayne Fisher
>            Assignee: Joe Bowser
>
> In the database code for Android, near the very bottom of the phonegap.js file, we find the following code:
> {code}
>     if (typeof window.openDatabase === "undefined") {
>         setupDroidDB();
>     } else {
>         window.openDatabase_orig = window.openDatabase;
>         window.openDatabase = function(name, version, desc, size){
>             // Some versions of Android will throw a SECURITY_ERR so we need 
>             // to catch the exception and seutp our own DB handling.
>             var db = null;
>             try {
>                 db = window.openDatabase_orig(name, version, desc, size);
>             } 
>             catch (ex) {
>                 db = null;
>             }
>             if (db == null) {
>                 setupDroidDB();
>                 return DroidDB_openDatabase(name, version, desc, size);
>             }
>             else {
>                 return db;
>             }
>         };
>     }
> {code}
> The comment makes reference to a SECURITY_ERR exception that appears to occur on some versions of Android. The following try/catch block will catch the SECURITY_ERR exception and proceed to setup the DroidDB.
> However, the try/catch block does not take into account that other exceptions can occur. In particular, from w3.org the following specifies an exception that should be raised if the specified version does not match the actual database version:
> {quote}
> If the database version provided is not the empty string, and the database already exists but has a different version, or no version, then the method must raise an INVALID_STATE_ERR exception.
> {quote}
> It would appear to me that the above code should be modified to be more selective about the handling of exceptions. If an INVALID_STATE_ERR exception is raised, it should not setup the DroidDB but instead allow it to propagate to the caller.
> I came across this issue when attempting to update a database to a new version due to a requirement for additional columns. My code attempted to open the new database version and if it failed (due to exception) it would fallback and attempt to open and upgrade the previous version. What happened was that it was never able to find the previous version since the INVALID_STATE_ERR exception was being thrown which was caught by the PhoneGap code which would then proceed to setup the DroidDB. There was no way to get to the original database.
> The above code appears the same in PhoneGap v1.2, 1.3, and 1.4. I didn't check 1.5. In 1.5 the code moved to be much earlier in the file and changed slightly but is effectively the same:
> {code}
>         // First patch WebSQL if necessary
>         if (typeof window.openDatabase == 'undefined') {
>             // Not defined, create an openDatabase function for all to use!
>             window.openDatabase = storage.openDatabase;
>         } else {
>             // Defined, but some Android devices will throw a SECURITY_ERR -
>             // so we wrap the whole thing in a try-catch and shim in our own
>             // if the device has Android bug 16175.
>             var originalOpenDatabase = window.openDatabase;
>             window.openDatabase = function(name, version, desc, size) {
>                 var db = null;
>                 try {
>                     db = originalOpenDatabase(name, version, desc, size);
>                 } 
>                 catch (ex) {
>                     db = null;
>                 }
>                 if (db === null) {
>                     return storage.openDatabase(name, version, desc, size);
>                 }
>                 else {
>                     return db;
>                 }
>             };
>         }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CB-482) window.openDatabase on Android doesn't handle the version parameter very well.

Posted by "Simon MacDonald (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-482?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13252591#comment-13252591 ] 

Simon MacDonald commented on CB-482:
------------------------------------

It seems like a safe change but I want someone with the SECURITY_ERR bug to be able to test it before I check in.
                
> window.openDatabase on Android doesn't handle the version parameter very well.
> ------------------------------------------------------------------------------
>
>                 Key: CB-482
>                 URL: https://issues.apache.org/jira/browse/CB-482
>             Project: Apache Callback
>          Issue Type: Bug
>          Components: Android
>    Affects Versions: 1.2.0, 1.3.0, 1.4.0, 1.5.0, 1.6.0
>            Reporter: Wayne Fisher
>            Assignee: Joe Bowser
>
> In the database code for Android, near the very bottom of the phonegap.js file, we find the following code:
> {code}
>     if (typeof window.openDatabase === "undefined") {
>         setupDroidDB();
>     } else {
>         window.openDatabase_orig = window.openDatabase;
>         window.openDatabase = function(name, version, desc, size){
>             // Some versions of Android will throw a SECURITY_ERR so we need 
>             // to catch the exception and seutp our own DB handling.
>             var db = null;
>             try {
>                 db = window.openDatabase_orig(name, version, desc, size);
>             } 
>             catch (ex) {
>                 db = null;
>             }
>             if (db == null) {
>                 setupDroidDB();
>                 return DroidDB_openDatabase(name, version, desc, size);
>             }
>             else {
>                 return db;
>             }
>         };
>     }
> {code}
> The comment makes reference to a SECURITY_ERR exception that appears to occur on some versions of Android. The following try/catch block will catch the SECURITY_ERR exception and proceed to setup the DroidDB.
> However, the try/catch block does not take into account that other exceptions can occur. In particular, from w3.org the following specifies an exception that should be raised if the specified version does not match the actual database version:
> {quote}
> If the database version provided is not the empty string, and the database already exists but has a different version, or no version, then the method must raise an INVALID_STATE_ERR exception.
> {quote}
> It would appear to me that the above code should be modified to be more selective about the handling of exceptions. If an INVALID_STATE_ERR exception is raised, it should not setup the DroidDB but instead allow it to propagate to the caller.
> I came across this issue when attempting to update a database to a new version due to a requirement for additional columns. My code attempted to open the new database version and if it failed (due to exception) it would fallback and attempt to open and upgrade the previous version. What happened was that it was never able to find the previous version since the INVALID_STATE_ERR exception was being thrown which was caught by the PhoneGap code which would then proceed to setup the DroidDB. There was no way to get to the original database.
> The above code appears the same in PhoneGap v1.2, 1.3, and 1.4. I didn't check 1.5. In 1.5 the code moved to be much earlier in the file and changed slightly but is effectively the same:
> {code}
>         // First patch WebSQL if necessary
>         if (typeof window.openDatabase == 'undefined') {
>             // Not defined, create an openDatabase function for all to use!
>             window.openDatabase = storage.openDatabase;
>         } else {
>             // Defined, but some Android devices will throw a SECURITY_ERR -
>             // so we wrap the whole thing in a try-catch and shim in our own
>             // if the device has Android bug 16175.
>             var originalOpenDatabase = window.openDatabase;
>             window.openDatabase = function(name, version, desc, size) {
>                 var db = null;
>                 try {
>                     db = originalOpenDatabase(name, version, desc, size);
>                 } 
>                 catch (ex) {
>                     db = null;
>                 }
>                 if (db === null) {
>                     return storage.openDatabase(name, version, desc, size);
>                 }
>                 else {
>                     return db;
>                 }
>             };
>         }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CB-482) window.openDatabase on Android doesn't handle the version parameter very well.

Posted by "Joe Bowser (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-482?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13253725#comment-13253725 ] 

Joe Bowser commented on CB-482:
-------------------------------

SECURITY_ERR bug is on Android 4.0 right? I just tested it on this end, and the test passes, assigning back to you if you want to put this into 1.6.1
                
> window.openDatabase on Android doesn't handle the version parameter very well.
> ------------------------------------------------------------------------------
>
>                 Key: CB-482
>                 URL: https://issues.apache.org/jira/browse/CB-482
>             Project: Apache Callback
>          Issue Type: Bug
>          Components: Android
>    Affects Versions: 1.2.0, 1.3.0, 1.4.0, 1.5.0, 1.6.0
>            Reporter: Wayne Fisher
>            Assignee: Joe Bowser
>             Fix For: 1.6.1
>
>
> In the database code for Android, near the very bottom of the phonegap.js file, we find the following code:
> {code}
>     if (typeof window.openDatabase === "undefined") {
>         setupDroidDB();
>     } else {
>         window.openDatabase_orig = window.openDatabase;
>         window.openDatabase = function(name, version, desc, size){
>             // Some versions of Android will throw a SECURITY_ERR so we need 
>             // to catch the exception and seutp our own DB handling.
>             var db = null;
>             try {
>                 db = window.openDatabase_orig(name, version, desc, size);
>             } 
>             catch (ex) {
>                 db = null;
>             }
>             if (db == null) {
>                 setupDroidDB();
>                 return DroidDB_openDatabase(name, version, desc, size);
>             }
>             else {
>                 return db;
>             }
>         };
>     }
> {code}
> The comment makes reference to a SECURITY_ERR exception that appears to occur on some versions of Android. The following try/catch block will catch the SECURITY_ERR exception and proceed to setup the DroidDB.
> However, the try/catch block does not take into account that other exceptions can occur. In particular, from w3.org the following specifies an exception that should be raised if the specified version does not match the actual database version:
> {quote}
> If the database version provided is not the empty string, and the database already exists but has a different version, or no version, then the method must raise an INVALID_STATE_ERR exception.
> {quote}
> It would appear to me that the above code should be modified to be more selective about the handling of exceptions. If an INVALID_STATE_ERR exception is raised, it should not setup the DroidDB but instead allow it to propagate to the caller.
> I came across this issue when attempting to update a database to a new version due to a requirement for additional columns. My code attempted to open the new database version and if it failed (due to exception) it would fallback and attempt to open and upgrade the previous version. What happened was that it was never able to find the previous version since the INVALID_STATE_ERR exception was being thrown which was caught by the PhoneGap code which would then proceed to setup the DroidDB. There was no way to get to the original database.
> The above code appears the same in PhoneGap v1.2, 1.3, and 1.4. I didn't check 1.5. In 1.5 the code moved to be much earlier in the file and changed slightly but is effectively the same:
> {code}
>         // First patch WebSQL if necessary
>         if (typeof window.openDatabase == 'undefined') {
>             // Not defined, create an openDatabase function for all to use!
>             window.openDatabase = storage.openDatabase;
>         } else {
>             // Defined, but some Android devices will throw a SECURITY_ERR -
>             // so we wrap the whole thing in a try-catch and shim in our own
>             // if the device has Android bug 16175.
>             var originalOpenDatabase = window.openDatabase;
>             window.openDatabase = function(name, version, desc, size) {
>                 var db = null;
>                 try {
>                     db = originalOpenDatabase(name, version, desc, size);
>                 } 
>                 catch (ex) {
>                     db = null;
>                 }
>                 if (db === null) {
>                     return storage.openDatabase(name, version, desc, size);
>                 }
>                 else {
>                     return db;
>                 }
>             };
>         }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Assigned] (CB-482) window.openDatabase on Android doesn't handle the version parameter very well.

Posted by "Joe Bowser (Assigned) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CB-482?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Joe Bowser reassigned CB-482:
-----------------------------

    Assignee: Filip Maj  (was: Simon MacDonald)

Actually, it's not your call.  This is a JS change!
                
> window.openDatabase on Android doesn't handle the version parameter very well.
> ------------------------------------------------------------------------------
>
>                 Key: CB-482
>                 URL: https://issues.apache.org/jira/browse/CB-482
>             Project: Apache Callback
>          Issue Type: Bug
>          Components: Android
>    Affects Versions: 1.2.0, 1.3.0, 1.4.0, 1.5.0, 1.6.0
>            Reporter: Wayne Fisher
>            Assignee: Filip Maj
>             Fix For: 1.6.1
>
>
> In the database code for Android, near the very bottom of the phonegap.js file, we find the following code:
> {code}
>     if (typeof window.openDatabase === "undefined") {
>         setupDroidDB();
>     } else {
>         window.openDatabase_orig = window.openDatabase;
>         window.openDatabase = function(name, version, desc, size){
>             // Some versions of Android will throw a SECURITY_ERR so we need 
>             // to catch the exception and seutp our own DB handling.
>             var db = null;
>             try {
>                 db = window.openDatabase_orig(name, version, desc, size);
>             } 
>             catch (ex) {
>                 db = null;
>             }
>             if (db == null) {
>                 setupDroidDB();
>                 return DroidDB_openDatabase(name, version, desc, size);
>             }
>             else {
>                 return db;
>             }
>         };
>     }
> {code}
> The comment makes reference to a SECURITY_ERR exception that appears to occur on some versions of Android. The following try/catch block will catch the SECURITY_ERR exception and proceed to setup the DroidDB.
> However, the try/catch block does not take into account that other exceptions can occur. In particular, from w3.org the following specifies an exception that should be raised if the specified version does not match the actual database version:
> {quote}
> If the database version provided is not the empty string, and the database already exists but has a different version, or no version, then the method must raise an INVALID_STATE_ERR exception.
> {quote}
> It would appear to me that the above code should be modified to be more selective about the handling of exceptions. If an INVALID_STATE_ERR exception is raised, it should not setup the DroidDB but instead allow it to propagate to the caller.
> I came across this issue when attempting to update a database to a new version due to a requirement for additional columns. My code attempted to open the new database version and if it failed (due to exception) it would fallback and attempt to open and upgrade the previous version. What happened was that it was never able to find the previous version since the INVALID_STATE_ERR exception was being thrown which was caught by the PhoneGap code which would then proceed to setup the DroidDB. There was no way to get to the original database.
> The above code appears the same in PhoneGap v1.2, 1.3, and 1.4. I didn't check 1.5. In 1.5 the code moved to be much earlier in the file and changed slightly but is effectively the same:
> {code}
>         // First patch WebSQL if necessary
>         if (typeof window.openDatabase == 'undefined') {
>             // Not defined, create an openDatabase function for all to use!
>             window.openDatabase = storage.openDatabase;
>         } else {
>             // Defined, but some Android devices will throw a SECURITY_ERR -
>             // so we wrap the whole thing in a try-catch and shim in our own
>             // if the device has Android bug 16175.
>             var originalOpenDatabase = window.openDatabase;
>             window.openDatabase = function(name, version, desc, size) {
>                 var db = null;
>                 try {
>                     db = originalOpenDatabase(name, version, desc, size);
>                 } 
>                 catch (ex) {
>                     db = null;
>                 }
>                 if (db === null) {
>                     return storage.openDatabase(name, version, desc, size);
>                 }
>                 else {
>                     return db;
>                 }
>             };
>         }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (CB-482) window.openDatabase on Android doesn't handle the version parameter very well.

Posted by "Wayne Fisher (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CB-482?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Wayne Fisher updated CB-482:
----------------------------

    Affects Version/s: 1.6.0
                       1.5.0

Added 1.5 and 1.6 to the list of affected versions.

                
> window.openDatabase on Android doesn't handle the version parameter very well.
> ------------------------------------------------------------------------------
>
>                 Key: CB-482
>                 URL: https://issues.apache.org/jira/browse/CB-482
>             Project: Apache Callback
>          Issue Type: Bug
>          Components: Android
>    Affects Versions: 1.2.0, 1.3.0, 1.4.0, 1.5.0, 1.6.0
>            Reporter: Wayne Fisher
>            Assignee: Joe Bowser
>
> In the database code for Android, near the very bottom of the phonegap.js file, we find the following code:
> {code}
>     if (typeof window.openDatabase === "undefined") {
>         setupDroidDB();
>     } else {
>         window.openDatabase_orig = window.openDatabase;
>         window.openDatabase = function(name, version, desc, size){
>             // Some versions of Android will throw a SECURITY_ERR so we need 
>             // to catch the exception and seutp our own DB handling.
>             var db = null;
>             try {
>                 db = window.openDatabase_orig(name, version, desc, size);
>             } 
>             catch (ex) {
>                 db = null;
>             }
>             if (db == null) {
>                 setupDroidDB();
>                 return DroidDB_openDatabase(name, version, desc, size);
>             }
>             else {
>                 return db;
>             }
>         };
>     }
> {code}
> The comment makes reference to a SECURITY_ERR exception that appears to occur on some versions of Android. The following try/catch block will catch the SECURITY_ERR exception and proceed to setup the DroidDB.
> However, the try/catch block does not take into account that other exceptions can occur. In particular, from w3.org the following specifies an exception that should be raised if the specified version does not match the actual database version:
> {quote}
> If the database version provided is not the empty string, and the database already exists but has a different version, or no version, then the method must raise an INVALID_STATE_ERR exception.
> {quote}
> It would appear to me that the above code should be modified to be more selective about the handling of exceptions. If an INVALID_STATE_ERR exception is raised, it should not setup the DroidDB but instead allow it to propagate to the caller.
> I came across this issue when attempting to update a database to a new version due to a requirement for additional columns. My code attempted to open the new database version and if it failed (due to exception) it would fallback and attempt to open and upgrade the previous version. What happened was that it was never able to find the previous version since the INVALID_STATE_ERR exception was being thrown which was caught by the PhoneGap code which would then proceed to setup the DroidDB. There was no way to get to the original database.
> The above code appears the same in PhoneGap v1.2, 1.3, and 1.4. I didn't check 1.5. In 1.5 the code moved to be much earlier in the file and changed slightly but is effectively the same:
> {code}
>         // First patch WebSQL if necessary
>         if (typeof window.openDatabase == 'undefined') {
>             // Not defined, create an openDatabase function for all to use!
>             window.openDatabase = storage.openDatabase;
>         } else {
>             // Defined, but some Android devices will throw a SECURITY_ERR -
>             // so we wrap the whole thing in a try-catch and shim in our own
>             // if the device has Android bug 16175.
>             var originalOpenDatabase = window.openDatabase;
>             window.openDatabase = function(name, version, desc, size) {
>                 var db = null;
>                 try {
>                     db = originalOpenDatabase(name, version, desc, size);
>                 } 
>                 catch (ex) {
>                     db = null;
>                 }
>                 if (db === null) {
>                     return storage.openDatabase(name, version, desc, size);
>                 }
>                 else {
>                     return db;
>                 }
>             };
>         }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira