I have few functions in my system that should be converted from CFML to CFSCRIPT. While working on this project I run to the situation where my structure outputs more result (a lot of empty rows) than it should, even query returns only one row. Here is example of my code in CFSCRIPT:
cfstoredproc( procedure="GetZip", datasource=Application.dsnRead ) {
cfprocparam( dbvarname="@Zip", value=trim(52401), cfsqltype="cf_sql_char", maxlength=5 );
cfprocresult( name="ZipResult" );
}
local.strZip = {};
strZip[ZipResult.RecID] = {
"City" : trim(ZipResult.City),
"State" : trim(ZipResult.State)
};
writeDump(strZip);
Here is what I get for the output:
array
1 [undefined array element]
2 [undefined array element]
3 [undefined array element]
4 [undefined array element]
5 [undefined array element]
6 [undefined array element]
7 [undefined array element]
8 [undefined array element]
9 [undefined array element]
10 [undefined array element]
11 [undefined array element]
12 [undefined array element]
13 [undefined array element]
14 [undefined array element]
...
I'm wondering what is the best way to output query result(s) in structure and use RecID
as a unique key? This example and query above always will return 1 record at the time but also I'm wondering how this code would work if I need to loop over the query result with multiple records?
Update: I think that I found the problem. The RecID
is auto increment id in my db table. When i return RecID
the value can be 56743
for example. So if I pass RecID as a key in my structure, that will cause so many rows in the structure. My question is how to prevent this? Is there a way to just set the key?