Skip to content

Instantly share code, notes, and snippets.

@bdcravens
Created February 3, 2013 17:28
Show Gist options
  • Save bdcravens/4702705 to your computer and use it in GitHub Desktop.
Save bdcravens/4702705 to your computer and use it in GitHub Desktop.
SQL Server 2000 <cfqueryparam> conversion
<cftry>
<cfset colList = "col1,col2,col3">
<cfquery name="cols" datasource="#datasource#">
SELECT column_name, data_type
FROM INFORMATION_SCHEMA.COLUMNS
where table_name = '#table_name#'
and column_name in (<cfqueryparam value="#colList#" list="true">)
</cfquery>
<cfscript>
types = structNew();
// todo: expand this list - see http://cfdocs.org/cfqueryparam
types['bigint']='CF_SQL_BIGINT';
types['bit']='CF_SQL_BIT';
types['datetime']='CF_SQL_TIMESTAMP';
types['int']='CF_SQL_INTEGER';
types['money']='CF_SQL_MONEY';
types['ntext']='CF_SQL_LONGVARCHAR';
types['nvarchar']='CF_SQL_VARCHAR';
types['text']='CF_SQL_LONGVARCHAR';
types['varchar']='CF_SQL_VARCHAR';
</cfscript>
<cfset colTypes = structNew()>
<cfloop query="cols">
<cfset colTypes[column_name]=data_type>
</cfloop>
INSERT INTO applications<br>
(<cfoutput>#colList#</cfoutput>)<br>
VALUES<br>
(
<cfloop list="#colList#" index="col">
<cfoutput>&lt;cfqueryparam value="###col###" cf_sql_type="#types[colTypes[col]]#"&gt;</cfoutput>,<br>
</cfloop>
)
<cfcatch><cfdump var="#cfcatch#"></cfcatch></cftry>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment