Page 1 of 1

How to call SQLite Insert query?

Posted: Thu 07 Jul 2011 12:19
by stevel
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?

Posted: Thu 07 Jul 2011 13:21
by AlexP
Hello,

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

Posted: Thu 07 Jul 2011 13:35
by stevel
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

Posted: Thu 07 Jul 2011 13:46
by stevel
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.

Posted: Fri 08 Jul 2011 10:46
by AlexP
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;