GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — SQLite Tutorial · jojoasd123/code_snippets@950c294

This repository was archived by the owner on Feb 2, 2026. It is now read-only.

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .gitignore
  • Python-SQLite
    • employee.db
    • employee.py
    • snippets.txt
    • sqlite_demo.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.gitignore‎

Copy file name to clipboardExpand all lines: .gitignore
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
.DS_Store
2+
__pycache__/
3+
*.pyc
24

35
# Video Scripts
46
s.txt
Collapse file

‎Python-SQLite/employee.db‎

Copy file name to clipboard
8 KB
Binary file not shown.
Collapse file

‎Python-SQLite/employee.py‎

Copy file name to clipboard
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
class Employee:
3+
"""A sample Employee class"""
4+
5+
def __init__(self, first, last, pay):
6+
self.first = first
7+
self.last = last
8+
self.pay = pay
9+
10+
@property
11+
def email(self):
12+
return '{}.{}@email.com'.format(self.first, self.last)
13+
14+
@property
15+
def fullname(self):
16+
return '{} {}'.format(self.first, self.last)
17+
18+
def __repr__(self):
19+
return "Employee('{}', '{}', {})".format(self.first, self.last, self.pay)
Collapse file

‎Python-SQLite/snippets.txt‎

Copy file name to clipboard
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
def insert_emp(emp):
3+
pass
4+
5+
6+
def get_emps_by_name(lastname):
7+
pass
8+
9+
10+
def update_pay(emp, pay):
11+
pass
12+
13+
14+
def remove_emp(emp):
15+
pass
16+
17+
18+
19+
20+
def update_pay(emp, pay):
21+
with conn:
22+
c.execute("""UPDATE employees SET pay = :pay
23+
WHERE first = :first AND last = :last""",
24+
{'first': emp.first, 'last': emp.last, 'pay': pay})
25+
26+
27+
def remove_emp(emp):
28+
with conn:
29+
c.execute("DELETE from employees WHERE first = :first AND last = :last",
30+
{'first': emp.first, 'last': emp.last})
Collapse file

‎Python-SQLite/sqlite_demo.py‎

Copy file name to clipboard
+52Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import sqlite3
2+
from employee import Employee
3+
4+
conn = sqlite3.connect(':memory:')
5+
6+
c = conn.cursor()
7+
8+
c.execute("""CREATE TABLE employees (
9+
first text,
10+
last text,
11+
pay integer
12+
)""")
13+
14+
15+
def insert_emp(emp):
16+
with conn:
17+
c.execute("INSERT INTO employees VALUES (:first, :last, :pay)", {'first': emp.first, 'last': emp.last, 'pay': emp.pay})
18+
19+
20+
def get_emps_by_name(lastname):
21+
c.execute("SELECT * FROM employees WHERE last=:last", {'last': lastname})
22+
return c.fetchall()
23+
24+
25+
def update_pay(emp, pay):
26+
with conn:
27+
c.execute("""UPDATE employees SET pay = :pay
28+
WHERE first = :first AND last = :last""",
29+
{'first': emp.first, 'last': emp.last, 'pay': pay})
30+
31+
32+
def remove_emp(emp):
33+
with conn:
34+
c.execute("DELETE from employees WHERE first = :first AND last = :last",
35+
{'first': emp.first, 'last': emp.last})
36+
37+
emp_1 = Employee('John', 'Doe', 80000)
38+
emp_2 = Employee('Jane', 'Doe', 90000)
39+
40+
insert_emp(emp_1)
41+
insert_emp(emp_2)
42+
43+
emps = get_emps_by_name('Doe')
44+
print(emps)
45+
46+
update_pay(emp_2, 95000)
47+
remove_emp(emp_1)
48+
49+
emps = get_emps_by_name('Doe')
50+
print(emps)
51+
52+
conn.close()

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.