-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_table.sh
58 lines (42 loc) · 1.31 KB
/
create_table.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
echo "----------------------create table-----------------------------"
read -p "enter database you want to create table : " db_name
if [[ -d "$db_name/$tb_name" ]]; then
echo "table existed before"
else
touch $db_name/$tb_name
touch $db_name/$metadata
echo "table created"
echo -n "@PK.id:" >> $db_name/$metadata
read -p "How many fields do you want in table? " fields_no
for ((c = 1; c <= $fields_no; ((c++)))); do
echo "Enter Field no.$c Name: "
read field
if [[ $c = $fields_no ]]; then
echo -n "$field" >>$db_name/$metadata
else
echo -n "$field:" >>$db_name/$metadata
fi
done
echo >>$db_name/$metadata
echo -n "int:" >>$db_name/$metadata
for ((i = 1; i <= $fields_no; ((i++)))); do
echo "enter Field no.$i Datatype: "
if [ $i = $fields_no ]; then
select datatype in "int" "varchar" "Exit";
do
case $datatype in
"int" | "varchar" )
echo -n "$datatype" >>$db_name/$metadata
break
;;
"Exit")
;;
* )
esac
done
fi
done
fi
. ./ connect_table.sh
. ./main.sh