Recent

Author Topic: [SOLVED] Is it possible to use parameters with ExecuteDirect?  (Read 2043 times)

guest48180

  • Guest
I have a lot of text fields on a form. One of them is txt_Recipe_Name. I can't find documentation through the Forum Search or anywhere else on how to use parameters with ExecuteDirect. I can use them with SQLQuery but not with ExecuteDirect. Is it possible to use parameters with ExecuteDirect? Or is there another way to accomplish an Insert on a table and be able to write my form data to the table fields?

This is what I have that I can't figure out how to make work:
Code: Pascal  [Select][+][-]
  1. SQLite3Connection1.ExecuteDirect('INSERT INTO recipe_names(name) VALUES(:r_name);');
How can I set :r_name to a text field (TEdit field) on my form?

For a SELECT statement, this works nicely:
Code: Pascal  [Select][+][-]
  1. SQLQuery2.SQL.Text:='SELECT * FROM recipe_ingredients WHERE name_id = :id';
  2. SQLQuery2.ParamByName('id').AsInteger:=SQLQuery1.FieldByName('name_id').AsInteger;

I use Prepared statements in PHP for all my MariaDB queries. But I can't find information on how to use them on databases within Lazarus. A wiki maybe?  :)

In any case, my main concern is being able to use data on my form to INSERT INTO an SQLite3 db. Anyone?

guest48180

  • Guest
Re: Is it possible to use parameters with ExecuteDirect?
« Reply #1 on: May 31, 2018, 07:56:13 am »
Thank you, Juassic Park. All I've seen used on CREATE, INSERT, and UPDATE was ExecuteDirect. Your answer showed me different. Thanks.

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: [SOLVED] Is it possible to use parameters with ExecuteDirect?
« Reply #2 on: May 31, 2018, 09:13:03 am »
which answer?
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

guest48180

  • Guest
Re: [SOLVED] Is it possible to use parameters with ExecuteDirect?
« Reply #3 on: May 31, 2018, 09:49:11 am »
In the link @answer here and in my above post.

kapibara

  • Hero Member
  • *****
  • Posts: 610
Re: [SOLVED] Is it possible to use parameters with ExecuteDirect?
« Reply #4 on: May 31, 2018, 11:59:19 am »
Lazarus trunk / fpc 3.2.2 / Kubuntu 22.04 - 64 bit

guest48180

  • Guest
Re: [SOLVED] Is it possible to use parameters with ExecuteDirect?
« Reply #5 on: May 31, 2018, 12:15:12 pm »
Quote
ExecuteDirect does not offer support for parameters, so only statements that do not need parsing and parameters substitution can be handled. If parameter substitution is required, use a TSQLQuery component and its ExecSQL method.

Thanks, kapibara.

 

TinyPortal © 2005-2018