Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

queries inside cfc's

Participant ,
Mar 25, 2008 Mar 25, 2008
I am having an issue with using a query inside a component:

I am passing two variables to a component; user name and password, the query returns the username, useraccess and staff id. When I invoke the component I want to check for a record and allow or deny access acordingly.

my issues, I am being forced to use a returntype of string or any. it won't take query.

I get an error everytime I try to use recordcount. Recordcount is not defined in...


<cfcomponent>
<cffunction name="mylogin" access="public" returntype="string" >
<cfargument name="UserName" type="string" required="yes">
<cfargument name="Password" type="string" required="yes">

<cfset var login="">

<cfquery datasource="TimeReporting" name="login" result="result">
SELECT UserName,UserPassword,UserAccess,staffID
FROM tblStaff WHERE UserName='#Arguments.UserName#'
AND UserPassword='#Arguments.Password#'
</cfquery>

<cfreturn mylogin>
</cffunction>
</cfcomponent>



here is the error message:

The following information is meant for the website developer for debugging purposes.
Error Occurred While Processing Request
Element RECORDCOUNT is undefined in MYLOGINRET.

ColdFusion cannot determine the line of the template that caused this error. This is often caused by an error in the exception handling subsystem.
Resources:

* Check the ColdFusion documentation to verify that you are using the correct syntax.
* Search the Knowledge Base to find a solution to your problem.

Browser Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12
Remote Address ::1
Referrer http://localhost/jays_dev/TMR/login.cfm
Date/Time 25-Mar-08 03:57 PM
Stack Trace
at cfaccess2d12ecfm319416303.runPage(C:\inetpub\wwwroot\jays_dev\TMR\access-1.cfm:44)
TOPICS
Getting started
674
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Mar 26, 2008 Mar 26, 2008
Thank you,

I haven't written very many cfc's and was under the impression that I had to return the function name. It does make sense to return the query name.
Translate
LEGEND ,
Mar 25, 2008 Mar 25, 2008
jbird5k wrote:
> <cfset var login="">

> <cfquery datasource="TimeReporting" name="login" result="result">

> <cfreturn mylogin>

If you look closely at these three lines of code you will probably see
the problem.

If not, it is not 'my' problem.

HTH
Ian

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 25, 2008 Mar 25, 2008
Hi

In your query you are returning the variable name is the function name <cfreturn mylogin>

If you want to get the recordcount you have to return the queryname

Replace your <cfreturn mylogin> with <cfreturn login>

Hope you understand your mistake
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 26, 2008 Mar 26, 2008
Thank you,

I haven't written very many cfc's and was under the impression that I had to return the function name. It does make sense to return the query name.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 26, 2008 Mar 26, 2008
<cfset var login="">
<cfset var myrecordcount="">

<cfquery name="login ...

</cfquery>

<cfset myrecordcount= login.recordcount>

<cfreturn myrecordcount>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Mar 26, 2008 Mar 26, 2008
LATEST
jbird5k,

Btw, you forgot to "var" scope the result name.

<cfset var login="">
<cfset var result="">
<cfquery datasource="TimeReporting" name="login" result="result">
...

Though if you are not using "result", you could also remove it entirely.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources