From: Michal Vaner Date: Sat, 30 Aug 2008 19:24:52 +0000 (+0200) Subject: Handle deleted items correctly in export X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=1477a267ff1174dfc2ee7ae6eb2e9cef9655dd39;p=pciids.git Handle deleted items correctly in export Need to do it in perl, SQL seems to be too weak to do this efectively --- diff --git a/scripts/export.pl b/scripts/export.pl index f8261b3..84e2aab 100755 --- a/scripts/export.pl +++ b/scripts/export.pl @@ -9,11 +9,18 @@ use PciIds::Db; use PciIds::DBQAny; my $db = PciIds::DBQAny::new( connectDb(), { - 'list' => 'SELECT id, name, note FROM locations WHERE name IS NOT NULL ORDER BY id' + 'list' => 'SELECT id, name, note FROM locations WHERE id like "PC/%" OR id like "PD/%" ORDER BY id' } ); +my $lastInvalid = undef; + foreach( @{$db->query( 'list', [] )} ) { my( $id, $name, $description ) = @{$_}; + next if defined $lastInvalid and substr( $id, 0, length $lastInvalid ) eq $lastInvalid; + if( !defined $name || $name eq '' ) { + $lastInvalid = $id; + next; + } $_ = $id; my $prefix = ( /^PD\/..$/ ) ? 'C ' : ''; s/^P.\///;