<rss version="2.0"><channel><title>RSS feed for InstantSpot site orangepips</title><link>http://orangepips.instantspot.com</link><language>en-us</language><copyright>This work is Copyright &#xA9; 2008 by orangepips</copyright><generator>RSSVille ColdFusion FeedMaker, version 1.0</generator><pubDate>Thu, 28 Aug 2008 17:36:29 GMT</pubDate><item><title>CF Equivalent MD5 Hashing Functions for SQL Server 2005+ &amp; Oracle 8+</title><link>http://orangepips.instantspot.com/blog/2008/05/23/CF-Equivalent-MD5-Hashing-Functions-for-SQL-Server-2005--Oracle-8</link><description>&lt;p&gt;Both Oracle and SQL Server have built-in hashing functions. The trick is neither returns a value that is immediately comparable to a hashed value in ColdFusion (i.e. 32 character, hex based, upper case). So some additional conversion is required.&lt;/p&gt;
&lt;h1&gt;Oracle 8+&lt;/h1&gt;
&lt;p&gt;I couldn&apos;t figure out how to make it work inline with a SELECT statement, so first create a database function MD5_HASH: &lt;br /&gt;
&lt;font face=&quot;Courier New&quot;&gt;&lt;br /&gt;
CREATE OR REPLACE FUNCTION MD5_HASH (v_input_string in varchar2) RETURN VARCHAR2 IS&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; v_checksum VARCHAR2(20);&lt;br /&gt;
BEGIN&lt;br /&gt;
&amp;nbsp;&amp;nbsp; v_checksum := dbms_obfuscation_toolkit.md5 (input_string =&amp;gt; v_input_string);&lt;br /&gt;
&amp;nbsp;&amp;nbsp; RETURN utl_raw.cast_to_raw(v_checksum);&lt;br /&gt;
END;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;Then use this with a SELECT statement. The &amp;quot;dbms_obfuscation_toolkit.md5()&amp;quot; generates a RAW value that is then converted with &amp;quot;utl_raw.cast_to_raw()&amp;quot; to return a string than is equivalent to a CF hash() call. So an example SELECT statement:&lt;/p&gt;
&lt;p&gt;&lt;font face=&quot;Courier New&quot;&gt;SELECT MD5_HASH([column]) FROM [table]&lt;/font&gt;&lt;/p&gt;
&lt;h1&gt;SQL Server 2005+&lt;/h1&gt;
&lt;p&gt;Note there is an &lt;a href=&quot;http://www.codeproject.com/KB/database/xp_md5.aspx&quot;&gt;option for earlier versions of SQL Server that involve installing a .dll&lt;/a&gt;, but this example takes advantage of a function introduced in 2005 &amp;quot;HashBytes()&amp;quot;.&lt;/p&gt;
&lt;p&gt;&lt;font face=&quot;Courier New&quot;&gt;SELECT UPPER( RIGHT( master.dbo.fn_varbintohexstr( HashBytes( &apos;MD5&apos;, [column] ) ), 32) )&lt;/font&gt;&lt;font face=&quot;Courier New&quot;&gt;&lt;br /&gt;
FROM [table]&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;A few notes:&lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;&lt;font face=&quot;Courier New&quot;&gt;master.dbo.fn_varbintohexstr()&lt;/font&gt; is an undocumented function, but &lt;a href=&quot;http://www.novicksoftware.com/udfofweek/Vol1/T-SQL-UDF-Volume-1-Number-26-fn_varbintohexstr.htm&quot;&gt;it has been around for awhile&lt;/a&gt;, and &lt;a href=&quot;http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=101713&quot;&gt;doesn&apos;t appear to be going anywhere&lt;/a&gt;, and I don&apos;t know another way to do the conversion&lt;/li&gt;
    &lt;li&gt;&lt;font face=&quot;Courier New&quot;&gt;RIGHT( [value], 32) &lt;/font&gt;is needed because the value returned has a leading 0x to indicate the value is hexadecimal, which ColdFusion does not do.&lt;/li&gt;
    &lt;li&gt;Finally &lt;font face=&quot;Courier New&quot;&gt;UPPER()&lt;/font&gt; is there because the value returned is lower cased.&lt;/li&gt;
&lt;/ol&gt;</description><pubDate>Fri, 23 May 2008 19:00:00 GMT</pubDate><guid>http://orangepips.instantspot.com/blog/2008/05/23/CF-Equivalent-MD5-Hashing-Functions-for-SQL-Server-2005--Oracle-8</guid><category>Coldfusion,Database</category></item><item><title>XML StAX Processing with Coldfusion</title><link>http://orangepips.instantspot.com/blog/2007/03/28/XML-StAX-Processing-with-Coldfusion</link><description>&lt;p&gt;Several problems with Coldfusion XML processing and solution set:&lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;&lt;strong&gt;Slow&lt;/strong&gt;: due to DOM processor (&lt;a href=&quot;http://xerces.apache.org/&quot;&gt;Xerces&lt;/a&gt;)&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Inconsistent Round-Tripping&lt;/strong&gt; (i.e. 	serialization / deserialization) :
    &lt;ol&gt;
        &lt;li&gt;(un-) escaping characters&lt;/li&gt;
        &lt;li&gt;non-printable characters&lt;/li&gt;
        &lt;li&gt;missing / multiple XML declaration(s)&lt;/li&gt;
        &lt;li&gt;character set problems&lt;/li&gt;
        &lt;li&gt;et al.&lt;/li&gt;
    &lt;/ol&gt;
    &lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Kludgy Tree API&lt;/strong&gt; yes you can use structure and 	array functions, just don&apos;t like it.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Note, don&apos;t see this as a flame on Adobe/Macromedia. The Coldfusion XML implementation uses best available technology at the time and APIs that fit in with the language paradigm. Just have better options now.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Slow Solution&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;http://woodstox.codehaus.org/&quot;&gt;Woodstox&lt;/a&gt;&lt;/strong&gt;: &lt;a title=&quot;CFDJ: Advanced XML Processing with StAX in ColdFusion&quot; href=&quot;http://coldfusion.sys-con.com/read/236002.htm&quot;&gt;Jim Collins wrote a CFDJ article about using a StAX XML processor with Coldfusion&lt;/a&gt;. Unfortunately, as near as I can tell, his &lt;a href=&quot;http://sourceforge.net/projects/cfsynergy&quot;&gt;open source project to integrate Coldfusion with Woodstox&lt;/a&gt; was never released. &lt;a title=&quot;SUN: Streaming APIs for XML Parsers&quot; href=&quot;http://java.sun.com/performance/reference/whitepapers/StAX-1_0.pdf&quot;&gt;Testing demonstrates&lt;/a&gt; a StAX processor, such as Woodstox, provides very efficient (read: fast) XML processing, and a more intuitive API, than a SAX processor. But still not intuitive enough for me. So enter...&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Round-Tripping &amp;amp; API Solutions&lt;br /&gt;
