when CachedUpdates=True,submission bulletin " Key violation.

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
samin
Posts: 16
Joined: Mon 10 May 2010 03:58

when CachedUpdates=True,submission bulletin " Key violation.

Post by samin » Tue 11 May 2010 08:03

Delphi7, UniDac 3.0.0.8, Win2003, MSSQL2000

create table dbo.tOrderDtl (
nItem numeric(4) not null,
nGoodsID numeric(8) not null,
nOrderQty numeric(16,3) not null default 0
constraint PK_TORDERDTL primary key nonclustered (nItem)
)


my sql is:
select Item = od.nItem,
GoodsID = od.nGoodsID,
OrderQty = od.nOrderQty
from tOrderDtl od
where od.sStoreNO = 'S110'
and od.sPaperNO = 'S110201004145000'

i use a UniQuery,
Set
CachedUpdates := True
LocalUpdate := True
Options.RequiredFields := False;
Options.SetFieldsReadOnly := False;

The path of the control is:
DBGrid-> DataSource-> ClientDataSet-> DataSetProvider-> UniQuery.

When I enter 1 in GoodsID field of the form, then move the cursor to the next line, enter 2 in the GoodsID field,
then move the cursor to the next line again, it pop error: "Key violation."
for it checks the Item fields of two records are both empty and thinks they're repeated.

But now my setting is "CachedUpdate", I don't like to trigger this inspection.

In addition, when DBGrid-> DataSource-> UniQuery, the above operation is well, no error.
And when the DBGrid-> DataSource-> ClientDataSet-> DataSetProvider-> ADOQuery (or BDEQuery), not error either.
I don't know which caused the problem, or where may I set to shield this inspection?

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Tue 11 May 2010 09:50

This problem is caused by the specificity of TClientDataSet and does not depend from UniDAC.

samin
Posts: 16
Joined: Mon 10 May 2010 03:58

Post by samin » Tue 11 May 2010 09:53

But I use ADO or BDE, equally also am do not have the question with CLientDataSet these two kinds

For me Email, I send Demo to give you?

samin
Posts: 16
Joined: Mon 10 May 2010 03:58

Post by samin » Tue 11 May 2010 10:03

I track should be under this method throw
procedure TCustomClientDataSet.InternalPost;
begin
inherited;
if State = dsEdit then
Check(FDSCursor.ModifyRecord(ActiveBuffer)) else
Check(FDSCursor.InsertRecord(ActiveBuffer));

Check(FDSCursor.InsertRecord(ActiveBuffer));

But FDSCursor.InsertRecord is a interface(IDSCursor), did not know that UniDAC does have realizes specifically?

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Tue 11 May 2010 11:16

FDSCursor.InsertRecord doesn't execute any UniQuery methods.
The problem occurs because SQL Server returns key flag for the nItem field, and therefore UniDAC returns this field by the IProviderSupport(DataSet).PSGetKeyFields method. ADO returns empty string by PSGetKeyFields for some obscure reason.

samin
Posts: 16
Joined: Mon 10 May 2010 03:58

Post by samin » Tue 11 May 2010 13:03

But I now CachedUpdates mode, I do not want to appear "Key violation.", Then what should we do?

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Tue 11 May 2010 13:46

This error is generated by TClientDataset and not connected with TUniQuery. To apply changes to database you should call the TClientDataSet.ApplyUpdates method.

samin
Posts: 16
Joined: Mon 10 May 2010 03:58

Post by samin » Tue 11 May 2010 14:01

WOW, I do not need to update this model back to the database, do not need TClientDataSet.ApplyUpdates,
I just used as a entry in the UI interface only,
I just know that I was CachedUpdates mode, I do not want to help me verify what "Key violation"

But I used to connect BDEQuery or ADOQuery ClientDataSet no such problems, we say the "Key violation" has nothing to do with Unidac it?

Give me a little solution? I just want to ignore this check only?

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Wed 12 May 2010 07:53

As I said, this behaviour is determined by TClientDataSet and not TUniQuery. When you change data TUniQuery doesn't check anything. It at all doesn't know about data changes in ClientDataSet. As a proof, when you connect DBGrid to UniQuery without ClientDataSet, the error doesn't occur.

samin
Posts: 16
Joined: Mon 10 May 2010 03:58

Post by samin » Wed 12 May 2010 09:04

Now, I method will make DBAccess.pas PSGetKeyFields the following revision not to spring that to be wrong.

function TCustomDADataSet.PSGetKeyFields: string;
var
i: integer;
KeyFieldDescs: TFieldDescArray;
QO: boolean;
QOInfo: TQuickOpenInfo;

begin
Result := '';
Exit;
...
...

But this question you can provide a switch?

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Wed 12 May 2010 10:04

You can use this revision, but for the standard behaviour this is not a correct solution. You create primary key field and use it as a non-key field (even if you are using local mode).

Hao
Posts: 1
Joined: Tue 30 Nov 2010 06:11

Post by Hao » Tue 07 Dec 2010 00:38

Easy Fix,

Set the keyfields of the Uniquery

Hao

Post Reply