O'Reilly logo

Programming ColdFusion by Rob Brooks-Bilson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Storing WDDX Packets

So far, in this chapter, we have covered all sorts of techniques for serializing and deserializing WDDX packets. All our examples have shown the serialization and deserialization process occurring on the same page. While great for illustrative purposes, the examples have little practical application. After all, why would you want to serialize and then deserialize a packet on the same page? This leads us to the topic for this section—storing your WDDX packets so that you can refer to them later. There are two ways you can store WDDX packets: in a text file or in a database (including LDAP directories). The next two sections discuss these two methods and provide examples of both storing and retrieving packets.

Storing Packets in a Text File

One of the most interesting things about WDDX is you can use it to store for data without having to write the data to a database. For example, record-set data stored in a WDDX packet is much more useful than it is when it’s stored in a delimited text file. Example 20-8 takes a query object and serializes it to a WDDX packet. The resulting WDDX pack is then written to a text file using the CFFILE tag.

Example 20-8. Storing a WDDX Packet Containing a Record Set in a Text File

<!--- get all employee records ---> <CFQUERY NAME="GetEmployeeInfo" DATASOURCE="ProgrammingCF" DBTYPE="ODBC"> SELECT * From EmployeeDirectory </CFQUERY> <!--- serialize the employee records to a wddx packet ---> <CFWDDX ACTION="CFML2WDDX" INPUT="#GetEmployeeInfo#" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required