Created
March 24, 2014 23:57
-
-
Save bennadel/9752062 to your computer and use it in GitHub Desktop.
Making ColdFusion's QueryNew() More Readable
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
<!--- Create the columns definitions for query new. ---> | |
<cfsavecontent variable="strColumns"> | |
data :: VARCHAR, | |
rfid :: VARCHAR, | |
date :: VARCHAR, | |
time :: VARCHAR, | |
gross :: VARCHAR, | |
tare :: VARCHAR, | |
net :: VARCHAR, | |
level :: VARCHAR, | |
rollover_id :: VARCHAR, | |
rb_dollars :: DECIMAL, | |
is_valid :: INTEGER, | |
is_invalid_account :: INTEGER, | |
is_invalid_entry :: INTEGER, | |
is_invalid_gross :: INTEGER, | |
is_invalid_tare :: INTEGER, | |
is_invalid_net :: INTEGER, | |
is_duplicate_credit :: INTEGER, | |
useraccount_id :: VARCHAR, | |
rfid_count :: VARCHAR, | |
address_id :: VARCHAR, | |
street1 :: VARCHAR, | |
street2 :: VARCHAR, | |
city :: VARCHAR, | |
state :: VARCHAR, | |
zip :: VARCHAR | |
</cfsavecontent> | |
<!--- | |
Manually create a query using the column mapping | |
defined in the CFSaveContent tag above. | |
---> | |
<cfset qCredit = QueryNew( | |
<!--- Column names. ---> | |
strColumns.ReplaceAll( "\s*::[^,]+", "" ).ReplaceAll( ",\s*", ", " ).Trim(), | |
<!--- Column types. ---> | |
strColumns.ReplaceAll( ",[^:]+::\s*", ", " ).ReplaceAll( "^[^:]+::\s*", "" ).Trim() | |
) /> |
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
<cfset qCredit = QueryNew( | |
"data, rfid, date, time, gross, tare, net, level, rolloverid, rb_dollars, is_valid, is_invalid_account, is_invalid_entry, is_invalid_tare, is_duplicate_credit, useraccount_id, rfid_count, address_id, street1, street2, city, state, zip", | |
"VARCHAR, VARCHAR, VARCHAR, VARCHAR, VARCHAR, VARCHAR, VARCHAR, VARCHAR, VARCHAR, DECIMAL, INTEGER, INTEGER, INTEGER, INTEGER, INTEGER, VARCHAR, VARCHAR, VARCHAR, VARCHAR, VARCHAR, VARCHAR, VARCHAR, VARCHAR" | |
) /> |
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
<sys:querynew name="qCredit"> | |
data :: VARCHAR, | |
rfid :: VARCHAR, | |
date :: VARCHAR, | |
time :: VARCHAR, | |
gross :: VARCHAR, | |
tare :: VARCHAR, | |
net :: VARCHAR, | |
level :: VARCHAR, | |
rollover_id :: VARCHAR, | |
rb_dollars :: DECIMAL, | |
is_valid :: INTEGER, | |
is_invalid_account :: INTEGER, | |
is_invalid_entry :: INTEGER, | |
is_invalid_gross :: INTEGER, | |
is_invalid_tare :: INTEGER, | |
is_invalid_net :: INTEGER, | |
is_duplicate_credit :: INTEGER, | |
useraccount_id :: VARCHAR, | |
rfid_count :: VARCHAR, | |
address_id :: VARCHAR, | |
street1 :: VARCHAR, | |
street2 :: VARCHAR, | |
city :: VARCHAR, | |
state :: VARCHAR, | |
zip :: VARCHAR | |
</sys:querynew> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment