Page 1 of 1

Error when I <DELETE FROM TABLE>

Posted: 09.05.2009, 14:50
by Cocky
Hi,
I am using stable version of ZEOS 6.6.4 for Lazarus with Firebird 2.1 stable (embedded). I have TZConnection (=ZCon1) and a TZQuerry (=ZQ1) both created at design time. Further I have a TMemo (=Memo1) to write some SQL statements and a Button (=Button1) to submit and execute with the following code:

Code: Select all

procedure TForm1.Button1Click(Sender : TObject);
begin
   ZCon1.Connect;
   ZQ1.SQL.Clear;
   ZQ1.SQL.Text := Memo1.Text;
   if not ZQ1.Active then ZQ1.Active := True;
   lblSelRecCount.Caption :=  IntToStr(ZQ1.RecordCount);
   lblSelActRecNr.Caption :=  IntToStr(ZQ1.RecNo);
   lblRecSize.Caption     :=  IntToStr(ZQ1.RecordSize);
   ZQ1.ExecSQL;
   ZCon1.Disconnect;
end;
Everything works fine (Select some records and so on). Except when I try to delete some records this way. E.g. with the SQL statement "DELETE FROM TESTTABLE". Then I get the following error message:

"Project raised exception class 'EZSQLException' with message: Cannot retrieve Resultset data"

I am not very familar with ZEOS or SQL. So could someone give me an idea what the cause is for this exception ?

Cocky

(P.S. my english skills are also poor ;))

Posted: 10.05.2009, 16:32
by Cocky
I am a little disappointed that nobody is able to help me with that. Meanwhile I know that it has to do with TDataset.Active property. It seems that the "DELETE" statement has no result. Therefor no Resultdata are created.

I would have been happy for every link, tipp or hint information. But it seems most of you would see it as a waste of time to help a newbie on his feets getting started with zeos engine ...

cu :(

Posted: 10.05.2009, 20:32
by mdaems
if not ZQ1.Active then ZQ1.Active := True;
This is the line that's wrong for your query. Setting a ZQuery Active is the same as opening it. And opening a resultset for a delete statement is useless.
So you actually need 2 buttons in your program to avoid this problem: Execute and Open. (Or a parser that decides for you which action to take) If you expect a resultset you should Open the query (or set it Active). If you don't expect a resultset use ExecSQL.

Concerning
But it seems most of you would see it as a waste of time to help a newbie on his feets getting started with zeos engine ...
Just have a look at the number of posts per day on these forums. It's about 6 and we're in the middle of the weekend. Please, a little patience can do miracles. Just check other posts to see Newbies are really helped when possible.

Mark

Posted: 11.05.2009, 18:11
by Cocky
Thank you very much for your answer mdaems ! :)

please dont get me wrong ... I tryed to solve that problem for about 3 days. I googled and used all the zeos/delphi sources I know. Finaly I was nearly about to throw the whole sql (and zeos-) stuff into the next trash. Maybe I got a little too nervous ... please forgive me for that ;)

Back to topic ... with the sample above I tryed to code a simple sql interpreter just by using a memo field and do an 'ExecSQL'. If I right understood this is not possible because I first have to decide to execute the sql statement with 'ExecSQL' OR with 'Open' method ?

[s]But if I try to execute a SQL statement (e.g. SELECT) wich has a resultset by using 'ExecSQL' it seems to work too. At least it throws no error message and .RecordCount, .RecNo and .RecordSize are shown ... :shock: [/s] //EDIT: does not work !

[s]What I want to ask ... is it possible to indicate somehow if a Resultset was created or not ?[/s]

Thanks in advance

Cocky

Posted: 13.05.2009, 19:30
by mdaems
If I right understood this is not possible because I first have to decide to execute the sql statement with 'ExecSQL' OR with 'Open' method ?
That's exactly your problem. Or you could just catch the EZSQLException and ignore it (just this one of course).
But maybe the easiest way to make the decision automatically is just searching for the SELECT keyword at the start of the query string. If it's there : use Open, otherwise just ExecSQL.

BTW : ExecSQL will probably work on a Select query, but will NOT show a resultset. So that won't help you.

Mark