Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Adarsh275/PetrolPump-Management-System/llms.txt

Use this file to discover all available pages before exploring further.

database.py is the single module that all UI components import for database interaction. It establishes the MySQL connection at module load time and exposes one function per CRUD operation per entity. Every other module in the project — create.py, read.py, update.py, delete.py, and app.py — imports from this file. This page documents every function signature, its SQL statement, and what it returns.
All SQL in get_all_info_* and delete_data_* functions uses Python string formatting (format()) rather than parameterized queries — this means they are vulnerable to SQL injection if exposed to untrusted input. Only the add_* and edit_* functions use the safe %s placeholder syntax supported by mysql.connector.

Connection Setup

The module connects to MySQL using mysql.connector at import time and exposes the cursor c and connection mydb as module-level globals. Every function in database.py uses these globals directly.
database.py
import mysql.connector
mydb = mysql.connector.connect(
    host="localhost",
    user="root",
    password="",
    database="Petrolpump_Management"
)
c = mydb.cursor()

create_table()

create_table() is an idempotent DDL helper that creates all six primary tables if they do not already exist. It is called once at application startup inside main() in app.py. It accepts no parameters and returns no value. The six tables created are: Petrolpump, Owners, Employee, Customer, Invoice, and Tanker. Each CREATE TABLE statement uses the IF NOT EXISTS guard so re-running the app against an already-initialised database is safe.

INSERT Functions

Each add_* function inserts a single record into its corresponding table, calls mydb.commit(), and returns None. All six functions use parameterized %s placeholders — the values are passed as a tuple, never interpolated into the SQL string directly.
Inserts one row into the Petrolpump table.
database.py
def add_Petrolpump_data(Registration_No, Petrolpump_Name, Company_Name, Opening_Year, State, City):
    c.execute(
        'insert into Petrolpump (Registration_No,Petrolpump_Name,Company_Name,Opening_Year,State,City) '
        'values (%s,%s,%s,%s,%s,%s)',
        (Registration_No, Petrolpump_Name, Company_Name, Opening_Year, State, City)
    )
    mydb.commit()
Registration_No
str
required
Unique primary key for the pump (e.g. "HPC805103"). Maximum 10 characters.
Petrolpump_Name
str
required
Trading name of the petrol pump (e.g. "Sumaraj Petroleum"). Maximum 50 characters.
Company_Name
str
Parent oil company (e.g. "Hindustan Petroleum Corporation"). Maximum 30 characters. Nullable.
Opening_Year
int
Four-digit year the pump opened (e.g. 2016). Nullable.
State
str
Indian state where the pump is located (e.g. "Bihar"). Maximum 30 characters. Nullable.
City
str
required
City of operation (e.g. "Hisua"). Maximum 40 characters.
Returns: None
Inserts one row into the Owners table.
database.py
def add_Owners_data(Owner_Name, Contact_NO, DOB, Gender, Address, Partnership):
    c.execute(
        'INSERT INTO Owners (Owner_Name, Contact_NO, DOB, Gender, Address, Partnership) '
        'VALUES (%s, %s, %s, %s, %s, %s)',
        (Owner_Name, Contact_NO, DOB, Gender, Address, Partnership)
    )
    mydb.commit()
Owner_Name
str
required
Full name of the owner; also the primary key (e.g. "Pawan Kumar"). Maximum 20 characters.
Contact_NO
str
required
10-digit mobile number stored as a fixed-length char(10) (e.g. "9431073500").
DOB
date
Date of birth in YYYY-MM-DD format (e.g. "1971-01-03"). Nullable.
Gender
str
Single character — "M" or "F". Nullable.
Address
str
Full postal address (e.g. "Friends colony more, Patna, Bihar"). Maximum 255 characters. Nullable.
Partnership
int
required
Ownership stake as a whole-number percentage (e.g. 35).
Returns: None
Inserts one row into the Employee table.
database.py
def add_Employee_data(Employee_ID, Emp_Name, Emp_Gender, Designation, DOB,
                      Salary, Emp_Address, Email_ID, Petrolpump_No, Manager_ID):
    c.execute(
        'INSERT INTO Employee (Employee_ID, Emp_Name, Emp_Gender, Designation, DOB, Salary, '
        'Emp_Address, Email_ID, Petrolpump_No, Manager_ID) '
        'VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)',
        (Employee_ID, Emp_Name, Emp_Gender, Designation, DOB,
         Salary, Emp_Address, Email_ID, Petrolpump_No, Manager_ID)
    )
    mydb.commit()
