Converting a database query to a WDDX packet using ColdFusion

Readability

Converting a database query to a WDDX packet using ColdFusion

The fol­low­ing exam­ple shows how you can con­vert a data­base query to a XML WDDX packet using Cold­Fu­sion and the <CFWDDX> tag.


    SELECT A.ARTISTID, A.FIRSTNAME, A.LASTNAME, A.ADDRESS, A.CITY, A.STATE
    FROM ARTISTS A

 


#xmlFormat(artistsWDDX)#

And the out­put of the <CFOUT­PUT> tag is as follows:


    
1.0 2.0 3.0 4.0 5.0 Aiden Austin Elicia Jeff Lori Donolan Weber Kim Baclawski Johnson 352 Corporate Ave. 25463 Main Street, Suite C 2523 National Blvd 903 Boardwalk Ave 6462 Cowtown Rd Denver Berkeley Los Angeles Hollywood Pierre CO CA CA FL SD

The following example shows how you can convert a database query to a XML WDDX packet using ColdFusion and the <CFWDDX> tag.

<cfquery name="getArtists" datasource="cfartgallery" maxRows="5">
    SELECT A.ARTISTID, A.FIRSTNAME, A.LASTNAME, A.ADDRESS, A.CITY, A.STATE
    FROM ARTISTS A
</cfquery>
 
<cfwddx action="cfml2wddx"
        input="#getArtists#"
        output="artistsWDDX" />
 
<cfoutput>#xmlFormat(artistsWDDX)#</cfoutput>

And the output of the <CFOUTPUT> tag is as follows:

<wddxPacket version='1.0'>
    <header/>
    <data>
        <recordset rowCount='5' fieldNames='ARTISTID,FIRSTNAME,LASTNAME,ADDRESS,CITY,STATE' type='coldfusion.sql.QueryTable'>
            <field name='ARTISTID'>
                <number>1.0</number>
                <number>2.0</number>
                <number>3.0</number>
                <number>4.0</number>
                <number>5.0</number>
            </field>
            <field name='FIRSTNAME'>
                <string>Aiden</string>
                <string>Austin</string>
                <string>Elicia</string>
                <string>Jeff</string>
                <string>Lori</string>
            </field>
            <field name='LASTNAME'>
                <string>Donolan</string>
                <string>Weber</string>
                <string>Kim</string>
                <string>Baclawski</string>
                <string>Johnson</string>
            </field>
            <field name='ADDRESS'>
                <string>352 Corporate Ave.</string>
                <string>25463 Main Street, Suite C</string>
                <string>2523 National Blvd</string>
                <string>903 Boardwalk Ave</string>
                <string>6462 Cowtown Rd</string>
            </field>
            <field name='CITY'>
                <string>Denver</string>
                <string>Berkeley</string>
                <string>Los Angeles</string>
                <string>Hollywood</string>
                <string>Pierre</string>
            </field>
            <field name='STATE'>
                <string>CO</string>
                <string>CA</string>
                <string>CA</string>
                <string>FL</string>
                <string>SD</string>
            </field>
        </recordset>
    </data>
</wddxPacket>

One thought on “Converting a database query to a WDDX packet using ColdFusion”

Leave a Reply