Recent

Author Topic: [SOLVED] Why this SQL isn't prepared?  (Read 368 times)

egsuh

  • Sr. Member
  • ****
  • Posts: 397
[SOLVED] Why this SQL isn't prepared?
« on: June 02, 2020, 08:43:00 am »
Hello,

Please look into the following statements. This SQL works well if I directly execute it within Firebird, e.g. through FlameRobin, etc.

But in Lazarus, the "Prepare" command is not executed.
I cannot find any reason. What would be possible reasons?

Code: Pascal  [Select][+][-]
  1.  with qr2 do begin
  2.       Close;
  3.       SQL.Clear;
  4.       SQL.Text := 'insert into SampleList ';
  5.       SQL.Add('(project_id, solicitor_id, respondent_id, keycode, email, pw, interviewer_id, status) ');
  6.       SQL.Add(' values (:pid, :sid, :rid, :kc, :em, :pw, :iid, :ss)');
  7.       SQL.Add(' returning respondent_id');
  8.  
  9.       Log(sql.text);
  10.  
  11.       Prepare;
  12.       Log('prepared');  
« Last Edit: June 02, 2020, 10:56:08 am by egsuh »

rvk

  • Hero Member
  • *****
  • Posts: 4189
Re: Why this SQL isn't prepared?
« Reply #1 on: June 02, 2020, 08:49:40 am »
How do you know, from the code shown, that the statement isn't prepared?

egsuh

  • Sr. Member
  • ****
  • Posts: 397
Re: Why this SQL isn't prepared?
« Reply #2 on: June 02, 2020, 08:58:33 am »
Ah..  the procedure Log writes the string to a file. SQL.Text is logged, but 'prepared' not.


rvk

  • Hero Member
  • *****
  • Posts: 4189
Re: Why this SQL isn't prepared?
« Reply #3 on: June 02, 2020, 09:01:47 am »
Ah..  the procedure Log writes the string to a file. SQL.Text is logged, but 'prepared' not.
You've shown too little code.

If this is your exact code, all lines should be executed.
Unless Log(sql.text) gives an exception.
(Or prepare gives an exception because of an error in the sql.text)

Zvoni

  • Sr. Member
  • ****
  • Posts: 373
Re: Why this SQL isn't prepared?
« Reply #4 on: June 02, 2020, 10:32:18 am »
Out of curiosity:
How can an SQL-Statement be prepared with unset parameters?
One System to rule them all, One IDE to find them,
One Code to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
People call me crazy, because i'm jumping out of perfectly fine aircrafts

rvk

  • Hero Member
  • *****
  • Posts: 4189
Re: Why this SQL isn't prepared?
« Reply #5 on: June 02, 2020, 10:41:39 am »
Out of curiosity:
How can an SQL-Statement be prepared with unset parameters?
With "unset parameters"? What's an unset parameter.

Prepare is best used with a parameterized statement which executes multiple times. It doesn't do much for a single statement because internally there a prepare is always done automatically.

Also see
https://firebirdsql.org/file/documentation/third_party_docs/Make%2520Interbase%2520Scream.pdf

egsuh

  • Sr. Member
  • ****
  • Posts: 397
Re: Why this SQL isn't prepared?
« Reply #6 on: June 02, 2020, 10:55:55 am »
I found the reason ... when there is a field name not in the table, the sql is not prepared.
That is, field pw was not in the table samplelist.

Well I thought that in that case, the exception would be raised at the "opening" stage.

rvk

  • Hero Member
  • *****
  • Posts: 4189
Re: Why this SQL isn't prepared?
« Reply #7 on: June 02, 2020, 10:59:06 am »
Well I thought that in that case, the exception would be raised at the "opening" stage.
Yes, there should have been an exception.
But maybe your 'eating' that exception at a higher level.

You could build a try/except/showmessage around the prepare to make sure.

 

TinyPortal © 2005-2018