question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

connection.execute() not working for me

See original GitHub issue

I am trying to use a prepared statement using connection.execute(). the PREG_CAPTURE function is a user defined function in MySQL. I’m using an ES6 multiline string.

Can anyone see why this is not working. Please note this is not intended to be production code so is a little rough.

var getGalleryForPostIDSql = `SELECT gallery_id, ID
FROM (SELECT PREG_CAPTURE( '/(\\[ngg.+id=)([0-9]+)+/' , post_content,2) as gallery_id, post_content,ID, post_type FROM wp_posts p) as t1
WHERE gallery_id IS NOT NULL AND post_type="post" AND ID = ?;`;

connection.connect();

var firstPromise = getVideos(videoSql);

firstPromise.then(function(results){
   //these results are definitely available
    var galleryIds = [];

    //console.log(results[0]);
    results.forEach(function(item,index,results){

        console.log(item); // is populated
        connection.execute(getGalleryForPostIDSql,item.ID, function(err, rows,fields){
            if(err) {
                console.log(err);
                process.exit();
            }
    console.log(rows);// logs an empty array

       });

    });
    return results;

}).then(function(results){
    console.log('next then method call');
}).then(function(){

}).catch(function (e) {
    console.log(e);
});

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
codecowboycommented, Mar 11, 2016

@sidorares thanks. I think I have come to the conclusion that the empty result is actually correct as I have flaws in my logic elsewhere. Thanks for your help - it got me a little further. You can close this issue now.

0reactions
sidorarescommented, Mar 11, 2016

Oops, yes, I meant [item.ID]. Do you get any rows back with this change? Why do you think empty result is incorrect?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Connection.Execute not working - CodeProject
can anybody please help me ----this is not returning anything public static void PopulateCacheUserPercentageMarksForClass()
Read more >
SQLAlchemy core engine.execute() vs connection.execute()
As I understand it, engine.execute() is the same as doing connection.execute() , followed by connection.close() . The tutorials I've ...
Read more >
Step 3: Proof of concept connecting to SQL using Node.js
Step 1: Connect; Step 2: Execute a query; Step 3: Insert a row ... If there are no rows, the request.on() function returns...
Read more >
Working with Engines and Connections — SQLAlchemy 2.0 ...
The first time the Connection.execute() method is called to execute a SQL statement, this transaction is begun automatically, using a behavior known as ......
Read more >
Python and MySQL Database: A Practical Introduction
fetchall() on all cursor objects is important. To execute a new statement on the same connection, you must ensure that there are no...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found