Employee_ID
str
required
Unique primary key (e.g. "MANG957"). Maximum 10 characters.
Emp_Name
str
required
Full name of the employee (e.g. "Aman Kumar"). Maximum 30 characters.
Emp_Gender
str
Single character — "M" or "F". Nullable.
Designation
str
Job role (e.g. "MANAGER", "NOZZEL PERSON", "COOKING"). Maximum 10 characters. Nullable.
DOB
date
Date of birth in YYYY-MM-DD format. Nullable.
Salary
int
Monthly salary in Indian Rupees (e.g. 65000). Nullable.
Emp_Address
str
required
Residential address. Maximum 255 characters.
Email_ID
str
required
Email address (e.g. "aman@outlook.com"). Maximum 100 characters.
Petrolpump_No
str
Foreign key referencing Petrolpump.Registration_No — the pump this employee works at. Nullable.
Manager_ID
str
Self-referencing foreign key pointing to the Employee_ID of this employee’s manager. Nullable (senior managers point to themselves in sample data).
Returns: None
Inserts one row into the Customer table.
database.py
def add_Customer_data(Customer_Code, C_Name, Phone_No, Email_ID, Gender, City, Age):
    c.execute(
        'INSERT INTO Customer (Customer_Code, C_Name, Phone_No, Email_ID, Gender, City, Age) '
        'VALUES (%s, %s, %s, %s, %s, %s, %s)',
        (Customer_Code, C_Name, Phone_No, Email_ID, Gender, City, Age)
    )
    mydb.commit()
Customer_Code
str
required
Unique primary key (e.g. "SFG252"). Maximum 10 characters.
C_Name
str
required
Customer’s full name (e.g. "Akash"). Maximum 30 characters.
Phone_No
str
10-digit contact number stored as char(10). Nullable.
Email_ID
str
Email address. Maximum 100 characters. Nullable.
Gender
str
Single character — "M" or "F". Nullable.
City
str
Customer’s city (e.g. "Bihar"). Maximum 50 characters. Nullable.
Age
int
Customer’s age in years (e.g. 27). Maximum 3 digits. Nullable.
Returns: None
Inserts one row into the Invoice table.
database.py
def add_Invoice_data(Invoice_No, Date, Payment_Type, Fuel_Amount, Fuel_Type,
                     Discount, Total_Price, Customer_Code):
    c.execute(
        'INSERT INTO Invoice (Invoice_No, Date, Payment_Type, Fuel_Amount, Fuel_Type, '
        'Discount, Total_Price, Customer_Code) '
        'VALUES (%s, %s, %s, %s, %s, %s, %s, %s)',
        (Invoice_No, Date, Payment_Type, Fuel_Amount, Fuel_Type,
         Discount, Total_Price, Customer_Code)
    )
    mydb.commit()
Invoice_No
str
required
Unique primary key (e.g. "XC34"). Maximum 10 characters.
Date
date
required
Transaction date in YYYY-MM-DD format (e.g. "2022-11-20").
Payment_Type
str
required
Payment method (e.g. "Cash", "UPI", "Credit Card", "Debit Card"). Maximum 20 characters.
Fuel_Amount
float
Volume of fuel dispensed in litres (e.g. 7.0). Nullable.
Fuel_Type
str
Name of the fuel product (e.g. "PetrolE10", "Diesel", "Gasoline91"). Maximum 15 characters. Nullable.
Discount
int
Percentage discount applied (e.g. 10). Nullable.
Total_Price
float
required
Final billed amount in Indian Rupees after discount (e.g. 640.83).
Customer_Code
str
Foreign key referencing Customer.Customer_Code. Nullable.
Returns: None
Inserts one row into the Tanker table.
database.py
def add_Tanker_data(Tanker_ID, Capacity, pressure, Fuel_ID, Fuel_Amount,
                    Fuel_Name, Fuel_Price, Petrolpump_No):
    c.execute(
        'INSERT INTO Tanker (Tanker_ID, Capacity, pressure, Fuel_ID, Fuel_Amount, '
        'Fuel_Name, Fuel_Price, Petrolpump_No) '
        'VALUES (%s, %s, %s, %s, %s, %s, %s, %s)',
        (Tanker_ID, Capacity, pressure, Fuel_ID, Fuel_Amount,
         Fuel_Name, Fuel_Price, Petrolpump_No)
    )
    mydb.commit()
