-
Notifications
You must be signed in to change notification settings - Fork 1
/
insert_data.sh
executable file
·137 lines (112 loc) · 2.49 KB
/
insert_data.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
#filename is a global variable
# <<< to pass a string
clear
data=()
source "functions";
source $(pwd)/use_Database.sh;
#filename is a global variable
# <<< to pass a string
data=()
# erroe regex / is accepted
function insert_check_primary
{
while true
do
echo "this column data type is ${col_types[0]} "
echo "enter the primary value"
read pvalue
if [[ -z $pvalue ]]
then
echo "must not be empty"
echo "try again"
echo "--------------------------------------"
elif [[ $pvalue =~ ^[a-zA-Z]+$ ]]
then
echo "must be a number"
elif [[ $pvalue == 0 ]]
then
echo "not accepted"
else
check_pk "$pvalue"
repeat="$?"
if [ "$repeat" -eq 1 ]
then
echo "repeated"
echo "try again"
elif [ ! "$repeat" -eq 1 ]
then
echo "not repeated data"
data+=("$pvalue")
break
else
echo "invalid"
fi
fi
done
}
function insert_data
{
reg=""
insert_check_primary
echo "${#col_names[@]}"
length=${#col_names[@]}
for ((i=1;i<length;i++))
do
while true
do
echo "this column data type is ${col_types[$i]} "
echo "enter the $ $i data"
read value
if [ ${col_types[$i]} = "number" ]
then
reg="^[0-9]+$"
elif [ ${col_types[$i]} = "string" ]
then
reg="^[a-zA-Z]+$"
else
echo "not vaid type"
fi
if [[ "$value" =~ $reg ]]
then
data+=("$value")
echo "your data saved successfully"
break
else
echo "not valid"
fi
done
done
}
while true
do
echo "Enter Your Table Name:"
read filename
if [[ -f "$filename" ]]
then
get_structure_of_table
insert_data
echo "------------------------------------------"
for i in "${col_names[@]}"; do
printf '%s' "$i |"
done
printf "\n"
printf "\n" >>"$filename"
get_All_Data
for value in "${data[@]}"
do
printf '%s' "$value:" >>"$filename"
printf '%s' "$value:"
done
printf "\n"
echo "------------------------------------------"
break
elif [[ -z "$filename" ]]
then
echo "you must enter table name"
else
echo "this name is not valid or file is existed"
fi
done
cd ..
source "DatabaseEngine.sh";