-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinsert_record.sh
executable file
·136 lines (114 loc) · 2.35 KB
/
insert_record.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
#!/usr/bin/bash
#this file is called with argument $1 db name and table name $2
export IFS=":"
typeset -i colNum=3
typeset -i i=-1
intPattern='[0-9]+$'
regex='^[a-z|A-Z|0-9][0-9|a-z|A-Z|_|\d]*$'
for col in `head -n 1 /var/7amasaDB/$1/$2`
do
flag=1
colNum=$colNum+1
constraint=`grep -w "$2" /var/7amasaDB/$1/.meta | cut -d: -f $colNum`
while true
do
tmpForm=$(yad \
--center \
--text-align=center \
--title "7amasa DB" \
--form --field="$col" \
--button=gtk-ok:0 \
--button=gtk-cancel:1 \
)
choice0=$?
if [ $choice0 = 1 ]
then
break 2
elif [ $choice0 = 252 ]
then
kill -9 `ps --pid $$ -oppid=`; exit
elif [ $choice0 = 0 ]
then
colVal=$(echo $tmpForm | awk 'BEGIN {FS="|" } { print $1 }')
if [[ $colVal =~ $regex ]]
then
if [ ! $colVal ]
then
if [ "$constraint" = "NS" -o "$constraint" = "NI" ]
then
flag=0
yad \
--title "7amasa DB Engine" \
--center \
--text-align=center \
--text "$col can't be null" \
--button="back":1
continue
else
colVal=" "
flag=1
fi
else
if [[ $colNum -eq 4 ]]
then
uniq=`grep -w "$colVal" /var/7amasaDB/$1/$2 | cut -d: -f 1`
if [ $uniq ]
then
flag=0
yad \
--title "7amasa DB Engine" \
--center \
--text-align=center \
--text "id with the same value exists" \
--button="back":1
continue
fi
fi
if [ "$constraint" = "NI" -o "$constraint" = "I" ]
then
if [[ $colVal =~ $intPattern ]]
then
flag=1
else
flag=0
yad \
--title "7amasa DB Engine" \
--center \
--text-align=center \
--text "$col must be an integer" \
--button="back":1
continue
fi
else
flag=1
fi
fi
if [ $flag -eq 1 ]
then
i=$i+1
columns[$i]=$colVal
break
fi
else
yad \
--title "7amasa DB Engine" \
--center \
--text-align=center \
--text "value contains unaccepted characters or white spaces" \
--button="back":1
continue
fi
fi
done
done
i=0
while [[ $i -lt ${#columns[*]}-1 ]]
do
newline=$newline${columns[$i]}":"
i=i+1
if [[ $i -eq ${#columns[*]}-1 ]]
then
newline="$newline${columns[$i]}"
fi
done
echo "$newline" >> /var/7amasaDB/$1/$2