Saravana Updated
Saravana Updated
PROJECT REPORT
COMPUTER SCIENCE
Topic: STOCK MANAGEMENT
Academic year: 2024 – 2025
DONE BY:
R.GOKULAVARADHAN(XII-A)
K.SARAVANAN(XII-A)
THARAKESHWAR(XII-A)
______________ ______________
Internal Examiner External Examiner
___________________
Signature of the Principal
Acknowledgement
I would like to express my greatest appreciation to the all individuals
who have helped and supported me throughout the project which led to
its success and final outcome of this project.
2. SYSTEM CONFIGURATION 6
3. INTRODUCTION 7
i) PYTHON
ii) MYSQL
4. RELATION BETWEEN PYTHON AND MYSQL 11
5. DATABASE CONNECTIVITY 12
7. DATABASE SCHEMA 13
9. SOURCE CODE 14
10. OUTPUT 19
11. CONCLUSION 23
12. BIBLIOGRAPHY 25
TABLE OF CONTENTS:
2.SYSTEM CONFIGURATION
HARDWARE CONFIGURATION
SOFTWARE REQUIREMENTS:
• Basic GPU – Any vendor DirectX 9.0 class or better (Pixel Shader Level 2)
3.INTRODUCTION
i) PYTHON:
Python is a high-level, interpreted scripting language developed in the late 1980s by
Guidovan Rossum at the National Research Institute for Mathematics and Computer Science
in the Netherlands. The initial version was published at the outsources newsgroup in 1991,
and version 1.0 was released in 1994.
Python 2.0 was released in 2000, and the 2.x versions were the prevalent releases until
December 2008. At that time, the development team made the decision to release version 3.0,
which contained a few relatively small but significant changes that were not backward
compatible with the 2.x versions. Python 2 and 3 are very similar, and some features of
Python 3 have been backported to Python 2. But in general, they remain not quite compatible.
As of this writing, the most recent python version available is 3.11.0. An official end of life
of January 1,2020 has been established for Python 2, after which time it will no longer be
maintained.
Python is still maintained by a core development team at the Institute, and Guido is still in
charge, having been given the title of BDFL (Benevolent Dictator for Life) by the Python
community. The name Python derives not from the snake, but from the British comedy troupe
Monty Python’s Flying Circus, of which Guido was, and presumably still is, a fan. It is
common to find references to Monty Python sketches and movies scattered throughout the
Python documentation.
Python is Popular
Python has been growing in popularity over the last few years. The 2018 Stack Overflow
Developer Survey ranked Python as the 7th most popular and the number one most wanted
technology of the year. World-class software development countries around the globe use
Python every single day. According to research by Dice, Python is also one of the hottest
skills to have and the most popular programming language in the world based on the
Popularity of programming Language Index.
Python is Interpreted
Many languages are compiled, meaning the source code you create needs to be translated into
machine code, the language of your computer’s processor, before it can be run. Programs
written in an interpreted language are passed straight to an interpreter that runs them directly.
This makes for a quicker development cycle because you just type in your code and unit,
without the intermediate compilation step. One potential downside to interpreted languages is
execution speed. Programs that are compiled into the native language of the computer
processor tend to run more quickly than interpreted programs. For some applications that are
particularly computationally intensive, like graphics processing or intense number crunching,
this can be limiting.
In practice, however, for most programs, the difference in execution speed is measured in
milliseconds, or seconds at most, and not appreciably noticeable to a human user. The
expediency of coding in an interpreted language is typically worth it for most applications.
Python is Free
The Python interpreter is developed under an OSI-approved open-source license, making it
free to install, use, and distribute, even for commercial purposes.
A version of the interpreter is available for virtually any platform there is, including all
flavors of Unix, Windows, macOS, smartphones and tablets, and probably anything else you
ever heard of. A version even exists for the half dozen people remaining who use OS/2.
Python is Portable
Because Python code is interpreted and not compiled into native machine instructions, code
written for one platform will work on any other platform that has the Python interpreter
installed. (This is true of any interpreted language, not just Python.
Python is Simple
As programming languages go, Python is relatively uncluttered, and the developers have
deliberately kept it that way. A rough estimate of the complexity of a language can be
gleaned from the number of keywords or reserved words in the language. These are words
that are reserved for special meaning by the compiler or interpreter because they designate
specific built-in functionality of the language. Python 3 has 33 keywords, and Python 2 has
31. By contrast, C++ has 62, Java has 53, and Visual Basic has more than 120, though these
latter examples probably vary somewhat by implementation or dialect.
ii) MYSQL:
Database Management System:
A Database Management System (DBMS) is a software application that interacts with the
user, applications and the database itself to capture and analyse data. The data stored in the
database can be modified, retrieved and deleted, and can be of any type like strings, numbers,
images etc.
Types of DBMS:
There are mainly 4 types of DBMS, which are Hierarchical, Relational, Network, and Object-
Oriented DBMS.
Hierarchical DBMS: As the name suggests, this type of DBMS has a style of
predecessor-successor type of relationship. So, it has a structure similar to that of a tree,
wherein the nodes represent records and the branches of the tree represent fields.
Relational DBMS (RDBMS): This type of DBMS, uses a structure that allows the
users to identify and access data in relation to another piece of data in the database.
Network DBMS: This type of DBMS supports many to many relations wherein multiple
member records can be linked.
Object-oriented DBMS: This type of DBMS uses small individual software called
objects. Each object contains a piece of data, and the instructions for the actions to be done
with the data.
• DCL (Data Control Language) – It allows you to control access to the database.
Example – Grant or Revoke access permissions.
• TCL (Transaction Control Language) – It allows you to deal with the transaction
of the database. Example – Commit, Rollback, Savepoint, Set Transaction.
• High Performance – Provides fast load utilities with distinct memory caches and table
index partitioning.
• Low Total Cost of Ownership – This reduces licensing costs and hardware
expenditures.
• Open Source & 24 * 7 Support – This RDBMS can be used on any platform and
offers 24*7 support for open source and enterprise edition.
• Secure Data Protection – MySQL supports powerful mechanisms to ensure that only
authorized users have access to the databases.
• Scalability & Flexibility – With MySQL you can run deeply embedded applications
and create data warehouses holding a humongous amount of data.
• Bit-string – These data types are either of a fixed length or varying length of bits.
There is also a variable-length bit string data type called BINARY LARGE
OBJECT(BLOB), which is available to specify columns that have large binary values, such
as images.
• Boolean –This data type has TRUE or FALSE values. Since SQL, has NULL values, a
three-valued logic is used, which is UNKNOWN.
• Date & Time –The DATE data type has: YEAR, MONTH, and DAY in the form
YYYY-MM-DD. Similarly, the TIME data type has the components HOUR, MINUTE, and
SECOND in the form HH:MM: SS. These formats can change based on the requirement.
• Timestamp & Interval –The TIMESTAMP data type includes a minimum of six
positions, for decimal fractions of seconds and an optional WITH TIME ZONE qualifier in
addition to the DATE and TIME fields. The INTERVAL data type mentions a relative value
that can be used to increment or decrement an absolute value of a date, time, or timestamp.
Python MySQL Database Connection: Arguments required to connect MySQL from Python.
You need to know the following detail of the MySQL server to perform the connection from
Python.
You need to know the following detail of the MySQL server to perform the connection from
Python.
• Username – i.e., the username that you use to work with MySQL Server. The default
username for the MySQL database is a root.
• Password – Password is given by the user at the time of installing the MySQL database.
If you are using root then you won’t need the password.
• Host Name – is the server’s name or Ip address on which MySQL is running. If you are
running on localhost, then you can use localhost, or its IP, i.e. 127.0.0.0
• Database Name – Database name to which you want to connect. This is an optional
argument.
READ Operation
READ Operation on any database means to fetch some useful information from the database.
Once our database connection is established, you are ready to make a query into this
database. You can use either fetchone() method to fetch single record or fetchall()method to
fetch multiple values from a database table.
• fetchone() − It fetches the next row of a query result set. A result set is an object that is
returned when a cursor object is used to query a table.
• fetchall() − It fetches all the rows in a result set. If some rows have already been
extracted from the result set, then it retrieves the remaining rows from the result set.
5.DATABASE CONNECTIVITY
Steps to connect MySQL database in Python using MySQL
Connector Python
5. Close the Cursor object using a cursor.close() and MySQL database connection using
connection.close() after your work completes.
OS:
The OS module in Python provides functions for interacting with the operating system.OS
comes under Python’s standard utility modules. This module provides a portable way of
using operating system-dependent functionality. The os module include many functions to
interact with the file system.
MySQL Connector:
MySQL Connector/Python enables Python programs to access MySQL databases, using an
API that is compliant with the Python Database API Specification v2
Platform:
The platform module in Python is quite handy for retrieving information about the system on
which your Python code is running.
9.SOURCE CODE:
import os
import mysql.connector
import datetime
# Database connection
def connect_db():
try:
print(f"Error: {err}")
return None
def clear_screen():
print("\n" * 5)
def product_mgmt(mydb):
while True:
if choice == 1:
add_product(mydb)
elif choice == 2:
search_product(mydb)
elif choice == 3:
update_product(mydb)
elif choice == 4:
delete_product(mydb)
elif choice == 5:
break
def purchase_mgmt(mydb):
while True:
if choice == 1:
add_order(mydb)
elif choice == 2:
list_order(mydb)
elif choice == 3:
break
def sales_mgmt(mydb):
while True:
print("\t\t\t 1. Sale Items")
if choice == 1:
sale_product(mydb)
elif choice == 2:
list_sale(mydb)
elif choice == 3:
break
def user_mgmt(mydb):
while True:
if choice == 1:
add_user(mydb)
elif choice == 2:
list_user(mydb)
elif choice == 3:
break
def db_mgmt(mydb):
while True:
if choice == 1:
create_database(mydb)
elif choice == 2:
list_database(mydb)
elif choice == 3:
break
def create_database(mydb):
mycursor = mydb.cursor()
try:
pprice FLOAT(8,2),
pqty INT(4),
pcat CHAR(30));"""
mycursor.execute(aa)
orderdate DATE,
pprice FLOAT(8,2),
pqty INT(4),
supplier CHAR(50),
pcat CHAR(30));"""
mycursor.execute(sql)
mydb.commit()
salesdate DATE,
pprice FLOAT(8,2),
pqty INT(4),
Total DOUBLE(8,2));"""
mycursor.execute(sql)
mydb.commit()
upwd CHAR(30));"""
mycursor.execute(sql)
mydb.commit()
print(f"Error: {err}")
finally:
mycursor.close()
def list_database(mydb):
mycursor = mydb.cursor()
mycursor.execute("SHOW TABLES;")
print(table)
mycursor.close()
def add_order(mydb):
mycursor = mydb.cursor()
now = datetime.datetime.now()
sql= "INSERT INTO orders(orderid, orderdate, pcode, pprice, pqty, supplier, pcat) VALUES (%s, %s, %s, %s,
%s, %s, %s)"
mycursor.execute(sql, val)
mydb.commit()
mycursor.close()
def list_order(mydb):
mycursor = mydb.cursor()
clear_screen()
print("-" * 85)
print("-" * 85)
print(order[0], "\t", order[1], "\t", order[2], "\t ", order[3], "\t", order[4], "\t ", order[5], "\t",
order[6])
print("-" * 85)
mycursor.close()
def add_product(mydb):
mycursor = mydb.cursor()
sql = "INSERT INTO product(pcode, pname, pprice, pqty, pcat) VALUES (%s, %s, %s, %s, %s)"
cnt = mycursor.fetchone()[0]
if cnt == 0:
mycursor.execute(sql, val)
mydb.commit()
else:
mycursor.close()
def update_product(mydb):
mycursor = mydb.cursor()
mydb.commit()
mycursor.close()
def delete_product(mydb):
mycursor = mydb.cursor()
mycursor.execute(sql, (code,))
mydb.commit()
mycursor.close()
def search_product(mydb):
while True:
if choice == 1:
list_product(mydb)
elif choice == 2:
list_product_by_code(mydb, code)
elif choice == 3:
list_product_by_category(mydb, cat)
elif choice == 4:
break
def list_product(mydb):
mycursor = mydb.cursor()
mycursor.execute("SELECT * FROM product")
clear_screen()
print("\t\t", product[0], "\t", product[1], "\t", product[2], "\t ", product[3], "\t\t", product[4])
mycursor.close()
mycursor = mydb.cursor()
mycursor.execute(sql, (code,))
clear_screen()
print("\t\t", product[0], "\t", product[1], "\t", product[2], "\t ", product[3], "\t\t", product[4])
mycursor.close()
mycursor = mydb.cursor()
sql = "SELECT * FROM product WHERE pcat = %s"
mycursor.execute(sql, (cat,))
clear_screen()
print("\t\t", product[0], "\t", product[1], "\t", product[2], "\t ", product[3], "\t\t", product[4])
mycursor.close()
def sale_product(mydb):
mycursor = mydb.cursor()
cnt = mycursor.fetchone()[0]
if cnt != 0:
product = mycursor.fetchone()
print(product)
price = product[2]
pqty = product[3]
#mydb.commit()
#sales_id =2#int(mycursor.fetchone())+1
sales_id = mycursor.fetchone()
sales_id = sales_id[0]+1
print(sales_id)
sql = "INSERT INTO sales(salesid, salesdate, pcode, pprice, pqty, Total) VALUES({}, '0{}', '{}', {},{},
{})".format(sales_id, datetime.datetime.now(), pcode, price, qty, total)
mycursor.execute(sql)
mydb.commit()
mycursor.execute("UPDATE product SET pqty = pqty - %s WHERE pcode = %s", (qty, pcode))
mydb.commit()
else:
else:
mycursor.close()
def list_sale(mydb):
mycursor = mydb.cursor()
print("-" * 80)
print("-" * 80)
print(sale[0], "\t", sale[1], "\t", sale[2], "\t ", sale[3], "\t\t", sale[4], "\t\t", sale[5])
print("-" * 80)
mycursor.close()
def add_user(mydb):
mycursor = mydb.cursor()
sql = "INSERT INTO user (uid, uname, upwd) VALUES (%s, %s, %s);"
mycursor.execute(sql, val)
mydb.commit()
mycursor.close()
def list_user(mydb):
mycursor = mydb.cursor()
clear_screen()
mycursor.close()
def main():
mydb = connect_db()
create_database(mydb)
if mydb is None:
return
while True:
clear_screen()
print("\t\t\t ****************\n")
print("\t\t 6. EXIT\n")
if choice == 1:
product_mgmt(mydb)
elif choice == 2:
purchase_mgmt(mydb)
elif choice == 3:
sales_mgmt(mydb)
elif choice == 4:
user_mgmt(mydb)
elif choice == 5:
db_mgmt(mydb)
elif choice == 6:
break
mydb.close()
if __name__ == "__main__":
main()