简体   繁体   中英

Python SQLite query always returns None

I have a SQL-file (SQLite format 3) that I can query with the DB Browser for SQLite (Windows). Whenever I use Python to access the db I get a Null result.

import sqlite3
conn = sqlite3.connect('C:/tmp/test.sql')
cursor = conn.cursor()

conn.execute('select count(*) from Player')
print("result is:", cursor.fetchone()) # result is: None
import sqlite3

connection = sqlite3.connect(database_name)
cursor = connection.cursor()

cursor.execute("select val from table_name where x = 'something';")
result = cursor.fetchone()

# directly returning result also gives null
if result:
    return result[0]  # tuple returned in result

cursor.close()
connection.close()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM