[sqlalchemy] Re: Please add some __len__ methods
Seems like I am learning more python on this list than I ever wanted... On 22 Okt., 15:37, Michael Bayer [EMAIL PROTECTED] wrote: On Oct 22, 2007, at 6:32 AM, klaus wrote: Hi all, I wonder why some classes/objects implement part of a list interface - but without a __len__ method. Obvious examples are: Query has __iter__ and __getitem__, both of which access the database. __len__ would be a nice alternative to a basic count(). can't put __len__ on query for the reasons simon described. would issue COUNT queries for every list() evaluation (which is basically every query). this is a python limitation that theres no way to force list() to use only __iter__ without calling __len__() first. Session has __iter__ and __contains__. __len__ could be used to indicate when the session gets too large and should be cleared. persistent, non-dirty objects in the session are weakly referenced in 0.4 and will automatically fall out of scope if not referenced elsewhere. that said, theres no reason __len__() couldnt be on Session anyway. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] loading of table attributes into orm object
hi there, i'm trying to construct a query using the or_ function as follows, or_(model.Sample.name == '') Traceback (most recent call last): File console, line 1, in ? AttributeError: type object 'Sample' has no attribute 'name' however when i instantiate an unrelated instance this now works, foo = model.Sample() or_(model.Sample.name == '') sqlalchemy.sql.expression._BinaryExpression object at 0xb71661ac is this the intended behaviour of the orm objects? regards, brendan --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] turbogears, sqlalchemy and utf8
Hello, I came across this errors when I was working with unicode mysql database. My record would not get displayed and I would get: UnicodeDecodeError: 'utf8' codec can't decode byte 0xbf in position 261: unexpected code byte I was referred to http://www.sqlalchemy.org/docs/04/dbengine.html#dbengine_establishing Encode the incoming data as Unicode, but when I tried to apply option like convert_unicode I wasn't successful. I just don't know where to put it? Config file are created like this. dev.cfg has sqlalchemy.dburi=mysql://user:[EMAIL PROTECTED]:3306/dbname I could use charset=utf8 but that doesn't fix my error, and charset is an option for mysqldb not sqlalchemy sqlalchemy.dburi=mysql://user:[EMAIL PROTECTED]:3306/dbname?charset=utf8 charset=ascii fixed the error but now I am limited to that character set. then assign_mapper happens then my class, controllers. Somewhere in between these items call create_engine('mysql://localhost/foo') Is it in mapper or some other sqlalchemy function? How do I set option like: convert_unicode=True via sqlalchemy.dburi ??? Adding it to the end via ?convert_unicode=True does not work. raise exceptions.DBAPIError(Connection failed, e) sqlalchemy.exceptions.DBAPIError: (Connection failed) (TypeError) 'convert_unicode' is an invalid keyword argument for this function Thanks, Lucas --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: turbogears, sqlalchemy and utf8
Lukasz Szybalski wrote: dev.cfg has sqlalchemy.dburi=mysql://user:[EMAIL PROTECTED]:3306/dbname sqlalchemy.convert_unicode = True --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: turbogears, sqlalchemy and utf8
On 10/23/07, Marco Mariani [EMAIL PROTECTED] wrote: Lukasz Szybalski wrote: dev.cfg has sqlalchemy.dburi=mysql://user:[EMAIL PROTECTED]:3306/dbname I did this in dev.cfg : sqlalchemy.convert_unicode = True sqlalchemy.dburi=mysql://user:[EMAIL PROTECTED]:3306/dbname now I get a different error? File /usr/lib/python2.4/site-packages/sqlalchemy/types.py, line 174, in con vert_result_value return value.decode(dialect.encoding) AttributeError: 'array.array' object has no attribute 'decode' --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: multiple inserts of sqlalchemy instances?
On 10/22/07, Barry Hart [EMAIL PROTECTED] wrote: I've written code similar to this with no problems. Are you using assign_mapper? If so, the save() call is unnecessary. Do you get this error on the first object or on some subsequent object? Barry - Original Message From: Lukasz Szybalski [EMAIL PROTECTED] To: sqlalchemy@googlegroups.com Sent: Monday, October 22, 2007 3:54:03 PM Subject: [sqlalchemy] multiple inserts of sqlalchemy instances? Hello, I need to save data multiple times in a for loop. I was trying to do something like this: You are able to select which group you want to be in: A,B,C,D for record in userchoice: new=model.User() #set some variables if record.group=='A': #set some more fields new.save() new.flush() elif record.group=='B': #set some more fields new.save() new.flush() If I do that I get: File /usr/lib/python2.4/site-packages/sqlalchemy/orm/mapper.py, line 838, in save_obj raise exceptions.FlushError(New instance %s with identity key %s conflicts with persistent instance %s % (mapperutil.instance_str(obj), str(instance_key), mapperutil.instance_str(existing))) FlushError: New instance [EMAIL PROTECTED] with identity key (class 'XXX.model.User', (19527, None), None) conflicts with persistent instance [EMAIL PROTECTED] Is there a way to do multiple inserts with sqlalchemy? I am having an issue with a second new.flush() Does this require multiple sessions for each save? I can't find any documentation on multiple inserts with assign_mapper. Lucas --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: multiple inserts of sqlalchemy instances?
On Oct 23, 2007, at 10:16 AM, Lukasz Szybalski wrote: I am having an issue with a second new.flush() Does this require multiple sessions for each save? I can't find any documentation on multiple inserts with assign_mapper. Lucas Your best bet is to use version 0.4 and to not use any extensions such as assign_mapper. if youre new to sqlalchemy and are just learning the mechanics of save() and flush(), the ORM tutorial is also pretty helpful to work through. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: loading of table attributes into orm object
On Oct 23, 2007, at 7:18 AM, Brendan Arnold wrote: hi there, i'm trying to construct a query using the or_ function as follows, or_(model.Sample.name == '') Traceback (most recent call last): File console, line 1, in ? AttributeError: type object 'Sample' has no attribute 'name' seems like you are calling this before your mappers have been configured, or if on an earlier 0.4 beta, before the mappers have been compiled. ensure youre on release 0.4, about midway through the betas we added the capability for mappedclass.mappedattribute to trigger a mapper compilation (i.e. a compile_mappers()). otherwise, try to send a reproducing test case since the above issue should not occur. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: turbogears, sqlalchemy and utf8
Lukasz Szybalski wrote: On 10/23/07, Marco Mariani [EMAIL PROTECTED] wrote: Lukasz Szybalski wrote: dev.cfg has sqlalchemy.dburi=mysql://user:[EMAIL PROTECTED]:3306/dbname I did this in dev.cfg : sqlalchemy.convert_unicode = True sqlalchemy.dburi=mysql://user:[EMAIL PROTECTED]:3306/dbname now I get a different error? File /usr/lib/python2.4/site-packages/sqlalchemy/types.py, line 174, in con vert_result_value return value.decode(dialect.encoding) AttributeError: 'array.array' object has no attribute 'decode' I'd guess the mysql-python DB-API installed on your system is an alpha or beta version? Try upgrading to 1.2.2 or 1.2.1 if so. Also, very few MySQL installations have unicode-safe connection encodings configured by default, so it's a very good idea to include the 'charset=utf8convert_unicode=0' in the database URL to avoid data corruption and encoding exceptions. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: multiple inserts of sqlalchemy instances?
On 10/23/07, Michael Bayer [EMAIL PROTECTED] wrote: On Oct 23, 2007, at 10:16 AM, Lukasz Szybalski wrote: I am having an issue with a second new.flush() Does this require multiple sessions for each save? I can't find any documentation on multiple inserts with assign_mapper. Lucas Your best bet is to use version 0.4 and to not use any extensions such as assign_mapper. So you cannot do multiple writes using extensions assign_mapper, mapper aka python class mapped to sql table? What I should use then is user_table = sqlalchemy.Table('Users', metadata, autoload=True) new=users_table.insert() and new.execute(somedictionary,somedictionary2) or new.execute(somedictionary) #change somedictionary new.execute(somedictionary) Thanks, Lucas --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] business object backend
hello all, We are using business object , a decisionnal layer upon our databases. I can connect to BO backend with odbc and execute sql order. is SQLAlchemy is able to connect to an ODBC driver other than MSSQL driver? I try also with mysql odbc driver unsuccessfully. thanks for your answer. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] case inconsistency in reflected column names between mac and windows
Hello, We're running into a problem with case in the reflected column names between mac and windows both using sqlalchemy 0.4.0. For example, in our mysql database, we have a table with columns named END_YEAR and DESCRIPTION. On a windows box: print table.c ['table.END_YEAR', 'table.DESCRIPTION'] On a mac: print table.c ['table.end_year', 'table.description'] This causes our code not to work cross-platform, as referencing columns through table.c is case-sensitive. Obviously we could get around this, but it seems to be a bug. We're not sure if this is a sqlalchemy issue or a discrepancy in MySQLdb between mac and windows versions. Does anyone have any insight into the cause? Thanks, Travis --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: loading of table attributes into orm object
yes you are right, i was using 0.4beta5, i have upgraded to 0.4.0 and it works as expected. thanks! brendan On 10/23/07, Michael Bayer [EMAIL PROTECTED] wrote: On Oct 23, 2007, at 7:18 AM, Brendan Arnold wrote: hi there, i'm trying to construct a query using the or_ function as follows, or_(model.Sample.name == '') Traceback (most recent call last): File console, line 1, in ? AttributeError: type object 'Sample' has no attribute 'name' seems like you are calling this before your mappers have been configured, or if on an earlier 0.4 beta, before the mappers have been compiled. ensure youre on release 0.4, about midway through the betas we added the capability for mappedclass.mappedattribute to trigger a mapper compilation (i.e. a compile_mappers()). otherwise, try to send a reproducing test case since the above issue should not occur. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: case inconsistency in reflected column names between mac and windows
It appears that this only occurs on macs running a ppc processor, not an intel processor. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: case inconsistency in reflected column names between mac and windows
On 10/23/07, Travis Kriplean [EMAIL PROTECTED] wrote: It appears that this only occurs on macs running a ppc processor, not an intel processor. I run into the same problem when I transfer mysql data over to Linux. Windows mysql is case insensitive while linux version cares what case it is. I don't know if there are settings that take care of it but I had to Capitalize the Table name. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: multiple inserts of sqlalchemy instances?
I have done something like this. I am using active mapper. I am new to all of this as well, but see if this helps any a = model.Document() a.first_name = kw.get('first_name') a.last_name = kw.get('last_name') b = model.Body() b.body_name = kw.get('body_name') And that is all I was doing of cource you need to make the form with the inputs for first, last, and body name and assign **kw to your dict() That is how I have been assigning multiple items during one run. I am by no means an expert, just thought this might help On 10/23/07, Lukasz Szybalski [EMAIL PROTECTED] wrote: On 10/23/07, Michael Bayer [EMAIL PROTECTED] wrote: On Oct 23, 2007, at 10:16 AM, Lukasz Szybalski wrote: I am having an issue with a second new.flush() Does this require multiple sessions for each save? I can't find any documentation on multiple inserts with assign_mapper. Lucas Your best bet is to use version 0.4 and to not use any extensions such as assign_mapper. So you cannot do multiple writes using extensions assign_mapper, mapper aka python class mapped to sql table? What I should use then is user_table = sqlalchemy.Table('Users', metadata, autoload=True) new=users_table.insert() and new.execute(somedictionary,somedictionary2) or new.execute(somedictionary) #change somedictionary new.execute(somedictionary) Thanks, Lucas --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: multiple inserts of sqlalchemy instances?
On Oct 23, 2007, at 1:07 PM, Lukasz Szybalski wrote: So you cannot do multiple writes using extensions assign_mapper, mapper aka python class mapped to sql table? you can do anything with assign_mapper, just that its usage is going to be more confusing since it auto-saves objects, and calling flush() for a single object is also error prone. for this reason assign_mapper is deprecated in version 0.4. What I should use then is user_table = sqlalchemy.Table('Users', metadata, autoload=True) new=users_table.insert() and new.execute(somedictionary,somedictionary2) or new.execute(somedictionary) #change somedictionary new.execute(somedictionary) if youd like to save multiple objects with the ORM: for rec in collection: x = MyObject(rec) sess.save(x) sess.flush() the error you got specifically indicates you created two objects with the same primary key attributes, in your case they both had (19527, None) for their composite primary key values. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] ActiveMapper -- Questions - NEED DOCUMENTATION
Hello, I was wondering if anyone can tell me how to access a column using active mapper. Or maybe you might know of a good documentational site for ActiveMapper? Here is a table example class Document(ActiveMapper): class mapping: __table__='document' id = column(Integer, primary_key=True) title = column(Unicode) name = column(Unicode) This is not my real table I am using just an example. How can I access title in my controller Would it be: a = model.Document.document.c.title or a = model.Document.title or a = model.Docment.c.title or a = model.Doucment.table.c.title I am not sure. Would also help if there were some good documentation out there for ActiveMapper. P.S. I cannot change to something else. I must stay with ActiveMapper 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: business object backend
we might be supporting mysql and sybase via ODBC at some point, but supporting pyodbc versus the more native drivers such as psycopg2 and mysqldb is a non-trivial task (not sure about the stability of odbc for DB's like oracle, postgres, I doubt one even exists for sqlite or firebird). On Oct 23, 2007, at 1:30 PM, jean-marc pouchoulon wrote: hello all, We are using business object , a decisionnal layer upon our databases. I can connect to BO backend with odbc and execute sql order. is SQLAlchemy is able to connect to an ODBC driver other than MSSQL driver? I try also with mysql odbc driver unsuccessfully. thanks for your answer. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: ActiveMapper -- Questions - NEED DOCUMENTATION
On Oct 23, 2007, at 4:42 PM, Wes Duff wrote: a = model.Docment.c.title should be that one Would also help if there were some good documentation out there for ActiveMapper. P.S. I cannot change to something else. I must stay with ActiveMapper ActiveMapper is unmaintained. I can't imagine why you couldn't switch from it to plain mappers or Elixir. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: ActiveMapper -- Questions - NEED DOCUMENTATION
I am working for a company right now that has all of thier database items on Active Mapper. I would love to change to something with more documentation. We plan on changing soon, but for right now I have to get this working. Thanks On 10/23/07, Michael Bayer [EMAIL PROTECTED] wrote: On Oct 23, 2007, at 4:42 PM, Wes Duff wrote: a = model.Docment.c.title should be that one Would also help if there were some good documentation out there for ActiveMapper. P.S. I cannot change to something else. I must stay with ActiveMapper ActiveMapper is unmaintained. I can't imagine why you couldn't switch from it to plain mappers or Elixir. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: ActiveMapper -- Questions - NEED DOCUMENTATION
Thanks alot for your info. Much appreciated. On 10/23/07, Wes Duff [EMAIL PROTECTED] wrote: I am working for a company right now that has all of thier database items on Active Mapper. I would love to change to something with more documentation. We plan on changing soon, but for right now I have to get this working. Thanks On 10/23/07, Michael Bayer [EMAIL PROTECTED] wrote: On Oct 23, 2007, at 4:42 PM, Wes Duff wrote: a = model.Docment.c.title should be that one Would also help if there were some good documentation out there for ActiveMapper. P.S. I cannot change to something else. I must stay with ActiveMapper ActiveMapper is unmaintained. I can't imagine why you couldn't switch from it to plain mappers or Elixir. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: case inconsistency in reflected column names between mac and windows
Travis Kriplean wrote: Hello, We're running into a problem with case in the reflected column names between mac and windows both using sqlalchemy 0.4.0. For example, in our mysql database, we have a table with columns named END_YEAR and DESCRIPTION. On a windows box: print table.c ['table.END_YEAR', 'table.DESCRIPTION'] On a mac: print table.c ['table.end_year', 'table.description'] This causes our code not to work cross-platform, as referencing columns through table.c is case-sensitive. Obviously we could get around this, but it seems to be a bug. We're not sure if this is a sqlalchemy issue or a discrepancy in MySQLdb between mac and windows versions. Does anyone have any insight into the cause? That's surprising to me. MySQL does some pretty silly things with casing but I was under the impression that they only go as far as database and table names, not all the way to column names. I would have guessed that column names would be stored in creation case? The SQLAlchemy reflection routines take the column names from the database as-is-- does a SHOW CREATE TABLE (for 0.4) or DESCRIBE (for 0.3) on these tables come back in the wrong case? Might also check the DDL used to create the tables and see what sort of quoting is going on with the column names. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] In a many to many relationship how to access some properties of that relationship
Greetings, for my model I have this: user_table=Table(users, metadata, Column(id, Integer, primary_key=True), Column(gender, Unicode), Column(age, Integer, ForeignKey(ages.id)), Column(occupation, Integer, ForeignKey(occupations.id)), Column(zipCode, Integer(5)) ) movie_table=Table(movies, metadata, Column(id, Integer, primary_key=True), Column(title, Unicode) ) movie_vote_table=Table(movie_votes, metadata, Column(id, Integer, primary_key=True), Column(user, Integer, ForeignKey(users.id)), Column(movie, Integer, ForeignKey(movies.id)), Column(score, Float) ) I've of course left out some of the other tables that weren't needed for this question so I of course a many to many relationship between the users and the movies they have rated. but the only problem is how do I access that score? It would be cool to have something like User.movies[0].score, User.movies[1].score .. etc. is this something I would want to use the association proxy for? -Jason --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: can't get pool_recycle to prevent gone away errors
Yes! That's it. Thanks so much, Jeff On Oct 23, 1:44 pm, Michael Bayer [EMAIL PROTECTED] wrote: On Oct 23, 2007, at 1:36 PM, jeffcodefork wrote: Hi, I'm running SA 0.4 on 3 instances of cherrypy, each with 10 threads. Each thread creates its own Session object when it initializes, and reuses the Session continually. This is what my SA init code looks like: db = sa.create_engine(mysql://%s:[EMAIL PROTECTED]/%s % (DBUSER, DBPASSWORD, DBHOST, DBINSTANCE), pool_size=40, pool_recycle=3600, max_overflow=2) Session = orm.sessionmaker(bind=db, autoflush=True, transactional=True) After leaving the dev server alone overnight, it comes up with the error: OperationalError: (OperationalError) (2006, 'MySQL server has gone away') Am I using pool_recycle incorrectly, or is there something else I should be doing to ensure Session pulls a good connection from the pool? you'd have to close() the Session when youre done with it, or just discard it; with a transactional=True session, its going to hold on to a connection persistently. you can turn on echo_pool=True to view connection checkout activity. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---