Hi!
I need to export some JSON from Database
First i need to do a primary query and then, a “subquery” for each primary query
The result will be something like this:
Id:1,name:alex,address:[street name:abc,number:123]
Id:2,name:ingrid,address:[street name:xpto,number:444]
and so on
But, when i finish the subquery, after the FIRST primary recordset, the recordset resets
Why??
there are some code before, but it’s not rellevant
[code]
dim jsonConsolidado as new JSONItem
while not rs.eof
dim dict as new Dictionary
for i=1 to rs.FieldCount
if instr(“nu_sequencia,st_tipovenda,dt_contabil”,rs.IdxField(i).name)>0 then // there is a reason for this // i’ll use to make a new query
continue
end if
dict.value(rs.IdxField(i).name) = rs.IdxField(i).StringValue // put all values inside dictionary, but nu_sequencia, st_tipovenda, dt_contabil
next
dim nu_sequencia, st_tipovenda, dt_contabil as string // i’ll use to make a new query now
nu_sequencia = rs.Field(“nu_sequencia”).StringValue
st_tipovenda = rs.Field(“st_tipovenda”).StringValue
dt_contabil = rs.Field(“dt_contabil”).StringValue
// IF THIS LINE IS UNCOMMENT, THE RS.MOVENEXT EXIT WHILE/WEND
// IF THIS LINE IS COMMENT, THE RS.MOVENEXT DO THE JOB!!!
dict.value("meios") = getDictMeios(nu_sequencia, st_tipovenda, dt_contabil) // to get the subquery contents
jsonConsolidado.Append dict
rs.MoveNext
wend[/code]
this is the getDictMeios code:
[code]dim strSQL as string
dim rs2 as RecordSet
dim i as integer
strSQL = " Select "
rs2 = app.db.SQLSelect(strSQL)
dim jsonConsolidado as new JSONItem
while not rs2.eof
dim dictMeios as new Dictionary
for i=1 to rs2.FieldCount
dictMeios.value(rs2.IdxField(i).name) = rs2.IdxField(i).StringValue
next
jsonConsolidado.Append dictMeios
rs2.MoveNext
wend
return jsonConsolidado[/code]