pythonsqlitefull-text-searchfts5

python and sqlite3, check if I can use fts5 extension?


I recently found out that FTS5 extension has been released.
What is the best way to check if my application can use it on users system?
Just python3 version check, or sqlite3.sqlite_version check according to release page?? Or something else?


Solution

  • This feels like it could work, found it in Using SQLite's FTS3/4 with Python 3

    import sqlite3
    
    con = sqlite3.connect(':memory:')
    cur = con.cursor()
    cur.execute('pragma compile_options;')
    available_pragmas = cur.fetchall()
    con.close()
    
    print(available_pragmas)
    
    if ('ENABLE_FTS5',) in available_pragmas:
        print('YES')
    else:
        print('NO')
    

    I run it in a few virtual machines, and none had fts4 enabled, yet I used it happily like nothing. From the documentation:

    Note that enabling FTS3 also makes FTS4 available. There is not a separate SQLITE_ENABLE_FTS4 compile-time option. A build of SQLite either supports both FTS3 and FTS4 or it supports neither.