getGeneratedKey(resultStruct)
Last updated February 15, 2008
Version: 1 | Requires: ColdFusion 8 | Library: DatabaseLib
Description:
This UDF takes the result struct from cfquery and returns the proper generated key from that struct.
Return Values:
Returns a value.
Example:
insert into artists
(firstName, lastName)
values(
'todd','sharp'
)
</cfquery>
<cfquery name="getArtists" datasource="cfartgallery">
select *
from artists
</cfquery>
<cfdump var="#getArtists#">
<cfoutput>#getGeneratedKey(r)#</cfoutput>
Parameters:
| Name | Description | Required |
|---|---|---|
| resultStruct | Structure. | Yes |
Full UDF Source:
<!---
Normalizes the various possible returned keys in the cfquery result struct.
@param resultStruct Structure. (Required)
@return Returns a value.
@author Todd Sharp (todd@cfsilence.com)
@version 1, October 14, 2008
--->
<cffunction name="getGeneratedKey" hint="i normalize the key returned from cfquery" output="false">
<cfargument name="resultStruct" hint="the result struct returned from cfquery" />
<cfif structKeyExists(arguments.resultStruct, "IDENTITYCOL")>
<cfreturn arguments.resultStruct.IDENTITYCOL />
<cfelseif structKeyExists(arguments.resultStruct, "ROWID")>
<cfreturn arguments.resultStruct.ROWID />
<cfelseif structKeyExists(arguments.resultStruct, "SYB_IDENTITY")>
<cfreturn arguments.resultStruct.SYB_IDENTITY />
<cfelseif structKeyExists(arguments.resultStruct, "SERIAL_COL")>
<cfreturn arguments.resultStruct.SERIAL_COL />
<cfelseif structKeyExists(arguments.resultStruct, "GENERATED_KEY")>
<cfreturn arguments.resultStruct.GENERATED_KEY />
<cfelse>
<cfreturn />
</cfif>
</cffunction>
Search CFLib.org
Latest Additions
Ryan Thompson-Jewell added
ListSplit
3 day(s) ago
Nathan Dintenfass added
RowsToColumns
4 day(s) ago
Barney Boisvert added
indentXml
4 day(s) ago
Barney Boisvert added
REReplaceCallbac...
4 day(s) ago
Top Rated
FolderSize
Rated 5.0, 7 time(s)
UniqueValueList
Rated 5.0, 6 time(s)
QuickSort
Rated 5.0, 3 time(s)
ListDeleteDuplic...
Rated 5.0, 3 time(s)