Skip to content

Commit fa99235

Browse files
author
Kepka
committed
cursors, placeholders
1 parent 452c48b commit fa99235

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

createDB/checkdb.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
conn = sqlite3.connect("contacts.sqlite")
44

5-
for row in conn.execute("SELECT * FROM contacts"):
5+
name = input("Please enter a name to search for: ")
6+
7+
for row in conn.execute("SELECT * FROM contacts WHERE name = ?", (name,)):
68
print(row)
79

810
conn.close()

createDB/contacts.sqlite

0 Bytes
Binary file not shown.

createDB/contacts2.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@
22

33
db = sqlite3.connect("contacts.sqlite")
44

5-
update_sql = "UPDATE contacts SET email = 'update@update.com' WHERE contacts.phone = 1234"
5+
new_email = "another.update@update.com"
6+
phone = input("Please enter the phone number: ")
7+
8+
# update_sql = f"UPDATE contacts SET email = {new_email} WHERE contacts.phone = {phone}"
9+
update_sql = f"UPDATE contacts SET email = ? WHERE contacts.phone = ?"
10+
print(update_sql)
11+
612
update_cursor = db.cursor()
7-
update_cursor.execute(update_sql)
8-
print(f"{update_cursor.rowcount} rows updated")
13+
update_cursor.execute(update_sql, (new_email, phone))
14+
# update_cursor.executescript(update_sql)
15+
# print(f"{update_cursor.rowcount} rows updated")
916

1017
update_cursor.connection.commit()
1118
update_cursor.close()

0 commit comments

Comments
 (0)