Skip to content

Instantly share code, notes, and snippets.

@mrbusche
Created June 11, 2014 02:38
Show Gist options
  • Save mrbusche/5da432a486962f8b9b1c to your computer and use it in GitHub Desktop.
Save mrbusche/5da432a486962f8b9b1c to your computer and use it in GitHub Desktop.
Batch insert records to a database
<cfscript>
totalrows = 5000; // this would come from a structCount or something similar
rowsPerInsert = 210;
//this creates a struct with alternating values of true/false for test purposes
stRows = {};
for(i=1; i<=totalRows; i++) {
stRows[i] = i MOD 2 ? true : false;
}
</cfscript>
<cfoutput>
<cfloop from="0" to="#totalRows - 1#" step="#rowsPerInsert#" index="totalRow">
<br><br>INSERT #totalRow#<br>
<cfloop from="1" to="#rowsPerInsert#" index="indRow">
<cfset rowNumber = totalRow + indRow>
<cfif rowNumber LTE totalRows>
#rowNumber# #stRows[rowNumber]#
<cfif indRow NEQ rowsPerInsert AND rowNumber NEQ totalRows> UNION ALL</cfif>
<br>
</cfif>
</cfloop>
</cfloop>
</cfoutput>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment