Skip to content

Commit 15f710a

Browse files
committed
bash script
0 parents  commit 15f710a

File tree

10 files changed

+206
-0
lines changed

10 files changed

+206
-0
lines changed

.idea/.gitignore

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/lab3.iml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CRUD.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
source databaseChecker.sh
2+
####################################### INSERT DATA ##############################################
3+
function insertData {
4+
local sqlStatment_invoice_master="INSERT INTO DB_Bash.invoice_master (Custname,invdate, invtotal) VALUES (\"$1\",\"$2\", $3);"
5+
# local sqlStatment_invoice_detail="INSERT INTO DB_Bash.invoice_detail (invID, itemname, unitprice, quantity)VALUES (1,'wood',500,22);"
6+
7+
mysql -u $USER -p$PASS -e "$sqlStatment_invoice_master"
8+
# mysql -u $USER -p$PASS -e "$sqlStatment_invoice_detail"
9+
existCodeChecker
10+
}
11+
function insertData_UI {
12+
echo "enter customer name : "
13+
read customer_name
14+
echo "enter invoice date : "
15+
read invdate
16+
echo "enter invoice total : "
17+
read invtotal
18+
insertData $customer_name $invdate $invtotal
19+
20+
}
21+
22+
####################################### Display Invoices #########################################
23+
function display_Invoices {
24+
local sqlStatment_invoice_detail="select * from DB_Bash.invoice_detail;"
25+
local sqlStatment_invoice_master="select * from DB_Bash.invoice_master;"
26+
mysql -u $USER -p$PASS -e "$sqlStatment_invoice_detail"
27+
mysql -u $USER -p$PASS -e "$sqlStatment_invoice_master"
28+
existCodeChecker
29+
}
30+
31+
####################################### Delete Invoices ##########################################
32+
function delete_Invoices {
33+
local sqlStatment_invoice_detail="DELETE FROM DB_Bash.invoice_master WHERE invID=$1;"
34+
local sqlStatment_invoice_master="DELETE FROM DB_Bash.invoice_detail WHERE id=$1;"
35+
mysql -u $USER -p$PASS -e "$sqlStatment_invoice_detail"
36+
mysql -u $USER -p$PASS -e "$sqlStatment_invoice_master"
37+
existCodeChecker
38+
}
39+
40+
41+
function delete_Invoices_UI {
42+
echo "enter ID"
43+
read id
44+
delete_Invoices $id
45+
}

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Bash Script Menu Demo
2+
3+
creating a bash script to preform a CRUD operation on mysql database
4+
5+
## Table of contents
6+
7+
- [Overview](#overview)
8+
- [Screenshot](#screenshot)
9+
- [Built with](#built-with)
10+
- [Author](#authors)
11+
12+
## Overview
13+
14+
### GIF
15+
16+
17+
![screen-gif](./documentation/Demo.GIF)
18+
19+
<p align="right">(<a href="#top">back to top</a>)</p>
20+
21+
### Built with
22+
23+
* [bash script](https://www.php.net/)
24+
25+
<p align="right">(<a href="#top">back to top</a>)</p>
26+
27+
28+
## Authors
29+
30+
31+
* LinkedIn - [Hegabovic](https://www.linkedin.com/in/hegab192)
32+
33+
<p align="right">(<a href="#top">back to top</a>)</p>

app.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
source menu.sh
4+
5+
database_checker
6+
createTables
7+
8+
while [ 1 ]; do
9+
menu
10+
done

databaseChecker.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#########################################################
2+
############ exit code
3+
### 0 success
4+
### 10 can not connect to database
5+
6+
USER=hegabovic
7+
PASS=Hegabo192
8+
DB=DB_Bash
9+
10+
####################################### Exist Code Checker ##############################################
11+
function existCodeChecker {
12+
if [ $? -ne 0 ]; then
13+
return 10
14+
fi
15+
return 0
16+
}
17+
18+
####################################### Database Checker ##############################################
19+
20+
function database_checker {
21+
local dbs="create database if not exists ${DB};"
22+
mysql -u $USER -p$PASS -e "$dbs"
23+
existCodeChecker
24+
}
25+
26+
function createTables {
27+
local createTable="create table if not exists DB_Bash.invoice_master
28+
(
29+
invID int primary key auto_increment,
30+
Custname varchar(100),
31+
invdate date,
32+
invtotal float
33+
);
34+
create table if not exists DB_Bash.invoice_detail
35+
(
36+
37+
id int primary key auto_increment,
38+
invID int,
39+
itemname varchar(50),
40+
unitprice int,
41+
quantity int,
42+
FOREIGN KEY (invID) REFERENCES invoice_master (invID)
43+
);"
44+
mysql -u $USER -p$PASS -e "$createTable"
45+
existCodeChecker
46+
}
47+
48+
49+
50+
51+
52+
53+

documentation/Demo.GIF

308 KB
Loading

menu.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
source CRUD.sh
2+
3+
function menu() {
4+
echo -ne "
5+
MAIN MENU
6+
1) Insert Invoices
7+
2) Delete Invoices
8+
3) Display Invoices
9+
4) Exit
10+
Choose an option: "
11+
read -r ans
12+
case $ans in
13+
1)
14+
insertData_UI
15+
menu
16+
;;
17+
2)
18+
delete_Invoices_UI
19+
menu
20+
;;
21+
3)
22+
display_Invoices
23+
menu
24+
;;
25+
4)
26+
echo "Bye bye."
27+
exit 0
28+
;;
29+
*)
30+
echo "Wrong option."
31+
exit 1
32+
;;
33+
esac
34+
}

0 commit comments

Comments
 (0)