29 September 2008

SQL Update

Try as i might, i NEVER remember how to do this:

UPDATE table1
SET snakesOnAPlane = t2.data
FROM table1 t1
JOIN table2 t2 ON t2.row1 = t1.row1
WHERE t1.row3 = 'helloWorld'

22 September 2008

SQL Transaction

bit like in cfmx here's a useful bit of t-sql / sql for rolling back on error.

BEGIN TRAN
insert into ()--....sql goes here

IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN

It's not perfect but it seems to work...sometimes....if the wind is blowing north, and it's a wednesday.

19 August 2008

Cold Fusion reload web service

ColdFusion does a very enthusiastic job of caching web services, which if you're still developing or making a few changes can be frustrating. I've found this code to be VERY useful to reload a web service cached by cfadmin.


<cfobject type="JAVA"
action="Create"
name="factory"
class="coldfusion.server.ServiceFactory">



<cfset RpcService = factory.XmlRpcService />



<cfset RpcService.refreshWebService("http://myURL/webservices/mycfc.cfc?WSDL")>

javascript web service

OK so AJAX / JS...whateves right?

This little bit of code allows you to call a web service from JavaScript. I have found many articles and ways of doing this on the interweb and non of them seem to work. This one works with CF web services.

The interesting thing i found is you don't need to pass parameters using the XMLHttpRequest method, to call a specific function just append &method= to the end of the wsdl string.


function ajaxFunction()

{

var xmlHttp;

try

{

// Firefox, Opera 8.0+, Safari

xmlHttp=new XMLHttpRequest();

}

catch (e)

{

// Internet Explorer

try

{

xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");

}

catch (e)

{

try

{

xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

}

catch (e)

{

alert("Your browser does not support AJAX!");

return false;

}

}

}

xmlHttp.onreadystatechange=function()

{

if(xmlHttp.readyState==4)

{

document.getElementById("myDivResponse").innerHTML = xmlHttp.responseText;

}

}

xmlHttp.open("GET","http://myurl/webserrvices/mycfc.cfc?WSDL&method=getSomething",true);

xmlHttp.send(null);

}