Tanker_ID
str
required
Unique primary key (e.g. "BR6872"). Maximum 10 characters.
Capacity
float
Total tank capacity in litres (e.g. 5000.0). Nullable.
pressure
float
Storage pressure in PSI or relevant unit (e.g. 550.0). Nullable.
Fuel_ID
str
required
Internal fuel product identifier (e.g. "A1234"). Maximum 10 characters.
Fuel_Amount
float
Current volume of fuel held in the tanker (e.g. 513.5). Nullable.
Fuel_Name
str
Human-readable fuel name (e.g. "PetrolE10", "Diesel", "CNG"). Maximum 20 characters. Nullable.
Fuel_Price
float
required
Price per litre in Indian Rupees (e.g. 101.72).
Petrolpump_No
str
Foreign key referencing Petrolpump.Registration_No. Nullable.
Returns: None

SELECT (View All) Functions

Each view_all_* function issues a SELECT * FROM <table> query and returns every row as a list of tuples. These functions take no parameters. The UI layer wraps the result in a Pandas DataFrame to render it in Streamlit.
FunctionSQL ExecutedReturns
view_all_Petrolpump_data()SELECT * FROM PetrolpumpList of tuples
view_all_Owners_data()SELECT * FROM OwnersList of tuples
view_all_Employee_data()SELECT * FROM EmployeeList of tuples
view_all_Customer_data()SELECT * FROM CustomerList of tuples
view_all_Invoice_data()SELECT * FROM InvoiceList of tuples
view_all_Tanker_data()SELECT * FROM TankerList of tuples

SELECT (View IDs Only) Functions

These functions fetch only the primary key column from each table. They are used to populate selectbox dropdowns in the Update and Remove views, so the user can pick an existing record by its identifier before acting on it. Each function takes no parameters and returns a list of single-element tuples.
FunctionSQL ExecutedReturned Column
view_only_Registration_No()SELECT Registration_No FROM PetrolpumpRegistration_No
view_only_Owner_Name()SELECT Owner_Name FROM OwnersOwner_Name
view_only_Employee_ID()SELECT Employee_ID FROM EmployeeEmployee_ID
view_only_Customer_Code()SELECT Customer_Code FROM CustomerCustomer_Code
view_only_Invoice_No()SELECT Invoice_No FROM InvoiceInvoice_No
view_only_Tanker_ID()SELECT Tanker_ID FROM TankerTanker_ID

SELECT (Get Single Record) Functions

Each get_all_info_* function looks up the full row for a specific primary key value. The PK is embedded into the SQL string using Python’s str.format() method — see the security note at the top of this page.
FunctionParameterSQL Executed
get_all_info_Petrolpump(selected_Petrolpump)Registration_No valueSELECT * FROM Petrolpump WHERE Registration_No="..."
get_all_info_Owners(selected_Owners)Owner_Name valueSELECT * FROM Owners WHERE Owner_Name="..."
get_all_info_Employee(selected_Employee)Employee_ID valueSELECT * FROM Employee WHERE Employee_ID="..."
get_all_info_Customer(selected_Customer)Customer_Code valueSELECT * FROM Customer WHERE Customer_Code="..."
get_all_info_Invoice(selected_Invoice)Invoice_No valueSELECT * FROM Invoice WHERE Invoice_No="..."
get_all_info_Tanker(selected_Tanker)Tanker_ID valueSELECT * FROM Tanker WHERE Tanker_ID="..."
All six functions return a list of tuples containing the matched row(s). Under normal operation the list will contain exactly one tuple, since the filter is on the primary key.

UPDATE Functions

Each edit_* function issues a parameterized UPDATE statement using %s placeholders, commits the transaction, then immediately calls the corresponding view_all_* function and returns its result. This pattern gives the UI a fresh snapshot of the table after every write.
Updates all editable fields for a pump identified by Registration_No.
database.py
def edit_Petrolpump_data(new_Petrolpump_Name, new_Company_Name, new_Opening_Year,
                         new_State, new_City, Registration_No):
    c.execute(
        "UPDATE Petrolpump SET Petrolpump_Name=%s, Company_Name=%s, Opening_Year=%s, "
        "State=%s, City=%s WHERE Registration_No=%s",
        (new_Petrolpump_Name, new_Company_Name, new_Opening_Year, new_State, new_City, Registration_No)
    )
    mydb.commit()
    data = view_all_Petrolpump_data()
    return data
