#!/bin/bash

CEGO=../../src/cego
ARANGE=1000
AINTERVAL=100
ACOUNT=50000

cat <<EOF > arbblow
#!/bin/bash
DBHOST=`hostname`
../../src/cgblow --mode=insert --server=$DBHOST --port=2200 --table=t1 --tableset=TS1 --user=lemke/lemke --interval=$AINTERVAL --count=$ACOUNT --protocol=fastserial \
--iset=i:$ARANGE,s:3 --dcond=a:i:9 --append --simulate $@
EOF

chmod 755 arbblow

NUMRUN=1000

rm -rf /tmp/cego.lock

i=0
while [ $i -lt $NUMRUN ] 
do
    ./mkdb TS1
    # use already created arb.sql

    cat <<EOF > arb.sql
drop if exists table t1;
create table t1 ( a int not null, b string(50));
create btree b1 on t1 ( a );
EOF

    ./arbblow >> arb.sql
    echo "update t1 set b = 'HUGO';" >> arb.sql

    $CEGO --mode=batch --dbxml=./db/chkdb.xml --user=lemke/lemke --poolsize=1000 --batchfile=arb.sql --tableset=TS1

    echo "Run $i done" >> optcheck.log

    if [ $? == 1 ]
    then
	echo "Exit on Error"
	exit 1
    fi

    i=$[$i+1]

done
