-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.py
More file actions
72 lines (55 loc) · 1.99 KB
/
2.py
File metadata and controls
72 lines (55 loc) · 1.99 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import aiosqlite
from rest_framework.decorators import api_view
@api_view(["GET", "POST"])
async def snippet_list(request):
name = request.GET["query"]
db = await aiosqlite.connect("db.sqlite")
# ruleid: aiosqlite-django
cursor = await db.execute(f"select * from Book where name = '{name}'")
await cursor.fetchone()
data = await cursor.fetchall()
await cursor.close()
await db.close()
return {"data": data}
@api_view(["GET", "POST"])
async def snippet_list2(request):
async with aiosqlite.connect("db") as db:
name = request.GET["query"]
# ruleid: aiosqlite-django
await db.execute(f"select * from Book where name = '{name}'")
# ok: aiosqlite-django
await db.execute(f"select * from Book where name = '123'")
await db.commit()
# ruleid: aiosqlite-django
async with db.execute(f"select * from Book where name = '{name}'") as cursor:
async for row in cursor:
do_smth(cursor)
return {"result": "ok"}
@api_view(["GET", "POST"])
async def snippet_list3(request):
name = request.GET["query"]
other_name = int(request.GET["query"])
db = await aiosqlite.connect("db")
cursor = await db.cursor()
# ruleid: aiosqlite-django
row = await cursor.execute(f"select * from Book where name = '{name}'")
# ok: aiosqlite-django
row = await not_a_cursor.execute(f"select * from Book where name = '{name}'")
# ok: aiosqlite-django
row = await cursor.execute(f"select * from Book where name = '{other_name}'")
await cursor.fetchall()
await cursor.close()
await db.close()
return {"result": "ok"}
@api_view(["GET", "POST"])
async def snippet_list4(request):
name = request.GET["query"]
async with aiosqlite.connect("db") as db:
# ok: aiosqlite-django
await db.execute("select * from Book where name = '123'")
await db.commit()
async with db.cursor() as cursor:
# ruleid: aiosqlite-django
row = await cursor.execute(f"select * from Book where name = '{name}'")
await cursor.fetchall()
return {"result": "ok"}