Page 1 of 1

when CachedUpdates=True,submission bulletin " Key violation.

Posted: Tue 11 May 2010 08:03
by samin
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?

Posted: Tue 11 May 2010 09:50
by Dimon
This problem is caused by the specificity of TClientDataSet and does not depend from UniDAC.

Posted: Tue 11 May 2010 09:53
by samin
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?

Posted: Tue 11 May 2010 10:03
by samin
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?

Posted: Tue 11 May 2010 11:16
by Dimon
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.

Posted: Tue 11 May 2010 13:03
by samin
But I now CachedUpdates mode, I do not want to appear "Key violation.", Then what should we do?

Posted: Tue 11 May 2010 13:46
by Dimon
This error is generated by TClientDataset and not connected with TUniQuery. To apply changes to database you should call the TClientDataSet.ApplyUpdates method.

Posted: Tue 11 May 2010 14:01
by samin
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?

Posted: Wed 12 May 2010 07:53
by Dimon
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.

Posted: Wed 12 May 2010 09:04
by samin
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?

Posted: Wed 12 May 2010 10:04
by Dimon
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).

Posted: Tue 07 Dec 2010 00:38
by Hao
Easy Fix,

Set the keyfields of the Uniquery

Hao