Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <cfif ThisTag.executionMode EQ "end">
- <cfset query = ThisTag.GeneratedContent & " " />
- <cfset ThisTag.GeneratedContent = "" />
- <cfinclude template="../../../_config/admin_config.cfm" />
- <cffunction name="getSqlType">
- <cfargument name="paramType" />
- <cfscript>
- if (paramType == "string") return "cf_sql_varchar";
- if (paramType == "text") return "cf_sql_longvarchar";
- if (paramType == "float") return "cf_sql_float";
- if (paramType == "money") return "cf_sql_money";
- if (paramType == "int") return "cf_sql_integer";
- if (paramType == "timestamp") return "cf_sql_timestamp";
- if (paramType == "bit" || paramType == "bool") return "cf_sql_bit";
- </cfscript>
- <cfthrow message="Invalid sql param type #paramType#" />
- </cffunction>
- <cfscript>
- sqls = [];
- currentSql = "";
- currentSqlType = "";
- currentSqlName = "";
- context = "literal";
- for (i = 1; i <= len(query); i++) {
- ch = mid(query, i, 1);
- if (context == "literal") {
- if (ch == "?") {
- context = "gettype";
- sql = {type="literal", sql=currentSql};
- arrayAppend(sqls, sql);
- currentSql = "";
- continue;
- }
- currentSql &= ch;
- } else if (context == "gettype") {
- if (ch == ":") {
- context = "getname";
- continue;
- }
- currentSqlType &= ch;
- } else if (context == "getname") {
- if (ch == " ") {
- context = "literal";
- sql = {type="param", paramType=currentSqlType, paramName=currentSqlName, value=attributes[trim(currentSqlName)]};
- arrayAppend(sqls, sql);
- currentSqlType = "";
- currentSqlName = "";
- continue;
- }
- currentSqlName &= ch;
- }
- }
- </cfscript>
- <cfquery result="sqlResult" datasource="#dsn#" username="#uname#" password="#pword#">
- <cfloop array="#sqls#" index="sql">
- <cfif sql.type EQ "literal">#sql.sql#</cfif>
- <cfif sql.type EQ "param">
- <cfqueryparam cfsqltype="#getSqlType(sql.paramType)#" value="#sql.value#">
- </cfif>
- </cfloop>
- </cfquery>
- <cfset caller[attributes.result] = sqlResult />
- </cfif>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement