Calling a calling a Stored procedure that has an out variable

I have a cfc which has a method that executes a stored procedure that saves information about a user. In that stored procedure, it produced an out variable which is the user id of the user (SELECT LAST_INSERT_ID() in MySQL) that ID is assiged as an OUT with a name but I’m confused as to how I get that information.

Ex:
<- in my general.cfc ->

<cfset results = saveCandidate.CreateNewCandidate(rc.FirstName, rc.LastName, rc.Gender, rc.Emp>

This works just fine but I want to get the Out variable defined in the stored proc as strCanID. If I just run this code on a page it will allow me to dump this variable but I’m a little confused as how I can store it when this is being called.

Thanks and happy Friday

Can you show your stored proc call, or better yet your entire DAO method? You’ll need to set the type=“out” or type=“inout” and the out variable should be defined with whatever variable name you set in your variable attribute. At that point, it should be like any other variable in in CF.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

saveCandidate.cfc

<cfif len(arguments.Grdlvl) LTE 0>


<CFIF len(arguments.BckStp) LTE 0>


<CFIF len(arguments.getHoldStatus) LTE 0>


<CFIF len(arguments.fdfHoldStartDate) LTE 0>


<CFIF len(arguments.fdfHoldEndDate) LTE 0>


<CFIF len(arguments.fdfSCDate) LTE 0>


<CFIF len(arguments.frgGender) LTE 0>

Check for errors in the form and if it’s clear then save the user.

<cfif vResults.hasErrors() EQ “NO”>

<cfset results = saveCandidate.CreateNewCandidate(rc.ftfFirstName, rc.ftfLastName, rc.frgGender, rc.EmpType, rc.BckStp, rc.getHoldStatus, rc.Grdlvl,
rc.fdfHoldStartDate, rc.fdfHoldEndDate, rc.fdfSCDate, getPlugin(“SessionStorage”).getVar(“userid”))>


getPlugin(“MessageBox”).setMessage(“info”,"Candidate " & rc.ftfFirstName & " " & rc.ftfLastName & " was saved. UserID = ");

Thanks

Since you’re setting the result of the CreateNewCandidate method into a variable called “results”, shouldn’t that be what you’re dumping. “strCanID” doesn’t exist any longer in this scope outside the method.

Also, if saveCandidate is a singleton, you need to VAR SCOPE variables such as queryOut and strCanID for thread safety.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Thanks, I’ll give that a go later on today.