CFLib.org – Common Function Library Project

convertDotNetDataset(dataset)

Last updated May 17, 2007
Download UDF

author

Anthony Petruzzi                                  Anthony Petruzzi

Version: 1 | Requires: ColdFusion MX7 | Library: DataManipulationLib

 
Rated 0 time(s). Average Rating: 0

Description:
Originally written by Joe Reinhart, so give him the credit. I just found this function useful and fixed a bug so it could be submitted. It will take a .Net Dataset and convert it to a CF structure of queries.

Return Values:
Returns a structure.

Example:

<cfinvoke webservice="http://www.example.com/query.asmx?WSDL" method="NameSearch" returnvariable="data">
    <cfinvokeargument name="LastName" value="xxxx"/>
    <cfinvokeargument name="FirstName" value="xxxx"/>
    <cfinvokeargument name="MidName" value="xxxx"/>
</cfinvoke>
<cfdump var="#convertDotNetDataset(data)#">

Parameters:

Name Description Required
dataset Dot net dataset. Yes

Full UDF Source:

<!---
Takes a .Net dataset and converts it to a CF structure of queries.

@param dataset      Dot net dataset. (Required)
@return Returns a structure.
@author Anthony Petruzzi (tonyp@rolist.com)
@version 1, May 17, 2007
--->

<cffunction name="convertDotNetDataset" access="public" returnType="struct" output="false"
            hint="takes a .Net dataset and converts it to a CF structure of queries">

    <cfargument name="dataset" required="true">
    <cfset var Local = StructNew()>
    <cfset Local.result = structNew() />
    <cfset Local.aDataset = arguments.dataset.get_any() />
    <cfset Local.xSchema = xmlParse(Local.aDataset[1]) />
    <cfset Local.xData = xmlParse(Local.aDataset[2]) />

    <!--- Create Queries --->
    <cfset Local.xTables = Local.xSchema["xs:schema"]["xs:element"]["xs:complexType"]["xs:choice"] />
    <cfloop from="1" to="#arrayLen(Local.xTables.xmlChildren)#" index="Local.i">
        <cfset Local.tableName = Local.xTables.xmlChildren[Local.i].xmlAttributes.name />
        <cfset Local.xColumns = Local.xTables.xmlChildren[Local.i].xmlChildren[1].xmlChildren[1].xmlChildren/>
        <cfset Local.result[Local.tableName] = queryNew("") />
        <cfloop from="1" to="#arrayLen(Local.xColumns)#" index="Local.j">
            <cfset queryAddColumn(Local.result[Local.tableName], Local.xColumns[Local.j].xmlAttributes.name, arrayNew(1)) />
        </cfloop>
    </cfloop>

    <!--- see if there are any row of data, if not exit --->
    <cfif NOT StructKeyExists(Local.xData["diffgr:diffgram"], "NewDataSet")>
        <cfreturn Local.result>
    </cfif>

    <!--- Populate Queries --->
    <cfset Local.xRows = Local.xData["diffgr:diffgram"]["NewDataSet"] />
    <cfloop from="1" to="#arrayLen(Local.xRows.xmlChildren)#" index="Local.i">
        <cfset Local.thisRow = Local.xRows.xmlChildren[Local.i] />
        <cfset Local.tableName = Local.thisRow.xmlName />
        <cfset queryAddRow(Local.result[Local.tableName], 1) />
        <cfloop from="1" to="#arrayLen(Local.thisRow.xmlChildren)#" index="Local.j">
            <cfset querySetCell(Local.result[Local.tableName], Local.thisRow.xmlChildren[Local.j].xmlName, Local.thisRow.xmlChildren[Local.j].xmlText, Local.result[Local.tableName].recordCount) />
        </cfloop>
    </cfloop>

    <cfreturn Local.result>
</cffunction>

Search CFLib.org


Latest Additions

John Bartlett John Bartlett added
browserDetect
5 day(s) ago

Rob Brooks-Bilson Rob Brooks-Bilson added
listCompare
8 day(s) ago

Stephen Withington Stephen Withington added
formToNameValueP...
16 day(s) ago

anthony petruzzi anthony petruzzi added
parseExcel
21 day(s) ago

Pablo Varando Pablo Varando added
returnRandomHEXC...
22 day(s) ago

Top Rated

Nathan Dintenfass                                 QueryStringChang...
Rated 5.0, 10 time(s)

Stephen Withington formToNameValueP...
Rated 5.0, 5 time(s)

Gyrus                                             HTMLSafe
Rated 5.0, 4 time(s)

Shlomy Gantz                                      viewCSS
Rated 5.0, 4 time(s)

Michael Sharman generateRandomKe...
Rated 5.0, 3 time(s)

Created by Raymond Camden / Design by Justin Johnson