<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>You Give Love a Bad (Dot) Name &#187; ColdFusion</title>
	<atom:link href="http://yougiveloveabad.name/archives/category/cf/feed/" rel="self" type="application/rss+xml" />
	<link>http://yougiveloveabad.name</link>
	<description>Not quite shot through the heart</description>
	<lastBuildDate>Mon, 06 Jun 2011 17:57:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>SQL Coalesce</title>
		<link>http://yougiveloveabad.name/archives/2010/11/04/sql-coalesce/</link>
		<comments>http://yougiveloveabad.name/archives/2010/11/04/sql-coalesce/#comments</comments>
		<pubDate>Thu, 04 Nov 2010 18:07:56 +0000</pubDate>
		<dc:creator>JC</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://yougiveloveabad.name/?p=111</guid>
		<description><![CDATA[Have you guys ever seen the Coalesce command in SQL? I'd never heard of it til today, and it looks really useful. Say you have a table of business contact information and you want to contact a user from it; but some of the businesses don't have specific contacts, just a position; and some don't [...]]]></description>
			<content:encoded><![CDATA[<p>Have you guys ever seen the Coalesce command in SQL? I'd never heard of it til today, and it looks really useful.</p>
<p>Say you have a table of business contact information and you want to contact a user from it; but some of the businesses don't have specific contacts, just a position; and some don't have either&#8230;</p>
<p>SELECT COALESCE(ContactName,ContactPosition,BusinessName) as theContact FROM foo</p>
<p>If ContactName is null, theContact will be the value of ContactPosition. If that's also null, it will be the value of BusinessName. Simple. handy. wish I'd known it 5 years ago.</p>
]]></content:encoded>
			<wfw:commentRss>http://yougiveloveabad.name/archives/2010/11/04/sql-coalesce/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Data truncated at ~32k&#8230; how to get CLOBbered</title>
		<link>http://yougiveloveabad.name/archives/2010/09/16/data-truncated-at-32k-how-to-get-clobbered/</link>
		<comments>http://yougiveloveabad.name/archives/2010/09/16/data-truncated-at-32k-how-to-get-clobbered/#comments</comments>
		<pubDate>Thu, 16 Sep 2010 14:13:58 +0000</pubDate>
		<dc:creator>JC</dc:creator>
				<category><![CDATA[ColdFusion]]></category>

		<guid isPermaLink="false">http://yougiveloveabad.name/?p=108</guid>
		<description><![CDATA[It was the strangest thing. A query using Coldfusion to a SQL 2005 server, extracting among other things, a large chunk of XML which needed to be parsed and transformed with XSL. It worked fine most of the time&#8230; but occasionally there would be very large XML strings, and they would get cut off at [...]]]></description>
			<content:encoded><![CDATA[<p>It was the strangest thing. A query using Coldfusion to a SQL 2005 server, extracting among other things, a large chunk of XML which needed to be parsed and transformed with XSL.</p>
<p>It worked fine most of the time&#8230; but occasionally there would be very large XML strings, and they would get cut off at 32k in length.</p>
<p>So, of course, I assume the database column is only that large and the data is being truncated on entry to it.</p>
<p>The DBA mentions that it's an n-something data type and I immediately assume that's the problem&#8230; darn 16 byte alphabets&#8230;</p>
<p>I ask him to convert it to VarChar(MAX).</p>
<p>The problem? Goes away. No more truncation.</p>
<p>I think nothing more of it&#8230; including not noticing that even the fields that were previously truncated now work. (probably because I was only parsing one day's worth of data at a time)</p>
<p>Flash forward a few months&#8230; we bring it into production. Bam. Same problem, only much worse because there's more data.</p>
<p>And now, because it's in production and the database is from a vendor product, changing the db field is a huge deal.</p>
<p>A week or so goes by with it truncating as we talk to the vendor.</p>
<p>And then I think to myself&#8230; what the hell column type has a 32k limit? it's 8k or frigging huge, with nothing in between. This is what I get for starting my database experience with MySQL&#8230; TEXT data type there is 65,535 characters; halve that for it being in unicode, and it's about 32k. But we're not working with MySQL here&#8230;.</p>
<p>So I go hunting. Is it a limit in a stored procedure on insert? I can't tell.. no acces to the procedures. Or even the database, really.</p>
<p>I finally whip out my <a href="/archives/2008/06/27/cfdbinfo-what-can-you-see/">CF_DBINFO</a> tag and take a look at the table structure. It's NText and lists the size as some huge number, way more than 32k. Weird.</p>
<p>I run a query to get the max length of the field and discover that len() is invalid for text fields. I research more and discover that you use datalength() for those. Again&#8230; way more than 32k. So where's the problem???</p>
<p>It's not my code&#8230; that's a straightforward select. And why did it start working when we changed data types?</p>
<p>I started wondering if maybe our driver didn't fully support SQL 2005. We had to switch from the default SQL driver that coldfusion uses because the default one doesn't support SSL and we require encrypted connections. Would that bite us in the arse?</p>
<p>Yes and no. By default, the driver handles data over a given amount as a LOB&#8230; it sends it in chunks. But we didn't have the DSN set to look for LOBs, so it would get the first 32k chunk and assume that was all.</p>
<p>One checkbox (CLOB &#8211; Enable Long Text Retrieval) in CF Administrator later&#8230; and everything's magically working.</p>
<p>Oh, and to some extent, I was right&#8230; it appears the driver doesn't fully understand SQL 2005. It only uses CLOBs on TEXT and NTEXT fields&#8230; VarChar(MAX) is exempted, despite being the same thing effectively. That's why the dev system started working when we switched the data type.</p>
<p>So&#8230; lesson of the day&#8230; Don't get CLOBbered. Check the box.</p>
]]></content:encoded>
			<wfw:commentRss>http://yougiveloveabad.name/archives/2010/09/16/data-truncated-at-32k-how-to-get-clobbered/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Proper Ordered List Hierarchy</title>
		<link>http://yougiveloveabad.name/archives/2009/12/17/proper-ordered-list-hierarchy/</link>
		<comments>http://yougiveloveabad.name/archives/2009/12/17/proper-ordered-list-hierarchy/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 21:06:44 +0000</pubDate>
		<dc:creator>JC</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Random]]></category>

		<guid isPermaLink="false">http://yougiveloveabad.name/archives/2009/12/17/proper-ordered-list-hierarchy/</guid>
		<description><![CDATA[In case I ever need it again, this is the CSS to force a "proper" ordered list hierarchy all the way to 6 layers deep. (pro tip &#8211; if it's 6 layers deep, you're doing something wrong) &#60;style type="text/css"&#62;   OL { list-style-type:upper-roman }   OL OL { list-style-type:upper-alpha }   OL OL OL { [...]]]></description>
			<content:encoded><![CDATA[<p>In case I ever need it again, this is the CSS to force a "proper" ordered list hierarchy all the way to 6 layers deep. (pro tip &#8211; if it's 6 layers deep, you're doing something wrong)</p>
<p>&lt;style type="text/css"&gt;<br />
  OL { list-style-type:upper-roman }<br />
  OL OL { list-style-type:upper-alpha }<br />
  OL OL OL { list-style-type:decimal }<br />
  OL OL OL OL { list-style-type:lower-roman }<br />
  OL OL OL OL OL { list-style-type:lower-alpha }<br />
  OL OL OL OL OL OL { list-style-type:lower-greek }<br />
&lt;/style&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://yougiveloveabad.name/archives/2009/12/17/proper-ordered-list-hierarchy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coldfusion: DNS Reverse Lookup</title>
		<link>http://yougiveloveabad.name/archives/2009/02/19/coldfusion-dns-reverse-lookup/</link>
		<comments>http://yougiveloveabad.name/archives/2009/02/19/coldfusion-dns-reverse-lookup/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 17:31:55 +0000</pubDate>
		<dc:creator>JC</dc:creator>
				<category><![CDATA[ColdFusion]]></category>

		<guid isPermaLink="false">http://yougiveloveabad.name/?p=61</guid>
		<description><![CDATA[I have no idea why this information was so difficult to find, but I'm posting it here in case I ever need it again. To do a reverse lookup in coldfusion: &#60;cfscript&#62; rawIP = createObject("java", "java.net.InetAddress").getByName('#ipaddress#').getAddress(); hostname = createObject("java", "java.net.InetAddress").getByAddress('#rawIP#').getHostName(); chostname = createObject("java", "java.net.InetAddress").getByAddress('#rawIP#').getCanonicalHostName(); &#60;/cfscript&#62; Note &#8212; this is slow. If you're doing them in [...]]]></description>
			<content:encoded><![CDATA[<p>I have no idea why this information was so difficult to find, but I'm posting it here in case I ever need it again.</p>
<p>To do a reverse lookup in coldfusion:</p>
<p>&lt;cfscript&gt;<br />
rawIP = createObject("java", "java.net.InetAddress").getByName('#ipaddress#').getAddress();<br />
hostname = createObject("java", "java.net.InetAddress").getByAddress('#rawIP#').getHostName();<br />
chostname = createObject("java", "java.net.InetAddress").getByAddress('#rawIP#').getCanonicalHostName();<br />
&lt;/cfscript&gt;</p>
<p>Note &#8212; this is <strong>slow</strong>. If you're doing them in bulk, you may need to go in small batches or set a higher timeout.</p>
<p>Also, this was perhaps useful: http://api.hostip.info/get_html.php?ip=#ipaddress#&amp;position=true &#8212; returns the country, city, state, and geotag info for an IP address, where available.</p>
]]></content:encoded>
			<wfw:commentRss>http://yougiveloveabad.name/archives/2009/02/19/coldfusion-dns-reverse-lookup/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Distance in CF &#8212; Mostly useless, but fun</title>
		<link>http://yougiveloveabad.name/archives/2009/02/19/distance-in-cf-mostly-useless-but-fun/</link>
		<comments>http://yougiveloveabad.name/archives/2009/02/19/distance-in-cf-mostly-useless-but-fun/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 17:31:30 +0000</pubDate>
		<dc:creator>JC</dc:creator>
				<category><![CDATA[ColdFusion]]></category>

		<guid isPermaLink="false">http://yougiveloveabad.name/?p=64</guid>
		<description><![CDATA[Assumption: table named locations that has a location name and the location's latitude &#38; longitude as a single field, with lat and lon comma separated, both in signed degrees format. This is an intentional cartesian join&#8230; so if you have a lot of locations, use with care. &#60;cfquery datasource="MyDSN" name="getDist"&#62; SELECT DISTINCT        a.latlon AS [...]]]></description>
			<content:encoded><![CDATA[<p>Assumption: table named locations that has a location name and the location's latitude &amp; longitude as a single field, with lat and lon comma separated, both in signed degrees format.</p>
<p>This is an intentional cartesian join&#8230; so if you have a lot of locations, use with care.</p>
<p>&lt;cfquery datasource="MyDSN" name="getDist"&gt;<br />
SELECT DISTINCT   <br />
    a.latlon AS thestart,<br />
    a.locName AS startname,<br />
    b.latlon AS theend,<br />
    b.locName AS endname<br />
FROM     locations a<br />
CROSS JOIN    locations b<br />
WHERE     a.locName&lt;&gt; b.locName<br />
ORDER BY     a.locName, b.locName<br />
&lt;/cfquery&gt;</p>
<p>&lt;cfoutput query="getDist" group="startname"&gt;<br />
&lt;h4&gt;#getDist.startname# to&#8230;&lt;/h4&gt;<br />
&lt;ul&gt;&lt;cfoutput&gt;<br />
&lt;li&gt;#getDist.endname# &#8212; #3963.0*acos(sin(listfirst(thestart)/57.295779513082323)*sin(listfirst(theend) / 57.295779513082323)+ cos(listfirst(thestart) / 57.295779513082323)*cos(listfirst(theend) / 57.295779513082323)*cos((listlast(theend) &#8211; listlast(thestart)) / 57.295779513082323))# Miles<br />
&lt;/li&gt;<br />
&lt;/cfoutput&gt;<br />
&lt;/ul&gt;<br />
&lt;/cfoutput&gt;</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>This is based on a snippet of SQL code someone forwarded to me which was signed "RBarryYoung, 31-Jan-2009" &#8212; so credit to RBarryYoung for it. <img src='http://yougiveloveabad.name/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://yougiveloveabad.name/archives/2009/02/19/distance-in-cf-mostly-useless-but-fun/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CFDBinfo &#8212; What can you see?</title>
		<link>http://yougiveloveabad.name/archives/2008/06/27/cfdbinfo-what-can-you-see/</link>
		<comments>http://yougiveloveabad.name/archives/2008/06/27/cfdbinfo-what-can-you-see/#comments</comments>
		<pubDate>Fri, 27 Jun 2008 19:16:36 +0000</pubDate>
		<dc:creator>JC</dc:creator>
				<category><![CDATA[ColdFusion]]></category>

		<guid isPermaLink="false">http://yougiveloveabad.name/?p=12</guid>
		<description><![CDATA[A month or so ago I had to throw together a script to help with some forensics, it strikes me that it might come in handy for other people, so I'm going to post it here. Just edit the first bit and provide it with your datasource name, and run it. You might need to [...]]]></description>
			<content:encoded><![CDATA[<p>A month or so ago I had to throw together a script to help with some forensics, it strikes me that it might come in handy for other people, so I'm going to <a title="Datasource Access Information" href="http://yougiveloveabad.name/wp-content/uploads/dbinfo.zip">post it here</a>. Just edit the first bit and provide it with your datasource name, and run it. You might need to adjust the timeout settings in ColdFusion Administrator &#8212; if your database user has access to a lot of stuff, it could take a very long time to run. </p>
<p>It uses one of the new CF8 tags, CFDBinfo, that hasn't gotten much press. It also highlights something that I found a bit disturbing, though I guess it makes sense&#8230; even though you assign a database name to your DSN in CF, CF isn't locked down to that DSN, it can interact with any database on the server that the user you put in there can access.</p>
<p>This snippet of code is also pretty useful &#8212; it shows all your DSN settings at once:</p>
<p><code>&lt;cfset sf = CreateObject("java", "coldfusion.server.ServiceFactory")&gt;<br />
&lt;cfdump var="#sf.DataSourceService.getDatasources()#" expand="true"&gt;<br />
</code></p>
<p>With either of these, please exercise caution.. don't put them somewhere anyone but you can execute them, and don't leave them up there any longer than it takes for you to extract the data you need. <img src='http://yougiveloveabad.name/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://yougiveloveabad.name/archives/2008/06/27/cfdbinfo-what-can-you-see/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Assorted Coldfusion stuff I need occasionally and always forget.</title>
		<link>http://yougiveloveabad.name/archives/2008/06/04/assorted-coldfusion-stuff-i-need-occasionally-and-always-forget/</link>
		<comments>http://yougiveloveabad.name/archives/2008/06/04/assorted-coldfusion-stuff-i-need-occasionally-and-always-forget/#comments</comments>
		<pubDate>Wed, 04 Jun 2008 22:48:51 +0000</pubDate>
		<dc:creator>JC</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Web Stats]]></category>

		<guid isPermaLink="false">http://yougiveloveabad.name/?p=9</guid>
		<description><![CDATA[I keep this in a file on my desktop.. may as well put it here, too&#8230; maybe it'll help someone someday. CRLF: cfset crlf = #chr(13)#&#38;#chr(10)# Variable Variables: cfset varvar = "MyVarName" cfset "#varvar#" = "whatever" #evaluate(varvar)# outputs "whatever", #varvar# outputs "MyVarName" Existence/Type Test: StructKeyExists() IsDefined() (isDefined fails on complex vars with[], use dot notation) [...]]]></description>
			<content:encoded><![CDATA[<p>I keep this in a file on my desktop.. may as well put it here, too&#8230; maybe it'll help someone someday.</p>
<p><strong>CRLF:</strong><br />
cfset crlf = #chr(13)#&amp;#chr(10)#</p>
<p><strong>Variable Variables:</strong><br />
cfset varvar = "MyVarName"<br />
cfset "#varvar#" = "whatever"<br />
#evaluate(varvar)# outputs "whatever", #varvar# outputs "MyVarName"</p>
<p><strong>Existence/Type Test:</strong><br />
StructKeyExists() IsDefined() (isDefined fails on complex vars with[], use dot notation) IsArray() IsStruct() IsQuery() IsSimpleValue() IsNumeric() IsDate() IsBinary() IsBinary()</p>
<p><strong>CFHTTP Connection Failure</strong><br />
Gzip bug &#8212; add this:<br />
cfhttpparam type="Header" name="Accept-Encoding" value="deflate;q=0"<br />
cfhttpparam type="Header" name="TE" value="deflate;q=0"<br />
Also check for redirect="yes|no" &#8212; sometimes redirect needs to be set to no</p>
<p><strong>Query Variables:</strong><br />
query_name.currentRow, query_name.columnList, query_name.RecordCount, result_name.sql</p>
<p><strong>Query of Queries:</strong><br />
cfquery dbtype="query" name="foo" &#8212; select * from query_name</p>
<p><strong>CFDirectory Performance:</strong><br />
listinfo="name" significantly improves performance, if you don't need other columns</p>
<p><strong>CFQueryParam:</strong><br />
Null="#YesNoFormat(NOT LEN(MyVar))#" will make the value NULL instead of empty<br />
List="yes" will internally CFParam all list values so you can do WHERE ID IN (cfqueryparam&#8230; list="yes") and get a valid list format. Add separator = '|' instead of delimiter='|' &#8212; for some reason this tag is different than all the other ones.<br />
CF_SQL_TIMESTAMP &#8212; datetime, smalldatetime (use CreateODBCDateTime() for this)<br />
CF_SQL_CHAR &#8212; char, nchar, unique identifier<br />
CF_SQL_VARCHAR &#8212; varchar, nvarchar, sysname<br />
CF_SQL_LONGVARCHAR &#8212; text, ntext<br />
CF_SQL_NUMERIC &#8212; numeric (scale='2' for 2 decimal places)<br />
CF_SQL_INTEGER &#8212; int<br />
CF_SQL_SMALLINT &#8212; smallint<br />
CF_SQL_TINYINT &#8212; tinyint<br />
CF_SQL_BIT &#8212; bit<br />
CF_SQL_FLOAT &#8212; float<br />
CF_SQL_DECIMAL &#8212; decimal, money, smallmoney (scale='2' for 2 decimal places)<br />
CF_SQL_BINARY &#8212; binary, timestamp</p>
<p><strong>Merge Log Files (Not CF, but useful!)</strong><br />
copy *.log merged.log</p>
<p><strong>CF Regex:</strong><br />
rereplace(foo, "[[:space:]]+", " ", "all") — turns all whitespace into single space<br />
rereplace(foo, ".*?", "", "all") — strips all HTML tags (probably fails if they span multiple lines)</p>
<p>(updated July 16)</p>
]]></content:encoded>
			<wfw:commentRss>http://yougiveloveabad.name/archives/2008/06/04/assorted-coldfusion-stuff-i-need-occasionally-and-always-forget/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>CF8 change gotcha</title>
		<link>http://yougiveloveabad.name/archives/2008/03/31/cf8-change-gotcha/</link>
		<comments>http://yougiveloveabad.name/archives/2008/03/31/cf8-change-gotcha/#comments</comments>
		<pubDate>Mon, 31 Mar 2008 16:07:07 +0000</pubDate>
		<dc:creator>JC</dc:creator>
				<category><![CDATA[ColdFusion]]></category>

		<guid isPermaLink="false">http://yougiveloveabad.name/?p=10</guid>
		<description><![CDATA[Here's a little thing I ran across today that might be worth noting &#8212; in CF8 there were apparently some changes in how a couple of the system commands work. I had an old snippet of code set up as a custom tag, it dumped out the last modified date of the file at the [...]]]></description>
			<content:encoded><![CDATA[<p>Here's a little thing I ran across today that might be worth noting &#8212; in CF8 there were apparently some changes in how a couple of the system commands work. I had an old snippet of code set up as a custom tag, it dumped out the last modified date of the file at the bottom of any page it was included in. Prior to CF8, CGI.CF_TEMPLATE_PATH and also getCurrentTemplatePath() would refer to the template which was calling a custom tag; post CF8, they refer to the custom tag. Which they probably should have done from the beginning&#8230; but it broke my code.</p>
<p>Oh, and the revised code snippet:</p>
<p>&lt;cfset fileObj =createObject("java","java.io.File").init(getBaseTemplatePath())&gt;<br />
&lt;cfset fileDate =createObject("java","java.util.Date").init(fileObj.lastModified())&gt;<br />
&lt;cfoutput&gt;Last Modified: #dateformat(fileDate,"m/d/yyyy")# #timeformat(fileDate)#&lt;/cfoutput&gt; (Much more efficient than the lovely looping through cfdirectory cruft that was leftover from CF 4.5)</p>
]]></content:encoded>
			<wfw:commentRss>http://yougiveloveabad.name/archives/2008/03/31/cf8-change-gotcha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

