#!/bin/ash
# *********************************************************************
#  Written by and copyright Carlo Strozzi <carlos@linux.it>.
#
#  Note: part of this code has been freely adapted from examples
#  provided in the book "Unix Relational Database Management", so
#  credits are due to the original authors.
#
#  depend: test for ``functional dependency'' betwen two columns.
#  Copyright (C) 2001 Carlo Strozzi <carlos@linux.it>
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#  2001-03-08 Beta code
#  2001-04-20 Added inline help
#
#  $Id$
# *********************************************************************

if [ "$1" = -h ] || [ "$1" = --help ]
then
   grep -v '^#' @NOSQLPATH@/nosql/help/depend.txt
   exit 1
fi

if [ $# != 2 ]
then
   echo Usage: depend column_1 column_2 >&2
   exit 1
fi

[ "$TMPDIR" = "" ] && TMPDIR=/tmp
f_tmp=`mktemp $TMPDIR/nosql.XXXXXX` || exit $?

trap "rm -f $f_tmp; trap 0; exit 0" 0 1 2 3 15

column "$@" | sorttable | uniq > $f_tmp || exit $?

if [ "`wc -l < $f_tmp`" = "`column $1 -i $f_tmp | uniq | wc -l`" ]
then
   echo true
   exit 0
else
   echo false
   exit 1
fi

#
# End of program.
#
