[Gambas-user] Extracting fields from a Result

T Lee Davidson t.lee.davidson at gmail.com
Sun Dec 31 22:23:56 CET 2017


On 12/31/2017 03:16 PM, Tobias Boege wrote:
> On Sun, 31 Dec 2017, T Lee Davidson wrote:
>> 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?
>>
> I agree that the original code should have worked. See the attached
> script which uses an in-memory SQLite3 database to demonstrate that
> it works with another driver.
> 
> A (minimal!) project and database dump, just enough to reproduce the
> behaviour, would be helpful.
> 
> Regards,
> Tobi

I installed a PostgreSQL server. PostgreSQL does not appear at first glance to be as easy to work with as MySQL.

After finally figuring out how to configure and use it, I was able to run a simple command-line application to successfully
print the field names. (Interestingly enough, even without the gb.db.postgresql database driver component enabled! Benoît?)

It does work as you expect it should, Doug.

You will find my code and the output below.


-- 
Lee


P.S.

On 12/31/2017 02:55 PM, Tobias Boege wrote:
> PS: when did this become a top-posting mailing list?

I've never known it to be either a top-posting or a bottom-posting list. People seem to post as they prefer.

I prefer top-posting because I dislike having to scroll through quote after quote after quote. It would be okay, I guess, if
people would trim quotes that do not add to the context. But, that doesn't always happen.

Benoît prefers bottom-posting, and apparently so do you. When those who prefer bottom-posting do so, I follow along in like manner.


P.P.S.
[code]
' Gambas module file

Public Sub Main()

  Dim hConn As New Connection
  Dim rField As ResultField
  Dim MyResult As Result

  hConn.Type = "postgresql"       ' Type of connection
  hConn.Host = "localhost"   ' Name of the server
  hConn.Login = "postgres"       ' User's name for the connection
  hConn.Port = "5432"        ' Port to use in the connection, usually 3306
  hConn.Name = "postgres"      ' Name of the database we want to use
  hConn.Password = "mypgpass" ' User's password
  hConn.Open()               ' Open the connection
  If Error Then
    Print "OUCH!!"
  Else
    Print "Connected."
  Endif

  MyResult = hConn.Exec("select * from users")

  Debug MyResult.Fields.Count
  Debug MyResult!id
  For Each rField In MyResult.Fields
    Print rField.Name
  Next

End
[/code]

[output]
Connected.
Main.Main.24: 3
Main.Main.25: 1
id
password
email
[/output]


More information about the User mailing list