- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path22_database.py
More file actions
Latest commit
34 lines (30 loc) · 1.16 KB
/
Copy path22_database.py
File metadata and controls
34 lines (30 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
importsqlite3
importcsv
defprintDB():
try:
result=theCursor.execute("SELECT id, FName, LName, Age, Address, Salary, HireDate FROM Employees")
forrowinresult:
print("ID: ", row[0])
print("First Name: ", row[1])
print("Last Name: ", row[2])
print("Age: ", row[3])
print("Address: ", row[4])
print("Salary: ", row[5])
print("Hire Date: ", row[6])
exceptsqlite3.OperationError:
print("The table doesn't exist")
except:
print("Couldn't get the data")
db_conn=sqlite3.connect('test.db')
print("Database Created")
theCursor=db_conn.cursor()
try:
db_conn.execute("CREATE TABLE Employees (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, FName TEXT, LName TEXT, Age INT NOT NULL, Address TEXT, Salary REAL, HireDate TEXT);")
db_conn.commit()
print("Table Created")
exceptsqlite3.OperationalError:
print("Table Not Created")
db_conn.execute("INSERT INTO Employees (FName, LName, Age, Address, Salary, HireDate) VALUES ('John', 'Doe', 30, '123 Main St', 10000.00, '2000-01-01');")
db_conn.commit()
printDB()
db_conn.close()