I just posted a small open source CFML project heredb.cfc is a standalone CFC with 472 lines of code.Here is the execute function in db.cfc.  This is just a partial example pulled from the 400+ lines of the code in db.cfc. If you have any suggestions for the rest of the CFC, feel free to post them.This code is currently optimized for speed so that it is not much slower than a regular <cfquery>. The project doesn't have any unit tests yet.<cffunction name=execute returntype=any output=no>    <cfargument name=name type=variablename required=yes hint=A variable name for the resulting query object.  Helps to identify query when debugging.>    <cfscript>    var queryStruct={        lazy=this.lazy,        datasource=this.datasource      };    var pos=0;    var processedSQL=;    var startIndex=1;    var curArg=1;    var running=true;    var db=structnew();    var cfquery=0;    var k=0;    var i=0;    var s=0;    var paramCount=arraylen(variables.arrParam);    if(this.dbtype NEQ  and this.dbtype NEQ datasource){        queryStruct.dbtype=this.dbtype;         structdelete(queryStruct, 'datasource');    }else if(isBoolean(queryStruct.datasource)){        this.throwError(db.datasource must be set before running db.execute() by either using db.table() or db.datasource=myDatasource;);    }    if(not isBoolean(this.cachedWithin)){        queryStruct.cachedWithin=this.cachedWithin;     }    queryStruct.name=db.&arguments.name;    if(len(this.sql) EQ 0){        this.throwError(The sql statement must be set before running db.execute(););    }    if(this.verifyQueriesEnabled){        if(compare(this.sql, variables.lastSQL) NEQ 0){            variables.lastSQL=this.sql;            variables.verifySQLParamsAreSecure(this.sql);            processedSQL=replacenocase(this.sql,variables.trustSQLString,,all);            processedSQL=variables.parseSQL(processedSQL, this.datasource);        }else{            processedSQL=replacenocase(replacenocase(this.sql,variables.trustSQLString,,all), variables.tableSQLString, ,all);        }    }else{        processedSQL=this.sql;    }    if(this.disableQueryLog EQ false){        ArrayAppend(this.arrQueryLog, processedSQL);    }    </cfscript>    <cftry>        <cfif paramCount>            <cfquery attributeCollection=#queryStruct#><cfloop condition=#running#><cfscript>                pos=find(?, processedSQL, startIndex);                </cfscript><cfif pos EQ 0><cfset running=false><cfelse><cfset s=mid(processedSQL, startIndex, pos-startIndex)>#preserveSingleQuotes(s)#<cfqueryparam attributeCollection=#variables.arrParam[curArg]#><cfscript>                startIndex=pos+1;                curArg++;                </cfscript></cfif></cfloop><cfscript>                if(paramCount GT curArg-1){                     this.throwError(db.execute failed: There were more parameters then question marks in the current sql statement.  You must run db.execute() before building any additional sql statements with the same db object.  If you need to build multiple queries before running execute, you must use a copy of db, such as db2=duplicate(db);<br /><br />SQL Statement:<br />&processedSQL);                 }                s=mid(processedSQL, startIndex, len(processedSQL)-(startIndex-1));                </cfscript>#preserveSingleQuotes(s)#</cfquery>        <cfelse>            <cfquery attributeCollection=#queryStruct#>#preserveSingleQuotes(processedSQL)#</cfquery>        </cfif>        <cfcatch type=database>            <cfscript>            if(this.autoReset){                structappend(this, this.config, true);            }            variables.arrParam=[]; // has to be created separately to ensure it is a separate object            </cfscript>            <cfif left(trim(processedSQL), 7) NEQ INSERT ><cfrethrow></cfif>            <cfscript>            if(this.disableQueryLog EQ false){                ArrayAppend(this.arrQueryLog, Query ##& ArrayLen(this.arrQueryLog)& failed to execute for datasource, &this.datasource&.<br />CFcatch.message: &CFcatch.message&<br />cfcatch.detail: &cfcatch.detail);            }            </cfscript>            <!--- return false when INSERT fails, because we assume this is a duplicate key error. --->            <cfreturn false>        </cfcatch>        <cfcatch type=any><cfscript>            if(paramCount and curArg GT paramCount){                this.throwError(db.execute failed: There were more question marks then parameters in the current sql statement.  You must use db.param() to specify parameters.  A literal question mark is not allowed.<br /><br />SQL Statement:<br />&processedSQL);            }            </cfscript><cfrethrow></cfcatch>    </cftry>    <cfscript>    if(this.autoReset){        structappend(this, this.config, true);    }    variables.arrParam=[]; // has to be created separately to ensure it is a separate object    </cfscript>    <cfif structkeyexists(db, arguments.name)>        <cfreturn db[arguments.name]>    <cfelse>        <cfreturn true>    </cfif></cffunction>
Open source CFML database project
performance;coldfusion;cfml
Points:I agree with @baynezy. The function is doing too much. What are yourunit tests like for this they must be a nightmare? (I just noticed you said you don't have any unit tests yet. Write the tests FIRST. You are doing yourself and your clients a disservice by writing code like this without tests. It's professionally irresponsible for you to release untested code).I've seen the CFC this comes out of, and you seem to be overusing/misusing the this scope. I'm fairly certain you generally should be using the variables scope for a lot of this?why have you written a UDF for throwError()? CFML already has this function built inwhen throwing an exception, you should be specifying an exception type, so calling code and then deal with said exception. Thrown exceptions are not for the human reader (ie: as indicated by your overly-long error messages), they're intended for the calling code.why do you switch to <cfscript> for a simple if & throw statement? You have a lot of very small CFScript blocks for seemingly no reason. It makes the code harder to read & bloated to be switching back and forth between tags and script.your k, i and s variables could probably stand having more descriptive names.returning a mix of boolean or result value is a bit grim.have you checked the thread safety of this method, given you're writing back to the CFC's this and variables scopes (I've seen the CFC, but have not studied it ;-)returning FALSE when an INSERT fails is bad. Either bubble the error back, or raise your own one (I'd do the former).I haven't checked your actual logic yet, but those were my initial observations from just glancing over the code.