storesafe / cordova-sqlite-evcore-extbuild-free

Cordova sqlite plugin with Android performance enhancements for PhoneGap Build, GPL v3 or commercial license options
Other
24 stars 13 forks source link

App crashes on Android during Insert of a string with more than 17 U+1FXXX characters #43

Closed asimo101 closed 5 years ago

asimo101 commented 6 years ago

This looks related to https://github.com/litehelpers/Cordova-sqlite-evcore-extbuild-free/issues/19 and a few others, with the difference being that when I try to insert just one or two emojis from above U+1Fxxx, the sqlite insert works just fine. But when I try to insert more than 17 such characters (need not be contiguous), my app crashes.

What is weirder is that this figure of 17 often varies, sometimes my app crashes at 18 such characters, sometimes it only crashes at 20 such characters, but never seems to work for more than 20.

In my code, I am simply reading off an input-text box, storing the value in a javascript var, and then inserting into the db using a parametrized query. On debug, I checked that my variables aren't at fault, and the crash comes from within the cordova exec, sadly I am unable to setup crash reporting on my phone in order to get a stack trace.

The same inputs without these 17+ emojis work, with everything else being the same.

Since this is not an error on reading a database entry into a string (utf8 or not), the suggestion to use NewString() instead of NewStringUTF() doesn't really apply.

Testing this on a Moto G3, 3rd Gen with Android 6.0

Here is a code snippet -

var userfile = app.researcherFile;
var mMessage = document.getElementById("id-message-body").value;
var mLanguage = this.getRadioVal( document.getElementById('language-form'), 'language' );
var mPlace = document.getElementById('input-place').innerHTML;
var mDate = document.getElementById('inputDate').value;

var db = null; 

var storage = window.localStorage;
if (storage.getItem("DBUploaded") == null)
    storage.setItem("DBUploaded","0");      

window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, function(externalDataDirectoryEntry) {

    toBeUploaded = 1;
    console.log('Full message ; ' + mMessage ); //This comes fine 
    db = window.sqlitePlugin.openDatabase({name: userfile, androidDatabaseLocation: externalDataDirectoryEntry.toURL()});
    db.transaction(function(tx) {
        tx.executeSql("INSERT INTO MESSAGES (Message, Language, Place, DateOfMessage) VALUES (?,?,?,?)",[mMessage,mLanguage,mPlace,mDate]); //crashes on 17+ emoji characters
    }, function(error) {
        console.log('Populate database error before close: ' + error.message);
        db.close(function() {
            window.plugins.toast.show('Database Error while entering record: ' + error.message, 'long', 'bottom', function(a){}, function(b){});
        });
        return;
    }, function() {
        console.log('Successful db insertion. Before close');
        db.close(function() {
            storage.setItem("DBUploaded","0");
            window.plugins.toast.show('Message added to Database!', 'long', 'bottom', function(a){}, function(b){});
            app.s3Upload(userfile, false);
        });
    });
});
brodycj commented 6 years ago

Already tracked in #7

brodycj commented 6 years ago

I am now planning to add a test case with 20 emoji characters, reopening for tracking purposes.

brodycj commented 5 years ago

Now covered by testing with 25 emoji characters, should not crash any more