Page 1 of 1

MyLoader/MyConnection after Exception

Posted: Thu 01 Mar 2007 11:50
by pJer
Hello!

I'm using version 4.30.0.12 of MyDac for C++ Builder 6. It works perfect until today.

I would like to load a table with some unique index.

I use TMyLoader for inserting the data. The program crashes when I'm in contradiction with unique index.

I know that one possibly solution would be that I store the row one by one using TMyQuery and checking if the value is duplicated. But I have a table which consists of many million records and this solution will take too much time.

The second solution would be with error handling.
If unique index "protest" against duplicated value I just handle with this information (just count the amount of duplicated values from tmp file for example). There is the "code":
while (reading from file line by line){
//read the line and prepare the values for MyLoader
try
{
MyLoader2->Finish();
ok++;
}
catch (Exception &exception)
{
not_ok++;
}
}


BUT, when I get first (duplicate) error I coudn't do anything else (insert, select, update,...). I get the same error as in first case (duplicate error...bla bla). I tried to reconnect the MyConnection in catch clause but without success.

I looked in Forum history but I haven't found any solution.

Thank's in advance...

pJer

Posted: Fri 02 Mar 2007 12:27
by Antaeus
In the new MyDAC version (MyDAC 5) we have added two modes to TMyLoader for handling records with duplicate primary keys. These modes can be set by the DuplicateKeys option. This option can take one of the following values:
  • dkNone - old behaviour, if a record with duplicate key is encountered, an error will be raised;
  • dkIgnore - records with duplicate primary keys are ignored;
  • dkReplace - records with duplicate primary keys are replaced.