crbatchmove duplicate key

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
lao
Posts: 71
Joined: Wed 10 Dec 2008 10:56

crbatchmove duplicate key

Post by lao » Thu 13 Jun 2013 15:40

Hi,
i try to use crbatchmove to copy about 1500 rows from table a on the server to table a on localhost.
postgresql database 9.1.
if tables have a primary key with 2 fields( first is timestamp and second varchar) when i use crbatchmove in mode appendupdate and (abortononkeyviol and abortonproblem =true)
i have a key violation( he does not found the key for update and try to insert new record.
if i move less than 1000 record it work.
Regards

DemetrionQ
Devart Team
Posts: 271
Joined: Wed 23 Jan 2013 11:21

Re: crbatchmove duplicate key

Post by DemetrionQ » Fri 14 Jun 2013 15:01

Hello.

    When working with data of TimeStamp fields, the TDateTime type is used, which is the Double type. The problem is in the specificity of work with floating-point types ( http://docwiki.embarcadero.com/RADStudi ... ing_Issues ). Therefore, in some cases, it is impossible to identify a record uniquely, if a TimeStamp field is used as a key field, and a "Key violation" error appear. To solve the problem you can use the following approaches:

 * Use data type mapping and map TimeStamp to String. You can do it with the following code:

Code: Select all

uses PgDataTypeMapUni;
...
UniConnection1.DataTypeMap.AddDBTypeRule(pgTimeStamp,ftString);
UniConnection1.DataTypeMap.AddDBTypeRule(pgTimeStampWithTimeZone,ftString);
 * Use Integer fields for primary key creation.

lao
Posts: 71
Joined: Wed 10 Dec 2008 10:56

Re: crbatchmove duplicate key

Post by lao » Fri 14 Jun 2013 15:21

hi DemetrionQ,
thank you for your response.
i try to map fields but does not resolv the problem.
i need to use timestamp as unique index.

any help will be welcome.
thanks

lao
Posts: 71
Joined: Wed 10 Dec 2008 10:56

Re: crbatchmove duplicate key

Post by lao » Tue 18 Jun 2013 08:51

Hi,
i resolved the problem by changing this in crbatchmove.pas

function TUniBatchMove.GetKeyValues: Variant;
var
i: integer;
begin
for i := 0 to FDestCountKeys - 1 do
begin
if FSrcKeyFields <> nil then
begin
if FSrcKeyFields.DataType=ftDateTime then
FKeyValues := FSrcKeyFields.AsString

else FKeyValues := FSrcKeyFields.AsVariant;
end
else
FKeyValues := ''
end;

if FDestCountKeys > 1 then
Result := VarArrayOf(FKeyValues)
else
if FDestCountKeys > 0 then
Result := FKeyValues[0]
else
Result := Null;
end;


UniConnection1.DataTypeMap.AddDBTypeRule(pgTimeStamp,ftString);
UniConnection1.DataTypeMap.AddDBTypeRule(pgTimeStampWithTimeZone,ftString);
does not work because the field type is recognized as tDateTime (in database is TimeStamp).
regards,

DemetrionQ
Devart Team
Posts: 271
Joined: Wed 23 Jan 2013 11:21

Re: crbatchmove duplicate key

Post by DemetrionQ » Wed 19 Jun 2013 12:05

Hello.

Data Type Mapping should be used before opening TUniQuery. Please make sure that after opening TUniQuery the time stamp field has the TStringField type. In this case, there is no need for the described modification.

lao
Posts: 71
Joined: Wed 10 Dec 2008 10:56

Re: crbatchmove duplicate key

Post by lao » Thu 20 Jun 2013 08:05

Hi,
that's what i do.
on show of my form,
i close uniconnection
and i add:
UniConnection1.DataTypeMap.AddDBTypeRule(pgTimeStamp,ftString);
UniConnection1.DataTypeMap.AddDBTypeRule(pgTimeStampWithTimeZone,ftString);

but in crbatchmove.pas in the function GetKeyValues,
FSrcKeyFields datatype is ftDateTime for my field timestamp.
regards.

DemetrionQ
Devart Team
Posts: 271
Joined: Wed 23 Jan 2013 11:21

Re: crbatchmove duplicate key

Post by DemetrionQ » Thu 20 Jun 2013 12:56

Hello.

I can't reproduce the problem when using data type mapping. Please provide the following information:
- the UniDAC version;
- the table creation script;
- the exact IDE version (for example RAD Studio 2009 Version 12.0.3420.21218).

lao
Posts: 71
Joined: Wed 10 Dec 2008 10:56

Re: crbatchmove duplicate key

Post by lao » Fri 21 Jun 2013 08:47

Hi Demetrion,
I am sorry the procedure you described works.
i have 2 uniconnections, 1 connected to the server(source for crbatchmove) and 1 connected to localhost (destination for crbatchmove) so i change the datatypemap for destination connection instead of source connection.
Regards.

DemetrionQ
Devart Team
Posts: 271
Joined: Wed 23 Jan 2013 11:21

Re: crbatchmove duplicate key

Post by DemetrionQ » Fri 21 Jun 2013 09:29

Glad to see that you solved the problem. If any other questions come up, please contact us.

lao
Posts: 71
Joined: Wed 10 Dec 2008 10:56

Re: crbatchmove duplicate key

Post by lao » Fri 21 Jun 2013 10:04

Hi,
i have an other question:
i try to batchmove table t1 (appendupdate mode) 5000 rows from server A(interbase) to server B (interbase): the batch take about 29 seconds.

i try with bde, same databases same table and the batch take 5 secondes.

i try to convert ours applications from interbase to postgresql that's why we buy unidac.

for the moment i try to convert application from bde to unidac.

is it normal to multiply by 6 the time?
What can i do to increase performances?
i try with transaction, autoprepare, prepareupdatesql,cachedupdates.
regards,

AndreyZ

Re: crbatchmove duplicate key

Post by AndreyZ » Wed 26 Jun 2013 09:17

I cannot reproduce the problem. Please specify the following:
- the script to create your table;
- the exact version of InterBase server and client you are using. You can learn it from the Info sheet of TUniConnection Editor;
- the exact version of UniDAC. You can learn it from the About sheet of TUniConnection Editor;
- the exact version of your IDE.
Also, you can try creating a small sample that demonstrates this problem and send it to andreyz*devart*com . This way, I will be able to help you faster.

Post Reply