[yunqa.de] Re: Autoincrement

  • From: Token PBX <tokenhr@xxxxxxxxx>
  • To: yunqa@xxxxxxxxxxxxx
  • Date: Wed, 4 Feb 2009 20:01:21 +0100

On Wed, Feb 4, 2009 at 3:40 PM, Delphi Inspiration <delphi@xxxxxxxx> wrote:

> Hello Mihaela,
>
> >I'm having problems with autoincrement fields.
> >I defined by table's key field as "id" INTEGER PRIMARY KEY AUTOINCREMENT
> >I'm using it in Delphi 2009 with TClientDataset just like the example with
> clientdataset grid.
>
> In order to reproduce your problem, I added the AUTOINCREMENT keyword to
> the create table statement in DISQLite3_ClientDataSet_Grid_Form_Main.pas:
>
>  DISQLite3Database.Execute(
>    'CREATE TABLE IF NOT EXISTS Products(' +
>    '"ID" INTEGER PRIMARY KEY AUTOINCREMENT,' +
>    '"Name" TEXT)');
>
> >The problem that I'm having is that when I'm adding new records  with a
> grid
> >(not using the api,  but with DeveloperExpress grid) then the
> autoincrement key field doesn't get incremented buy SQLite3  but my id filed
> is left
> >empty. Therefore I nedded to implement a "OnNewRecord" evet of
> TClientDataset to provide the value for id field. I tried
> Disqlite3database.LastInsertRowID function but it always returns zero.
>
> Unfortunately I can not reproduce your findings. Inserting a new record
> using the grid automatically fills the ID column as well.
>
> Ccan you please provide a simple example project (source code, no binaries,
> standard Delphi components only) so I can see what and why it is not working
> for you?
>
> Ralf
>
> _______________________________________________
> Delphi Inspiration mailing list
> yunqa@xxxxxxxxxxxxx
> //www.freelists.org/list/yunqa
>

Hi!
I just loaded The ClientDataset_Grid project in Delphi 2009, and changed the
table create command as you suggested. I also added the "ID" field in the
select stament. So the situation now is:

CREATE:

    DISQLite3Database.Execute(
      'CREATE TABLE IF NOT EXISTS Products(' +
      '"ID" INTEGER PRIMARY KEY AUTOINCREMENT,' +
      '"Name" TEXT)');

SELECT:

  DISQLite3UniDirQuery.SelectSQL := 'SELECT ID, Name FROM Products';

And the problem is still present.
When new record is added the ID filed is empty and after adding another
record the "Key Violatin" exception gets thrown.

Thanks for your quick reply and please help again.

My Best Regards.

Mihaela Mihaljevic Jakic
mihaela@xxxxxxxx

Other related posts: