[sqlalchemy] boolean value for column_property
Hi guys, I just discovered column_property and I am trying to make a boolean property out of a table column. Let's say I have this didactic table: tblUsers = Table('users', metadata, Column('user', Integer), Column('type', Integer)) mapper(Users, tblUsers, properties = dict(isSubcontractor = column_property(select([True], tblUsers.c.type == 2))) I want to have a property on the object that would say if the user is a subcontractor or not: Users.isSubcontractor I am not sure if this is column_property's fault or rather the way I am using select there. Also, if there's a simpler way to do this I am thankful. 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: with_statement support in session objects
I am using a decorator that handles all this dirty work: @session_manager('get_session') def do_session_stuff(self): pass Gunnlaugur Briem wrote: Hi, trying to be careful to close all sessions when I'm done with them, I find myself doing this all the time: session = Session() try: do_stuff_with(session) finally: session.close() This would be neater: with Session() as session: do_stuff_with(session) but the sessionmaker-produced class does not implement the context manager protocol (the __enter__ and __exit__ methods) used by the with statement. Now, I can add on the context manager protocol using contextlib: from contextlib import closing with closing(Session()) as session: do_stuff_with(session) but is there any reason for the session itself not to support the context manager protocol and save me the extra closing()? Regards, - Gulli Earn more money. Click here to be trained in human resources and launch your career. http://ads.lavabit.com/fc/BLSrjwrsFB3b2AgV4nQOOBOi9zEHy45QcpNGLOxaH5Pv5FyYj3gBD3XRd2w/ --~--~-~--~~~---~--~~ 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: Can't connect to local MySQL server
Check that /tmp is writable. morecowbell wrote: make sure your mysqld.sock is in the location mysql expects it to be. default is /tmp/mysql.sock; if you are using darwinports, depending on mysql version it's /opt/local/var/run/mysqld/mysqld.sock (append mysql version to mysqld). otherwise, head over to forums.mysql.com ; i'm pretty sure that's a recurring topic On Oct 9, 10:32 am, Heston James - Cold Beans [EMAIL PROTECTED] wrote: Hello Guys, I'm receiving errors in my application on a fairly regular basis now and I'm not sure how to begin solving it. Please find attached a backtrace for the error. It seems that its struggling to connect to the MySQL server, however I get this after the application has been running and querying the database for some time. Any ideas what might be causing this? I'd appreciate your thoughts. The code which throws the error is a very simple query(some_object).get(id) Cheers all, Heston database error.txt 2KViewDownload All is not lost! Click now for professional data recovery. http://ads.lavabit.com/fc/Ioyw6kddBdoHqvp8dQvFql5wMsNmVjGUbfiH2HQQRf8TY9twaC7w1U/ --~--~-~--~~~---~--~~ 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] concurrency issues?
Hi, I am writing an application server using twisted and sqlalchemy. On the server - database relation I use a pool of threads each with its own database connection, session etc. The problem is that I have 2 tables (one with products and one with events that might happen to a product) and I think I might have concurrency problems with them (i.e: when selecting a chunk of 50 products from the first table, I need to know for certain that another thread is not inserting the same event in the second table as I am doing with the already selected chunk from the first table). I am using a transactional, autoflushing session. I was thinking about table locking but, it doesn't seem like a good option. Any advices? 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: concurrency issues?
Yes, I understand, thank you for your answer. I was hoping that I could find something more pythonic to do the table locking - I know that it isn't quite portable and that's why there isn't something more code oriented, but I didn't want to get to issue a LOCK table for this. Thanks. Kyle Schaffrick wrote: On Mon, 6 Oct 2008 11:24:00 -0700 (PDT) Michael Bayer [EMAIL PROTECTED] wrote: On Oct 6, 2:19 pm, coder_gus [EMAIL PROTECTED] wrote: Hi, I am writing an application server using twisted and sqlalchemy. On the server - database relation I use a pool of threads each with its own database connection, session etc. The problem is that I have 2 tables (one with products and one with events that might happen to a product) and I think I might have concurrency problems with them (i.e: when selecting a chunk of 50 products from the first table, I need to know for certain that another thread is not inserting the same event in the second table as I am doing with the already selected chunk from the first table). I am using a transactional, autoflushing session. I was thinking about table locking but, it doesn't seem like a good option. Any advices? Thanks. you might want to use a SELECTFOR UPDATE so that the selected rows are locked for the duration of that transaction. Hmm, as I read it the OP wants to protect concurrent insertions, two writers attempting to write duplicate rows, in which case I don't think SELECT FOR UPDATE would help. Doesn't it only lock the selected rows? If that's the case, then this class of concurrency hazard seems to be at it's heart a consistency hazard. I think the easiest way to deal with it would be if you can find a way to describe your notion of duplicate event to the DBMS you're using with e.g. UNIQUE or CHECK constraints, such that the DBMS itself can detect attempts to insert duplicate events and reject them as constraint violations. If you can find a way to do that, DBMS's with optimistic concurrency control (the ones where this race could potentially occur) will automatically handle the race condition, arbitrating between two transactions that are attempting to write the same event (thus causing a constraint violation) by aborting one of them. When this happens, SA throw an exception from the commit() call that you can optionally catch in your Python code. If you *can't* find a way to do that, then I think you're probably right in that you'll have to resort to table-locking. Ick :) Hope that makes some sense. -Kyle Click here to become certified in medical billing and training at these schools. http://ads.lavabit.com/fc/Ioyw6kdeEaSzjSWNjKwc4O0fXNjfbcf7uVQWxA2MYuW88QaqyfdO6x/ --~--~-~--~~~---~--~~ 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: Interval and mx.TimeDelta
Probably you could get away with import psycopg2.extensions psycopg2.extensions.register_type(psycopg2._psycopg.MXDATETIME) psycopg2.extensions.register_type(psycopg2._psycopg.MXINTERVAL) psycopg2.extensions.register_type(psycopg2._psycopg.MXDATE) psycopg2.extensions.register_type(psycopg2._psycopg.MXTIME) assuming that you have psycopg2 compiled with the appropriate mx headers. Hope it helps. Michael Bayer wrote: my understanding is that mx is no longer supported with psycopg2. You might want to ask on their list; SA just passes through objects for PG's date/time types. On May 29, 2008, at 2:27 PM, Eoghan Murray wrote: Hi, I'm trying to use mx.TimeDelta instead of datetime.timedelta on an Interval column (with Postgres). It seems to work fine until I get to intervals a day, at which point it fails with: ProgrammingError: (ProgrammingError) invalid input syntax for type interval: 1:00:00:00.00 'INSERT INTO mytable (id, mytime) VALUES (%(id)s, % (mytime)s)' {'mytime': mx.DateTime.DateTimeDelta object for '1:00:00:00.00' at 9a5bdb8, 'id': 105461L} Any idea where I could hook in to give the desired 24:00:00.00? Thanks! Eoghan Internet Security Software - Click here. http://ads.lavabit.com/fc/Ioyw6kdbg20SYEDQ5FhJFllX2acTjh0tOS1KgVe74mslLV2hYt6kMo/ --~--~-~--~~~---~--~~ 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] how to see table mappers and unload them if needed
Is there a way I can get all the mappers for a Table? And if yes how can I unload them? 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: how to see table mappers and unload them if needed
I got it ... sorry for spamming. clear_mappers() does it. The thing is that I have the model for a table which mappers has to be cleared before being serialized and sent over the wire using twisted's perspective broker and the same table has to be remapped on the server to a model's child which subclasses pb.RemoteCopy. It works now ... sorry for asking before doing a deeper research. Thanks. coder_gus wrote: Is there a way I can get all the mappers for a Table? And if yes how can I unload them? Thanks. Looking for insurance? Compare and save today. Click here. http://ads.lavabit.com/fc/Ioyw6kdcVeESdyS59NTA1luTR3qrfUN2pMhCaaMmHgjTKKt8SZHIYY/ --~--~-~--~~~---~--~~ 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] connect sql server
Hi, How can I connect to sql server with windows authentication using sqlalchemy? Using pymssql I haven't find a way. 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 -~--~~~~--~~--~--~---