[sqlalchemy] integer fields return long python type on query

2010-02-10 Thread Simone Orsi
Hi all,

I have a lot of integer fields in a mysql db and when I query them I get
always a long python type instead of an integer python type.

Is quite annoying to convert long to int every time... how can I get rid
of this?

I remember that with mysql-python you can pass an instance of
MySQLdb.converters to the cursor to automatically do that. Is there a
wrapper for this?

TIA,
Simone

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@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] AttributeError: 'MySQLCompiler' object has no attribute 'mapped_table'

2010-02-05 Thread Simone Orsi
Hi all,
can anybody explain why this:

session.query(Answer).all() - [Answer('...'), ... ]

works, but this:

session.query(func.sum(Answer.close_answer1)).all()

throws the following error?

*** AttributeError: 'MySQLCompiler' object has no attribute
'mapped_table'

The class 'Answer' is mapped correctly since I can search/insert/
update any records.

Thanks in advance

PS: sqlalchemy-0.5.8

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@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] AttributeError: 'MySQLCompiler' object has no attribute 'mapped_table'

2010-02-05 Thread Simone Orsi
Hi Michael,

On 02/05/2010 04:16 PM, Michael Bayer wrote:
 Simone Orsi wrote:
   
 Hi all,
 can anybody explain why this:

 session.query(Answer).all() - [Answer('...'), ... ]

 works, but this:

 session.query(func.sum(Answer.close_answer1)).all()

 throws the following error?

 *** AttributeError: 'MySQLCompiler' object has no attribute
 'mapped_table'

 The class 'Answer' is mapped correctly since I can search/insert/
 update any records.

 Thanks in advance

 PS: sqlalchemy-0.5.8
 
 there is likely an object being passed to the library at some point
 incorrectly.Can't go any further without a complete stack trace.

   

here's the class

class Answer(object):
def __init__(self, **kwargs):
self.title = kwargs.get('title')
self.isMandatory = kwargs.get('isMandatory')
self.qtype = kwargs.get('qtype')
self.close_answer1 = kwargs.get('close_answer1')
self.close_answer2 = kwargs.get('close_answer2')
self.close_answer3 = kwargs.get('close_answer3')
self.close_answer4 = kwargs.get('close_answer4')
self.close_answer5 = kwargs.get('close_answer5')
self.close_answer0 = kwargs.get('close_answer0')
self.open_answer = kwargs.get('open_answer')
   
def __repr__(self):
return Answer('%s') % (self.title)

the table

tables['answers_table'] = Table('answers', metadata,
Column('id', Integer, primary_key=True),
Column('title', String),
Column('isMandatory', Boolean),
Column('qtype', String),
Column('close_answer1', Integer, default=0),
Column('close_answer2', Integer, default=0),
Column('close_answer3', Integer, default=0),
Column('close_answer4', Integer, default=0),
Column('close_answer5', Integer, default=0),
Column('close_answer0', Integer, default=0),
Column('open_answer', Text),
Column('question', Integer, ForeignKey('questions.id')),
Column('questionnaire', Integer,
ForeignKey('questionnaires.id')), )

and the mapper

mappers['answers_table'] = sa.orm.mapper(Answer,
 tables['answers_table'],
 allow_column_override=True,
 properties = { '_question'
: sa.orm.relation(Question),
   
'_questionnaire' : sa.orm.relation(Questionnaire), })


What I'm tryin to do is to take the sum of every column column_answer*
for the entire table.
As I said I can do this

session.query(Answer).filter_by(questionnaire=questionnaire_sql_id,qtype='closed').all()

as well as other operations w/ that class but when I try to do this

sum = session.query([func.sum(Answer.close_answer1),
...]).filter_by(questionnaire=questionnaire_sql_id,qtype='closed').all()

no way... here's the log:
 
[...]
  Module sqlalchemy.orm.session, line 763, in query
  Module sqlalchemy.orm.query, line 68, in __init__
  Module sqlalchemy.orm.query, line 74, in __init_mapper
AttributeError: 'MySQLCompiler' object has no attribute 'mapped_table'

Previous lines are Plone-related thus unuseful in this case...

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@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.