The psycopg approach changes the return data type for fetch, which is
not extension, but replacement, and thus direct violation of the spec.
Well, it has to be explicitly requested, but still. The KInterbasDB/FDB
approach was much cleaner as it extends Cursor with additional fetch*
methods (like fetchonemap) that return dict-like object. When I created
firebird-driver, I thought to keep this feature, but firebird-driver
supports scrollable cursor with collection of new fetch* methods, so
Cursor will end with 18! individual fetch methods. Which is awful, so I
didn't keep the feature as designed in FDB. But I always wanted to have
it in some sort, as it's really useful.
The to_dict() method is a compromise that I don't liked much either
(which is the reason why it was not implemented in early driver
version), as it does not fit well to some fetch patterns.
But recently I realized that most used pattern is:
for row in cur.execute(cmd):
...
into which to_dict() can be integrated nicely without much hassle and
ugly code.
BTW, simple loop like:
for row in cur.execute(cmd):
d = cur.to_dict(row)
...
May create a lot of dictionaries, and thus consume significant amount of
memory (at least until GC kicks in) or have unstable performance
(because GC kicks in).
To process a lot of rows one by one, it's better to use constructs like:
d = {}
for row in cur.execute(cmd):
d = cur.to_dict(row, d)
...
That use only one dictionary for all rows fetched. Guess it would be
worth to timeit as well?
BTW, after three-year detour to create firebird-driver, new Firebird QA
based on pytest and internal suite of tools for Firebird trace
(IBPhoenix developed new trace plugin better suited for machine data
processing than standard awful text to be parsed), I'm back to Saturnin
(and thus Firebird Butler). You may expect some nice updates next year.
best regards
Pavel Cisar
IBPhoenix
Dne 29. 10. 22 v 16:28 Tomasz Tyrakowski napsal(a):