1

I've tried all possible formats for the select query:

var queryCust = "SELECT * FROM customers WHERE CustBarcode = '" + CustomerBarcode + "';";

or

var queryCust = "SELECT * FROM customers WHERE CustBarcode like '" + CustomerBarcode + "';";

or

var queryCust = "SELECT * FROM customers WHERE cast(CustBarcode as text) = '" + CustomerBarcode "';";

or with and without ' ' but nothing works, the query didn't return any value!

I've even tried

db.executeSql('SELECT * FROM customers WHERE CustBarcode = ?', [ CustBarcode ], function(rs) {...

but didn't worked, even when tried to convert with javascript CustBarcode to string or integer.

below is the function:

alert(queryCust);

db.executeSql(queryCust, [], function(rs) {
    alert(rs.rows.item(0).CustBarcode);

    var DescCust = "";

    if (rs.rows.item(0).Status == 'NEW'){
        DescCust = rs.rows.item(0).Desc + ' ' + rs.rows.item(0).Address;
    } else {
        DescCust = rs.rows.item(0).CustCode + ' ' + rs.rows.item(0).Desc + ' ' + rs.rows.item(0).Address;
    }

    document.getElementById("custDesc").innerHTML = DescCust;

}, function(error) {
    alert('SELECT SQL statement ERROR while building DescCust: ' + error.message);
});
Tony
  • 1,099
  • 9
  • 19
  • Did you try using the query in your SQL DB interface (eg phpMyAdmin)? – Sv443 Nov 20 '18 at 16:29
  • I don't have it, the table is created in phonegap application like this tx.executeSql('CREATE TABLE IF NOT EXISTS customers (CustBarcode, CustCode, Desc, Address, Long, Lat, Status)'); – Tony Nov 20 '18 at 16:31
  • then try using your query just like you created the table and see if it returns something. Also did you even write some data to the DB? Else it makes sense it can't return something because it's empty. – Sv443 Nov 20 '18 at 16:33
  • of course their is data in the table tx.executeSql('INSERT INTO customers VALUES (?,?,?,?,?,?,?)', [... and i am able to perform select * from customers it's returning results, but the problem is with the WHERE condition – Tony Nov 20 '18 at 16:35
  • Can you tell me what exactly you get if you use `SELECT * FROM customers`? – Sv443 Nov 21 '18 at 10:52
  • I figured it out.. CustBarcode contain an integer of 19 number ! JavaScript is rounding the number.. that's why i am not getting any result ! because after rounding the number the where condition is never met ! take a look at this link for more infos : https://stackoverflow.com/questions/15529337/prevent-javascript-number-function-from-rounding-big-numbers – Tony Nov 21 '18 at 11:01

0 Answers0