'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

Every Select statement leads to "result is: None".

Any ideas?

Bart.



Solution 1:[1]

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()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 QOPS