X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-live.git;a=blobdiff_plain;f=yarrg%2FCommodsDatabase.pm;h=999dda779611b441e2131348e4b6efa5acce0228;hp=e14c0eb401e10a0f299b9b2c0564ce69d492266a;hb=8c65bca26f3f2da973f5edf140491d551b50e2ec;hpb=9089113ed14d3a01ebe805ee15bd08705a59f172 diff --git a/yarrg/CommodsDatabase.pm b/yarrg/CommodsDatabase.pm index e14c0eb..999dda7 100644 --- a/yarrg/CommodsDatabase.pm +++ b/yarrg/CommodsDatabase.pm @@ -178,17 +178,23 @@ sub nooutput ($) { if $ekindcount; } -sub db_check_referential_integrity () { +sub db_check_referential_integrity ($) { + my ($full) = @_; + # non-full is done only for market data updates; it avoids + # detecting errors which are essentially missing metadata and + # old schemas, etc. + foreach my $bs (qw(buy sell)) { nooutput(< 0 GROUP BY commodclassid,posinclass HAVING count(*) > 1; SELECT commodclass,commodclassid,count(*) - FROM commods NATURAL JOIN commodclasses + FROM commods JOIN commodclasses USING (commodclassid) WHERE posinclass > 0 GROUP BY commodclassid HAVING count(*) != maxposinclass; SELECT * - FROM commods NATURAL JOIN commodclasses + FROM commods JOIN commodclasses USING (commodclassid) WHERE posinclass < 0 OR posinclass > maxposinclass; END + } } -sub db_chkcommit () { - db_check_referential_integrity(); +sub db_chkcommit ($) { + my ($full) = @_; + db_check_referential_integrity($full); $dbh->commit(); }