[Gambas-user] Extracting fields from a Result
Doug Hutcheson
owlbrudder at gmail.com
Tue Jan 2 04:00:32 CET 2018
On Mon, 2018-01-01 at 12:34 -0500, T Lee Davidson wrote:
> On 01/01/2018 12:17 PM, T Lee Davidson wrote:
> > On 01/01/2018 02:47 AM, Doug Hutcheson wrote:
>
> [snip]
> > > Why am I seeing these password problems when the Connection
> > > objects they are using connect perfectly?
> >
> > Good question. I am having a similar issue, but all I get is
> > "Cannot open database:" - no reason given. "Common.CheckDB.34" tops
> > the Stack backtrace.
> >
> > I don't know if it's related, but when I set the properties for the
> > Connection, I did not enable "Remember password". Yet, I got
> > an error message, "Unable to save password. Cannot store passwords
> > on desktop KDE5: No wallet found". The error is correct;
> > there is no wallet. But I shouldn't have gotten any error because I
> > did not elect to save the password.
> >
> > The Connection can read the database statically through the IDE,
> > but apparently not at runtime.
>
> BTW, Doug, did you try the command line application version I posted?
> Or, in your graphical application, you could try setting
> the database connection programmatically to bypass the IDE's
> Connection component as that appears it might have issues (or we're
> doing something wrong).
>
> [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]
>
Hi Lee. Your code as it stands reports:[doug at womble
CommandLinePostgreSQLtestApp]$ ./CommandLinePostgreSQLtestApp.gambas Connected.Main.Main.22: Query failed: ERROR: relation "users" does not existLINE 1: select * from users ^
Main.Main.22 [doug at womble CommandLinePostgreSQLtestApp]$
I changed the code to connect to my database and the following was the
output:[doug at womble CommandLinePostgreSQLtestApp]$
./CommandLinePostgreSQLtestApp.gambas Connected.Main.Main.24:
35Main.Main.25: Main.Main.25: Unknown field:
txtMasterDatabaseMain.Main.25
35 is the correct field count; txtMasterDatabase is the first field in
the table.
I have attached two source archives: one is my PostgreSQL test
application - the one which started this thread - and the other is your
command line application. Please feel free to point out if I have done
something stupid, because I am at the start of my Gambas learning curve
and welcome any input.
Regards, Doug
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20180102/e768872e/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CommandLinePostgreSQLtestApp-0.0.3.tar.gz
Type: application/x-compressed-tar
Size: 239865 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20180102/e768872e/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PostgreSQL_test-0.0.1.tar.gz
Type: application/x-compressed-tar
Size: 12506 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20180102/e768872e/attachment-0003.bin>
More information about the User
mailing list