Illudium PU36, queryRowToStruct?

2009-08-16 Thread Glyn Jackson

Hi,

Thank you to everyone on house of fusion who has been very helpful so far with 
my stupid questions. I have another ;)
 
I was looking at some code I generated for a gateway by Illudium PU36. The read 
and update functions do not make any sense in that it does not have any return 
for me to get! However I noticed a function called queryRowToStruct I am 
assuming this has something to do with how I can return the query or access the 
query from my service layer, however this is a private function so my service 
layer cannot access it if this was true. I am just confused because without a 
way to return the query whats the point in these functions?

Are they wrong, or should I give them a return? or I am missing the purpose?

Thanks Glyn

-

!---Read---
cffunction name=readAdminUsers access=public output=false 
returntype=void
  cfargument name=adminusers type=salesMaxx.model.objects.adminusers 
required=true /
  cfset var qRead =  /
  cfset var strReturn = structNew() /
  cftry
cfquery name=qRead datasource=#variables.dsnBean.getname()# 
username=#variables.dsnBean.getusername()# 
password=#variables.dsnBean.getpassword()#

SELECT

adminId,

firstname,

surname,

email,

username,

password,

role,

lastLogin,

flag,

IP,

userLog,

createddatetime

FROMadminusers

WHERE   adminId = cfqueryparam 
value=#arguments.adminusers.getadminId()# CFSQLType=cf_sql_integer /

/cfquery
cfcatch type=database
  !--- leave the bean as is and set an empty query for the conditional 
logic below ---
  cfset qRead = queryNew(id) /
/cfcatch
  /cftry
  cfif qRead.recordCount
cfset strReturn = queryRowToStruct(qRead)
cfset arguments.adminusers.init(argumentCollection=strReturn)
  /cfif
/cffunction




cffunction name=queryRowToStruct access=private output=false 
returntype=struct

cfargument name=qry type=query required=true



cfscript

/**

 * Makes a row of a query into a structure.

 * 

 * @param query  The query to work with. 

 * @param rowRow number to check. Defaults to row 
1. 

 * @return Returns a structure. 

 * @author Nathan Dintenfass (nat...@changemedia.com) 

 * @version 1, December 11, 2001 

 */

//by default, do this to the first row of the query

var row = 1;

//a var for looping

var ii = 1;

//the cols to loop over

var cols = listToArray(qry.columnList);

//the struct to return

var stReturn = structnew();

//if there is a second argument, use that for the row 
number

if(arrayLen(arguments) GT 1)

row = arguments[2];

//loop over the cols and build the struct from the 
query row

for(ii = 1; ii lte arraylen(cols); ii = ii + 1){

stReturn[cols[ii]] = qry[cols[ii]][row];

}   

//return the struct

return stReturn;

/cfscript

/cffunction


~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:325484
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4


Re: Illudium PU36, queryRowToStruct?

2009-08-16 Thread Francois Levesque

That looks more like a DAO than a gateway.
Notice that the read method takes in an adminUsers object. At the end of the
method it initializes it with what the query returned, so you can access
it's properties from the calling page.

Also, typically an update method will only need to return true on success
or false on error. The object's properties are still available in the bean
through the get*X* methods.

hth,

Francois Levesque
http://blog.critical-web.com/


On Sun, Aug 16, 2009 at 1:56 PM, Glyn Jackson glyn.jack...@newebia.co.ukwrote:


 Hi,

 Thank you to everyone on house of fusion who has been very helpful so far
 with my stupid questions. I have another ;)

 I was looking at some code I generated for a gateway by Illudium PU36. The
 read and update functions do not make any sense in that it does not have any
 return for me to get! However I noticed a function called queryRowToStruct
 I am assuming this has something to do with how I can return the query or
 access the query from my service layer, however this is a private function
 so my service layer cannot access it if this was true. I am just confused
 because without a way to return the query whats the point in these
 functions?

 Are they wrong, or should I give them a return? or I am missing the
 purpose?

 Thanks Glyn

 -

 !---Read---
 cffunction name=readAdminUsers access=public output=false
 returntype=void
  cfargument name=adminusers type=salesMaxx.model.objects.adminusers
 required=true /
  cfset var qRead =  /
  cfset var strReturn = structNew() /
  cftry
cfquery name=qRead datasource=#variables.dsnBean.getname()#
 username=#variables.dsnBean.getusername()#
 password=#variables.dsnBean.getpassword()#

