How to call SQLite Insert query?

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
stevel
Posts: 125
Joined: Tue 02 Nov 2010 19:01

How to call SQLite Insert query?

Post by stevel » Thu 07 Jul 2011 12:19

I have defined a query in SQLite database. Its an INSERT query with input parameters. This is defined in the database.

With UniDAC, how can I pass parameters to and run this query?

or is it not possible and the only possibilities are to use UniQuery with INSERT statement in the SQL or UniConnection.ExceSQL with INSERT statement?

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Thu 07 Jul 2011 13:21

Hello,

Please specify what you mean by "defined a query in SQLite database" and give us an example.

stevel
Posts: 125
Joined: Tue 02 Nov 2010 19:01

Post by stevel » Thu 07 Jul 2011 13:35

I created a query inside the database using a database administration tool. (Like same way you create stored procedures in SQL Server, MySQL or Firebird)

Image:
Image

stevel
Posts: 125
Joined: Tue 02 Nov 2010 19:01

Post by stevel » Thu 07 Jul 2011 13:46

Sorry about this. Upon further investigation I found that SQLite does not support queries, and that the query that was created is created and saved inside the administration tool.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Fri 08 Jul 2011 10:46

Hello,


Databases does not support “storing the INSERT statements”. Many databases use stored procedures and functions for this purpose, however SQLite does not support this feature. Thats why you should use parameterized queries with such UniDAC components as UniQuery or UniSQL.

For example:

Code: Select all

var
  UniQuery: TUniQuery;
begin
  UniQuery:= TUniQuery.Create(nil);
  UniQuery.Connection := UniConnection1;
  UniQuery.Sql.Text := 'INSERT INTO T_TEST(F_ID, F_DATE) VALUES(:ID, :DATE)';
  UniQuery.Prepare;
  UniQuery.ParamByName('ID').DataType := ftInteger;
  UniQuery.ParamByName('ID').ParamType := ptInput;
  UniQuery.ParamByName('BILLDATE').DataType := ftInteger;
  UniQuery.ParamByName('BILLDATE').ParamType := ptInput;
  UniQuery.ParamByName('ID').AsInteger := 1;
  UniQuery.ParamByName('BILLDATE').AsDate := now;
  UniQuery.Execute;

Post Reply