SQLite->id autoincrement

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
albourgz
Posts: 147
Joined: Wed 06 May 2009 12:17
Location: belgium

SQLite->id autoincrement

Post by albourgz » Tue 28 Apr 2020 19:59

Hi,
using c++ builder 10.3.2/vcl/win32/unidac 8.1.2/direct mode.

In db:

Code: Select all

create table LIBELLES (id integer primary key autoincrement not null, libelle nvarchar(50), categ nvarchar(10), seq integer);
sqllite allows this:

Code: Select all

insert into libelles(libelle,categ, seq) values ('aaa','bbb',1);
insert into libelles(id, libelle,categ, seq) values (null, 'aaa','bbb',1);
Each time, an id is automatically allocated.

In c++ builder, I have a TUniQuery and a TDBNavigator
UniQuery1.SQL:

Code: Select all

SELECT ID, LIBELLE 
FROM LIBELLES
WHERE Categ=:CATEG
ORDER BY SEQ, LIBELLE
UniQuery1.SQLInsert:

Code: Select all

INSERT INTO LIBELLES
  (libelle, categ, seq)
VALUES
  (:libelle, :categ, :seq)
When I insert a row, I get an exception:
Project pTSheet.exe raised exception class EDatabaseError with message 'Field 'id' must have a value'.
How can I ignore this error as an autoincremented is created by db?
Regards.

MaximG
Devart Team
Posts: 1437
Joined: Mon 06 Jul 2015 11:34

Re: SQLite->id autoincrement

Post by MaximG » Wed 29 Apr 2020 10:33

To get auto-increment fields automatically, you can choose between:

- disabling the option RequiredFields :

Code: Select all

 UniQuery1->Options->RequiredFields = false;
- assigning the false value to the "id" field in the Required property:

Code: Select all

UniQuery1->FieldByName("id")->Required = false;

Post Reply