SELECT

adminId,

firstname,

surname,

email,

username,

password,

role,

lastLogin,

flag,

IP,

userLog,

createddatetime

FROMadminusers

WHERE   adminId = cfqueryparam
 value=#arguments.adminusers.getadminId()# CFSQLType=cf_sql_integer /

/cfquery
cfcatch type=database
  !--- leave the bean as is and set an empty query for the conditional
 logic below ---
  cfset qRead = queryNew(id) /
/cfcatch
  /cftry
  cfif qRead.recordCount
cfset strReturn = queryRowToStruct(qRead)
cfset arguments.adminusers.init(argumentCollection=strReturn)
  /cfif
 /cffunction




 cffunction name=queryRowToStruct access=private output=false
 returntype=struct

cfargument name=qry type=query required=true



cfscript

/**

 * Makes a row of a query into a structure.

 *

 * @param query  The query to work with.

 * @param rowRow number to check. Defaults to
 row 1.

 * @return Returns a structure.

 * @author Nathan Dintenfass (
 nat...@changemedia.com)

 * @version 1, December 11, 2001

 */

//by default, do this to the first row of the query

var row = 1;

//a var for looping

var ii = 1;

//the cols to loop over

var cols = listToArray(qry.columnList);

//the struct to return

var stReturn = structnew();

//if there is a second argument, use that for the
 row number

if(arrayLen(arguments) GT 1)

row = arguments[2];

//loop over the cols and build the struct from the
 query row

for(ii = 1; ii lte arraylen(cols); ii = ii + 1){

stReturn[cols[ii]] = qry[cols[ii]][row];

}

//return the struct

return stReturn;

/cfscript

/cffunction


 

~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:325485
Subscription: 

Re: Illudium PU36, queryRowToStruct?

2009-08-16 Thread Matt Quackenbush

It appears as though that code is expecting the object to be provided in the
'adminusers' argument, and then is converting the query to a struct, and is
then re-initializing the 'adminusers' object with that struct.  Assuming the
init() method on the adminusers object is built to accept these properties
and will re-populate itself, then that's all you need to do.  Because CF
passes CFCs by reference, your adminusers object will magically have all
of the updated info in it wherever you called readAdminUsers() from.

HTH


~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:325486
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


Re: Illudium PU36, queryRowToStruct?

2009-08-16 Thread Glyn Jackson

 quote: Because CF passes CFCs by reference, your adminusers object will 
 magically have all of the updated info in it wherever you called 
 readAdminUsers() from. 

really, no way? so my admin object will have the data populated using the 
getters and setters! thats cool!

so let me see if I understand this. say I wanted to get data from my database 
where ID = 1

in my service layer I would do something like this...

var userDetails = variables.adminUsersGateway.readAdminUsers(arguments.bean);

then in my handler I could setadminusers.getname() to get the name.

do I have to use the object first to set the userID then pass in my object?.



~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:325487
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


Re: Illudium PU36, queryRowToStruct?

2009-08-16 Thread Glyn Jackson

This really works! Look at me I am starting to get this (is it really sad 
this is making me smile with joy lol)


I love this object stuff! So here is what I am doing,

I have just checked my user exist, got their details and set there session in 4 
lines of code in my handler! Now that's cool, right?

if (resultCount.recordcount eq 1){
variables.adminUsersService.getUserByID(userBean);//Get User Deatils, Object 
Will Have The User ID Already
variables.adminUsersService.setCurrentUser(userBean);// Setup User Session
}

I can see now how to make this better no need for the resultCount line I have 
do this via the object also! 

~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:325488
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


Re: Illudium PU36, queryRowToStruct?

2009-08-16 Thread Matt Quackenbush

Heh.  I so totally LOVE those A HA!!! moments!  And no, it's not sad that
those things make you smile.  Hell, I'm smiling just because it's cool to
see someone else get it.  :-)

Oh, and yes, you are absolutely correct.  You do not need the resultCount
line, because you can just get the object from your service (which utilizes
the gateway/dao to populate it).


~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:325489
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


Re: Illudium PU36, queryRowToStruct?

2009-08-16 Thread Glyn Jackson

Glad its not just me. Thanks again for you help, I am sure I will have more 
questions but I have a bit to be going on with now for a while at least.

Glyn 

~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:325490
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4