#!/bin/sh
#
# this is invoked multiple times asynchronously by 'concur'
# for concurrency testing.
#

TABLE=$1
SUB_ID=$2

# 1. lock a record (all subs competing for same record)
echo "all processes will compete to lock record id=37012.. only one will succeed.."
shsql -id $SUB_ID "select * from $TABLE where id = 37012 for update"

# 2. allocate a serial number..
NEWNUM=`shsql "select _sequence from $TABLE" `

# 3. insert a new record
shsql -id $SUB_ID "insert into $TABLE (id, item_title, current_price, seller)
        values ($NEWNUM, 'New entry', 40.00, 's19' )" 

# 4. lock new record
shsql -id $SUB_ID "select * from $TABLE where id = $NEWNUM for update"

# 5. update new record
shsql -id $SUB_ID "update $TABLE 
	set item_title = 'New entry showing an item on consignment from HB Bros. Auctions, offered for sale by $SUB_ID',
	status = 'MODIFIED' where id = $NEWNUM"

