tags:

views:

43

answers:

1

How can this be rewritten using the new scripting syntax along with the hibernate query language in CF9?

<cfcomponent output="no">
<cffunction name="Login" output="no">
    <cfargument name="UsrName">
    <cfargument name="UsrPassword">

    <cfquery name="local.qry">
    SELECT * FROM UsrView
    WHERE UsrName = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.UsrName#">
    AND UsrPassword = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.UsrPassword#">
    </cfquery>
    <cfreturn local.qry>
</cffunction>
</cfcomponent>
+2  A: 

Is this what you are after?

component{
  public query function Login(UsrName,UsrPassword){
    // get array of entities matching filter
    var arrayOfUsers = EntityLoad('User',{
      UsrName=arguments.UsrName, UsrPassword=arguments.UsrPassword
    });
    // convert entity array to a query object
    return EntitytoQuery(arrayOfUsers);
  }
}
John Whish
Wow! That's fantastic!I wonder if I should return the arrayOfUsers instead of EntitytoQuery(arrayOfUsers)?This is a start-from-scratch project, so I don't have any need to maintain legacy code or methodology.What's the better way to handle data coming from a SQL Select statement now? Is it arrayOfUsers, or EntitytoQuery(arrayOfUsers)?
cf_PhillipSenn
@cf_PhilipSenn it depends. :) If you have methods in your entity that your view layer might need to call, then return an array of users. If you need to populate something like a cfselect, then query is the way to go.
Henry
@cf_PhilipSenn and I think CFQUERY is more efficient than EntityToQuery() or HQL.
Henry