On 10 Oct 15:41, Cédric Krier wrote:
> On 10 Oct 06:13, Sharoon Thomas wrote:
> > Hello everyone,
> > Is it possible to copy a query ?
> It will be a great feature.
> > My use case is to have a query pass on to a pagination object which creates
> > multiple versions of
> > the query for each page by changing the LIMIT and OFFSET. Without copying
> > if I set the limit
> > and offset, it would update the same on the existing Select instance.
> > On trying to use copy.copy or copy.deepcopy here is the stack trace I get:
> > >>> sel2 = deepcopy(sel)
> > Traceback (most recent call last):
> > File "<stdin>", line 1, in <module>
> > File
> > "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py",
> > line 174, in deepcopy
> > y = copier(memo)
> > TypeError: 'Column' object is not callable
> I think it is because FromItem override __getattr__ and so copy method
> thinks there is a __deepcopy__ or __copy__ method.
> Probably we should add those method to FromItem.
A quick test shows the even with such patch:
diff -r 6a49ad9f9e97 sql/__init__.py
--- a/sql/__init__.py Sun Aug 03 19:58:34 2014 +0200
+++ b/sql/__init__.py Fri Oct 10 18:58:00 2014 +0200
@@ -166,6 +166,8 @@
def __getattr__(self, name):
+ if name.startswith('__') and name.endswith('__'):
+ raise AttributeError
return Column(self, name)
def __add__(self, other):
copy doesn't work.
I guess __copy__ and __deepcopy__ should be implemented for each object.