Created
February 3, 2013 17:28
-
-
Save bdcravens/4702705 to your computer and use it in GitHub Desktop.
SQL Server 2000 <cfqueryparam> conversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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><cfqueryparam value="###col###" cf_sql_type="#types[colTypes[col]]#"></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