Assorted Coldfusion stuff I need occasionally and always forget.
I keep this in a file on my desktop.. may as well put it here, too… maybe it'll help someone someday.
CRLF:
cfset crlf = #chr(13)#&#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) IsArray() IsStruct() IsQuery() IsSimpleValue() IsNumeric() IsDate() IsBinary() IsBinary()
CFHTTP Connection Failure
Gzip bug — add this:
cfhttpparam type="Header" name="Accept-Encoding" value="deflate;q=0"
cfhttpparam type="Header" name="TE" value="deflate;q=0"
Also check for redirect="yes|no" — sometimes redirect needs to be set to no
Query Variables:
query_name.currentRow, query_name.columnList, query_name.RecordCount, result_name.sql
Query of Queries:
cfquery dbtype="query" name="foo" — select * from query_name
CFDirectory Performance:
listinfo="name" significantly improves performance, if you don't need other columns
CFQueryParam:
Null="#YesNoFormat(NOT LEN(MyVar))#" will make the value NULL instead of empty
List="yes" will internally CFParam all list values so you can do WHERE ID IN (cfqueryparam… list="yes") and get a valid list format. Add separator = '|' instead of delimiter='|' — for some reason this tag is different than all the other ones.
CF_SQL_TIMESTAMP — datetime, smalldatetime (use CreateODBCDateTime() for this)
CF_SQL_CHAR — char, nchar, unique identifier
CF_SQL_VARCHAR — varchar, nvarchar, sysname
CF_SQL_LONGVARCHAR — text, ntext
CF_SQL_NUMERIC — numeric (scale='2' for 2 decimal places)
CF_SQL_INTEGER — int
CF_SQL_SMALLINT — smallint
CF_SQL_TINYINT — tinyint
CF_SQL_BIT — bit
CF_SQL_FLOAT — float
CF_SQL_DECIMAL — decimal, money, smallmoney (scale='2' for 2 decimal places)
CF_SQL_BINARY — binary, timestamp
Merge Log Files (Not CF, but useful!)
copy *.log merged.log
CF Regex:
rereplace(foo, "[[:space:]]+", " ", "all") — turns all whitespace into single space
rereplace(foo, ".*?", "", "all") — strips all HTML tags (probably fails if they span multiple lines)
(updated July 16)
Filed by JC at June 4th, 2008 under ColdFusion, Web Stats
For some reason it keeps puking when I try to edit this in…
CF Regex:
rereplace(foo, "[[:space:]]+", " ", "all") — turns all whitespace into single space
rereplace(foo, ".*?", "", "all") — strips all HTML tags (probably fails if they span multiple lines)
CF Host & Instance
host = CreateObject("java", "java.net.InetAddress").getLocalHost().getHostName();
cfserv = createObject("java","jrunx.kernel.JRun").getServerName();
Comment by JC — June 27, 2008 @ 3:37 pm