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” />

<cfset var fs=arguments.formStruct />
<cfset StructDelete(fs,’fieldnames’) />

<cfloop index=“i” list=“#StructKeyList(fs)#”>
<cfquery name=“colType” datasource=“#arguments.datasource#”>
select name,xtype from syscolumns where name=’#i#’ and id=
(select id from sysobjects where name=’#arguments.table#’)
</cfquery>
<cfif colType.recordCount eq 1>
<cfquery name=“update” datasource=“#arguments.datasource#” result=“x”>
update #arguments.table# set #i#=
<cfif ListFind(‘173,175,61,34,239,99,231,58,35,167‘, colType.xtype) >
‘#StructFind(form,i)#’
            <cfelseif ListFind(‘127,104,106,62,56,60,108,59,52,122‘, colType.xtype)>
#val(StructFind(form,i))+0#
</cfif>
Where #arguments.identifier#=’#StructFind(form,arguments.identifier)#’
</cfquery>
</cfif>
</cfloop>
</cffunction>

This function has only been tested on SQL Server 2000 and the present code can only work on SQL Server. The same concept can probably be extended to other databases for those who need to.

This is a proof of concept and it has not been secured against stuffs like, em, SQL injection and other bla bla.

Error Selecting on AD Linked Server Columns

Looks like not all columns are born equal on Active Directory linked server on SQL Server.

I have a pretty little view which initially was selecting just four columns (mail, samaccountname, company and displayname) from a linked AD on an SQL Server 2000. Trust me, there was a reason to add more columns to the view. However, my attempt to include all the columns I wanted (valid columns!) was throwing error

Server: Msg 7346, Level 16, State 2, Line 1
Could not get the data of the row from the OLE DB provider ‘ADsDSOObject’. Could not convert the data value due to reasons other than sign mismatch or overflow.

After banging my head on the desk a couple of times, I started debugging by adding a column at a time. In the end, I discovered that the following columns won’t play nice: otherTelephone, otherMobile, otherHomePhone and may be a million other columns like that.

Nospetco accounts frozen

Or at least, that is the gist I have been hearing since I got holed up in a company retreat of recent. Actually, the pace of office work has been so frenetic the last few weeks that I don’t even have time to look at myself in the mirror.

Not only are Nospetco accounts frozen by EFCC, I also heard that the cousin schemes: Sefteg, Wealthsolutions, Treasure Lines also got the deep freezer treatment. The truth is, I don’t care if they are frozen, defrosted or smashed. All I know is that deep inside me, it is all scam. It still amazes me how people could be so greedy that they become gullible.

Somewhere on the internet, someone (a Dipo Tepede’s friend) wrote some articles which can’t be better written about this get rich quick scheme. You can link to the articles from here.

Do you ever wonder . . .

Why the sun lightens our hair, but darkens our skin?

Why women can’t put on mascara with their mouth closed?

Why you ever see the headline “Psychic Wins Lottery”?

Why “abbreviated” is such a long word?

Why doctors call what they do “practice”?And…

Why is it that to stop Windows, you have to click on “Start”?

Why is lemon juice made with artificial flavor, and dishwashing liquid made with real lemons?

Why is the man who invests all your money called a broker?

Why is the time of day with the slowest traffic called rush hour?

Why isn’t there mouse-flavored cat food?

When dog food is new and improved tasting, who tests it?

Why didn’t Noah swat those two mosquitoes?

Why do they sterilize the needle for lethal injections?

You know that indestructible black box that is used on airplanes?

Why – don’t they make the whole plane out of that stuff?

Why don’t sheep shrink when it rains?

Why are they called apartments when they are all stuck together?

If con is the opposite of pro, is Congress the opposite of progress?

If flying is so safe, why do they call the airport the terminal?