Page 1 of 1

SQLite->id autoincrement

Posted: Tue 28 Apr 2020 19:59
by albourgz
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.

Re: SQLite->id autoincrement

Posted: Wed 29 Apr 2020 10:33
by MaximG
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;