App crash with SQLite

Versión Fuse 1.2.1 (Build 13974)
Windows 10 64-Bits

I implement SQLite from here https://github.com/bolav/fuse-sqlite. When i make a simple “INSERT INTO” the app is crash and close. No one message error is displayed in console. In Fuse´s emulator work very well but in my smartphone crash.

My js code:

const Observable = require("FuseJS/Observable");
const GeoLocation = require("FuseJS/GeoLocation");
const sqlite = require('SQLite');

//User from HomePage
var user = Observable();
user = this.Parameter.map(function (p) { return p.user; });

var sku = Observable();
var skuValidError = Observable(false);
var description = Observable();
var format = Observable();
var m2 = Observable();
var precioxcaja = Observable();

//Variables of Selection
var optionsFinished = Observable();
var option_finished = Observable("");
var OptionsTipo = Observable();
var option_tipo = Observable("");
var OptionsBrands = Observable();
var option_brand = Observable("");
var OptionStatus = Observable();
var option_status = Observable("");

//Coordenates
var TimeoutLocation = Observable();
var timeOutMs = 5000;
var lat, lon;
GeoLocation.getLocation(timeOutMs).then((location) => {
  lat = location.latitude.toString(); //Convert to String for save data with SQLite without problems
  lon = location.longitude.toString();
  console.log("lat:" + lat + " " + "lon:" + lon);
}).catch((error) => {
  console.log("Error: " + error);
});

var contentText = Observable();

var finishFloor = ["Mate", "Brillante", "Decorado", "Madera"];

optionsFinished.onValueChanged(module, function () {
  option_finished.value = optionsFinished.toArray().join("");
  debug_log(option_finished.value);
});

var typologies = ["Exterior", "Rustico", "Fachada", "Muro", "Baño", "Marmol", "Regadera"];

OptionsTipo.onValueChanged(module, function () {
  option_tipo.value = OptionsTipo.toArray().join(" ");
  debug_log(option_tipo.value);
});

var brands = ["Vitrolex", "Lamosa", "Interceramic", "Traficmaster", "Daltile", "Innovatile", "Tecnopiso"];

OptionsBrands.onValueChanged(module, function () {
  option_brand.value = OptionsBrands.toArray().join("");
  debug_log(option_brand.value);
});

var status = ["Experiencia Vitromex", "Boutique"];

OptionStatus.onValueChanged(module, function () {
  option_status.value = OptionStatus.toArray().join("");
  debug_log(option_status.value);
});

//Validate SKU
function validateSKU() {
  let skuVal = sku.value;
  let patron = /^\d*$/;
  patron.test(skuVal) && skuVal.length == 6 && skuVal != ""
    ? skuValidError.value = false
    : skuValidError.value = true;
}

//Contain all data of fields´s view
var infoSku = Observable(function () {
  var data = {
    sku: sku.value,
    description: description.value,
    format: format.value,
    finished: option_finished.value,
    tipo: option_tipo.value,
    m2: m2.value,
    precioxcaja: precioxcaja.value,
    brand: option_brand.value,
    status: option_status.value,
    user: user.value,
    lat: lat,
    lon: lon,
  };
  console.log(JSON.stringify(data));
  return data;
});


// INIT SQLite DATABASE //
var db = sqlite.open("VitroApp.sqlite");
//db.execute("DROP TABLE newSkus");
db.execute("CREATE TABLE IF NOT EXISTS newSkus " +
  "(id INTEGER PRIMARY KEY," +
  "sku INT," +
  "description VARCHAR," +
  "format NCHAR," +
  "finished NCHAR," +
  "tipo NCHAR," +
  "m2 FLOAT," +
  "precioxcaja FLOAT," +
  "brand NCHAR," +
  "status NCHAR," +
  "user NCHAR," +
  "lat VARCHAR," +
  "lon VARCHAR)"
);

// HERE CRASH :(
function createSku() {
  let val = infoSku.value;

  let query = db.prepare("INSERT INTO newSkus VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)");
  query.execute(null,
    val.sku,
    val.description,
    val.format,
    val.finished,
    val.tipo,
    val.m2,
    val.precioxcaja,
    val.brand,
    val.status,
    val.user,
    val.lat,
    val.lon
  );

  console.log("Successfull query");
}

function getInfo() {
  var r = db.query("SELECT * FROM newSkus");
  console.log(JSON.stringify(r));
}

function goBack() {
  router.goBack();
}

