Postgresql Provider SequenceMode=smPost bug ?

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
asamkaskus
Posts: 5
Joined: Wed 07 Aug 2013 15:40

Postgresql Provider SequenceMode=smPost bug ?

Post by asamkaskus » Fri 31 Oct 2014 09:07

Hi

I'm using UniDAC express with PostgresqlDAC trial.
With TUniQuery.SpecificOptions.SequenceMode = smPost, I'm expecting the primary key field ( Id, type autoincrement, primary key ), would only be given when I TUniQuery.post a record.
But what really happend is, it actually issuing a SELECT nextval ( monitored with SQLMonitor ) when I issue TUniQuery.Append and I got the current Id before posting.

I hope it is a bug.

Anybody experience this ?

Thanks
Andy

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Postgresql Provider SequenceMode=smPost bug ?

Post by azyk » Fri 31 Oct 2014 11:19

Unfortunately we couldn't reproduce the problem as you have described it. Please, try to compose a small sample to demonstrate the problem including a script to create test tables and send it to andreyz*devart*com .

asamkaskus
Posts: 5
Joined: Wed 07 Aug 2013 15:40

Re: Postgresql Provider SequenceMode=smPost bug ?

Post by asamkaskus » Fri 31 Oct 2014 13:34

Let me discribe this simple program.

Tabl1 in Postgresql,
Primary key Id, autoincrement ( serial ).

In Delphi :
- Put TUniCOnnection, TPostgreqlUniProvider, TUniQuery and TUniDataSource
- Set TUniConnection.AutoCommit = FALSE
- Connect to the database
- Set TUniQuery.SpecificOptions.SequenceMode=smPost
- Set TUniQuery.Options.DefaultValues := TRUE
- TUniQuery SQL is set to 'SELECT * FROM Table1 WHERE Id=:iId', generate the other SQL, then set it to Active = TRUE
- Put a TDBEdit, pointing to Table1.Id
- Put a button, when pressed, just issue TUniQuery.Append;
- You can see when the button is pressed, TDBEdit displays a value ( while we haven't issue TUniQuery.Post ).

I hope you can reproduce the problem.

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Postgresql Provider SequenceMode=smPost bug ?

Post by azyk » Mon 03 Nov 2014 09:25

In your sample, you are setting the TUniQuery.Options.DefaultValues property to True. This means that the dataset requests values for the Id field from the server, since values for this field are set on the server side. Such behavior is correct. More details about the DefaultValues property can be found in our online documentation: http://www.devart.com/unidac/docs/index ... values.htm

asamkaskus
Posts: 5
Joined: Wed 07 Aug 2013 15:40

Re: Postgresql Provider SequenceMode=smPost bug ?

Post by asamkaskus » Tue 04 Nov 2014 12:47

thank you for your answer azyk.

If so, then how can I set the Id to received value upon posting the record, while maintaining all other field's default values ? I got other fields such as ctr, status, etc each with its own default values.

asamkaskus
Posts: 5
Joined: Wed 07 Aug 2013 15:40

Re: Postgresql Provider SequenceMode=smPost bug ?

Post by asamkaskus » Wed 05 Nov 2014 03:42

as comparison, IBDAC can you this feature as I needed.
I can see defaultvalues as true, and still can have the autoincrement Id as smPost mode with no error.

I haven't tried PgDAC.

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

Re: Postgresql Provider SequenceMode=smPost bug ?

Post by AlexP » Wed 05 Nov 2014 05:15

When creating a field with the Serial type, PostgreSQL creates a sequence and assigns it as the default field value, therefore we fill in this field value. To avoid this behavior, you can use the usual integer type instead of the serial type, fill in it using the trigger function with a sequence

asamkaskus
Posts: 5
Joined: Wed 07 Aug 2013 15:40

Re: Postgresql Provider SequenceMode=smPost bug ?

Post by asamkaskus » Wed 05 Nov 2014 08:52

thank you AlexP

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

Re: Postgresql Provider SequenceMode=smPost bug ?

Post by AlexP » Wed 05 Nov 2014 09:03

You are welcome. Feel free to contact us if you have any further questions

Post Reply