&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a title=&quot;XML object model&quot; href=&quot;http://www.xom.nu/&quot;&gt;XOM&lt;/a&gt;&lt;/strong&gt; provides a very easy to use API that roundtrips XML like a champ. Correct I/O is XOM&apos;s middle name. But it doesn&apos;t integrate natively with a StAX processor unless you use...&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;http://dsd.lbl.gov/nux/&quot;&gt;NUX&lt;/a&gt; &lt;/strong&gt;is like a Swiss Army knife for XML. But the purpose of this entry just know it&apos;s the glue between XOM and Woodstox (&lt;em&gt;note that NUX includes the XOM jar so you do not need to download it separately&lt;/em&gt;).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Code&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Download the Woodstox and NUX jars and configure them in your Coldfusion classpath. The examples below build upon each other.&lt;/p&gt;
&lt;p&gt;&lt;u&gt;Setup&lt;/u&gt;&lt;/p&gt;
&lt;p&gt;Creates a &lt;a href=&quot;http://www.xom.nu/apidocs/nu/xom/Builder.html&quot;&gt;XOM Builder object&lt;/a&gt; backed by a StAX processor.&lt;font face=&quot;courier new,courier&quot;&gt; &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size=&quot;2&quot; face=&quot;courier new,courier&quot;&gt;inputFactory = createObject(&amp;quot;java&amp;quot;, &amp;quot;com.ctc.wstx.stax.WstxInputFactory&amp;quot;).init()&lt;br /&gt;
builder = createObject(&amp;quot;java&amp;quot;, &amp;quot;nux.xom.io.StaxUtil&amp;quot;).createBuilder(local.joInputFactory, javacast(&amp;quot;null&amp;quot;, &amp;quot;&amp;quot;)&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;u&gt;XMLParse() Alternative&lt;/u&gt;&lt;/p&gt;
&lt;p&gt;Returns a &lt;a href=&quot;http://www.xom.nu/apidocs/nu/xom/Document.html&quot;&gt;XOM Document object&lt;/a&gt;. Note: provide &lt;em&gt;XMLString &lt;/em&gt;variable.&lt;/p&gt;
&lt;p&gt;&lt;font size=&quot;2&quot; face=&quot;courier new,courier&quot;&gt;document = builder.create(XMLString)&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;u&gt;XMLSearch() Alternative&lt;/u&gt;&lt;/p&gt;
&lt;p&gt;Returns a &lt;a href=&quot;http://www.xom.nu/apidocs/nu/xom/Nodes.html&quot;&gt;XOM Nodes object&lt;/a&gt; (i.e. an iterator of Node objects). Note: provide &lt;em&gt;XQueryString&lt;/em&gt; variable.&lt;/p&gt;
&lt;p&gt;&lt;font size=&quot;2&quot; face=&quot;courier new,courier&quot;&gt;nodes = createObject(&amp;quot;java&amp;quot;, &amp;quot;nux.com.xquery.XQueryUtil&amp;quot;).xquery(document, XQueryString)&lt;br /&gt;
&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size=&quot;2&quot; face=&quot;courier new,courier&quot;&gt;loop from=&amp;quot;0&amp;quot; to=&amp;quot;#nodes.size() - 1#&amp;quot; index=&amp;quot;idx&amp;quot; &lt;br /&gt;
element = nodes.get(javacast(&amp;quot;int&amp;quot;, idx)) &lt;br /&gt;
attributeValue = element.getAttribute(&amp;quot;attributeName&amp;quot;).getValue() &lt;br /&gt;
attributeText = element.getValue &lt;br /&gt;
/loop &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;u&gt;ToString() Alternative&lt;/u&gt;&lt;/p&gt;
&lt;p&gt;Creates a string representation of the XML.&lt;/p&gt;
&lt;p&gt;&lt;font size=&quot;2&quot; face=&quot;courier new,courier&quot;&gt;XMLString = document.toXML()&lt;/font&gt;&lt;/p&gt;</description><pubDate>Wed, 28 Mar 2007 15:04:00 GMT</pubDate><guid>http://orangepips.instantspot.com/blog/2007/03/28/XML-StAX-Processing-with-Coldfusion</guid><category>XML,Coldfusion</category></item></channel></rss>