Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does ArrayClear function differently in CF5 and CF7

Status
Not open for further replies.

LuciGoose

Programmer
Apr 20, 2010
1
US
The below code works just fine in CF5, but trying to port this code over to CF MX7 it clears all arrays and there is no data in the multi-dimenional array. It seems like it should put the array data into the Struct then clear it out for the next loop, but it appears to clear the data out of the Struct. Any ideas?



<!---Start Code--->
<!--- query for taking TableNames--->
<cfquery name="GetTableNames" Datasource=#application.Datasource#>
SELECT DISTINCT(TableName)
FROM cc_Profile_Column
WHERE TableName <> 'Address'
</cfquery>
<!---looping all tables and storing values in session--->
<cfloop query="GetTableNames">
<cfset l_TableName=GetTableNames.TableName>
<!--- Getting column names based on the tablename--->
<cfquery name="GetColumnNames" Datasource=#application.Datasource#>
SELECT ColumnName
FROM cc_Profile_Column
WHERE Tablename='#l_TableName#'
ORDER BY SortOrder
</cfquery>
<!--- Storing all columnnames in list l_SetAllColumns--->
<cfloop query="GetColumnNames">
<cfset l_SetAllColumns="#ValueList(GetColumnNames.ColumnName)#">
</cfloop>
<!--- Fetching records from contact table--->
<cfquery name=#l_TableName# Datasource=#application.Datasource#>
SELECT #l_SetAllColumns#
FROM #l_TableName#
WHERE ContactID=#l_ContactID#
</cfquery>
<!--- checking if record exists--->
<cfset GetRecordCount="#l_TableName#.RecordCount">
<cfif #Evaluate(GetRecordCount)#>
<!--- Executing query storing each row in datastructure and further storing data structutre(s) into session.ProfileData array--->
<cfloop query="#l_TableName#">
<cfset l_counter=l_counter+1>
<!--- Converting list of columnnames into array--->
<cfset l_ColumnNamesArray=ListtoArray(l_SetAllColumns)>
<cfloop index="i" from = "1" to = "#ArrayLen(l_ColumnNamesArray)#">
<cfset QueryVar="#l_TableName#.#l_ColumnNamesArray#">
<!--- storing database values in array--->
<cfset l_DbValues=Evaluate(QueryVar)>
</cfloop>
<!--- initilaizing the structure, intializing inside cfoutput query so as to make seperate datastrctures for each row --->
<cfset l_RowName =StructNew()>
<!--- inserting data in structure--->
<cfset value=StructInsert(l_RowName, "Key", "#l_TableName#:#l_DbValues[1]#")>
<cfset value=StructInsert(l_RowName, "Action", "")>
<cfset value=StructInsert(l_RowName, "DatabaseValues", "#l_DbValues#")>
<cfset value=StructInsert(l_RowName, "sessionValues", "#l_DbValues#")>

<!--- Strong data Structutre in main session.ProfileData array--->
<cfif session.AdministratorID GT 0>
<cfset session.ProfileData[l_Counter]=l_RowName>
<cfelse>
<cfset session.ProfileDataNotEditable[l_Counter]=l_RowName>
</cfif>
<!--- Clearing array so blank array is used next time--->
<cfset l_ArrayClean=ArrayClear(l_DbValues)>
</cfloop>

</cfif>
<cfset l_SetAllColumns="">
<cfset l_ArrayClean=ArrayClear(l_ColumnNamesArray)>
</cfloop>
 
Disclaimers: I have not used CF5

That is a bit too much code to be able to debug. But one thing I did notice is your comment about "Clearing array so blank array is used next time".

It sounds like you should be creating new objects, rather than trying to reuse old ones. Especially if you are storing that information in a persistent scope.

Though arrays are _usually_ an exception, most objects in MX+ are passed "by reference". Meaning you are often working a pointer to an object, not an independent copy. So code that attempts to reuses objects improperly, can lead to some unexpected results.

----------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top