[Gambas-user] For Each ?WHAT? in Result
Tobias Boege
taboege at ...626...
Sat Jan 10 11:59:05 CET 2015
On Sat, 10 Jan 2015, Lewis Balentine wrote:
> On 01/10/2015 03:04 AM, Caveat wrote:
> > On 10/01/15 09:52, Lewis Balentine wrote:
> >> Result (gb.db)
> >> This class represents the result of a SQL request.
> >> This class is not creatable.
> >> This class acts like a read / write array.
> >> This class is *enumerable* with the FOR EACH keyword.
> >>
> >> Guess this should be obvious but not to me .... pray tell what
> >> type/class does one use to enumerate it ??
> >> I tried "ResultField[]"
> >> I tried "Collection"
> >> I tried to try "record"
> >> As a last resort I tried String[]
> >> Suffice it to say: I have not a clue :-\
> >>
> >> ========
> >> Dim MyResult as Result
> >> Dim MyRecord as ?????
> >>
> >> Result = Connection.Find (Something)
> >>
> >> For Each MyRecord in MyResult
> >> Print MyRecord["Field1Name"]
> >> Print MyRecord["Field2Name"]
> >> Print MyRecord["Field3Name"]
> >> Next
> >> ============
> >> regards,
> >>
> >> Lewis
> >
> > I presume you started here http://gambaswiki.org/wiki/comp/gb.db/result
> > And then clicked on the big obvious link to FOR EACH, arriving here:
> > http://gambaswiki.org/wiki/lang/foreach
> > And then didn't look at the second example... :-P
> >
> > Kind regards,
> > Caveat
> >
>
> Thank thee ... :-)
> I did follow that path and I did miss the nuance of the second example.
>
Better yet, don't click on the "FOR EACH" link but on the "enumerable" link.
This brings you to the Result-specific documentation for enumeration. You
want to remember this because not every class is mentioned in the FOR EACH
language documentation.
As you see, Result has a different way of being enumerated. Instead of
returning the objects in the result, a new iteration moves an internal
cursor through the rows of the result data. This means, each execution of
the loop body
For Each hResult
Print hResult!onefield
Next
will yield a different print (unless some rows contain the same value, of
course).
Regards,
Tobi
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
More information about the User
mailing list