> Op 5 sep. 2019, om 00:10 heeft Keith Medcalf <kmedc...@dessus.com> het > volgende geschreven: > > > On Wednesday, 4 September, 2019 12:18, Rob Sciuk <r...@controlq.com> wrote: > >> Forgive me if this is an FAQ, but in looking over the python3 interface to >> SQLITE3, I cannot see a way to get the result code (SQLITE_OK) after an >> execute() command. > >> My use case is to differentiate between an empty row set (OK) vs an error >> of some kind in the query. > >> Anyone figured this out? > > If there is an error then an exception will be thrown. No exception means no > error. Otherwise, iterating over the cursor will return the rows. If there > are no rows then it is like iterating over an empty list -- there is nothing > to return (the cursor object is a generator that yields row tuples and it > will internally raise StopIteration when it is out of data to return, just > like any other generator). > > -- Possibly the Python documentation is overwhelming here as data can also be retrieved with explicit fetch steps. The example where the cursor is treated as a generator shows how simple it is: >>> for row in c.execute('SELECT * FROM stocks ORDER BY price'): print(row)
('2006-01-05', 'BUY', 'RHAT', 100, 35.14) ('2006-03-28', 'BUY', 'IBM', 1000, 45.0) ('2006-04-06', 'SELL', 'IBM', 500, 53.0) ('2006-04-05', 'BUY', 'MSFT', 1000, 72.0) (from https://docs.python.org/3/library/sqlite3.html <https://docs.python.org/3/library/sqlite3.html>) Personal note: even more simple is to use the execute method directly from the connection instance. _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users