0

I have this error every time I try to run a query to DB:

Error: Missing query string

I don't understand what could be wrong with my code, the query is correct I have tested it:

function getChannelCTSize(octopusMac, channelID, adcTicks, callback){
    var queryString = "SELECT Channels.CT_size FROM Channels INNER JOIN Octopus ON Octopus.Id=Channels.Octopus_Id WHERE Octopus.Mac = ? AND Channels.Channel_Id = ?";
    var filter = [octopusMac, channelID];

    var query = mariaDB.query({
        sql: queryString
    }, filter );

    query.on('error', function(err) {
        if (err) {
            console.log(err.code);
            return
        }
    })
        .on('result', function(row) {
            callback(result[0].CT_size, channelID, octopusMac, adcTicks);
        })
        .on('end', function() {
            mariaDB.release();
        });
}
7
  • which node package are you using for mariadb? Commented Mar 13, 2017 at 14:28
  • I am using mariasql Commented Mar 13, 2017 at 14:28
  • you mean this package node-mariasql Commented Mar 13, 2017 at 14:33
  • yes sorry my bad Commented Mar 13, 2017 at 14:33
  • what should the filter do? Just return entries with octopusMac like the value you gave to the method? Commented Mar 13, 2017 at 14:36

1 Answer 1

1

The query function of mariasql should be invoked with a string as first argument (the query) instead of an object)

It should look like:

var queryString = "SELECT Channels.CT_size FROM Channels INNER JOIN Octopus ON Octopus.Id=Channels.Octopus_Id WHERE Octopus.Mac = :octopusMac AND Channels.Channel_Id = :channelID";

var query = mariaDB.query(queryString, { octopusMac, channelID }, function(err, rows) {
  if (err)
    console.log(err.code);

  callback(rows[0].CT_size, channelID, octopusMac, adcTicks);
})
Sign up to request clarification or add additional context in comments.

2 Comments

I have tried this but the code never returns any err
The second argument in your example has a typo on syntax. It should be an array. An object works too if you prepare the statement with :octopusMac or whatever name in there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.