We use stored procedures for everything. We also use sequences and want to return the sequence number back from the stored procedure as an out parameter. We still haven't gotten to select statements yet in our prototype work, but that is beginning to scare me too. I am new to JavaScript, so it could be me making a newbie mistake with promises. Here is my route.
res.send('Invite sent to ' + req.body.userFirstName);
} catch (err) {
if (conn) conn.end();
console.error("Catch Block: ", err);
res.status(500).send('Error: ' + err.text);
}
});
And I get this as my result from my console.log deconstruction of the dbResponse object:
There has to be a better way to get to the data vs what I have in my function. I can't imagine doing this kind of stuff for 100 rows of data vs one out param.
[
[
I have upgraded to version 3. I like the new response, but
It doesn't seem you have the ability for me to pick up the error. It doesn't throw an error and the error message is the same old response as before. Now I have to figure out which "response" envelope is being returned and then pick through the rubble.
It would be nice to have a dbResponse.error.code and dbResponse.error.msg
This is the easiest one to work with I have seen so far (mssql):
console.log(result.recordsets.length) // count of recordsets returned by the procedure
console.log(result.recordsets[0].length) // count of rows contained in first recordset
console.log(result.recordset) // first recordset from result.recordsets
console.log(result.returnValue) // procedure return value
console.log(result.output) // key/value collection of output values
console.log(result.rowsAffected) // array of numbers, each number represents the number of rows affected by executed statement
If I have 5 statements in the stored procedure, there are 5 numbers in the "rowsAffected".
Can I get the best practices for catching an error with version 3.0?
Tom Miller
added a comment - I have upgraded to version 3. I like the new response, but
It doesn't seem you have the ability for me to pick up the error. It doesn't throw an error and the error message is the same old response as before. Now I have to figure out which "response" envelope is being returned and then pick through the rubble.
It would be nice to have a dbResponse.error.code and dbResponse.error.msg
This is the easiest one to work with I have seen so far (mssql):
console.log(result.recordsets.length) // count of recordsets returned by the procedure
console.log(result.recordsets [0] .length) // count of rows contained in first recordset
console.log(result.recordset) // first recordset from result.recordsets
console.log(result.returnValue) // procedure return value
console.log(result.output) // key/value collection of output values
console.log(result.rowsAffected) // array of numbers, each number represents the number of rows affected by executed statement
If I have 5 statements in the stored procedure, there are 5 numbers in the "rowsAffected".
Can I get the best practices for catching an error with version 3.0?
My concern is how hard it is to get to the stuff in the result.
I am completely fine with @NewRcrdID but it will be nice not to have to put the out params.
And the @NewRrcdID comes back in the response. There are actual 3 parts to the response:
response[0] -first SQL statement or error for first SQL statement
response[1] - statistics of first SQL statement (affectedRows etc)
response[2] - select @NewRcrdID; // wish it would drop the @ sign on the column name as it makes it much harder to get to the data.
((dbResponse[0])[0])['@full_error'];
((dbResponse[2])[0])['@NewRcrdID'];
It currently doesn't throw an error either. I have to do this manually:
Something like this is more logical and less error prone:
dbResponse.error.code;
dbResponse.error.message;
(dbResponse.data[0].UserID).toString(); // first record or single row
dbResponse.data[0] // rows of data
dbResponse.data[1].NewRcrdID;
dbResponse.res.affectedRows;
Or is this available already and I just don't know it?
Do you need testers for the new connector?
Tom Miller
added a comment - My concern is how hard it is to get to the stuff in the result.
I am completely fine with @NewRcrdID but it will be nice not to have to put the out params.
And the @NewRrcdID comes back in the response. There are actual 3 parts to the response:
response [0] -first SQL statement or error for first SQL statement
response [1] - statistics of first SQL statement (affectedRows etc)
response [2] - select @NewRcrdID; // wish it would drop the @ sign on the column name as it makes it much harder to get to the data.
((dbResponse[ 0 ])[ 0 ])[ '@full_error' ];
((dbResponse[ 2 ])[ 0 ])[ '@NewRcrdID' ];
It currently doesn't throw an error either. I have to do this manually:
const dbResponseError = ((dbResponse[ 0 ])[ 0 ])[ '@full_error' ];
if (dbResponseError) throw {
name: 'Database Error:' ,
message: dbResponseError
};
My main problem is needing to access everything like this:
const dbResponseError = ((dbResponse[ 0 ])[ 0 ])[ '@full_error' ];
const strUserId = (((dbResponse[ 0 ])[ 0 ]).UserID).toString();
This is very error prone.
Something like this is more logical and less error prone:
dbResponse.error.code;
dbResponse.error.message;
(dbResponse.data[ 0 ].UserID).toString(); // first record or single row
dbResponse.data[ 0 ] // rows of data
dbResponse.data[ 1 ].NewRcrdID;
dbResponse.res.affectedRows;
Or is this available already and I just don't know it?
Do you need testers for the new connector?
output parameters will be returned as a resultset without need to use user variables.
Diego Dupin
added a comment - I'm not sure to understand the problem.
With actual driver, if you have some OUT parameters, you'll have to use user variable like you indicate.
await conn.query( 'CALL auth_user_P__userinvite_sp(?,?,?,?,?,?,?,?,?,@NewRcrdID)' , [params...]);
const dbResponse = await conn.query( 'SELECT @NewRcrdID;' );
With 3.0 release (before the end of the month), it can be simplier :
const dbResponse = await conn.execute( 'CALL auth_user_P__userinvite_sp(?,?,?,?,?,?,?,?,?,?,?)' , [params... ]);
output parameters will be returned as a resultset without need to use user variables.
I am hoping I am missing something or you will add something to the system to make this information more accessible for multi-statement queries without jumping through hoops.
Tom Miller
added a comment - I am new to JavaScript and I may be missing some syntatical sugar, but this is what I came up with as a work around:
const dbResponseError = ((dbResponse[ 0 ])[ 0 ])[ '@full_error' ];
if (dbResponseError) throw {
name: 'Database Error:' ,
message: dbResponseError
};
const statement2Res = ((dbResponse[ 2 ])[ 0 ])[ '@NewRcrdID' ];
I am hoping I am missing something or you will add something to the system to make this information more accessible for multi-statement queries without jumping through hoops.
People
Diego Dupin
Tom Miller
Votes:
0Vote for this issue
Watchers:
2Start watching this issue
Dates
Created:
Updated:
Git Integration
Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.
{"report":{"fcp":1184.5,"ttfb":272.30000019073486,"pageVisibility":"visible","entityId":108055,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"9f258dad-641e-4799-9dd2-17118280c752","navigationType":0,"readyForUser":1261.9000000953674,"redirectCount":0,"resourceLoadedEnd":1518.8000001907349,"resourceLoadedStart":287.59999990463257,"resourceTiming":[{"duration":252.80000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":287.59999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":287.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":540.4000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":253.09999990463257,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":287.90000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":287.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":541,"responseStart":0,"secureConnectionStart":0},{"duration":428,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":288,"connectEnd":288,"connectStart":288,"domainLookupEnd":288,"domainLookupStart":288,"fetchStart":288,"redirectEnd":0,"redirectStart":0,"requestStart":543.6999998092651,"responseEnd":716,"responseStart":567.8000001907349,"secureConnectionStart":288},{"duration":590.0999999046326,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true&whisper-enabled=true","startTime":288.30000019073486,"connectEnd":288.30000019073486,"connectStart":288.30000019073486,"domainLookupEnd":288.30000019073486,"domainLookupStart":288.30000019073486,"fetchStart":288.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":545.3000001907349,"responseEnd":878.4000000953674,"responseStart":577.4000000953674,"secureConnectionStart":288.30000019073486},{"duration":284.90000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":288.40000009536743,"connectEnd":288.40000009536743,"connectStart":288.40000009536743,"domainLookupEnd":288.40000009536743,"domainLookupStart":288.40000009536743,"fetchStart":288.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":546.4000000953674,"responseEnd":573.3000001907349,"responseStart":570.8000001907349,"secureConnectionStart":288.40000009536743},{"duration":287.30000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":288.59999990463257,"connectEnd":288.59999990463257,"connectStart":288.59999990463257,"domainLookupEnd":288.59999990463257,"domainLookupStart":288.59999990463257,"fetchStart":288.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":547.9000000953674,"responseEnd":575.9000000953674,"responseStart":573.9000000953674,"secureConnectionStart":288.59999990463257},{"duration":287.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":288.80000019073486,"connectEnd":288.80000019073486,"connectStart":288.80000019073486,"domainLookupEnd":288.80000019073486,"domainLookupStart":288.80000019073486,"fetchStart":288.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":548.9000000953674,"responseEnd":576.4000000953674,"responseStart":574.6999998092651,"secureConnectionStart":288.80000019073486},{"duration":258.69999980926514,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":289,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":289,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":547.6999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":294.6000003814697,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":289.19999980926514,"connectEnd":289.19999980926514,"connectStart":289.19999980926514,"domainLookupEnd":289.19999980926514,"domainLookupStart":289.19999980926514,"fetchStart":289.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":556.9000000953674,"responseEnd":583.8000001907349,"responseStart":580.4000000953674,"secureConnectionStart":289.19999980926514},{"duration":265.19999980926514,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":289.30000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":289.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":554.5,"responseStart":0,"secureConnectionStart":0},{"duration":302.30000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":289.5,"connectEnd":289.5,"connectStart":289.5,"domainLookupEnd":289.5,"domainLookupStart":289.5,"fetchStart":289.5,"redirectEnd":0,"redirectStart":0,"requestStart":559.0999999046326,"responseEnd":591.8000001907349,"responseStart":590.0999999046326,"secureConnectionStart":289.5},{"duration":681.6999998092651,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":290.30000019073486,"connectEnd":290.30000019073486,"connectStart":290.30000019073486,"domainLookupEnd":290.30000019073486,"domainLookupStart":290.30000019073486,"fetchStart":290.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":961.0999999046326,"responseEnd":972,"responseStart":971.4000000953674,"secureConnectionStart":290.30000019073486},{"duration":1228.4000000953674,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":290.40000009536743,"connectEnd":290.40000009536743,"connectStart":290.40000009536743,"domainLookupEnd":290.40000009536743,"domainLookupStart":290.40000009536743,"fetchStart":290.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":1507.6999998092651,"responseEnd":1518.8000001907349,"responseStart":1518.0999999046326,"secureConnectionStart":290.40000009536743},{"duration":201.2999997138977,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":850.8000001907349,"connectEnd":850.8000001907349,"connectStart":850.8000001907349,"domainLookupEnd":850.8000001907349,"domainLookupStart":850.8000001907349,"fetchStart":850.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":1021.1999998092651,"responseEnd":1052.0999999046326,"responseStart":1050.5,"secureConnectionStart":850.8000001907349},{"duration":423.19999980926514,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1116.8000001907349,"connectEnd":1116.8000001907349,"connectStart":1116.8000001907349,"domainLookupEnd":1116.8000001907349,"domainLookupStart":1116.8000001907349,"fetchStart":1116.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":1507.9000000953674,"responseEnd":1540,"responseStart":1539.4000000953674,"secureConnectionStart":1116.8000001907349}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":90,"responseStart":272,"responseEnd":285,"domLoading":284,"domInteractive":1554,"domContentLoadedEventStart":1554,"domContentLoadedEventEnd":1605,"domComplete":2399,"loadEventStart":2399,"loadEventEnd":2399,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1523},{"name":"bigPipe.sidebar-id.end","time":1523.9000000953674},{"name":"bigPipe.activity-panel-pipe-id.start","time":1524.6999998092651},{"name":"bigPipe.activity-panel-pipe-id.end","time":1529.1999998092651},{"name":"activityTabFullyLoaded","time":1622.1999998092651}],"measures":[],"correlationId":"f6c481bf5ca8c2","effectiveType":"4g","downlink":9.5,"rtt":0,"serverDuration":107,"dbReadsTimeInMs":16,"dbConnsTimeInMs":24,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
I have upgraded to version 3. I like the new response, but
It doesn't seem you have the ability for me to pick up the error. It doesn't throw an error and the error message is the same old response as before. Now I have to figure out which "response" envelope is being returned and then pick through the rubble.
It would be nice to have a dbResponse.error.code and dbResponse.error.msg
This is the easiest one to work with I have seen so far (mssql):
console.log(result.recordsets.length) // count of recordsets returned by the procedure
console.log(result.recordsets[0].length) // count of rows contained in first recordset
console.log(result.recordset) // first recordset from result.recordsets
console.log(result.returnValue) // procedure return value
console.log(result.output) // key/value collection of output values
console.log(result.rowsAffected) // array of numbers, each number represents the number of rows affected by executed statement
If I have 5 statements in the stored procedure, there are 5 numbers in the "rowsAffected".
Can I get the best practices for catching an error with version 3.0?