Reputation: 3130
I am new to ColdFusion and want to rewrite my project from ASP.NET to learn ColdFusion step by step.
My SQL Server stored procedure for authentication (ASP.NET) looks like this:
CREATE PROCEDURE sp_auth
@suser VARCHAR(20),
@spswd VARCHAR(20)
AS
SELECT COUNT(*) FROM Users.SUsers WHERE suname=@suser AND supasswd=@spswd AND off_bit=0
GO
Application.cfc snippet.
<cfstoredproc procedure="sp_auth" datasource="cftraderelay">
<cfprocparam value="#cflogin.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="20" type="in">
<cfprocparam value="#cflogin.password#" cfsqltype="CF_SQL_VARCHAR" maxlength="20" type="in">
<cfprocresult name="auth_pass" maxrows="1">
</cfstoredproc>
<cfif auth_pass GTE 1>
<cfloginuser name="#cflogin.name#" password = "#cflogin.password#" roles="#roles#">
<cfelse>
<cfoutput>
<h2>Your login information is not valid.<br> Please Try again</h2>
</cfoutput>
<cfinclude template="login.cfm">
<cfabort>
</cfif>
What is right form of 'cfif auth_pass GTE 1' logic? How to access the value of 'auth_pass'. Cos I get "Complex object types cannot be converted to simple values" error by far.
Am I strictly supposed to use out type of cfprocparam in this case, not cfprocresult (modify SQL query for the OUTPUT variable)?
Can I access cfprocresult value right in the cfif statement?
Upvotes: 1
Views: 703
Reputation: 29870
auth_pass
contains a recordset, not a number, so you cannot compare it to 1. You perhaps want auth_pass.recordCount
?
The best tool for examining the contents of a variable is <cfdump>
. That and familiairising yourself with the docs for the code you're using, eg: <cfprocresult>
, <cfstoredproc>
, <cfquery>
(the latter for details on query objects) if you run into problems and can't guess the solution.
Upvotes: 2