[Gambas-user] Extracting fields from a Result

T Lee Davidson t.lee.davidson at gmail.com
Sun Dec 31 18:49:43 CET 2017


Yes, MyResult!txtMasterDatabase should work. (Did you copy/paste that name, or type it in directly?) The For Each loop should
work as well.

I tried a simple command-line application on a MySQL data table with just one row. All the application does is, first connect to
the database, and then 'MyResult = hConn.Exec("select * from users")'

A For Each loop prints the field names just fine. And, 'Print MyResult!id' displays the correct value.

Perhaps there is a bug in the Gambas PostgreSQL driver. Can you test on a MySQL table to see if that works for you?


-- 
Lee


On 12/31/2017 01:26 AM, Doug Hutcheson wrote:
> This just gets more interesting.
> 
> The For Each ... Next loop fails on the first line, as previously described.
> 
> After some bashing and hacking, I found a simple loop works fine:
>               For intLoop = 0 To MyResult.Fields.Count - 1
>                 Message(MyResult.Fields[intLoop].Name & ": " & MyResult[intLoop] & ": " & MyResult.Fields[intLoop].Length & ": "
> & MyResult.Fields[intLoop].Type)
>               Next
> 
> Given a field named txtMasterDatabase, should the following work?
> Message(MyResult!txtMasterDatabase)
> ... because it throws 'Unknown field txtMasterDatabase ..."
> 
> Many thanks for help on this.
> 
> Kind regards,
> Doug
> 
> On Sun, 2017-12-31 at 12:00 +1000, Doug Hutcheson wrote:
>> Darn. Still getting used to the conventions. I should have said I am running Gambas 3.10.0 on Fedora 28 Linux.
>>
>> On Sun, 2017-12-31 at 11:44 +1000, Doug Hutcheson wrote:
>>> Hi everyone.
>>>
>>> I have successfully connected to my PostgreSQL database and the field count in the Result from my query is correct, but all
>>> my attempts to extract data from the fields have failed. I am cobbling together code from the wiki and from other posts here,
>>> but I am still missing something.
>>>
>>> The table I am reading from has exactly one row and 35 fields. The first field is named txtMasterDatabase.
>>>
>>> My code declares a Field and a Result as follows:
>>>           Dim $Field As ResultField
>>>           Dim $Result As Result
>>>
>>> The query works correctly:
>>>            $Query = "Select * From abpa.tblParameters"
>>>            $Result = $Con.Exec($Query)
>>>
>>> The field count is correct - 35:
>>>            Message("Fields count = " & $Result.Fields.Count)
>>>
>>> Now I try to loop through the fields in the result:
>>>            For Each $Field In $Result.Fields
>>>             Message($Field.Name)
>>>            Next
>>>
>>> The problem occurs on the For Each line in that the Basic IDE displays an error at this point:
>>> Unknown field: txtMasterDatabase in FRMStart:41
>>>
>>> As I said above, the first field in the tuple is named txtMasterDatabase, so Gambas is at least seeing it. Why is it telling
>>> me the field is unknown?
>>>
>>> Thanks for any help and Happy New Year,
>>> Doug
> 
> 
> 
> --------------------------------------------------
> 
> This is the Gambas Mailing List
> https://lists.gambas-basic.org/listinfo/user
> 
> Hosted by https://www.hostsharing.net
> 


More information about the User mailing list