YoSTEALTH added the comment:
note: sqlite_namedtuplerow.patch _cache method conflicts with attached database
with say common table.column name like "id"
Using namedtuple method over sqlite3.Row was a terrible idea for me. I thought
namedtuple is like tuple so should be faster then dict! wrong. I wasted 2 days
change my work to namedtuple and back to sqlite3.Row, the speed difference on
my working project was:
namedtuple 0.035s/result
sqlite3.Rows 0.0019s/result
for(speed test) range: 10000
namedtuple 17.3s
sqlite3.Rows 0.4s
My solution was to use sqlite3.Row (for speed) but to get named like usage by
convert dict keys() with setattr names:
class dict2named(dict):
def __init__(self, *args, **kwargs):
super(dict2named, self).__init__(*args, **kwargs)
self.__dict__ = self
Usage:
for i in con.execute('SELECT * FROM table'):
yield dict2named(i)
Now i can use:
print(i.title)
and handy dict methods for dash column names:
print(i['my-title'])
print(i.get('my-title', 'boo'))
Now working project speed:
sqlite3.Rows 0.0020s/result
for(speed test) range: 10000
sqlite3.Rows 0.8s with dict2named converting
This i can work with, tiny compromise in speed with better usage.
----------
nosy: +YoSTEALTH
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue13299>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com