-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.sh
executable file
·108 lines (102 loc) · 4.51 KB
/
main.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
#!/bin/bash
connected='';
while true
do
result=$(zenity --text-info \
--title="Database Management System" \
--height 400 --width 600 \
--text="Write your query:" \
--editable)
# Check if result is empty (user clicked "x" or canceled)
if [ -z "$result" ]; then
break
fi
# Replace '*' with 'all'
result=${result//\*/all}
case "${result,,}" in
"create database "*)
# Extract database name from the user input
db_name=$(echo $result | awk '{print $3}')
# Create directory with the database name
if [ -z "$db_name" ]; then
echo "Database Name Can Not Be Empty!" |
zenity --text-info --title="ERROR" \
--height 400 --width 600 --font="Arial 20"
else
mkdir -p "databases/$db_name"
# Display dialog with result
echo "Database '$db_name' is created!" |
zenity --text-info --title="Successful" \
--height 400 --width 600 --font="Arial 20"
fi
;;
"show databases"*)
# list all directories in databases dir
db=$(ls databases)
# Display dialog with databases
echo "$db" | zenity --text-info --title="Databases" \
--height 400 --width 600 --font="Arial 20"
;;
"drop database "*)
# Extract database name from the user input
db_name=$(echo $result | awk '{print $3}')
# Drop directory with the database name
if [ -z "$db_name" ]; then
echo "Database Name Can Not Be Empty!" |
zenity --text-info --title="ERROR" \
--height 400 --width 600 --font="Arial 20"
elif [ -d databases/$db_name ];then
rm -df "databases/$db_name"
# Display dialog with result
echo "Database '$db_name' is dropped!" |
zenity --text-info --title="Successful" \
--height 400 --width 600 --font="Arial 20"
else
echo "Database '$db_name' Not Found!" |
zenity --text-info --title="ERROR" \
--height 400 --width 600 --font="Arial 20"
fi
;;
"use "*)
# Extract database name from the user input
db_name=$(echo $result | awk '{print $2}')
if [ -z "$db_name" ]; then
echo "Database Name Can Not Be Empty!" |
zenity --text-info --title="ERROR" \
--height 400 --width 600 --font="Arial 20"
elif [ -d databases/$db_name ]
then
echo -e "Connected to $db_name Successfully" |
zenity --text-info --title="Successful" \
--height 400 --width 600 --font="Arial 20"
connected=$db_name;
else
echo "Wrong Database Name" |
zenity --text-info --title="ERROR" \
--height 400 --width 600 --font="Arial 20"
echo $connected;
fi
;;
*)
if [[ "${result,,}" == "create table "* || "${result,,}" == "drop table "* || "${result,,}" == "show tables"* ]]; then
source ./ddl.sh $result ;
if [ ! $? -eq 0 ];then
# Display dialog with result
echo "Wrong Statement, $result" |zenity --text-info --title="ERROR" \
--height 400 --width 600 --font="Arial 20"
fi
elif [[ "${result,,}" == "insert into "* || "${result,,}" == "select "* || "${result,,}" == "update "* || "${result,,}" == "delete from "* ]]; then
source ./dml.sh $result ;
if [ ! $? -eq 0 ];then
# Display dialog with result
echo "Wrong Statement, $result" |zenity --text-info --title="ERROR" \
--height 400 --width 600 --font="Arial 20"
fi
else
# Display dialog with result
echo "Wrong Statement, $result" |zenity --text-info --title="ERROR" \
--height 400 --width 600 --font="Arial 20"
fi
;;
esac
done