I just came up for air after a couple of long days and thought I'd take a minute to revisit this ready for tomorrow.
It looks like I'm not actually sure about how to handle the query build within the loop.
I do indeed have several loops where I put the CFQUERY outside of it and then build the the query inside the loop so as discussed it's one payload rather than 50 individual queries
However after working on this particular piece I've found that I have to add in two pieces of data from a previous query. So The question now is how could I tweak this so that it goes in one shot rather than individual queries? Presume that form_game_uid could be a list of up to 50 unique values and the query must append these values are they came out of the GetGamesAff query.
<CFSET AffiliateList = #Valuelist(GetGamesAff.gamecredit_affiliate_uid)#>
<CFSET RedemptioncodeList = #Valuelist(GetGamesAff.gamecredit_redemptioncode_uid)#>
<CFSET ListPosition = "0">
<CFLOOP LIST="#form_game_uid#" INDEX="game_uid">
<CFSET ListPosition = ListPosition + 1>
<CFQUERY NAME="AddGame" DATASOURCE="#datasource#">
INSERT INTO endusergames
(
endusergames_enduser_uid,
endusergames_game_uid,
endusergames_affiliate_uid,
endusergames_redemptioncode_uid
)
VALUES
(
<cfqueryparam value="#session.useruid#" cfsqltype="CF_SQL_INT">,
<cfqueryparam value="#game_uid#" cfsqltype="CF_SQL_TINYINT">,
<cfqueryparam value="#val(ListGetAt(affiliatelist,ListPosition))#" cfsqltype="CF_SQL_INT">,
<cfqueryparam value="#val(ListGetAt(Redemptioncodelist,ListPosition))#" cfsqltype="CF_SQL_INT">
)
</CFQUERY>
</CFLOOP>
https://forums.adobe.com/people/ACS+LLC wrote Presume that form_game_uid could be a list of up to 50 unique values and the query must append these values are they came out of the GetGamesAff query. |
Then you should place the loop not outside, but within the query, as follows:
<cfset affiliateList = valueList(getGamesAff.gamecredit_affiliate_uid)>
<cfset redemptionCodeList = valueList(getGamesAff.gamecredit_redemptioncode_uid)>
<cfset listPosition = "0">
<cfquery name="addgame" datasource="#datasource#">
insert into endusergames
(
endusergames_enduser_uid,
endusergames_game_uid,
endusergames_affiliate_uid,
endusergames_redemptioncode_uid
)
values
<cfloop list="#form_game_uid#" index="game_uid">
<cfset listPosition = listPosition + 1>
(
<cfqueryparam value="#session.useruid#" cfsqltype="cf_sql_int">,
<cfqueryparam value="#game_uid#" cfsqltype="cf_sql_tinyint">,
<cfqueryparam value="#val(listgetat(affiliatelist, listPosition))#" cfsqltype="cf_sql_int">,
<cfqueryparam value="#val(listgetat(redemptioncodelist, listPosition))#" cfsqltype="cf_sql_int">
)<cfif listPosition lt listLen(form_game_uid)>,</cfif>
</cfloop>
</cfquery>