HJCotton.net

October 6, 2010

Corrupted Queries in Coldfusion 7

by @ 9:56 pm. Filed under Coldfusion.

Yeah, yeah, Coldfusion 7 is ancient, but it’s still out there!

For a while now I’ve had an application running on Coldfusion 7 that randomly throws exceptions because of some really poorly formed SQL in seemingly random queries. The thing is, I can’t explain the malformed SQL from looking at the queries – they are fine, and the horribly mangled SQL I see in the exception logs could not possibly be generated by any conditional logic in the query. Let me provide an example:

<cffunction name="getUsers" access="public" output="false" returntype="query">
  <cfargument name="username" type="string" required="false" default="">
 
  <cfset var Local = StructNew()>
 
  <cfquery name="Local.qryUsers" datasource="dsn">
    SELECT USR.Username
           ,USR.Email
           ,USR.Name
    FROM tblUsers USR
 
    WHERE 1 = 1
    <cfif Len(Arguments.username)>
      AND USR.Username = <cfqueryparam value="#Arguments.username#" cfsqltype="cf_sql_varchar">
    </cfif>
 
    ORDER BY USR.Username ASC
  </cfquery>
 
  <cfreturn Local.qryUsers>
</cffunction>

The above function would run fine 99% of the time until the SQL generated would cause an exception. The SQL from the previous cfquery that caused the exception would resemble something like this:

  ELECT USR.Username
               ,USR.Email
               ,USR.Name
  FROM tblUsers USR
  1 = 1
  ASC

Needless to say, completely and utterly mangled – and no way to account for it! Where has half the bloody query run off to?! It is likely only a matter of time until a completely malformed query executes and results in massive data loss and corruption. So what is the solution to this craziness?

My hypothesis is that SQL statements sometimes band together and run off at the thought of being transported to the database server for execution. This may very well be true! Adobe could not be reached for questioning, but they have released a hotfix that erects a 12 foot high fence around the edges of cfquery in order to prevent any bits from falling out or otherwise escaping at inopportune times. Handy!

The hotfix is available here.
The blog post here discusses the issue in far more depth.

August 15, 2010

Google Power Meter

by @ 6:04 pm. Filed under Tweet-A-Watt.

I had heard that the Tweet-A-Watt could now be hooked up to Google Power Meter, so I decided to give it a go. It’s actually pretty easy – I just followed the instructions here and had it up and running in a few minutes.

I have actually been trying to track down the cause of a recent increase in my electricity usage, and it’s more than likely to be the fault of the dehumidifier in my basement (I have a strong dislike for these things already, necessary though they are). This little guy actually draws a LOT of electricity, but I already knew that. Still, it will be really useful to see the power usage trends over time and find out what it really costs me to run. Given an average cost per kilowatt hour,  Power Meter will give you some useful figures back about the cost to run a device. Based on my latest bill from PP&L (is it worth switching?), my average cost has been 13 cents / kW h since the rate caps expired in PA.

google_power_meter

July 29, 2010

No need to read the privacy policy

by @ 9:43 pm. Filed under Humorous, Technology.

This is the confirmation dialog that appears when you install the Speed Tracer extension in Google Chrome.

Google Speed Tracer

“This extension needs access to: All data on your computer and the websites you visit.”

If only spyware installations were so up front about their intentions!

July 26, 2010

Attachment filenames containing special characters and cfmailparam

by @ 7:30 pm. Filed under Coldfusion.

When you use cfmailparam to attach a file to an email being sent within cfmail, you may get an error that the file cannot be found (even when it actually exists). I noticed this particular condition when the attachment filename contained a plus sign ‘+’, but it probably occurs for other special characters as well. It doesn’t appear that cfmailparam can handle these well, and they get replaced with spaces. Based on the blog posts I’ve read, there doesn’t seem to be a quick workaround.

<cfmail from="#fromEmail#" to="#toEmail#" subject="Email w/ Attachment" type="html">
    I attached this file for your review. I <strong>swear</strong>, it's not a virus!
    <cfmailparam file="#ExpandPath('FileC+D.doc')">
</cfmail>

The solution I ended up using? Use ReReplace to replace invalid characters. This means that the attachment’s filename will have to change, but it is the only workaround I could find.

In ColdFusion 7, you’ll have to do this when the file is uploaded or just prior to it being attached. In 8 and beyond, you may be able to skip that intermediary step of using cffile to copy and save the file in order to get the filename you want. Instead, you may be able to use the content attribute of cfmailparam to feed in the contents of the file and give the content the filename to use, as per Ben Nadel’s excellent post here.

July 25, 2010

Socialist!

by @ 9:46 pm. Filed under Humorous, Political.

Just one of literally dozens of great songs by Roy Zimmerman.

April 1, 2010

Attending NCDevCon?

by @ 7:41 pm. Filed under Uncategorized.

NCDevCon follows on the heels of the free CFinNC held in Raligh, NC last October. I attended CFinNC and was impressed with the overall quality of the conference. Granted, many of the presentations seemed to be re-badged presentations from CFUnited, but in the end, it matters not: you can’t beat the price for these presentations! There are plenty of inexpensive hotels within a few miles of the campus, so even though I’m an out-of-towner, this conference isn’t something that breaks the bank! See you there!

March 18, 2010

Ruby Arduino Development

