[thelist] Bustin' back in da scene

Rory.Plaire at wahchang.com Rory.Plaire at wahchang.com
Thu Nov 8 21:50:16 CST 2001


Well,

After being starved from the severing of the T-1 to the workplace by our
ISP, who, like the smelly schmelt of Lake Michigan bobbing on the sides of
the piers of Milwuakee's East Side in the cold and rainy Wisconsin spring,
appeared bankrupt on the surface of the rising tides from melting enthusiasm
in our world of technology, I finally can email and browse again.

Feeling removed from the community and regarding the backlog of 1000 emails
to be read as inevitably lost in the swift and don't-look-back current of
internet life, may I humbly contribute tips to the betterment of evolt!
(But, whoa! that tip jar is now looking a little empty... but please enjoy!
8)

<rory disposition="good to be back!" alt="8)"/>



<tip type="ColdFusion Uber-Dynamic Querying" author="rory">
Have a page which needs to determine which query to run based on a choice
from the user, but has the same output needs regardless of the query run?

Try this:

<cfparam name="sUserChoice" default="">

<cfif isDefined("Form.selUserChoice")>
	<cfset sUserChoice=Form.selUserChoice>
</cfif>

<cfswitch expression="#sUserChoice#">
	<cfcase value="choice1">
		<cfquery datasource="myData" name="qryMyStuff">
			SELECT	stuff1_id
			,		stuff1_desc
			FROM		tblStuff1
		</cfquery>
		<cfset id="stuff1_id">
		<cfset desc="stuff1_desc">
	</cfcase>
	
	<cfcase value="choice2">
		<cfquery datasource="myData" name="qryMyStuff">
			SELECT	stuff2_id
			,		stuff2_desc
			FROM		tblStuff2
		</cfquery>
		<cfset id="stuff2_id">
		<cfset desc="stuff2_desc">
	</cfcase>	
	
	<cfcase value="choice3">
		<cfquery datasource="myData" name="qryMyStuff">
			SELECT	stuff3_id
			,		stuff3_desc
			FROM		tblStuff3
		</cfquery>
		<cfset id="stuff3_id">
		<cfset desc="stuff3_desc">
	</cfcase>
</cfswitch>

...

<cfoutput query="qryMyStuff">
	#Evaluate(id)#: #Evaluate(desc)#
</cfoutput>

</tip>



<tip type="ColdFusion SQL statement techniques." author="rory">
Conjure up your SQL in chunks, putting dashes of table columns here,
sprinkling modicums of WHERE conditions there? 

In CF, the server niftily and transparently doubles all of your single
quotes when executing a CFQUERY.

But, when you pass it a constructed SQL statement you have stuffed in a
variable, like this: 

<cfquery datasource="myData" name="myQuery">
	#theSQL#
</cfquery>

all of the single quotes you have put around the strings in your WHERE
clause are now double quoted. Let's guess... your DBMS gags.

Enter: PreserveSingleQuotes().

It prevents CF from auto-doubling your single-quoting.

But, now you have to do it.
</tip>



<tip type="ColdFusion output techniques" author="rory">
I had a co-worker who wondered why a simple page was taking minutes to
download /from the intranet/.

After looking at the source, it seemed that the page was over a megabyte in
size. Whoa. 

Most of it was whitespace. Whoooa. Not good.

CF turns out to output everything that is in a template (page).
Additionally, sometimes, CF'ers have templates with no HTML content in them;
only logic to perform some intellegence critical to the application,
possibly ending in a redirect or a prompt to close the window. CF outputs
the whitespace in these intermediate pages, too. This is all more painful
when there are CFLOOPs involved, as you can imagine.

This following little tag does a couple of tricks, one of which is to stop
CF from outputing all but that which is in the CFOUTPUT tags.

<cfsetting enablecfoutputonly="Yes">

But remember to set this at the bottom of your page:

<cfsetting enablecfoutputonly="No">

or maybe that next page, where you have HTML content not in CFOUTPUT tags...
will mysteriously never be sent to the browser!

I used this technique when I used this tip:
http://lists.evolt.org/archive/Week-of-Mon-20001023/153512.html
</tip>




More information about the thelist mailing list