Coldfusion Update Function

If you ever had gotten stuck with writing insert and update statement for a table with a zillion columns, you can understand my pain.

And applications (most of them) must work with data. Select is cool, in fact, the dudes that crafted the SQL standards even created the almighty shortcut, *, which can select from 1 to a zillion columns. But how do you have a quick work around to update say a table with 150 columns? The truth, there is not shortcut. You have to do the grunt work.

ColdFusion has a CFUPDATE but I hate it like crazy. When your form has submit and cancel on it, you can imagine the hell. So I invented something. It might be a little crude but it works.

I crafted a function that takes a form struct, the table name and unique identifier. Right now, I only have a function that works with one identifier, extending it to support multiple identifiers won’t be a difficult task.

<cffunction name=“updateTable” returntype=“void” displayname=“Update Table”><cfargument name=“formStruct” type=“struct” required=“yes” hint=“This is the form object to be passed” /><cfargument name=“table” type=“string” required=“yes” hint=“This is the name of the table” /><cfargument name=“identifier” type=“string” required=“yes” hint=“This is the name of the unique identifier” /><cfargument name=“datasource” type=“string” required=“yes” hint=“This is the name of the datasource” />