module.exports = {
  //Variables
  sku: sku,
  skuValidError: skuValidError,
  description: description,
  format: format,
  optionsFinished: optionsFinished,
  option_finished: option_finished,
  finishFloor: finishFloor,
  OptionsTipo: OptionsTipo,
  option_tipo: option_tipo,
  typologies: typologies,
  OptionsBrands: OptionsBrands,
  option_brand: option_brand,
  m2: m2,
  precioxcaja: precioxcaja,
  brands: brands,
  OptionStatus: OptionStatus,
  option_status: option_status,
  status: status,
  user: user,
  TimeoutLocation: TimeoutLocation,
  infoSku: infoSku,
  //Functions
  // show_dialog:show_dialog,
  createSku: createSku,
  validateSKU: validateSKU,
  getInfo: getInfo,
  goBack: goBack
}

I downgrade to version 1.0.0 but get works.

Please somebody coment?

I gave the sqlite library a go with a simplified testcase:

<App>
    <SQLite ux:Global="SQLite" />
    <JavaScript>
    var sqlite = require('SQLite');
    var db = sqlite.open("file.sqlite");
    db.execute("create table if not exists ids (id integer primary key)");

    function doRead() {
        var r = db.query("select * from ids");
        debug_log(JSON.stringify(r));
    }

    function doWrite() {
        db.execute("insert into ids values (?)", 1);
        db.execute("insert into ids values (?)", 2);
        db.execute("insert into ids values (?)", 3);
        console.log("wrote some");
    }

    module.exports = {
        doWrite: doWrite,
        doRead: doRead
    };
    </JavaScript>
    <Grid RowCount="2">
        <Panel HitTestMode="LocalBounds" Clicked="{doWrite}" Color="#18f" />
        <Panel HitTestMode="LocalBounds" Clicked="{doRead}" Color="#f81" />
    </Grid>
</App>

and it does everything I would expect it to do just fine. It writes fine, it reads fine, and it crashes when I try to write again and violate the unique constraints.

Since you’re getting that datatype mismatch error, it’s clear that in one of your INSERT statements you’re passing some values that are not valid for the columns they’re expected to end up into. It might be a NULL or an empty string somewhere, or basically anything else.

You need to add some logging throughout the file to see which is the query that the app crashes with, and take it from there: console.log() is your friend. It might help if you ran preview on device from Terminal/CMD so that you see the log there; use this command: fuse preview -tandroid -vv.

Yeah baby !!

I change this:

 db.execute("CREATE TABLE IF NOT EXISTS newSkus " +
  "(id INTEGER PRIMARY KEY," + ...

 let query = db.prepare("INSERT INTO newSkus VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)");
  query.execute(null,
    val.sku,
    val.description,
    val.format,
    val.finished,
    val.tipo,
    val.m2,
    val.precioxcaja,
    val.brand,
    val.status,
    val.user,
    val.lat,
    val.lon
  );

By this:

 db.execute("CREATE TABLE IF NOT EXISTS newSkus " +
    "(id INTEGER PRIMARY KEY AUTOINCREMENT," + ...

let query = db.prepare("INSERT INTO newSkus VALUES (null,?,?,?,?,?,?,?,?,?,?,?,?)")
    .execute(
    val.sku,
    val.description,
    val.format,
    val.finished,
    val.tipo,
    val.m2,
    val.precioxcaja,
    val.brand,
    val.status,
    val.user,
    val.lat,
    val.lon
  );

And set my config in .unoproj :

{
  "Packages": [
    "Fuse",
    "FuseJS",
    "Fuse.GeoLocation",
    "Fuse.Maps"
  ],
  "Projects": [
    "Dialogs/Fuse.Dialogs.unoproj",
    "fuse_modules/bolav/fuse-sqlite/sqlite_include.unoproj",
  ],
  "Includes": [
    "fuse_modules/bolav/fuse-sqlite/*.uno/Bundle",
    "fuse_modules/bolav/fuse-sqlite/*.uxl/Bundle",
    "fuse_modules/bolav/fuse-sqlite/*.ux/Bundle",
    "fuse_modules/bolav/fuse-sqlite/bundle.sqlite:Bundle",
    "HidingPanel.ux:UXFile",
    "MainView.ux:UXFile",
    "Resources.ux:UXFile",
    "StateAnimation.ux:UXFile",
    "*",
    "Modules/*.js/Bundle",
  ],
  "Android": {
    "Geo": {
      "ApiKey": "xxxxx-xxxxx-xxxxxx-xxxxxxx"
    },
    "Icons": {
      "LDPI": "Pages/Icons/icons/ldpi.png",
      "MDPI": "Pages/Icons/icons/mdpi.png",
      "HDPI": "Pages/Icons/icons/hdpi.png",
      "XHDPI": "Pages/Icons/icons/xhdpi.png",
      "XXHDPI": "Pages/Icons/icons/xxhdpi.png",
      "XXXHDPI": "Pages/Icons/icons/xxxhdpi.png"
    }
  },
  "Excludes": [
    "fuse_modules/"
  ],
  "FusePM": {
    "Dependencies": [
      "https://github.com/bolav/fuse-sqlite"
    ]
  }
}

Thanks a lot !! :slight_smile: