connection.execute() not working for me
See original GitHub issueI 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:
- Created 8 years ago
- Comments:5 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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.
Oops, yes, I meant
[item.ID]
. Do you get any rows back with this change? Why do you think empty result is incorrect?