new_Petrolpump_Name
str
required
New trading name.
new_Company_Name
str
New parent oil company name.
new_Opening_Year
int
Updated opening year.
new_State
str
Updated state.
new_City
str
required
Updated city.
Registration_No
str
required
Primary key identifying the record to update.
Returns: Result of view_all_Petrolpump_data() — full updated table as a list of tuples.
Updates all editable fields for an owner identified by Owner_Name.
database.py
def edit_Owners_data(new_Contact_NO, new_DOB, new_Gender, new_Address,
                     new_Partnership, Owner_Name):
    c.execute(
        "UPDATE Owners SET Contact_NO=%s, DOB=%s, Gender=%s, Address=%s, "
        "Partnership=%s WHERE Owner_Name=%s",
        (new_Contact_NO, new_DOB, new_Gender, new_Address, new_Partnership, Owner_Name)
    )
    mydb.commit()
    data = view_all_Owners_data()
    return data
new_Contact_NO
str
required
Updated 10-digit contact number.
new_DOB
date
Updated date of birth (YYYY-MM-DD).
new_Gender
str
Updated gender ("M" or "F").
new_Address
str
Updated postal address.
new_Partnership
int
required
Updated ownership stake percentage.
Owner_Name
str
required
Primary key identifying the owner to update.
Returns: Result of view_all_Owners_data() — full updated table as a list of tuples.
Updates all editable fields for an employee identified by Employee_ID.
database.py
def edit_Employee_data(new_Emp_Name, new_Emp_Gender, new_Designation, new_DOB,
                       new_Salary, new_Emp_Address, new_Email_ID,
                       new_Petrolpump_No, new_Manager_ID, Employee_ID):
    c.execute(
        "UPDATE Employee SET Emp_Name=%s, Emp_Gender=%s, Designation=%s, DOB=%s, "
        "Salary=%s, Emp_Address=%s, Email_ID=%s, Petrolpump_No=%s, Manager_ID=%s "
        "WHERE Employee_ID=%s",
        (new_Emp_Name, new_Emp_Gender, new_Designation, new_DOB, new_Salary,
         new_Emp_Address, new_Email_ID, new_Petrolpump_No, new_Manager_ID, Employee_ID)
    )
    mydb.commit()
    data = view_all_Employee_data()
    return data
new_Emp_Name
str
required
Updated full name.
new_Emp_Gender
str
Updated gender ("M" or "F").
new_Designation
str
Updated job designation.
new_DOB
date
Updated date of birth (YYYY-MM-DD).
new_Salary
int
Updated monthly salary in INR.
new_Emp_Address
str
required
Updated residential address.
new_Email_ID
str
required
Updated email address.
new_Petrolpump_No
str
Updated pump assignment (FK to Petrolpump.Registration_No).
new_Manager_ID
str
Updated manager reference (FK to Employee.Employee_ID).
Employee_ID
str
required
Primary key identifying the employee to update.
Returns: Result of view_all_Employee_data() — full updated table as a list of tuples.
Updates all editable fields for a customer identified by Customer_Code.
database.py
def edit_Customer_data(new_C_Name, new_Phone_No, new_Email_ID, new_Gender,
                       new_City, new_Age, Customer_Code):
    c.execute(
        "UPDATE Customer SET C_Name=%s, Phone_No=%s, Email_ID=%s, Gender=%s, "
        "City=%s, Age=%s WHERE Customer_Code=%s",
        (new_C_Name, new_Phone_No, new_Email_ID, new_Gender, new_City, new_Age, Customer_Code)
    )
    mydb.commit()
    data = view_all_Customer_data()
    return data
new_C_Name
str
required
Updated customer name.
new_Phone_No
str
Updated 10-digit phone number.
new_Email_ID
str
Updated email address.
new_Gender
str
Updated gender ("M" or "F").
new_City
str
Updated city.
new_Age
int
Updated age in years.
Customer_Code
str
required
Primary key identifying the customer to update.
Returns: Result of view_all_Customer_data() — full updated table as a list of tuples.
Updates all editable fields for an invoice identified by Invoice_No.
database.py
def edit_Invoice_data(new_Date, new_Payment_Type, new_Fuel_Amount, new_Fuel_Type,
                      new_Discount, new_Total_Price, new_Customer_Code, Invoice_No):
    c.execute(
        "UPDATE Invoice SET Date=%s, Payment_Type=%s, Fuel_Amount=%s, Fuel_Type=%s, "
        "Discount=%s, Total_Price=%s, Customer_Code=%s WHERE Invoice_No=%s",
        (new_Date, new_Payment_Type, new_Fuel_Amount, new_Fuel_Type,
         new_Discount, new_Total_Price, new_Customer_Code, Invoice_No)
    )
    mydb.commit()
    data = view_all_Invoice_data()
    return data
