APSW Python Sqlite: how do you use it?

41 views
Skip to first unread message

Veek M

unread,
Jan 24, 2023, 9:10:17 AM1/24/23
to python-sqlite

Why does the APSW - Python module for sqlite provide us with Connection() when it's a wrapper around the C library sqlite3_open() ??

How do you use sqlite3_open in Python/APSW? The function signature is:

int sqlite3_open( const char *filename, sqlite3 **db_ptr )

So what can we use in python for a pointer - where is this use documented in APSW - instead APSW documents the abstraction it provides (Connection and such)?

http://www.cesarkallas.net/arquivos/apostilas/python/exemplos/APSW%20-%20Another%20Python%20SQLite%20Wrapper.htm

Everything you can do from the C API to SQLite 3, you can do from Python.

https://rogerbinns.github.io/apsw/example.html

Roger Binns

unread,
Jan 24, 2023, 9:31:44 AM1/24/23
to Python-SQLite group
On Tue, 24 Jan 2023, at 05:21, Veek M wrote:
> Why does the APSW - Python module for sqlite provide us with
> Connection() when it's a wrapper around the C library sqlite3_open() ??

Because that is how Python modules work. You get objects that seem Pythonic but behind the scenes is doing all the necessary work to interface with a C library.

> How do you use sqlite3_open in Python/APSW? The function signature is:
>
> *int sqlite3_open( const char *filename, sqlite3 **db_ptr )*
...
> So what can we use in python for a pointer

If you want to use the C APIs directly then you do not need APSW. Python comes with a module named ctypes that lets you do so:

https://docs.python.org/3/library/ctypes.html

Go ahead and proceed using that, and please let us know how you get on.

> *Everything you can do from the C API to SQLite 3, you can do from Python.*

That is correct - you can write simple Python code and APSW deals with all the C interfacing behind the scenes. There is far more to it that just calling sqlite3_open including lots of memory management, error checking and handling, statement caches, conversion between data formats, iterators ... - over 11,000 lines of C code glue.

Roger
Reply all
Reply to author
Forward
0 new messages