Recent

Author Topic: SQLQUERY Active:=False / Active = True  (Read 350 times)

zilez2003

  • New member
  • *
  • Posts: 9
SQLQUERY Active:=False / Active = True
« on: April 14, 2022, 09:29:00 am »
Hi Everyone,

I made small app which connects to Firebird databases.

I use SQLQuery3 to provide parameter to SQLQuery4. Source looks like this :

SQLQuery4.Active:=False;
SQLQuery4.Prepare;
SQLQuery4.ParamByName('type').value:=SQLQuery3.FieldByName('type').value;
SQLQuery4.Active:=True;

When I first time execute this code, everything is fine. But, when I try to execute it second time (After changing selected row in SQLQuery3) i receive error ->

"Access violation

Press OK to ignore and risk data corruption.
Press abort to kill a program"

This error is raised on the row ->

SQLQuery4.Active:=True;


I am not sure what causes this, as I used this code in Delphi long time ago without any problems.

Would appreciate if someone could help.
« Last Edit: April 14, 2022, 09:34:55 am by zilez2003 »

af0815

  • Hero Member
  • *****
  • Posts: 996
Re: SQLQUERY Active:=False / Active = True
« Reply #1 on: April 14, 2022, 09:39:00 am »
One major point: Lazarus is NOT Delphi - Lazarus is __most__ sourcecode compatible in mode Delphi, but it is not Delphi !

The code show nothing about the used queries.

Code: Pascal  [Select][+][-]
  1. SQLQuery4.ParamByName('type').value:=SQLQuery3.FieldByName('type').value;
split this line and use a variable to see if it is comming from SQLQuery3 with wrong or a error in SQLQuery3. Maybe on the second try the parameter is not ok.

Another point of failure is, you corrupt in the meantime your SQL-Statements.

BTW: For such chaining often a master/slave Query is used. So the slaver query can read new datas if the row of the master is changed automatic. For SQLdb based queries. If you use componnets for the IB Connection it may be different.

« Last Edit: April 14, 2022, 09:41:44 am by af0815 »
regards
Andreas

zilez2003

  • New member
  • *
  • Posts: 9
Re: SQLQUERY Active:=False / Active = True
« Reply #2 on: April 14, 2022, 05:35:37 pm »
Thanks for your reply - problem solved using master-detail relationship via dataset property of SQLQuery.
I understand that Lazarus is not Delphi, but I don't understand why closing and reopening same query causes such error as described. 

wp

  • Hero Member
  • *****
  • Posts: 9923
Re: SQLQUERY Active:=False / Active = True
« Reply #3 on: April 14, 2022, 05:46:50 pm »
I don't understand why closing and reopening same query causes such error as described.
Yes, that's strange... Could you prepare a small project showing the issue? Pack .pas, .lfm, .lpi, and .lpr files, as well as the sqlite database file (unless it's created by the project) into a common zip and upload it via "Attachments and other options".

af0815

  • Hero Member
  • *****
  • Posts: 996
Re: SQLQUERY Active:=False / Active = True
« Reply #4 on: April 14, 2022, 06:07:59 pm »
...but I don't understand why closing and reopening same query causes such error as described. 
This message is unspecific.
One Problem can be, the parameter is not valid, because the dataset of SQLquery3 is lost. You can try to catch an exception on the SQLQuery4.Active:=True; Statement and look if your IBComponnets deliver a description of the problem. If this works, depends on the component. If i catch the exception on my SQLDB-Query i got the message from the server in the exception.
   
regards
Andreas

 

TinyPortal © 2005-2018