Showing posts with label ColdFusion. Show all posts
Showing posts with label ColdFusion. Show all posts

Tuesday, January 31, 2012

Regular Expression (RegEx) Remove illegal ones

Yesterday I was working on a site which pulled data from a third party xml file. We were having problems with illegal characters and as we have no control over what was being entered we decided to handle it on our end. Just thought I would post up a handy RegEx which cleaned it up for us.

cleanXML = reReplaceNoCase(xml, "[^-a-zA-Z0-9@`!""##$%&'()*+,-./:;\[{<\|=\]}>^~?_ ]", "", "ALL");

Wednesday, July 13, 2011

SQL Stored Procedures Performance

I've been told there are performance gains when using 'Stored Procedures'. Lately I've been wondering what the real gains of performance are and does it relate to a simple select statement?

First we need to create a test set of tables:

Now some code to generate data for the tables:

Now lets make the store procedure to select results:

And now the code we used to test the execution time of cfquery and cfstoredproc:


Now the results I got are very mixed. Sometimes the procedure is faster; sometimes it is not. I've never done anything like this before so I'm wondering if EXECUTIONTIME is the best thing to be comparing? Will using a store procedure in cases like this be that much faster (on such a simple select) or is it more for all the other benefits you get with using it?

Thursday, April 7, 2011

ColdFusion - Var Scoping.

A couple of days ago I was making a little program to recursively list files in sub-directories.
In doing so I ran into a good example of why var scoping is so important.

File structure:

Non var scoped code:


Non var scoped results:


However when I properly var scoped the variables. 

var scoped code:


var scoped results:


In simple terms, when the function is being run the second time, ColdFusion is being lazy. Instead of making and declaring a new variable it is using the old one. Adding var scoping will make sure that whenever the function is run the variables are scoped to that instance of the function.