File tree Expand file tree Collapse file tree 2 files changed +66
-0
lines changed
challenges/intermediate-literalstring Expand file tree Collapse file tree 2 files changed +66
-0
lines changed Original file line number Diff line number Diff line change
1
+ """
2
+ TODO:
3
+
4
+ You're writing a web backend.
5
+ Annotate a function `execute_query` which runs SQL, but also can prevent SQL injection attacks.
6
+ """
7
+
8
+ from typing import Iterable
9
+
10
+
11
+ def execute_query (sql , parameters : Iterable [str ] = ...):
12
+ """No need to implement it"""
13
+
14
+
15
+ ## End of your code ##
16
+ def query_user (user_id : str ):
17
+ query = f"SELECT * FROM data WHERE user_id = { user_id } "
18
+ execute_query (query ) # expect-type-error
19
+
20
+
21
+ def query_data (user_id : str , limit : bool ) -> None :
22
+ query = """
23
+ SELECT
24
+ user.name,
25
+ user.age
26
+ FROM data
27
+ WHERE user_id = ?
28
+ """
29
+
30
+ if limit :
31
+ query += " LIMIT 1"
32
+
33
+ execute_query (query , (user_id ,))
Original file line number Diff line number Diff line change
1
+ """
2
+ TODO:
3
+
4
+ You're writing a web backend.
5
+ Annotate a function `execute_query` which runs SQL, but also can prevent SQL injection attacks.
6
+ """
7
+
8
+ from typing import LiteralString , Iterable
9
+
10
+
11
+ def execute_query (sql : LiteralString , parameters : Iterable [str ] = ...):
12
+ ...
13
+
14
+
15
+ ## End of your code ##
16
+ def query_user (user_id : str ):
17
+ query = f"SELECT * FROM data WHERE user_id = { user_id } "
18
+ execute_query (query ) # expect-type-error
19
+
20
+
21
+ def query_data (user_id : str , limit : bool ) -> None :
22
+ query = """
23
+ SELECT
24
+ user.name,
25
+ user.age
26
+ FROM data
27
+ WHERE user_id = ?
28
+ """
29
+
30
+ if limit :
31
+ query += " LIMIT 1"
32
+
33
+ execute_query (query , (user_id ,))
You can’t perform that action at this time.
0 commit comments