There is a major and important change in trunk about DAL and I need help with testing:
BEFORE:
>>> a = DAL('sqlite://filename.db')
>>> b = DAL('sqlite://filename.db')
>>> a is b
False
NOW
>>> a = DAL('sqlite://filename.db')
>>> b = DAL('sqlite://filename.db')
>>> a is b
True
Now DAL is a singleton. You can still have multiple connections to different databases but not multiple connections to the same database (which does not make sense anyway). This means you can also do:
>>> a = DAL('sqlite://filename.db')
>>> a.define_table('person',Field('name'))
>>> b = DAL('sqlite://filename.db')
>>>
b.person.name
and also
>>> x = pickle.dumps(a)
>>> b = pickle.loads(x)
Yes. Now any DAL object (db) is fully packable as long as unpicked after there is an existing connection to the same database. This has some major and useful consequences. For example you can do:
db = DAL(uri)
….
rows = db(query).select()
x = pickle.dumps(rows)
db =DAL(uri)
y = pickle.loads(rows)
y.first().delete_record()
In other words you can pickle ANY rows object and when unpicked it looks the same as the original including all the special methods.
Is this 100% backward compatible? I think yes except that:
1) now if you cache, pickle and unpickle Rows and Row you get the original object back, not some approximation of it.
2) Given
db.define_table('person',Field('name'))
db.define_table('thing',Field('name'),Field('owner','reference person'))
id = db.person.insert(name='Tim')
db.thing.insert(name='chair',owner=id)
rows = db(db.person).select()
rows.first().thing used to belong of class Set now rows.first().thing is class LazySet. This is the only place class LazySet exists. It has the same methods as class Set. As before you can still do:
print rows.first().thing.select()
print rows.first().thing(db.thing.name.startswith('c')).select()
print rows.first().thing.delect()
This is rare corner case. We did not change the behavior, only the name of an internal class.
Now any Rows object can be stored in a session. Since the session is loaded before the db=DAL() is called the db in the session is created as DAL('<lazy>') by the unpickler. This is a little messy and works until one tries to access a session object that stored a set of Rows created with a db using a different uri then the current one. For example session.rows=db().select() breaks if you change your db password. Should this be a concern?
The logic is quite complex and I may have missed something. Please help me test it and check it.
Massimo