Friday, 30 July 2010

when cfparam wont cut it

Random a couple of weeks ago , that in all honesty I should have known


I use cfparam alot, its easy to use and does the Job, but as I have gotten older default values for variables have gotten a little bit more complex than yes/no/now().


So....... at one point I started to do stuff like this (not exactly like this or I would need a better job.)


<!--- set a var--->

<cfset myname =" 'Ted'">


<!--- set a default --->

<cfparam name="myName" default="#_SayMyName()#">


<!--- putput the var --->

<cfoutput>#myName#</cfoutput>


<!--- Function to set default--->

<cffunction name="_SayMyName" returntype="string" output="yes">

<cfreturn>

</cffunction>


Which looks fine and dandy. but then on the execution plan I started to notice that the Function (that held a database lookup in the RL example) the function always executed.


The reason for this, is simple #_SayMyName()# runs the function, there I have said it.


But the golden child that was cfparam now isn't the all problem solving tag as I had previously thought.


So to cut a long story short... the correct answer is thus.


<cfif>

<cfset myname =" _SayMyName()">

</cfif>


*Head bangs off desk*

Functions within cfquery/cfstoredproc loss of datasource

When is the data-source of your query not the data-source of the query ?


So I have a query block that call a table, and within the block I have a function that gets a value I need in the query.


<cfquery datasource="DB1">

Select *

from myTableInDB1

Where id = <cfqueryparam value="#val(_getID())#" cfsqltype="cf_sql_numeric">

</cfqueryparam>


<cffunction name="_getID" returntype="numeric" output="yes">

<cfset q=" ''">

<cfquery datasource="DB2" name="q">

Select top 1 id from AnotherTable

</cfquery>

<cfreturn>

</cfreturn>


So I want everything from myTableInDB1 that is in the DB1 data-source. and I want to pull back everything that has an ID equal to the response from a function.


Sadly that function contains another query which gets an ID from AnotherTable from Another datasource (DB2).


So what happens is I get an error that says myTableInDB1 does not exit in data source, which leads to lots of toy being chucked all over the place. and a moment remenisant of installing a printer in windows 98 "WHAT DO YOU MEAN IT RIGHT @#+-ing THERE!!!"


But what realy happens its the datasource in _getID() is used for both queries.


This issue was compounded that the _getID() set an application variable the first time it was executed, so on subsequent calls to the page the First query would run fine, but err every time I reset CF.


To solve this:


<cfset thisid=" val(_getID())">

<cfquery datasource="DB1">

Select *

from myTableInDB1

Where id = <cfqueryparam value="#thisID #" cfsqltype="cf_sql_numeric">

</cfqueryparam>


Another Head vs Desk moment.


NOTE: This works/doesn't works for both cfquery and cfstoredproc</cfquery></cfset></cfset></cffunction></cfquery>

Thursday, 22 July 2010

Pricing gone crazy

Re-visiting an old post (Digital Distribution WTF !!!) , I have just come across another digital vs. physical pricing inequality. After listening to the extended cut of Prodigy’s newest album Invaders Must Die on Spotify, I thought I’d quite like a copy. So off I trundle to Amazon to find out how much it is, much to my joy, there’s the special edition version, with 2CD’s and a DVD with booklet. All this physical stuff for the grand price of £4.99. Then I scroll down another couple of lines and see the digital download of said album, which contains the contents of only the 2 CD’s (a grand total of 27 tracks) for the ridiculous price of £9.98. So for double the price of the actual physical media, I could purchase 27 digital tracks. O, and I get free delivery, so it really is double the price!. Seems like a no-brainer to me! Or alternatively, I could just get the CD and make a perfectly legal digital backup of it :¬) I think I know which option I’ll be going with. Thanks Amazon for trying to rip us off!


Ad's

Sunday, 11 July 2010

GMail gets HTML in its signatures

It seems a truly geeky thing to get all excited about, but browsing through the Official GMail Blog this morning it was quite nice to read that Google have finally got round to upgrading their signature system in their brilliant e-mail service.

Instead of having a simple, plain and boring text-style signature to your e-mails, if you're a GMail user (and one that, like me, refuses to use an e-mail client such as Outlook) you can now make your signature much more fancy, as witnessed in this image on the GMail blog website:

If you want to find out more about setting up HTML in your GMail signature, simply visit the link below. 

Meanwhile, I've got to start thinking about just what colour I want my name to appear in...

http://gmailblog.blogspot.com/2010/07/rich-text-signatures.html