-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_user_query.py
More file actions
35 lines (31 loc) · 961 Bytes
/
test_user_query.py
File metadata and controls
35 lines (31 loc) · 961 Bytes
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
"""测试用户ID查询"""
import sys
sys.path.insert(0, '.')
from db_models import get_user_by_username, get_user_id_by_username
import sqlite3
print("=== 直接SQLite查询 ===")
conn = sqlite3.connect('punch_timer.db')
cursor = conn.cursor()
cursor.execute("SELECT id, username FROM users WHERE username = ?", ('1184975',))
result = cursor.fetchone()
print(f"SQLite结果: {result}")
conn.close()
print("\n=== 使用db_models查询 ===")
try:
user = get_user_by_username('1184975')
print(f"get_user_by_username结果: {user}")
print(f"类型: {type(user)}")
if user:
print(f"user[0] (ID): {user[0]}")
except Exception as e:
print(f"错误: {e}")
import traceback
traceback.print_exc()
print("\n=== 使用get_user_id_by_username ===")
try:
user_id = get_user_id_by_username('1184975')
print(f"用户ID: {user_id}")
except Exception as e:
print(f"错误: {e}")
import traceback
traceback.print_exc()