-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 15f710a
Showing
10 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
||
 | ||
|
||
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |