On Wed, 19 Apr 2023, at 08:59, Peter Maivald wrote:
> I've been
> using the SQLite package on debian for some time and apparently they do
> have SQLITE_ENABLE_COLUMN_METADATA on.
I went and checked a bunch of Linux distros and they all had the option on, but they didn't agree on most other options! For example only some have SQLITE_ENABLE_API_ARMOR, which APSW also enables by default.
So it will be enabled by default in the next release:
https://github.com/rogerbinns/apsw/issues/435
> The times I most use table and
> column names is for prototyping and testing, when I want to
> automatically display or log as much information about the query as
> possible.
That is also where I want to make APSW more useful. There is a lot of work behind the scenes to catch any potential bugs in code, and give useful diagnostics. That is one reason API armour is on, and why apsw.trace exists.
> While thinking about this, I realized that I often like to see if
> there's any data before deciding what to do next.
This is a bit tricky. It would be easy if Python had a standard way of telling if an iterator is exhausted, but you can't without asking for the next item. If the status is C_ROW then you are sitting at a result row, but that doesn't mean there are any more.
Code I've done recently uses apsw.ext.query_info() to get the information about the query and columns, and then for/else for the rows:
for row in con.execute("....."):
print(row)
else:
print("no rows returned")
> It's also occurred to me to be able to call something like
> sqlite3_reset on a cursor to start a result set over again
That is quite doable, although as you noted it isn't that necessary. The second time someone finds it useful I'll add it.
> I just tried import apsw, and it worked! Apparently I had the debian
> calibre package installed which has a dependency on python3-apsw. That
> was good for a while, but I got interested in apsw.ext which the
> python3-apsw package doesn't have (or any other debian package I think).
The various distros are behind by varying amounts. The version of APSW requires at least the corresponding version of the SQLite library, so they have to decide to update SQLite first. Repology has a nice table of what version is in each distro:
https://repology.org/project/python:apsw/versions
> To install from pypi, I needed to uninstall python3-apsw
That is not the case. The pypi installation completely ignores whatever SQLite is on your system, and even if it didn't that SQLite would probably be too old.
The trick is to install with --user which puts apsw below your home directory. It is only if you are running pip as root that you'll clash with the system package. When you get to Python 3.11 pip will give an error message that "This environment is externally managed" and points to PEP 668 for details.
> What is the difference between fetch --all and --sqlite (or are these
> the same)?
In the olden days there used to be additional components distributed from the SQLite site like fts and an asyncvfs (WAL is better). So --all gets everything while --sqlite only gets SQLite. The SQLite team now include fts directly in the distributed amalgamation, so --all doesn't get anything extra. But every time I go to remove --all I see rumblings on the forum about there being something that would apply. I'll go ahead and remove it from the docs, until it actually does something again.
> What is the difference between build and build_ext?
build_ext only builds an extension coded in C. build runs all the build steps which could include doc, translation tables, fortran extensions, and build_ext. It was an important distinction over 20 years ago. Python has been trying to replace setup.py completely, but so far nothing has stuck, which is why I am still stuck on setup.py.
> Do you need both and in what order (build doesn't take the --definevalues argument)?
I should probably reorder the doc to have this first, but what I want you to do, and what would have been easiest is to follow the recommended command:
https://rogerbinns.github.io/apsw/build.html#recommended
Unfortunately the install step is discouraged in recent Python versions so updating those instructions is going to be tricky. As you can probably tell, Python keeps making it difficult for compiled extensions.
build can be omitted, and doesn't take --definevalues because build_ext does as that is affecting the compilation.
> Where does test get apsw from? It wouldn't run until I ran the install,
> is that required?
Yes, the tests import apsw as the first thing so apsw has to be somewhere Python looks for it.
I think I am going to have to combine the Download and Building pages into one, and have it start with the most likely to be used things, then getting into the weeds as the page progresses.
Roger