#!/bin/sh
#
# This file is released under the terms of the Artistic License.
# Please see the file LICENSE, included in this package, for details.
#
# Copyright The DBT-2 Authors
#

if [ "x${DBT2DBNAME}" = "x" ]; then
	echo "DBT2DBNAME not defined."
	exit 1
fi

while getopts "l:" OPT; do
	case ${OPT} in
	l)
		PORT=${OPTARG}
		;;
	esac
done

if [ ! "x${PORT}" = "x" ]; then
	PORTARG="-p ${PORT}"
fi
PSQL="psql -X ${PORTARG} -d ${DBT2DBNAME}"

echo "Checking dbt2 database '${DBT2DBNAME}'..."
echo

# Load tables
echo customer
${PSQL} -c "select count(*) from customer"
echo district
${PSQL} -c "select count(*) from district"
echo history 
${PSQL} -c "select count(*) from history"
echo item    
${PSQL} -c "select count(*) from item"
echo new_order
${PSQL} -c "select count(*) from new_order"
echo order_line
${PSQL} -c "select count(*) from order_line"
echo orders  
${PSQL} -c "select count(*) from orders"
echo stock   
${PSQL} -c "select count(*) from stock"
echo warehouse
${PSQL} -c "select count(*) from warehouse"
