FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
code_snippets/Python-SQLite/sqlite_demo.py at master · Samakwa/code_snippets · GitHub
Samakwa
/
code_snippets
Public
forked from
CoreyMSchafer/code_snippets
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
code_snippets
/
Python-SQLite
/
sqlite_demo.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
52 lines (35 loc) · 1.17 KB
Breadcrumbs
code_snippets
/
Python-SQLite
/
sqlite_demo.py
Copy path
File metadata and controls
52 lines (35 loc) · 1.17 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import
sqlite3
from
employee
import
Employee
conn
=
sqlite3
.
connect
(
':memory:'
)
c
=
conn
.
cursor
()
c
.
execute
(
"""CREATE TABLE employees (
first text,
last text,
pay integer
)"""
)
def
insert_emp
(
emp
):
with
conn
:
c
.
execute
(
"INSERT INTO employees VALUES (:first, :last, :pay)"
, {
'first'
:
emp
.
first
,
'last'
:
emp
.
last
,
'pay'
:
emp
.
pay
})
def
get_emps_by_name
(
lastname
):
c
.
execute
(
"SELECT * FROM employees WHERE last=:last"
, {
'last'
:
lastname
})
return
c
.
fetchall
()
def
update_pay
(
emp
,
pay
):
with
conn
:
c
.
execute
(
"""UPDATE employees SET pay = :pay
WHERE first = :first AND last = :last"""
,
{
'first'
:
emp
.
first
,
'last'
:
emp
.
last
,
'pay'
:
pay
})
def
remove_emp
(
emp
):
with
conn
:
c
.
execute
(
"DELETE from employees WHERE first = :first AND last = :last"
,
{
'first'
:
emp
.
first
,
'last'
:
emp
.
last
})
emp_1
=
Employee
(
'John'
,
'Doe'
,
80000
)
emp_2
=
Employee
(
'Jane'
,
'Doe'
,
90000
)
insert_emp
(
emp_1
)
insert_emp
(
emp_2
)
emps
=
get_emps_by_name
(
'Doe'
)
print
(
emps
)
update_pay
(
emp_2
,
95000
)
remove_emp
(
emp_1
)
emps
=
get_emps_by_name
(
'Doe'
)
print
(
emps
)
conn
.
close
()
Back
|
FazBrowse Home
|
New Git URL