Search code examples
androidsqlitecordovaweb-sql

Android Cordova WebSQL can't count - could not prepare statement (1 too many SQL variables)


This error only occurs on a few (recent model android 5) android devices. I am giving SQLite this and it doesn't seem to be able to count!

executeSql("update email set IsMarkedAsRead=?, IsMarkedAsReadOnServer=?,IsFlagged=?,IsFlaggedOnServer=? where LocalEmailID=?", [email.IsMarkedAsRead, email.IsMarkedAsRead, email.IsFlagged, email.IsFlagged, email.LocalEmailID], null, sqlerror)

There are 5 question marks and 5 elements in the variable array unless I am going mental...

Throws this error:

could not prepare statement (1 too many SQL variables)

Then throws this error (presumably the first one triggers this too):

the statement callback raised an exception or statement error callback did not return false

We have a cordova app using the standard Web SQL (which uses the native Sqlite exposed by the browser or the MSOpenTech polyfill if needed). There are several places in the codebase where we call SQL statements and this error appears. In some cases there are no parameters and we are passing an empty array, but it still says 1 too many variables. On most devices there is no error - only happens on some android devices. So far have seen this on at least two devices (these are users in the field, have not reproduced in testing).

Example device with this problem: Samsung Galaxy S5 Duos with user agent string of Mozilla/5.0 (Linux; Android 5.0; SM-G900FD Build/LRX21T; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/50.0.2661.86 Mobile Safari/537.36

Any ideas?


Solution

  • Thanks @nyluke for you comments. I ended up upgrading the database engine to this Cordova Sqlite plugin: https://github.com/litehelpers/cordova-sqlite-ext

    I am hoping this will solve the problem. I will update this answer if I get more bug reports.

    Update

    Several months after upgrading to Cordova Sqlite plugin I have never seen this bug again. Definitely solved the problem.

    The WebSQL standard cordova plugin should not to be recommended as it is buggy. Most problematic it limits you to 50mb and deleting data won't recover the space so eventually your app will die...