SQLite AUTOINCREMENT Error mit UniDac TUniQuery

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Dstein
Posts: 2
Joined: Sat 07 Apr 2018 11:02

SQLite AUTOINCREMENT Error mit UniDac TUniQuery

Post by Dstein » Thu 16 Sep 2021 07:05

When creating a small Windows 32-bit app with SQLite as the daba, I get an error message.
When an insert is executed via dbNavigator and dbNavigator POST is saved, the error message occurs.
An exception of class EDatabaseError has occurred in project XYZ with the message Feld IDNR must have a value.
The annoying thing for me, I have written several apps based on SQLite before 2020, which are working without any problem even now. But all current projects generate the same error.
I have tried various settings and versions from unidac75d25proV7.5.13 to the current unidac_9.0.1_d25pro version. Also tried different sqlite3.dll (sqlite3_3.23.1.dll, sqlite3_3.35.5.dll, sqlite3_3.8.10.2.dll) versions in cross tests. After weeks of trying, I give up, I can't find the cause or wrong parameter, for the error message.
DevEnvironment:
- Delphi 10.2.3 2631 Tokyo Enterprise Build 2004 (11/03/2018), Delphi 10.2 Release 3.
- Universal Data Access Components, UniDac Professional License
- SQLite.dll Version 3.35.5

To minimize cross behavior, I wrote attached testapp as absolute simple project.
The app creates a SQLite database (existing one is deleted before) and creates via TUniScript a table with two fields, index and fills the table with two records.

CREATE TABLE Test (
IDNR INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL,
Betreff VARCHAR (100) COLLATE NOCASE);
CREATE INDEX pkIDNR ON Test (IDNR ASC);
INSERT INTO Test (Betreff) VALUES ('Betreff 11');
INSERT INTO Test (Betreff) VALUES ('Betreff 22');

Since by script "INSERT INTO Test (Subject) VALUES ('Subject 11');" a record with AUTOINCREMENT value can be created, the database and INCREMENT method probably works.

Access to the table is done with TUniQuery. Whereas with SQL Generator the insert script is different than with MS SQL.
// SQLite
INSERT INTO Test
(IDNR, Betreff)
VALUES
(:IDNR, :Betreff)

// MS SQL
INSERT INTO dbo.Test
(Betreff)
VALUES
(:Betreff)
SET :IDNR = SCOPE_IDENTITY()

But why does the simple insert via dbNavigator not work. When comparing old SQL-InsertSource and current SQL-InsertSource I could not find any difference.
Does anyone have an idea where my thinking error or missing parameter is?

Dstein
Posts: 2
Joined: Sat 07 Apr 2018 11:02

Re: SQLite AUTOINCREMENT Error mit UniDac TUniQuery

Post by Dstein » Fri 17 Sep 2021 17:28

I think I have found the cause.
The Required option in the IDNR field must be False!

UniQuery1->Options->RequiredFields = false;

At least the error message is gone and the AUTOINCREMENT works.
This is different from the MS SQL provider.

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

Re: SQLite AUTOINCREMENT Error mit UniDac TUniQuery

Post by MaximG » Mon 20 Sep 2021 19:14

Yes, this is the correct procedure to resolve the issue. Feel free to contact us if you have any questions.

Post Reply