Advertisement
Guest User

Untitled

a guest
Jun 6th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <cfif ThisTag.executionMode EQ "end">
  2.     <cfset query = ThisTag.GeneratedContent & " " />
  3.     <cfset ThisTag.GeneratedContent = "" />
  4.    
  5.     <cfinclude template="../../../_config/admin_config.cfm" />
  6.    
  7.     <cffunction name="getSqlType">
  8.         <cfargument name="paramType" />
  9.         <cfscript>
  10.             if (paramType == "string") return "cf_sql_varchar";
  11.             if (paramType == "text") return "cf_sql_longvarchar";
  12.             if (paramType == "float") return "cf_sql_float";
  13.             if (paramType == "money") return "cf_sql_money";
  14.             if (paramType == "int") return "cf_sql_integer";
  15.             if (paramType == "timestamp") return "cf_sql_timestamp";
  16.             if (paramType == "bit" || paramType == "bool") return "cf_sql_bit";
  17.         </cfscript>
  18.         <cfthrow message="Invalid sql param type #paramType#" />
  19.     </cffunction>
  20.    
  21.     <cfscript>
  22.        
  23.         sqls = [];
  24.         currentSql = "";
  25.         currentSqlType = "";
  26.         currentSqlName = "";
  27.         context = "literal";
  28.        
  29.         for (i = 1; i <= len(query); i++) {
  30.             ch = mid(query, i, 1);
  31.             if (context == "literal") {
  32.                 if (ch == "?") {
  33.                     context = "gettype";
  34.                     sql = {type="literal", sql=currentSql};
  35.                     arrayAppend(sqls, sql);
  36.                     currentSql = "";
  37.                     continue;
  38.                 }
  39.                 currentSql &= ch;
  40.             } else if (context == "gettype") {
  41.                 if (ch == ":") {
  42.                     context = "getname";
  43.                     continue;
  44.                 }
  45.                 currentSqlType &= ch;
  46.             } else if (context == "getname") {
  47.                 if (ch == " ") {
  48.                     context = "literal";
  49.                     sql = {type="param", paramType=currentSqlType, paramName=currentSqlName, value=attributes[trim(currentSqlName)]};
  50.                     arrayAppend(sqls, sql);
  51.                     currentSqlType = "";
  52.                     currentSqlName = "";
  53.                     continue;
  54.                 }
  55.                
  56.                 currentSqlName &= ch;
  57.             }
  58.         }
  59.        
  60.     </cfscript>
  61.    
  62.     <cfquery result="sqlResult" datasource="#dsn#" username="#uname#" password="#pword#">
  63.         <cfloop array="#sqls#" index="sql">
  64.             <cfif sql.type EQ "literal">#sql.sql#</cfif>
  65.             <cfif sql.type EQ "param">
  66.                 <cfqueryparam cfsqltype="#getSqlType(sql.paramType)#" value="#sql.value#">
  67.             </cfif>
  68.         </cfloop>
  69.     </cfquery>
  70.    
  71.     <cfset caller[attributes.result] = sqlResult />
  72.    
  73. </cfif>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement