[yunqa.de] Re: Autoincrement

  • From: Token PBX <tokenhr@xxxxxxxxx>
  • To: yunqa@xxxxxxxxxxxxx
  • Date: Thu, 5 Feb 2009 08:12:13 +0100

On Wed, Feb 4, 2009 at 8:01 PM, Token PBX <tokenhr@xxxxxxxxx> wrote:

>
>
> 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
>
>
>
>

Hi!

I've solved this problem by removing the key field from the select statement
and grid. But now I have another issue.

Whenever I change/ update fileds of a table and want to apply updates I get
the following error: "unable to find record no key specified"

My application has the same setup as the ClientDataset_Grid project :

Each table has the folowing,

TDISQLite3UniDirQuery
TDataSetProvider
TClientDataSet
TDataSource

No fields are defined at design time.

Please help.

Mihaela MJ.

Other related posts: