[Gambas-user] Maybe a bug in how Gambas manages open DB connections

Benoit Minisini gambas at ...1...
Fri Sep 5 14:02:45 CEST 2008


On vendredi 05 septembre 2008, Leonardo Miliani wrote:
> I would like to get your attention on what I think is a bug of how
> Gambas manages open DB connections.
>
> In a project of mine, I manage 2 connections to a MySQL DB.
> In a form of that project I open the first connection and get a result
> with the Connection.Find() method; then, I open the second connection.
> After this, if I try to make another operation on the first connection I
> get an "Invalid object" error.
> It seems that Gambas, when it opens the second connection, deletes all
> the old ones so it has no more references to other connections but the
> last one.
>
> Example code:
> PRIVATE Connessione AS NEW Connection
> PRIVATE Risultato AS Result
>
> PUBLIC SUB Form_Open()
>   WITH Connessione
>     .Name = MySQL.NomeDB
>     .Type = "mysql"
>     .User = MySQL.Utente
>     .Password = MySQL.Password
>     .Host = MySQL.Host
>     .Open
>   END WITH
> END
>
> PUBLIC SUB btnCercaTarga_Click()
> DIM Connessione AS NEW Connection
> DIM Connessione2 AS NEW Connection
> DIM Risultato AS Result
> DIM Risultato2 AS Result
>
>   Risultato = Connessione.Find("auto", "targa=&1", Trim(txtTarga.Text))
>   IF Risultato.Available = FALSE THEN
>     RETURN
>   END IF
>
>   WITH Connessione2
>     .Name = MySQL.NomeDB
>     .Type = "mysql"
>     .User = MySQL.Utente
>     .Password = MySQL.Password
>     .Host = MySQL.Host
>     .Open
>   END WITH
>
>   Risultato.MoveFirst  **  <---------------  Here I get the error **
> [...]
>
>
> To solve this, I had to call the Connection.Find() method another time
> before to access to the Result class.

I cannot reproduce the problem with your code. Which version of Gambas do you 
use?

Note that your code is incorrect anyway: you declare a new connection object 
is a local variable named Connessione in btnCercaTarga_Click which overrides 
the global variable with the same name, and that connection object is not 
initialized.

REgards,

-- 
Benoit Minisini




More information about the User mailing list