Can't find table dbstat

Asked by At
c.execute('select sum(unused), sum(pgsize), sum(payload), count(*) from dbstat')

or

c.execute('select sum(unused), sum(pgsize), sum(payload), count(*) from main.dbstat')

I'm using sqlite3 database, and I'm trying to get the statistics of the database from the dbstat table. This line works fine on Linux not on Window. In both cases I made sure that I'm using the same sqlite3 version and the same python3 version. I would love to know why this doesn't work on windows.

Error:

c.execute('select sum(unused), sum(pgsize), sum(payload), count(*) from dbstat') sqlite3.OperationalError: no such table: dbstat

1 Answers

0
MohammedAlSafwan On

@Shawn ... ok, figured out what was going on. Python on Windows has a different sqlite3.dll than Python on Linux. The one on Windows didn't have the SQLITE_ENABLE_DBSTAT_VTAB. To make it work, you can compile the sqlite3.dll yourself from the source code like @Shawn said or you can download the compiled dll from their website, where it has the option enabled, and add it do the DLLs folder in the python director.

You can check the sqlite3 compiled options by calling

PRAGMA compile_options;

If you want to check the python sqlite3.dll run this python script

import sqlite3
conn = sqlite3.connect('test.db')

c = conn.cursor()

c.execute('PRAGMA compile_options;')
available_pragmas = c.fetchall()
print(available_pragmas)
conn.close()

Python3.7 output will look like this

[('COMPILER=msvc-1916',), ('ENABLE_FTS4',), ('ENABLE_FTS5',), ('THREADSAFE=1',)]