by @ 8:32 pm. Filed under Arduino, Ruby.

My CPRuby presentation from Thursday, March 18 2010: “Physical Computing with Ruby and Arduino”

RAD-CPRuby03182010.zip

December 12, 2009

CF9 Ternary Operator

by @ 11:22 pm. Filed under Coldfusion.

Coldfusion 9 finally has a ternary operator. It’s certainly a lot prettier to use than an IIF(), and you won’t have to deal with those odd occasions where you need to use DE() to get things to work. Here’s an example of how it works in CF9 and the equivalent using an IIF() and a standard “if” (keep in mind that the loops are to demonstrate performance only – they are otherwise quite out-of-place):

<cfparam name="URL.name">
<cfparam name="URL.isLight">
 
<cfset startTernary = GetTickCount()>
<cfloop from="1" to="10000" index="i">
	<cfset beerName = !URL.isLight? URL.name & " is a good beer" : "No light beers in this list!">
</cfloop>
<cfset endTernary = GetTickCount()>
 
<cfset startIIF = GetTickCount()>
<cfloop from="1" to="10000" index="i">
	<cfset beerName = IIF(!URL.isLight, "'#URL.name# is a good beer'", "'No light beers in this list!'")>
</cfloop>
<cfset endIIF = GetTickCount()>
 
<cfset startIf = GetTickCount()>
<cfloop from="1" to="10000" index="i">
	<cfif URL.isLight>
		<cfset beerName = "No light beers in this list!">
	<cfelse>
		<cfset beerName = "#URL.name# is a good beer">
	</cfif>
</cfloop>
<cfset endIf = GetTickCount()>
 
<cfoutput>
	Ternary: #endTernary - startTernary#ms<br />
	IIF: #endIIF - startIIF#ms<br />
	If: #endIf - startIf#ms<br />
</cfoutput>

Even over 10,000 iterations, the ternary option is head-to-head with a standard if statement, and only slightly faster than an IIF:
Ternary: 62ms
IIF: 77ms
If: 62ms

I’ve always heard that IIFs were slow, but I’ve always found them so handy that I overlooked whatever the performance consequences might be. While noticeable in these tests, it’s not something that would affect most projects at all. These results are also backed up in this post by Ben Nadel.

I won’t be using CF9 in a production setting in the immediate future, so until then it’ll still be IIFs for me. Still, some of these new language improvements and features are definitely worth looking into (even if they should have been added long ago!).

WITF Car Donation

by @ 7:01 pm. Filed under Humorous.

Dear Hadyn,

Thanks so much for recently donating your car to public broadcasting through the Car Talk vehicle donation program. Your thoughtfulness resulted in a net gift of $35.00 to WITF.

Excellent! Almost enough for a case of good beer… but not anywhere near what the sticker suggests:

HJ Chevrolet Free2.jpg

November 4, 2009

Abandoned PA Turnpike (PikeToBike Trail)

by @ 8:25 pm. Filed under Adventures.

Last Saturday, Alison and I headed to see the “abandoned” portion of the PA turnpike, which is now an 8.5 mile trail. There’s all sorts of video and photos online about it, and it surprised me that I hadn’t even known about it prior to stumbling upon PikeToBike.org while looking up some Appalachian Trail info. Perhaps the biggest reason it’s worth going to see is that this section of the turnpike has been abandoned since 1968 and contains both the longest (and shortest) tunnels on the PA turnpike. The whole stretch has kind of a “Centralia, Highway 61″ feel to it because of the cracked roadway, illegal dumping and ample graffitti, but it is nonetheless quite a cool place to visit.

img_4131.jpg

PikeToBike has a lot of information about the trail. It’s not officially open, but is apparently well traveled. We didn’t encounter anyone the entire time we were there. The Sidling Hill tunnel is supposedly 1.3 miles long (I didn’t measure) and… far darker than I expected. The damp tunnels eat light! If darkness weren’t pressing in from outside, too, I’d have liked to explore the ends of the tunnels a bit more. There are some huge fans sitting on top of the entrance of the Sidling Hill tunnel that I’ll have to explore next time. There’s also an air space in the upper part of the tunnel that can be accessed, which would be pretty cool to get into had I been armed with a more powerful flashlight. It was kind of an eery feeling just walking/riding through this tunnel with such a limited amount of light. For some reason I expected to be crashing into abandoned vehicles, old mattresses and the homeless, but both tunnels are barren throughout. However, the effects of vandalism and time are apparant in the entire length of the tunnels and particularly on the tunnel entrances.

PikeToBike lists some of the projects that would be worthwhile on the property; including paving one of the four lanes (in order to make it accessible via road bike) and adding some minimal lighting the the tunnels. This is on top of tunnel maintenance and repair, which is also pretty badly needed. The roadway is pretty rough but is fine for mountain biking. If you’re going through the tunnels, bring a real flashlight!

Go check it out for yourself!

HJCotton.net

pages:

categories:

search:

archives:

May 2012
S M T W T F S
« Oct    
 12345
6789101112
13141516171819
20212223242526
2728293031  

So it goes.
— Kurt Vonnegut

general links:

Dscn1175.jpg

Dscn1175.jpg

05-29-2010

05-29-2010

other:

Page 1 of 6First21Last

20 queries. 0.874 seconds