SQLite Autoincrement issue

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
swierzbicki
Posts: 451
Joined: Wed 19 Jan 2005 09:59

SQLite Autoincrement issue

Post by swierzbicki » Mon 03 Nov 2014 19:12

Hello,

I'm getting an error Each time I want to insert a new record on my table.
SQLite is complaining about my autoincrement field that can't be null.

Here is my table structure :

Code: Select all

CREATE TABLE Etiquettes (
  Id_Etiquette        integer NOT NULL PRIMARY KEY AUTOINCREMENT,
  Id_Fournisseur      varchar(10),
  Id_Lot_Fournisseur  varchar(12),
  Compteur            varchar(6),
  Id_Matiere          varchar(6),
  Longueur            varchar(6),
  Date_Creation       datetime,
  Date_Impression     datetime,
  Quantite            integer,
  PCB                 integer
);
Here is my connection object :

Code: Select all

object UniConnection1: TUniConnection
  ProviderName = 'SQLite'
  Database = 
    '\Database.db3'
  SpecificOptions.Strings = (
    'SQLite.UseUnicode=True')
  Options.KeepDesignConnected = False
  Connected = True
  LoginPrompt = False
  Left = 72
  Top = 192
end
Here is my Dataset object :

Code: Select all

object qrEtiquettes: TUniQuery
  Connection = UniConnection1
  SQL.Strings = (
    'select * from Etiquettes')
  Left = 352
  Top = 120
end
And finally my code :

Code: Select all

     qrEtiquettes.append;
      qrEtiquettes.FieldByName('Date_Creation').AsDateTime := now;
      qrEtiquettes.FieldByName('Id_Lot_Fournisseur').asString := edtlot.Text;
      qrEtiquettes.FieldByName('Id_Fournisseur').AsString := 'TEST';
      qrEtiquettes.FieldByName('Longueur').asString := StrPadLeft(inttostr((trunc(speditQuantite.Value) * 100) + I),6,'0');
      qrEtiquettes.FieldByName('Compteur').asString := StrPadLeft(inttostr(dernierCompteur + I),6,'0');
      qrEtiquettes.FieldByName('Quantite').asinteger := qte;

      qrEtiquettes.Post;
As you can see, I don't even set my autoincrement field !
What is wrong ?

Server version: 3.8.7

Client version: 3.8.7

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

Re: SQLite Autoincrement issue

Post by AlexP » Tue 04 Nov 2014 06:14

Hello,

This error is due to that the NOT NULL attribute is set in the DDL definition of your auto-incremental field. In the new version, we process this attribute correctly and set the Required property to True for such fields. To solve the problem, you should remove the NOT NULL attribute from the DDL (this attribute is not need for auto-incremental fields), or set the UniQuery1.Options.RequiredFields property to false.

swierzbicki
Posts: 451
Joined: Wed 19 Jan 2005 09:59

Re: SQLite Autoincrement issue

Post by swierzbicki » Wed 12 Nov 2014 09:49

Thank you. I have removed my "NOT NULL" attribute

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

Re: SQLite Autoincrement issue

Post by AlexP » Wed 12 Nov 2014 10:23

If you have any further questions, feel free to contact us.

Post Reply