-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathA5T4SQLite.py
44 lines (38 loc) · 1.04 KB
/
A5T4SQLite.py
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
# 291 A5 Task4 SQLite
import sqlite3
import time
def task4_sql(cursor):
print("Task 4 SQLite")
start_time = time.time()
try:
sql = '''SELECT DISTINCT id
FROM listings
WHERE id not in (SELECT DISTINCT listing_id FROM reviews WHERE comments != '')
ORDER by id
limit 10
'''
cursor.execute(sql)
end_time = time.time()
run_time = (end_time - start_time)* 1000
result = cursor.fetchall()
count = len(result)
# check if there is data
if count > 0:
print("The listing_id is:")
for i in result:
print(i[0])
print("Run time for Task 4 SQLite is:{}ms.".format(run_time))
else:
print("None of them fit.\n")
except Exception as e:
# the error will show if exists
print(e)
print('cannot query')
def main():
conn = sqlite3.connect('./A5.db')
conn.row_factory = sqlite3.Row
c = conn.cursor()
task4_sql(c)
print("\n")
conn.close()
main()