SQLite Forum

python inteface
Login

python inteface

(1) By vishal vagare (vishalvagare) on 2021-02-20 10:21:16 [link]

Hi

i have compiled SQLITE3(sqlite3.c and shell.c) with GCC compiler,is there any way(or interface) to fetch the sqlite3 executable through python code?
Or how can i  directly import sqlite3 which is compiled in GCC?

(2) By Simon Slavin (slavin) on 2021-02-20 14:00:48 in reply to 1

Please don't confuse the sqlite3 executable with the sqlite3 API.

The sqlite3 executable is useful for testing sqlite3 features and examining sqlite3 databases manually.  It can be used by scripting languages, such as batch files to be executed by a shell.  You should never install the sqlite3 shell tool on any computer you don't own, since it may be incompatible with later versions of the OS.

The SQLite3 API can be called directly by numerous programming languages including Python:

<https://www.pythoncentral.io/introduction-to-sqlite-in-python/>

<https://docs.python.org/3/library/sqlite3.html>

(3) By Keith Medcalf (kmedcalf) on 2021-02-20 21:51:35 in reply to 1 [link]

In Python you execute the code line snippet `import sqlite3` which imports the sqlite3.py wrapper, which in turn imports the compiled extension (pysqlite2) with the name _sqlite3, which in turn loads the standard dynamic loadable library sqlite3 created by the compiler (and/or shipped with Python).

The particular filename extensions and locations vary based on the Operating System and version of Python, which you have not provided.

Basically, in order to have the Python pysqlite2 (sqlite3) extension use a version of sqlite3 that you have compiled yourself, you have to find the version of the sqlite3 dynamic load library that is being loaded and replace it with a compatible version that you have compiled yourself -- this may also include issuing magical incantations to your Operating System to *make it so*.

The sqlite3 executable is, strangely enough, an executable.  You cause it to be executed by a Python program in the same manner as you cause any other executable to be executed in the Python environment -- by using os.system or other method for executing executables.