Mar 29, 2015; 18:17
Jolle Carlestam
Re: DS Question
29 mar 2015 kl. 16:44 skrev deco rior <decorior@tennissource.net>:
>
> Hi,
>
> I find myself doing this.. Is there a quicker way in DS
>
> local(resultarray) = array
> with row in mydsb->sql(#sqlcode)->rows
> do
> {
> #resultarray->insert(#row)
> }
Ah, finally at the computer again.
First, I don=92t fully understand why you do what you do here. You=92re iterating thru a perfectly valid storage object, the DS rows, and putting the items into another storage object, the array, without any further fine tuning. All that does is force you to do another iteration on the resultarray when you want the actual data.
So here=92s suggestion one to deal with that.
local(resultrows = mydsb->sql(#sqlcode)->rows)
And then, wherever you=92re doing the grabbing of data from your #resultarray you do the same but with #resultrows.
Or if you want to do the fine-tuning directly at the point where you get your DS rows.
local(mydata = (with row in mydsb->sql(#sqlcode)->rows select map('one' = #row(::one)), 'two' = #row(::two)) -> asstaticarray
That will give you an array, or rather a staticarray, of maps where each map is one record from the query.
I use this technique plentiful to give me data that I can json send to Angularjs.
Here=92s an example for that straight out of my code library:
local(
rows = ds_portalDB -> sql("SELECT IFNULL(country_name_swedish,country_name) AS label, country_iso3a AS value FROM country
WHERE display = '1'
ORDER BY label;", -1) -> rows,
listitems = (with row in #rows select map('text' = #row(::label), 'value' = #row(::value)))
)
return json_serialize('success' = true, 'listitems' = #listitems)
HDB
Jolle
#############################################################
This message is sent to you because you are subscribed to
the mailing list Lasso Lasso@lists.lassosoft.com
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <Lasso-unsubscribe@lists.lassosoft.com>
Send administrative queries to <Lasso-request@lists.lassosoft.com>