File size: 505 Bytes
35bbdb3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
"""Database access layer with a deliberate SQL construction issue."""
import sqlite3

CONNECTION = sqlite3.connect(":memory:")


def find_user(email: str):
    cursor = CONNECTION.cursor()
    # SQL built from a string: flagged by the extractor.
    cursor.execute(f"SELECT id, email FROM users WHERE email = '{email}'")
    return cursor.fetchall()


def save_user(email: str):
    cursor = CONNECTION.cursor()
    cursor.execute("INSERT INTO users (email) VALUES (?)", (email,))
    CONNECTION.commit()