robotframework-demo/Project/task4/Script/SC2_Database/10_Kingbase Physical/kingbaseV8DB.sh

44 lines
1.5 KiB
Bash

#!/bin/sh
table_name="test_db"
create_table="create table ${table_name}(user_code VARCHAR(20),user_name VARCHAR(20),user_desc VARCHAR(50));"
drop_table="drop table ${table_name};"
query_table="select count(*) from ${table_name};"
#ksql="/opt/Kingbase/ES/V8/Server/bin/ksql"
if [ $1 = "create" ]
then
ksql -h 127.0.0.1 -U SYSTEM -d $2 -p 54321 -c "${create_table}"
if [ $? -ne 0 ]
then
ksql -h 127.0.0.1 -U SYSTEM -d $2 -p 54321 -c "${drop_table}"
ksql -h 127.0.0.1 -U SYSTEM -d $2 -p 54321 -c "${create_table}"
fi
exit
elif [ $1 = "drop" ]
then
ksql -h 127.0.0.1 -U SYSTEM -d $2 -p 54321 -c "${drop_table}"
exit
elif [ $1 = "insert" ]
then
res=1;num=1
while [ ${num} -lt 11 ]
do
insert_table="insert into ${table_name} values(${num},'test','test');"
ksql -h 127.0.0.1 -U SYSTEM -d $2 -p 54321 -c "${insert_table}"
res=$?
let num=${num}+1
done
exit
elif [ $1 = "query" ]
then
# $ksql -d OSRDB -c "${query_table}"
queryres=`ksql -h 127.0.0.1 -U SYSTEM -d $2 -p 54321 -c "${query_table}"`
queryres1=${queryres##*-}
queryres2=${queryres1%%(*}
echo ${queryres2}
exit
else
echo "error"
fi