[Lazarus] is it me or a bug that i ve been fighting?
waldo kitty
wkitty42 at windstream.net
Tue Jan 20 21:29:03 CET 2009
Joost van der Sluis wrote:
> Op maandag 19-01-2009 om 18:29 uur [tijdzone -0500], schreef waldo
> kitty:
>> it works out that MySQLConnection.Close is TCustomConnection.Close but if i
>> hover the mouse over "Close" in "Procedure Close;" in the public section of the
>> TCustomConnection definition stuffs, the editor wants to point to the textfile
>> close routine Close(var t:Text); which definitely isn't the same thing :(
>
> You can find the code in the fpc-code-dir under
> packages/fcl-db/src/base/database.inc. What primarily happens is that
> doDisConnect is called.
hummm... ok...
>> and with all of the searching i've done, i still don't see anything that
>> indicates where i can actually lay eyes on the code for TCustomConnection.Close
>> nor do i see anything indicating that it is assigned to another routine going by
>> another name :?
>
> Take a look at TDatabase.DoDisconnect in the same file. It first closes
> all queries which are linked to this dataset, and thereafter it closes
> all transactions.
ok... well, the query is closed by my code after the variables are loaded with
the data... then we attempt to close the connection via a routine that all will
use to close the connection... this routine does two things...
transaction.active := false;
connection.close;
is it enough to set transaction.active:=false? i note there's no
transaction.close... in any case, the error pops up when the connection.close is
called... so, i'd say that, yes, i've closed the query and the transaction
before attempting to close the connection...
also, could it be that because i'm not using a datasource that is causing the
problem?
> So try to close those yourself before you close the database-connection.
> See where it goes wrong...
by the above, i am, aren't i?... in fact, here's code...
MySQLConnection: TMySQL50Connection;
CompanyDataSQLQuery: TSQLQuery;
SQLTransaction: TSQLTransaction;
the CompanyEdit_co_* fields are all TEdits...
procedure TkimsForm.LoadCompanyData(Sender: TObject);
begin
if MySQLConnection.Connected then begin
ShowStatus('Connected #1');
CloseConnection(Sender);
end;
if not MySQLConnection.Connected then ShowStatus('NOT Connected #1');
MySQLConnection.DatabaseName := 'foo';
MySQLConnection.HostName := 'bar';
MySQLConnection.Password := 'fubar';
MySQLConnection.UserName := 'snafu';
ShowStatus('Connecting to database ' + MySQLConnection.DatabaseName + '...');
MySQLConnection.Open;
// If we're connected, retrieve our company info
if MySQLConnection.Connected then begin
ShowStatus('Connected');
ShowStatus('Opening query...');
CompanyDataSQLQuery.Open;
if CompanyDataSQLQuery.Active then begin
CompanyDataSQLQuery.First;
ShowStatus('Query ACTIVE and at first record...');
while not CompanyDataSQLQuery.EOF do begin
ShowStatus('Loading data from row...');
CompanyEdit_co_name.text :=
CompanyDataSQLQuery.FieldByName('co_name').AsString;
CompanyEdit_co_address1.text :=
CompanyDataSQLQuery.FieldByName('co_address1').AsString;
CompanyEdit_co_address2.text :=
CompanyDataSQLQuery.FieldByName('co_address2').AsString;
CompanyEdit_co_city.text :=
CompanyDataSQLQuery.FieldByName('co_city').AsString;
CompanyEdit_co_state.text :=
CompanyDataSQLQuery.FieldByName('co_state').AsString;
CompanyEdit_co_postal.text :=
CompanyDataSQLQuery.FieldByName('co_postal').AsString;
CompanyEdit_co_phone.text :=
CompanyDataSQLQuery.FieldByName('co_phone').AsString;
CompanyEdit_co_fax.text :=
CompanyDataSQLQuery.FieldByName('co_fax').AsString;
CompanyEdit_co_contact.text :=
CompanyDataSQLQuery.FieldByName('co_contact').AsString;
CompanyEdit_co_taxpercent.text :=
CompanyDataSQLQuery.FieldByName('co_taxpercent').AsString;
CompanyEdit_co_commission_rate1.text :=
CompanyDataSQLQuery.FieldByName('co_commission_rate1').AsString;
CompanyEdit_co_commission_rate2.text :=
CompanyDataSQLQuery.FieldByName('co_commission_rate2').AsString;
CompanyEdit_co_commission_percent1.text :=
CompanyDataSQLQuery.FieldByName('co_commission_percent1').AsString;
CompanyEdit_co_commission_percent2.text :=
CompanyDataSQLQuery.FieldByName('co_commission_percent2').AsString;
CompanyDataSQLQuery.Next;
end;
ShowStatus('Closing query...');
CompanyDataSQLQuery.Close;
end;
if not CompanyDataSQLQuery.Active then
ShowStatus('Query NOT ACTIVE');
end;
if MySQLConnection.Connected then begin
ShowStatus('Connected #2');
CloseConnection(Sender);
end;
if not MySQLConnection.Connected then ShowStatus('NOT Connected #2');
end;
procedure TkimsForm.CloseConnection(Sender: TObject);
begin
// The SQLTransaction gets activated automatically, but before we can close
// the connection we have to set the SQLTransaction.Active to false.
if SQLTransaction.Active then begin
ShowStatus('Deactivating SQLTransaction...');
SQLTransaction.Active := False;
SQLTransaction.
end;
if not SQLTransaction.Active then ShowStatus('SQLTransaction NOT Active.')
else ShowStatus('SQLTransaction Active.');
// MySQLConnection.CloseTransactions;
// MySQLConnection.CloseDataSets;
// MySQLConnection.Connected:=False;
if MySQLConnection.Connected then begin
ShowStatus('Closing MySQLConnection...');
MySQLConnection.Close; // <-- error occurs here on first execution
// when error occurs, we do not get to the following lines... ignore the
// error and run LoadCompanyData a second time and the error does not show
// and we DO get to the following with the "MySQLConnection Closed" result...
end;
if not MySQLConnection.Connected then ShowStatus('MySQLConnection Closed.')
else ShowStatus('MySQLConnection NOT Closed!');
end;
procedure TkimsForm.ShowStatus(const S: String);
begin
Memo1.Lines.Add(TimeToStr(now) + ': ' + S);
StatusBar.SimpleText := S;
end;
so, if i'm understanding what you're saying, i should try to use the commented
// MySQLConnection.CloseTransactions;
// MySQLConnection.CloseDataSets;
// MySQLConnection.Connected:=False;
lines instead of the single MySQLConnection.Close option?
>> now i know why i much prefer the old-style procedural coding methods :P
>>
>>> If you get the stack backtrace you can mail it and hope some one knows
>>> about...
>> i still don't know what this involves :(
>
> Run the application in gdb, and when the crash occurs, type 'bt' on the
> gdb-prompt. But you must have the fcl-db package compiled with
> debug-information for it to make any sense. If you really want to try,
> add the fcl-db/src/base fcl-db/src/sqldb fcl-db/src/dbase and
> fcl-db/src/sqldb/mysql paths to your compiler-options path and rebuild
> your application within Lazarus. That way you can 'step' into the fcl-db
> sources...
run it from gdb?? don't know if i know how other than F9 from the GUI... i don't
know that i've seen a gdb command line option in the View menu where i might be
able to type 'bt' but i'll take another look...
i'll definitely take a look at adding those paths for the step option... that
was one of my tricks along with the watch window back in my heavy coding days of
TP/BP stuff :)
BTW: thanks for popping in on this... i was hoping that you would based on
seeing other database related messages from you and also seeing your name in a
bunch of the db related sources ;)
--
NOTE: NEW EMAIL ADDRESS!!
_\/
(@@) Waldo Kitty, Waldo's Place USA
__ooO_( )_Ooo_____________________ telnet://bbs.wpusa.dynip.com
_|_____|_____|_____|_____|_____|_____ http://www.wpusa.dynip.com
____|_____|_____|_____|_____|_____|____ ftp://ftp.wpusa.dynip.com
_|_Eat_SPAM_to_email_me!_YUM!__|_____ wkitty42 -at- windstream.net
---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 090120-0, 01/20/2009
Tested on: 1/20/09 15:29:04
avast! - copyright (c) 1988-2009 ALWIL Software.
http://www.avast.com
More information about the Lazarus
mailing list