Re: Python/SQLite best practices

2019-08-06 Thread Chris Angelico
On Wed, Aug 7, 2019 at 2:28 AM Dennis Lee Bieber wrote: > > On Mon, 5 Aug 2019 20:12:27 +0200, Karsten Hilbert > declaimed the following: > > > >Transactions involving several commands may require passing > >around of connections and/or cursors, however. > > > > Probably both -- as I reca

Re: Python/SQLite best practices

2019-08-06 Thread Jonathan Moules
* To be reliably INSERTed Byte data should be first converted to sqlite3.Binary(my_data) explicitly Interesting. Is that Python 2 specific, or also in Python 3. Because the latter would surprise me (not saying it isn't the case). Only tried on Python 3. I'm inserting raw byte versions of web

Re: Python/SQLite best practices

2019-08-05 Thread Cameron Simpson
On 06Aug2019 00:01, Jonathan Moules wrote: Some gotcha tips from using SQLite with Python that I've encountered. [...] * To be reliably INSERTed Byte data should be first converted to sqlite3.Binary(my_data) explicitly Interesting. Is that Python 2 specific, or also in Python 3. Because the

Re: Python/SQLite best practices

2019-08-05 Thread Jonathan Moules
Some gotcha tips from using SQLite with Python that I've encountered. You may already know some/all of these: * SQLite doesn't have a "Truncate" function - simply delete the file if possible for larger datasets. * Explicitly committing is good because the default python sqlite3 library does it

Re: Python/SQLite best practices

2019-08-05 Thread Chris Angelico
On Tue, Aug 6, 2019 at 7:45 AM David Raymond wrote: > The context manager transaction feature I can see using, and might actually > start switching to it as it's explicit enough. Though oddly, __enter__ > doesn't seem to actually begin a transaction, not even a deferred one. It's > only __exit_

RE: Python/SQLite best practices

2019-08-05 Thread David Raymond
"What's the advantage of this over letting the connection object do that for you? As the context manager exits, it will automatically either commit or roll back. If you want to guarantee closing _as well_, then you can do that, but you can at least use what already exists." After review I guess I

Re: Python/SQLite best practices

2019-08-05 Thread Chris Angelico
On Tue, Aug 6, 2019 at 5:05 AM David Raymond wrote: > I believe the default Connection context manager is set up for the context to > be a single transaction, with a commit on success or a rollback on a failure. > As far as I know it does NOT close the connection on exiting the context > manage

RE: Python/SQLite best practices

2019-08-05 Thread David Raymond
nsaction stuff cur.execute("commit;") except something bad: blah finally: conn.rollback() conn.close() -Original Message- From: Python-list On Behalf Of Dave via Python-list Sent: Monday, August 05, 2019 1:49 PM To: python-list@python.org Subject: Py

Re: Python/SQLite best practices

2019-08-05 Thread Karsten Hilbert
On Mon, Aug 05, 2019 at 08:12:27PM +0200, Karsten Hilbert wrote: > Transactions involving several commands may require passing > around of connections and/or cursors, however. Among chains of python code, that is. Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B -- https://mai

Re: Python/SQLite best practices

2019-08-05 Thread Karsten Hilbert
On Mon, Aug 05, 2019 at 01:49:24PM -0400, Dave via Python-list wrote: > * Passing connections and cursors - good, bad indifferent? I try to avoid > passing file handles unless necessary, so I view connections and cursors the > same. Connections may be more long-lived, per thread perhaps. Cursor

Python/SQLite best practices

2019-08-05 Thread Dave via Python-list
I'm looking for some tips from experienced hands on on this subject. Some of the areas of interest are (feel free to add more): * Passing connections and cursors - good, bad indifferent? I try to avoid passing file handles unless necessary, so I view connections and cursors the same. Though