[Gambas-user] For Each ?WHAT? in Result

Caveat Gambas at ...1950...
Sat Jan 10 13:16:15 CET 2015


But the documentation arrived at by following the enumerable link 
doesn't give a fully working code example, and also doesn't document 
whether the order of the enumeration is predictable, which we'd better 
hope it is if you ever decide to use an "order by" clause :-D

I'll see if have time to sign up and edit the page later, unless someone 
else can already take care of this?

Thanks and kind regards
Caveat

On 10/01/15 11:59, Tobias Boege wrote:
> 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
>





More information about the User mailing list