[sqlalchemy] EOFError while querying
Hi , I am getting EOFError while querying a table . The select contains String fields, integer fields , a BLOB and a TEXT filed. The error happens consistently. This is happening in a customer envt. Anybody has any idea on what could be the issue? Thanks in advance stack trace is given below Traceback (most recent call last): File ./xx/src/xx/web/xx/xx/controllers/ ControllerImpl.py, line 286, in get_tasks File ./xx/src/xx/web/xx/xx/viewModel/Userinfo.py, line 1602, in get_tasks File /home/xx/xx/tg2env/lib/python2.6/site-packages/ SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/orm/query.py, line 1267, in all return list(self) File /home/xx/xx/tg2env/lib/python2.6/site-packages/ SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/orm/query.py, line 1425, in instances for row in fetch] File /home/xx/xx/tg2env/lib/python2.6/site-packages/ SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/orm/query.py, line 1424, in genexpr rows = [rowtuple(proc(context, row) for proc in process) File /home/xx/xx/tg2env/lib/python2.6/site-packages/ SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/orm/query.py, line 2156, in proc return row[column] File /home/xx/xx/tg2env/lib/python2.6/site-packages/ SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/engine/base.py, line 1348, in __getitem__ return self.__parent._get_col(self.__row, key) File /home/xx/xx/tg2env/lib/python2.6/site-packages/ SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/engine/base.py, line 1620, in _get_col return processor(row[index]) File /home/xx/xx/tg2env/lib/python2.6/site-packages/ SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/types.py, line 284, in process return self.process_result_value(impl_processor(value), dialect) File /home/xx/xx/tg2env/lib/python2.6/site-packages/ SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/types.py, line 778, in process_result_value return loads(str(value)) EOFError query is as follows tasks=DBSession.query(Task.task_id, Task.name, Task.user_name, Task.entity_name, Task.cancellable, \ TaskResult.timestamp, TaskResult.endtime, TaskResult.status, TaskResult.results, \ Task.entity_type, Task.short_desc).\ join(TaskResult).\ filter(and_(Task.repeating == True,TaskResult.visible == True)).\ filter(Task.submitted_on = ago).\ order_by(TaskResult.timestamp.desc()).limit(limit).all() Thanks -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Re: Using custom function expression throws 'TypeError: an integer is required' in orm query
Yes, the __eq__() and __hash__() functions are overridden to compare the primary keys (e.g. self.id==other.id, or hash(self.id)). The orm query works as expected once I remove them from the Entity class definition. On Jul 1, 4:03 pm, Michael Bayer mike...@zzzcomputing.com wrote: does your Entity class have some overridden __eq__(), __cmp__(), __hash__() on it ? I think there might be an issue here but I need a lot more specifics. On Jul 1, 2011, at 6:34 AM, Adrian wrote: I just tested it and session.execute(query.statement) returns the proper resultset. The 'similarity' functions returns REAL. --- In [13]: query.all() --- TypeError Traceback (most recent call last) /usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.pyc in all(self) 1675 1676 - 1677 return list(self) 1678 1679 @_generative(_no_clauseelement_condition) /usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.pyc in instances(self, cursor, _Query__context) 1916 1917 if filter: - 1918 rows = filter(rows) 1919 1920 if context.refresh_state and self._only_load_props \ /usr/local/lib/python2.7/dist-packages/sqlalchemy/util/ _collections.pyc in unique_list(seq, hashfunc) 594 if not hashfunc: 595 return [x for x in seq -- 596 if x not in seen 597 and not seen.__setitem__(x, True)] 598 else: TypeError: an integer is required # the last value in the row is the similarity value In [14]: session.execute(query).fetchall() Out[14]: [(10581, u'STI', u'STI', None, u'4-[(4-methylpiperazin-1-yl)methyl]-N- [4-methyl-3-[[4-(3-pyridyl)pyrimidin-2-yl]amino]phenyl]benzamide', None, None, u'Cc1ccc(cc1Nc2nccc(n2)c3cccnc3)NC(=O)c4ccc(cc4)C[NH +]5CC[NH+](CC5)C', 495.619, 37, 29, 8, 0, 0.275862, 2, 2, 0, 41, 8, 5, 4, 0, 0, 88.68, 2.588, 0.241379, True, False, False, False, False, False, False, False, False, False, 1.0), (8099, u'MPZ', u'MPZ', None, u'4-[(4-methylpiperazin-1-yl)methyl]-N- [3-[[4-(3-pyridyl)pyrimidin-2-yl]amino]phenyl]benzamide', None, None, u'C[NH+]1CC[NH+](CC1)Cc2ccc(cc2)C(=O)Nc3(c3)Nc4nccc(n4)c5cccnc5', 481.592, 36, 28, 8, 0, 0.285714, 2, 2, 0, 40, 8, 5, 4, 0, 0, 88.68, 2.292, 0.214286, True, False, False, False, False, False, False, False, False, False, 0.811594202898551), (9593, u'PRC', u'PRC', None, u'N-[4-methyl-3-[[4-(3- pyridyl)pyrimidin-2-yl]amino]phenyl]pyridine-3-carboxamide', None, None, u'Cc1ccc(cc1Nc2nccc(n2)c3cccnc3)NC(=O)c4cccnc4', 382.418, 29, 22, 7, 0, 0.318182, 0, 0, 0, 32, 6, 4, 4, 0, 0, 92.69, 2.143, 0.0454545, True, False, False, False, False, False, False, False, False, False, 0.691176470588235), (5653, u'G6G', u'G6G', None, u'N-[3-[[3-[4-(4-methoxyanilino)-1,3,5- triazin-2-yl]-2-pyridyl]amino]-4-methyl-phenyl]-4-[(4- methylpiperazin-1-yl)methyl]benzamide', None, None, u'Cc1ccc(cc1Nc2c(cccn2)c3ncnc(n3)Nc4ccc(cc4)OC)NC(=O)c5ccc(cc5)C[NH +]6CC[NH+](CC6)C', 617.743, 46, 35, 11, 0, 0.314286, 2, 2, 0, 51, 11, 6, 5, 0, 0, 122.83, 3.668, 0.228571, True, False, False, False, False, False, False, False, False, False, 0.619047619047619), (1153, u'406', u'406', None, u'4-[[(1R,3R)-3- (dimethylamino)pyrrolidin-1-yl]methyl]-N-[4-methyl-3-[(4-pyrimidin-5- ylpyrimidin-2-yl)amino]phenyl]-3-(trifluoromethyl)benzamide', None, None, u'Cc1ccc(cc1Nc2nccc(n2)c3cncnc3)NC(=O)c4ccc(c(c4)C(F)(F)F)C[N@@H +]5CC[C@@H](C5)[NH+](C)C', 578.631, 42, 30, 12, 3, 0.4, 2, 2, 0, 46, 10, 5, 4, 0, 0, 101.57, 3.187, 0.3, True, False, False, False, False, False, False, False, False, False, 0.526881720430108), (8552, u'NIL', u'NIL', None, u'4-methyl-N-[3-(4-methylimidazol-1- yl)-5-(trifluoromethyl)phenyl]-3-[[4-(3-pyridyl)pyrimidin-2- yl]amino]benzamide', None, None, u'Cc1ccc(cc1Nc2nccc(n2)c3cccnc3)C(=O)Nc4cc(cc(c4)n5cc(nc5)C)C(F)(F)F', 529.516, 39, 28, 11, 3, 0.392857, 0, 0, 0, 43, 8, 5, 5, 0, 0, 97.62, 3.771, 0.107143, True, False, False, False, False, False, False, False, False, False, 0.50561797752809)] On Jun 30, 3:27 pm, Michael Bayer mike...@zzzcomputing.com wrote: On Jun 30, 2011, at 9:23 AM, Adrian wrote: SQAlchemy 0.7.1 / pyscopg 2.2.1 / PostgreSQL 9.0 --- I have a weird problem with orm queries that contain custom functions, in this case from postgres contrib modules. When I do a query like this session.query(Entity, func.similarity(Entity.string, 'querystring')).all() # postgres pg_trgm extension I will get the error below. However, when I specify one or all the columns of the Entity individually it works. It also works if the function is in the .order_by() clause. Any ideas where the problem could come from? this seems like it has to do
[sqlalchemy] Re: Using custom function expression throws 'TypeError: an integer is required' in orm query
I found the problem now - the __hash__() function I had did not return an integer, it returned a tuple of the composite primary key. I changed it now and it works, thanks for your help! On Jul 4, 8:50 am, Adrian adr...@schreyer.me wrote: Yes, the __eq__() and __hash__() functions are overridden to compare the primary keys (e.g. self.id==other.id, or hash(self.id)). The orm query works as expected once I remove them from the Entity class definition. On Jul 1, 4:03 pm, Michael Bayer mike...@zzzcomputing.com wrote: does your Entity class have some overridden __eq__(), __cmp__(), __hash__() on it ? I think there might be an issue here but I need a lot more specifics. On Jul 1, 2011, at 6:34 AM, Adrian wrote: I just tested it and session.execute(query.statement) returns the proper resultset. The 'similarity' functions returns REAL. --- In [13]: query.all() --- TypeError Traceback (most recent call last) /usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.pyc in all(self) 1675 1676 - 1677 return list(self) 1678 1679 @_generative(_no_clauseelement_condition) /usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.pyc in instances(self, cursor, _Query__context) 1916 1917 if filter: - 1918 rows = filter(rows) 1919 1920 if context.refresh_state and self._only_load_props \ /usr/local/lib/python2.7/dist-packages/sqlalchemy/util/ _collections.pyc in unique_list(seq, hashfunc) 594 if not hashfunc: 595 return [x for x in seq -- 596 if x not in seen 597 and not seen.__setitem__(x, True)] 598 else: TypeError: an integer is required # the last value in the row is the similarity value In [14]: session.execute(query).fetchall() Out[14]: [(10581, u'STI', u'STI', None, u'4-[(4-methylpiperazin-1-yl)methyl]-N- [4-methyl-3-[[4-(3-pyridyl)pyrimidin-2-yl]amino]phenyl]benzamide', None, None, u'Cc1ccc(cc1Nc2nccc(n2)c3cccnc3)NC(=O)c4ccc(cc4)C[NH +]5CC[NH+](CC5)C', 495.619, 37, 29, 8, 0, 0.275862, 2, 2, 0, 41, 8, 5, 4, 0, 0, 88.68, 2.588, 0.241379, True, False, False, False, False, False, False, False, False, False, 1.0), (8099, u'MPZ', u'MPZ', None, u'4-[(4-methylpiperazin-1-yl)methyl]-N- [3-[[4-(3-pyridyl)pyrimidin-2-yl]amino]phenyl]benzamide', None, None, u'C[NH+]1CC[NH+](CC1)Cc2ccc(cc2)C(=O)Nc3(c3)Nc4nccc(n4)c5cccnc5', 481.592, 36, 28, 8, 0, 0.285714, 2, 2, 0, 40, 8, 5, 4, 0, 0, 88.68, 2.292, 0.214286, True, False, False, False, False, False, False, False, False, False, 0.811594202898551), (9593, u'PRC', u'PRC', None, u'N-[4-methyl-3-[[4-(3- pyridyl)pyrimidin-2-yl]amino]phenyl]pyridine-3-carboxamide', None, None, u'Cc1ccc(cc1Nc2nccc(n2)c3cccnc3)NC(=O)c4cccnc4', 382.418, 29, 22, 7, 0, 0.318182, 0, 0, 0, 32, 6, 4, 4, 0, 0, 92.69, 2.143, 0.0454545, True, False, False, False, False, False, False, False, False, False, 0.691176470588235), (5653, u'G6G', u'G6G', None, u'N-[3-[[3-[4-(4-methoxyanilino)-1,3,5- triazin-2-yl]-2-pyridyl]amino]-4-methyl-phenyl]-4-[(4- methylpiperazin-1-yl)methyl]benzamide', None, None, u'Cc1ccc(cc1Nc2c(cccn2)c3ncnc(n3)Nc4ccc(cc4)OC)NC(=O)c5ccc(cc5)C[NH +]6CC[NH+](CC6)C', 617.743, 46, 35, 11, 0, 0.314286, 2, 2, 0, 51, 11, 6, 5, 0, 0, 122.83, 3.668, 0.228571, True, False, False, False, False, False, False, False, False, False, 0.619047619047619), (1153, u'406', u'406', None, u'4-[[(1R,3R)-3- (dimethylamino)pyrrolidin-1-yl]methyl]-N-[4-methyl-3-[(4-pyrimidin-5- ylpyrimidin-2-yl)amino]phenyl]-3-(trifluoromethyl)benzamide', None, None, u'Cc1ccc(cc1Nc2nccc(n2)c3cncnc3)NC(=O)c4ccc(c(c4)C(F)(F)F)C[N@@H +]5CC[C@@H](C5)[NH+](C)C', 578.631, 42, 30, 12, 3, 0.4, 2, 2, 0, 46, 10, 5, 4, 0, 0, 101.57, 3.187, 0.3, True, False, False, False, False, False, False, False, False, False, 0.526881720430108), (8552, u'NIL', u'NIL', None, u'4-methyl-N-[3-(4-methylimidazol-1- yl)-5-(trifluoromethyl)phenyl]-3-[[4-(3-pyridyl)pyrimidin-2- yl]amino]benzamide', None, None, u'Cc1ccc(cc1Nc2nccc(n2)c3cccnc3)C(=O)Nc4cc(cc(c4)n5cc(nc5)C)C(F)(F)F', 529.516, 39, 28, 11, 3, 0.392857, 0, 0, 0, 43, 8, 5, 5, 0, 0, 97.62, 3.771, 0.107143, True, False, False, False, False, False, False, False, False, False, 0.50561797752809)] On Jun 30, 3:27 pm, Michael Bayer mike...@zzzcomputing.com wrote: On Jun 30, 2011, at 9:23 AM, Adrian wrote: SQAlchemy 0.7.1 / pyscopg 2.2.1 / PostgreSQL 9.0 --- I have a weird problem with orm queries that contain custom functions, in this case from postgres contrib modules. When I do a query like this session.query(Entity,
[sqlalchemy] How to explicit name aliased classes in joins of orm.query
Hi there, I have a problem to understand how aliased classes are used in orm.query. I have an polymorphic single-inheritance table, which is a lookup table for about 10 other tables. On some of that tables there are more than one column which relates to that table, so they have to be aliased. The SQL query would be something like: SELECT * FROM building JOIN condition ON building.id = condition.building_id JOIN lookup_1 ON condition.rating_id = lookup_1.id AND lookup_1.category_id = 6 JOIN lookup_2 ON condition.care_level_id = lookup_2.id AND lookup_2.category_id = 7 WHERE lookup_1.value LIKE %good OR lookup_2.value LIKE well-groomed This leads to several problems, probably I'm using the wrong approach because I miss something. I didn't found something on google or sqlalchemy docs... If I do sonething like this: query = session.query(Building).join('condition','rating').filter(BuildingRating.value.like('%good')) query =query.join('condition','care_level').filter(BuildingCareLevel.value.like('well- groomed')) This won't work because the lookup table appears in two parts of the query. So it has to be aliased: query = session.query(Building).join('condition','rating', aliased=True).filter(BuildingRating.value.like('%good')) query =query.join('condition','care_level', aliased=True).filter(BuildingCareLevel.value.like('well-groomed')) Solves this problem, but it creates an AND condition between both criterias. So I need the aliased Object like: rating = aliased(BuildingRating) care_level = aliased(BuildingCareLevel) to make later: .query(Building).filter( or_( rating.value.like(%good), care_level.value.like(well_groomed) ) ) But I couldn't work out how to explicit name the aliased classes or get the aliased name. If I could do something like: rating = aliased(BuildingRating) care_level = aliased(BuildingCareLevel) query = session.query(Building).join('condition', rating).join('condition', care_level) query = query.filter( or_( care_level.value.like('well-groomed'), rating.value.like('%good') ) ) The problem would be solved or is there another way to do that? Thanks a lot Michael (I use sqlalchemy 0.6.8 on linux with sqlite and python 2.6.5) -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] EOFError while querying
loads() implies you're using PickleType even though not indicated here (just a query by itself tells us very little btw) and the EOFError implies the binary data being loaded is not a valid pickle string. On Jul 4, 2011, at 3:09 AM, rajasekhar911 wrote: Hi , I am getting EOFError while querying a table . The select contains String fields, integer fields , a BLOB and a TEXT filed. The error happens consistently. This is happening in a customer envt. Anybody has any idea on what could be the issue? Thanks in advance stack trace is given below Traceback (most recent call last): File ./xx/src/xx/web/xx/xx/controllers/ ControllerImpl.py, line 286, in get_tasks File ./xx/src/xx/web/xx/xx/viewModel/Userinfo.py, line 1602, in get_tasks File /home/xx/xx/tg2env/lib/python2.6/site-packages/ SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/orm/query.py, line 1267, in all return list(self) File /home/xx/xx/tg2env/lib/python2.6/site-packages/ SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/orm/query.py, line 1425, in instances for row in fetch] File /home/xx/xx/tg2env/lib/python2.6/site-packages/ SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/orm/query.py, line 1424, in genexpr rows = [rowtuple(proc(context, row) for proc in process) File /home/xx/xx/tg2env/lib/python2.6/site-packages/ SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/orm/query.py, line 2156, in proc return row[column] File /home/xx/xx/tg2env/lib/python2.6/site-packages/ SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/engine/base.py, line 1348, in __getitem__ return self.__parent._get_col(self.__row, key) File /home/xx/xx/tg2env/lib/python2.6/site-packages/ SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/engine/base.py, line 1620, in _get_col return processor(row[index]) File /home/xx/xx/tg2env/lib/python2.6/site-packages/ SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/types.py, line 284, in process return self.process_result_value(impl_processor(value), dialect) File /home/xx/xx/tg2env/lib/python2.6/site-packages/ SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/types.py, line 778, in process_result_value return loads(str(value)) EOFError query is as follows tasks=DBSession.query(Task.task_id, Task.name, Task.user_name, Task.entity_name, Task.cancellable, \ TaskResult.timestamp, TaskResult.endtime, TaskResult.status, TaskResult.results, \ Task.entity_type, Task.short_desc).\ join(TaskResult).\ filter(and_(Task.repeating == True,TaskResult.visible == True)).\ filter(Task.submitted_on = ago).\ order_by(TaskResult.timestamp.desc()).limit(limit).all() Thanks -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] How to explicit name aliased classes in joins of orm.query
On Jul 4, 2011, at 2:29 AM, Michael Tils wrote: rating = aliased(BuildingRating) care_level = aliased(BuildingCareLevel) to make later: .query(Building).filter( or_( rating.value.like(%good), care_level.value.like(well_groomed) ) ) But I couldn't work out how to explicit name the aliased classes or get the aliased name. If I could do something like: rating = aliased(BuildingRating) care_level = aliased(BuildingCareLevel) query = session.query(Building).join('condition', rating).join('condition', care_level) query = query.filter( or_( care_level.value.like('well-groomed'), rating.value.like('%good') ) ) this is nearly a valid query. join is called as in join(rating, Building.condition), join(care_level, Building.condition). Assuming BuildingRating and BuildingCareLevel are both single table off of whatever Building.condition is it should be straightforward. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Aw: Re: [sqlalchemy] How to explicit name aliased classes in joins of orm.query
Hello, thanks for your help. The joins Building.condition and Building.care_level are pointing the same table. The table is a single-inheritance construct. The query: session.query(Building).join(rating, Building.condition).join(care_level, Building.care_level) produces this error: sqlalchemy.exc.ArgumentError: Can't determine join between 'building' and '%(34604496 lookup)s'; tables have more than one foreign key constraint relationship between them. Please specify the 'onclause' of this join explicitly. This error can be fixed via string property names: session.query(Building).join('care_level').join('rating') This works, but with this method i have no alias names. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/Z-JEIbJEInkJ. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Aw: Re: Aw: Re: [sqlalchemy] How to explicit name aliased classes in joins of orm.query
Here is my mapping, this time in german... Building class: class Lookup(OrmBaseObject): id = 0 lookupCategoryId = 0 category = LookupCategory value = '' properties = { 'lookupCategoryId':tables['lookup'].c.lookup_category_id, 'category': relationship(LookupCategory, uselist=False) } lookupMapper = mapper(Lookup, tables['lookup'], properties=properties, polymorphic_on=tables['lookup'].c.lookup_category_id, polymorphic_identity=0) #well-groomed class Pflegezustand(Lookup): pass #Year of Construction-Class class Baujahrklasse(Lookup): pass mapper(Nutzungsklasse, inherits=lookupMapper, polymorphic_identity=1) mapper(Charakteristik, inherits=lookupMapper, polymorphic_identity=4) mapper(Baujahrklasse, inherits=lookupMapper, polymorphic_identity=5) mapper(Pflegezustand, inherits=lookupMapper, polymorphic_identity=6) #BuildingCondition class GebaeudeZustand(OrmBaseObject): gebaeudeId = 0 gebaeude = Gebaeude charakteristikId = 0 charakteristik = Charakteristik baujahrklasseId = 0 baujahrklasse = Baujahrklasse pflegezustandId = 0 pflegezustand = Pflegezustand properties = { gebaeudeId: tables['gebaeude_zustand'].c.gebaeude_id, gebaeude: relationship(Gebaeude, uselist=False), charakteristikId: tables['gebaeude_zustand'].c.charakteristik_id, charakteristik: relationship(Lookup, uselist=False, primaryjoin=and_(tables['gebaeude_zustand'].c.charakteristik_id == tables['lookup'].c.id, tables['lookup'].c.lookup_category_id == 4)), baujahrklasseId: tables['gebaeude_zustand'].c.baujahrklasse_id, baujahrklasse: relationship(Baujahrklasse, uselist=False, primaryjoin=tables['gebaeude_zustand'].c.baujahrklasse_id == tables['lookup'].c.id, ), pflegezustandId: tables['gebaeude_zustand'].c.pflegezustand_id, pflegezustand: relationship(Pflegezustand, uselist=False, primaryjoin=and_(tables['gebaeude_zustand'].c.pflegezustand_id == tables['lookup'].c.id, tables['lookup'].c.lookup_category_id == 6)) } mapper(GebaeudeZustand, tables['gebaeude_zustand'], properties=properties) #Building class Gebaeude(OrmBaseObject): id = 0 adresseId = 0 adresse = Adresse gemarkungSchluessel = 0 gemarkung = Gemarkung zustand = None nutzung = None dachflaechen = [] properties = { 'adresseId': tables['gebaeude'].c.adresse_id, 'adresse': relationship(Adresse, uselist=False), 'gemarkungSchluessel': tables['gebaeude'].c.gemarkung_schluessel, #'gemarkung': relationship(Gemarkung, uselist=False), 'zustand': relationship(GebaeudeZustand, uselist=False), 'nutzung': relationship(GebaeudeNutzung, uselist=False), 'dachflaechen': relationship(Dachflaeche, uselist=True) } mapper(Gebaeude, tables['gebaeude'], properties=properties) Thats all relevant parts... -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/oYuPh59lYvYJ. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] confused on avoiding sql injections using ORM
Hello all. I use Pylons 0.9.7 and sqlalchemy. I use the Object Relational Mapper with declarative syntax in a few of my modules. I was reading chapter 7 of the Pylons book and I understood that sql injections can be avoided using the expression api. But can this be also done using ORM? I tryed on my software and sql injections do work. Is it possible to avoide it with ORM or will i have to totally avoide using an ORM layer of sqlalchemy and only use the expression api? Happy hacking. Krishnakant. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: Aw: Re: Aw: Re: [sqlalchemy] How to explicit name aliased classes in joins of orm.query
On Jul 4, 2011, at 3:25 PM, Michael Tils wrote: Here is my mapping, this time in german... OK, sifting through lots of extraneous details as well as the lack of the actual table definitions, it seems like you're looking to join from Building-BuildingCondition-Lookup. I don't use aliased=True very often, but I think its usage pattern would allow this: lc1 = aliased(LookupSubclassOne) lc2 = aliased(LookupSubclassTwo) query(Building).\ join(Building.condition,aliased=True).\ join(lc1, BuildingCondition.rating, from_joinpoint=True).\ join(Building.condition, aliased=True).\ join(lc2, BuildingCondition.care_level, from_joinpoint=True).\ filter(...) I don't talk about aliased=True often because it has a specific effect on subsequent modifications to the query, which are then reset on the next call to join(), and its a little confusing/hard to explain. In this case, the second and fourth calls to join() add from_joinpoint=True so that it goes from the previous joinpoint. For a full explicit approach, just alias everything: bc1 = aliased(BuildingCondition) bc2 = aliased(BuildingCondition) lc1 = aliased(LookupSubclassOne) lc2 = aliased(LookupSubclassTwo) query(Building).\ join(bc1, Building.condition).\ join(lc1, bc1.rating).\ join(bc2, Building.condition).\ join(lc2, bc2.care_level).\ filter(...) note I'm using the 0.7 style of joins here where you can say join(target, onclause) without an embedded tuple. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Re: confused on avoiding sql injections using ORM
Think about it this way: There's two kinds of strings when you're dealing with SQL: 1) SQL language, 2) your data input. Don't ever include (2) in (1) –– let the API do it. \malthe On 4 July 2011 21:41, Krishnakant Mane krm...@gmail.com wrote: Hello all. I use Pylons 0.9.7 and sqlalchemy. I use the Object Relational Mapper with declarative syntax in a few of my modules. I was reading chapter 7 of the Pylons book and I understood that sql injections can be avoided using the expression api. But can this be also done using ORM? I tryed on my software and sql injections do work. Is it possible to avoide it with ORM or will i have to totally avoide using an ORM layer of sqlalchemy and only use the expression api? Happy hacking. Krishnakant. -- You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-disc...@googlegroups.com. To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Re: confused on avoiding sql injections using ORM
Can you give an example of sql injection working with ORM? Some sample code etc. On Jul 5, 5:41 am, Krishnakant Mane krm...@gmail.com wrote: Hello all. I use Pylons 0.9.7 and sqlalchemy. I use the Object Relational Mapper with declarative syntax in a few of my modules. I was reading chapter 7 of the Pylons book and I understood that sql injections can be avoided using the expression api. But can this be also done using ORM? I tryed on my software and sql injections do work. Is it possible to avoide it with ORM or will i have to totally avoide using an ORM layer of sqlalchemy and only use the expression api? Happy hacking. Krishnakant. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Re: confused on avoiding sql injections using ORM
On 05/07/11 03:03, Malthe Borch wrote: Think about it this way: There's two kinds of strings when you're dealing with SQL: 1) SQL language, 2) your data input. Don't ever include (2) in (1) –– let the API do it. How does one do this with the orm? I am talking about things like session.add etc, obviously for inserts. Say I create an instance of a mapped class and then attach some values to it. And want to do session.add. Happy hacking. Krishnakant. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.