0

I'm currently working on a Node.js project and I'm struggling with the wildcard in my mysql query. Here's the code:

exports.getList = function (shop, callback) {
    var sql = "SELECT * FROM chain.shop WHERE shopName = ? AND shopPlace = ?;";

    if (shop.shopName == null)
        shop.shopName = "*";
    if (shop.shopPlace == null)
        shop.shopPlace = "*";

    conn.query(sql, [shop.shopName, shop.shopPlace], function (err, result) {
        if (err) throw err;

        callback(result);
        console.log(this.sql); // shows exectued query
    });
}

Let's say the shopPlace is null, the executed query will be something like

"SELECT * FROM chain.shop WHERE shopName = 'myShop' AND shopPlace = '*';"

This delivers no results as it can't find a shopPlace named '*'. I was wondering how to use the * as a wildcard in this example, rather than a string with single quotes.

Thanks in advance!

DeChaun
  • 1
  • 1

0 Answers0