Postgresql Provider SequenceMode=smPost bug ?
-
asamkaskus
- Posts: 5
- Joined: Wed 07 Aug 2013 15:40
Postgresql Provider SequenceMode=smPost bug ?
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
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
Re: Postgresql Provider SequenceMode=smPost bug ?
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 ?
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.
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.
Re: Postgresql Provider SequenceMode=smPost bug ?
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 ?
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.
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 ?
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.
I can see defaultvalues as true, and still can have the autoincrement Id as smPost mode with no error.
I haven't tried PgDAC.
Re: Postgresql Provider SequenceMode=smPost bug ?
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 ?
thank you AlexP
Re: Postgresql Provider SequenceMode=smPost bug ?
You are welcome. Feel free to contact us if you have any further questions