new_Date
date
required
Updated transaction date (YYYY-MM-DD).
new_Payment_Type
str
required
Updated payment method.
new_Fuel_Amount
float
Updated fuel volume in litres.
new_Fuel_Type
str
Updated fuel product name.
new_Discount
int
Updated discount percentage.
new_Total_Price
float
required
Updated final billed amount in INR.
new_Customer_Code
str
Updated customer foreign key.
Invoice_No
str
required
Primary key identifying the invoice to update.
Returns: Result of view_all_Invoice_data() — full updated table as a list of tuples.
Updates all editable fields for a tanker identified by Tanker_ID.
database.py
def edit_Tanker_data(new_Capacity, new_pressure, new_Fuel_ID, new_Fuel_Amount,
                     new_Fuel_Name, new_Fuel_Price, new_Petrolpump_No, Tanker_ID):
    c.execute(
        "UPDATE Tanker SET Capacity=%s, pressure=%s, Fuel_ID=%s, Fuel_Amount=%s, "
        "Fuel_Name=%s, Fuel_Price=%s, Petrolpump_No=%s WHERE Tanker_ID=%s",
        (new_Capacity, new_pressure, new_Fuel_ID, new_Fuel_Amount,
         new_Fuel_Name, new_Fuel_Price, new_Petrolpump_No, Tanker_ID)
    )
    mydb.commit()
    data = view_all_Tanker_data()
    return data
new_Capacity
float
Updated total tank capacity in litres.
new_pressure
float
Updated storage pressure.
new_Fuel_ID
str
required
Updated internal fuel product identifier.
new_Fuel_Amount
float
Updated current fuel volume in litres.
new_Fuel_Name
str
Updated human-readable fuel name.
new_Fuel_Price
float
required
Updated price per litre in INR.
new_Petrolpump_No
str
Updated pump assignment foreign key.
Tanker_ID
str
required
Primary key identifying the tanker to update.
Returns: Result of view_all_Tanker_data() — full updated table as a list of tuples.

DELETE Functions

Each delete_data_* function builds a DELETE FROM statement using Python’s str.format() to embed the primary key value, then calls mydb.commit(). Like the get_all_info_* functions, these use string interpolation rather than parameterized queries — see the security note at the top of this page.
FunctionParameterSQL ExecutedReturns
delete_data_Petrolpump(selected_Petrolpump)Registration_NoDELETE FROM Petrolpump WHERE Registration_No="..."None
delete_data_Owners(selected_Owners)Owner_NameDELETE FROM Owners WHERE Owner_Name="..."None
delete_data_Employee(selected_Employee)Employee_IDDELETE FROM Employee WHERE Employee_ID="..."None
delete_data_Customer(selected_Customer)Customer_CodeDELETE FROM Customer WHERE Customer_Code="..."None
delete_data_Invoice(selected_Invoice)Invoice_NoDELETE FROM Invoice WHERE Invoice_No="..."None
delete_data_Tanker(selected_Tanker)Tanker_IDDELETE FROM Tanker WHERE Tanker_ID="..."None

Special Function: TOTAL_Amount()

TOTAL_Amount(tanker_id) is the Python wrapper that calls the MySQL stored function TOTAL_AMOUNT(TID). Because mysql.connector does not support calling stored functions with callproc(), the implementation uses two consecutive c.execute() calls: the first sets a session variable with the tanker ID, and the second calls the function through that variable.
database.py
def TOTAL_Amount(tanker_id):
    query = "SET @p0='{}';".format(tanker_id)
    c.execute(query)

    query = "SELECT `TOTAL_AMOUNT`(@p0) AS `TOTAL_AMOUNT`;"
    c.execute(query)
    result = c.fetchall()
    return result
tanker_id
str
required
The Tanker_ID primary key of the tanker to calculate the total fuel value for (e.g. "BR6872"). The value is embedded into the SET statement via str.format().
Returns: A list of tuples, each containing one float value representing FUEL_PRICE × FUEL_AMOUNT for the given tanker. Under normal operation the list contains exactly one tuple: [(total_amount,)]. The MySQL stored function TOTAL_AMOUNT(TID) that this calls is defined as:
DELIMITER $$
CREATE FUNCTION `TOTAL_AMOUNT`(`TID` VARCHAR(10)) RETURNS float
    DETERMINISTIC
BEGIN
    DECLARE BILL FLOAT;
    DECLARE RATE FLOAT;
    DECLARE VOL FLOAT;

    SET RATE = (SELECT FUEL_PRICE FROM TANKER WHERE TANKER_ID = TID);
    SET VOL  = (SELECT FUEL_AMOUNT FROM TANKER WHERE TANKER_ID = TID);

    SET BILL = RATE * VOL;

    RETURN BILL;
END$$
DELIMITER ;

Build docs developers (and LLMs) love