Skip to content

Commit

Permalink
bash script
Browse files Browse the repository at this point in the history
  • Loading branch information
Hegabovic committed Apr 17, 2022
0 parents commit 15f710a
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/lab3.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions CRUD.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
source databaseChecker.sh
####################################### INSERT DATA ##############################################
function insertData {
local sqlStatment_invoice_master="INSERT INTO DB_Bash.invoice_master (Custname,invdate, invtotal) VALUES (\"$1\",\"$2\", $3);"
# local sqlStatment_invoice_detail="INSERT INTO DB_Bash.invoice_detail (invID, itemname, unitprice, quantity)VALUES (1,'wood',500,22);"

mysql -u $USER -p$PASS -e "$sqlStatment_invoice_master"
# mysql -u $USER -p$PASS -e "$sqlStatment_invoice_detail"
existCodeChecker
}
function insertData_UI {
echo "enter customer name : "
read customer_name
echo "enter invoice date : "
read invdate
echo "enter invoice total : "
read invtotal
insertData $customer_name $invdate $invtotal

}

####################################### Display Invoices #########################################
function display_Invoices {
local sqlStatment_invoice_detail="select * from DB_Bash.invoice_detail;"
local sqlStatment_invoice_master="select * from DB_Bash.invoice_master;"
mysql -u $USER -p$PASS -e "$sqlStatment_invoice_detail"
mysql -u $USER -p$PASS -e "$sqlStatment_invoice_master"
existCodeChecker
}

####################################### Delete Invoices ##########################################
function delete_Invoices {
local sqlStatment_invoice_detail="DELETE FROM DB_Bash.invoice_master WHERE invID=$1;"
local sqlStatment_invoice_master="DELETE FROM DB_Bash.invoice_detail WHERE id=$1;"
mysql -u $USER -p$PASS -e "$sqlStatment_invoice_detail"
mysql -u $USER -p$PASS -e "$sqlStatment_invoice_master"
existCodeChecker
}


function delete_Invoices_UI {
echo "enter ID"
read id
delete_Invoices $id
}
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Bash Script Menu Demo

creating a bash script to preform a CRUD operation on mysql database

## Table of contents

- [Overview](#overview)
- [Screenshot](#screenshot)
- [Built with](#built-with)
- [Author](#authors)

## Overview

### GIF


![screen-gif](./documentation/Demo.GIF)

<p align="right">(<a href="#top">back to top</a>)</p>

### Built with

* [bash script](https://www.php.net/)

<p align="right">(<a href="#top">back to top</a>)</p>


## Authors


* LinkedIn - [Hegabovic](https://www.linkedin.com/in/hegab192)

<p align="right">(<a href="#top">back to top</a>)</p>
10 changes: 10 additions & 0 deletions app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

source menu.sh

database_checker
createTables

while [ 1 ]; do
menu
done
53 changes: 53 additions & 0 deletions databaseChecker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#########################################################
############ exit code
### 0 success
### 10 can not connect to database

USER=hegabovic
PASS=Hegabo192
DB=DB_Bash

####################################### Exist Code Checker ##############################################
function existCodeChecker {
if [ $? -ne 0 ]; then
return 10
fi
return 0
}

####################################### Database Checker ##############################################

function database_checker {
local dbs="create database if not exists ${DB};"
mysql -u $USER -p$PASS -e "$dbs"
existCodeChecker
}

function createTables {
local createTable="create table if not exists DB_Bash.invoice_master
(
invID int primary key auto_increment,
Custname varchar(100),
invdate date,
invtotal float
);
create table if not exists DB_Bash.invoice_detail
(
id int primary key auto_increment,
invID int,
itemname varchar(50),
unitprice int,
quantity int,
FOREIGN KEY (invID) REFERENCES invoice_master (invID)
);"
mysql -u $USER -p$PASS -e "$createTable"
existCodeChecker
}







Binary file added documentation/Demo.GIF
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions menu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
source CRUD.sh

function menu() {
echo -ne "
MAIN MENU
1) Insert Invoices
2) Delete Invoices
3) Display Invoices
4) Exit
Choose an option: "
read -r ans
case $ans in
1)
insertData_UI
menu
;;
2)
delete_Invoices_UI
menu
;;
3)
display_Invoices
menu
;;
4)
echo "Bye bye."
exit 0
;;
*)
echo "Wrong option."
exit 1
;;
esac
}

0 comments on commit 15f710a

Please sign in to comment.