Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using StructKeyExists in place of IsDefined

For code enhancement purposes, we are going to convert all isDefined() calls to structKeyExists(). A couple of things that I need to know are:

How do we define a query in structKeyExists()? For instance:

<cfquery name="getname" datasource="dsn">select * from table</cfquery>

<cfif isDefined('getname') and getname.recordcount neq "">Do this</cfif>

Since there is no scope defined for isDefined(), what scope should we use for structkeyExists()?

like image 663
Regual Avatar asked Feb 08 '14 17:02

Regual


People also ask

What is StructKeyExists?

StructKeyExists()Determines whether a specific key is present in a structure. StructKeyExists( struct=struct, key=string ); Returns: Boolean. Argument.

Is defined CF?

Cystic fibrosis (CF) is an inherited disorder that causes severe damage to the lungs, digestive system and other organs in the body. Cystic fibrosis affects the cells that produce mucus, sweat and digestive juices. These secreted fluids are normally thin and slippery.


1 Answers

The default scope is variables, so StructKeyExists(variables,"getname") will perform your check for you.

However, unless there's missing logic in the example above, you don't need the isDefined/StructKeyExists check, because if you run a query, it'll always be defined, just with no rows present, so your second check on getname.recordcount should be sufficient.

like image 59
barnyr Avatar answered Oct 03 '22 06:10

barnyr