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

Leonardo Miliani leonardo at ...1237...
Fri Sep 5 23:37:32 CEST 2008


Benoit Minisini ha scritto:
> 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,
> 

Ops.... I forgot the version: 2.8.1, but got the same error with
previous versions 2.8 and, if I remember correctly, 2.7.

-- 
Ciao.
Leo.

Web: www.leonardomiliani.com
E-mail: leonardo at ...1237...
Scegli software opensource - Choose opensource software

Co-fondatore di Gambas-it.org
Il sito di riferimento della comunità italiana degli utenti di Gambas
www.gambas-it.org




More information about the User mailing list