Bug 12488: Make bulkmarcimport.pl -d use DELETE instead of TRUNCATE

On MySQL >= 5.5 bulkmarcimport.pl with the -d (delete) switch gives
an error like "Cannot truncate a table referenced in a foreign
key constraint". This patch proposes to replace the offending
TRUNCATE with DELETE. Auto incerement counters are reset to 1 to
preserve the functionality from TRUNCATE.

To test:
- Make sure you havae a test database with some records and items
- Run bulkmarcimport.pl with the -d switch
- Observe the error described above
- Apply this patch
- Run bulkmarcimport.pl with the -d switch again
- Observe the lack of an error
- Verify that the newly imported records and items have biblionumber
  and itemnumbers starting with 1

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(cherry picked from commit b7b4694666)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
(cherry picked from commit 1e65ab6f7f)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Magnus Enger 2019-02-11 11:07:21 +01:00 committed by Lucas Gass
parent 0dd262a02e
commit 2e8092c678
1 changed files with 6 additions and 3 deletions

View File

@ -176,9 +176,12 @@ if ($fk_off) {
if ($delete) {
if ($biblios){
print "deleting biblios\n";
$dbh->do("truncate biblio");
$dbh->do("truncate biblioitems");
$dbh->do("truncate items");
$dbh->do("DELETE FROM biblio");
$dbh->do("ALTER TABLE biblio AUTO_INCREMENT = 1");
$dbh->do("DELETE FROM biblioitems");
$dbh->do("ALTER TABLE biblioitems AUTO_INCREMENT = 1");
$dbh->do("DELETE FROM items");
$dbh->do("ALTER TABLE items AUTO_INCREMENT = 1");
}
else {
print "deleting authorities\n";