Recent

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

Landslyde

  • Full Member
  • ***
  • Posts: 163
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?
« Last Edit: May 31, 2018, 07:56:37 am by Landslyde »
Linux Mint 19
Lazarus 1.8.4
FPC 3.0.4

Landslyde

  • Full Member
  • ***
  • Posts: 163
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.
Linux Mint 19
Lazarus 1.8.4
FPC 3.0.4

mangakissa

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

Landslyde

  • Full Member
  • ***
  • Posts: 163
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.
Linux Mint 19
Lazarus 1.8.4
FPC 3.0.4

kapibara

  • Sr. Member
  • ****
  • Posts: 493
Re: [SOLVED] Is it possible to use parameters with ExecuteDirect?
« Reply #4 on: May 31, 2018, 11:59:19 am »
Lazarus trunk / fpc 3.0.4 / Debian Stretch 64-bit

Landslyde

  • Full Member
  • ***
  • Posts: 163
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.
Linux Mint 19
Lazarus 1.8.4
FPC 3.0.4