1 # Copyright 2005-2007 Interchange Development Group and others
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version. See the LICENSE file for details.
8 # $Id: exists.oc,v 1.3 2007-03-30 23:40:48 pajamian Exp $
10 CodeDef exists OrderCheck 1
11 CodeDef exists Description Existing record
12 CodeDef exists Routine <<EOR
14 my($ref, $name, $value, $code) = @_;
16 $code =~ s/(\w+)(:+(\w+))?\s*//;
18 or return (0, $name, errmsg("no table specified"));
22 my $db = database_exists_ref($tab)
25 "Table %s doesn't exist",
28 return(0, $name, $msg);
33 $used = $db->record_exists($value);
36 #::logDebug("Doing foreign key check, tab=$tab col=$col value=$value");
37 $used = $db->foreign($value, $col);
40 #::logDebug("Checking exists, tab=$tab col=$col, used=$used");
42 return (1, $name, '');
46 "Key %s does not exist in %s, try again.",
50 return(0, $name, $msg);