Page 1 of 1

SQLite Autoincrement issue

Posted: Mon 03 Nov 2014 19:12
by swierzbicki
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

Re: SQLite Autoincrement issue

Posted: Tue 04 Nov 2014 06:14
by AlexP
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.

Re: SQLite Autoincrement issue

Posted: Wed 12 Nov 2014 09:49
by swierzbicki
Thank you. I have removed my "NOT NULL" attribute

Re: SQLite Autoincrement issue

Posted: Wed 12 Nov 2014 10:23
by AlexP
If you have any further questions, feel free to contact us.