[sqlalchemy] Re: How to lock tables in mysql with SqlAlchemy?
jason kirtland 写道: Ting Zhou wrote: Dear All, I would like to lock a table like LOCK TABLES table_name in mysql command. How can I do that with SqlAlchemy. I have defined a class |//|//|class Pointer(Entity): using_options(tablename='Pointer',autosetup=True) id=Field(MSInteger,primary_key=True) ||I need to lock table ||'Pointer'.|// You can lock the tables by executing the SQL directly. I'm not sure what that looks like in Elixir, but in plain SA it'd be something like: conn = engine.connect() conn.execute(LOCK TABLES Pointer WRITE) ... do stuff with conn conn.execute(UNLOCK TABLES) Thank you. This is what I am doing at the moment. I am hoping it can be done more pythonically. Best wishes Ting --~--~-~--~~~---~--~~ 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] help required urgent
hi all this time i am in big trouble , i recently changed my job and on the new job was handed over project involving SA, i am a newbie as far as SA is concerned but have had little prior experience with it.my problem is as follows the project i have been handed was coded by someone before me it has two layers a vb layer and a python layer that works with SA,the vb team designed the tables in a mssql backend each table having a uniqueidentifier field as primary key and an integer autoincrement field with an unique constraint ,i need to transfer data from msssql db to another db ,every thing goes fine if i remove the autoincrement field the transfer happens perfectly, but when the autoincrement field is added i get errors on transferring data to the target db mainly because each table may have lets say the autoincrement field value as 5 but with different uniqueidentifiers ,and so when data is transfered it generates an integrity exception and if i leave the autoincrement field out of the mapper i still get an error as null cannot be inserted into an identity column.How do i make SA understand to leave the autoincrement field value i.e. not to insert anything into it and let the field take the default value set in the database. any help will be great i need to turn in this stuff in a day. TIA --~--~-~--~~~---~--~~ 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] what happens on save?
Hello I have the following code in my pylons app: refugee = Refugee(value, geometry) model.Session.save(refugee) model.Session.commit() Refugee is the class mapped to my Table object (refugees_table). geometry is an instance of a custom type, for which I created a Geometry(TypeEngine) class. In commit(), SQLAlchemy compares the geometry object to some other geometry object (yes, my Geometry class defines the compare_values method). I'd just like to know what object my geometry object is compared to? I'm just saving a new object in the db table so why there's a need to compare it to something else? I know this is a weird question, but I have other problems that are the consequences of this object comparison, so I'm trying to understand what it is going on in SQLAlchemy. Thanks, -- Eric --~--~-~--~~~---~--~~ 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 lock tables in mysql with SqlAlchemy?
On Apr 25, 2008, at 2:50 AM, Ting Zhou wrote: Thank you. This is what I am doing at the moment. I am hoping it can be done more pythonically. locking tables is a coarse grained action that can lead to deadlocks. Finer grained row locking is available using SELECT...FOR UPDATE which the ORM supports directly using query.with_lockmode(read|update), and select() supports using the for_update keyword argument: select([cols], for_update=True|read) --~--~-~--~~~---~--~~ 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: what happens on save?
On Apr 25, 2008, at 11:37 AM, Eric Lemoine wrote: In commit(), SQLAlchemy compares the geometry object to some other geometry object (yes, my Geometry class defines the compare_values method). I'd just like to know what object my geometry object is compared to? I'm just saving a new object in the db table so why there's a need to compare it to something else? my guess there would be None what does debugging your compare_values() method give you ? --~--~-~--~~~---~--~~ 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: what happens on save?
On Apr 25, 2008, at 11:37 AM, Eric Lemoine wrote: Hello I have the following code in my pylons app: refugee = Refugee(value, geometry) model.Session.save(refugee) model.Session.commit() Refugee is the class mapped to my Table object (refugees_table). geometry is an instance of a custom type, for which I created a Geometry(TypeEngine) class. In commit(), SQLAlchemy compares the geometry object to some other geometry object (yes, my Geometry class defines the compare_values method). I'd just like to know what object my geometry object is compared to? I'm just saving a new object in the db table so why there's a need to compare it to something else? actually, it shouldnt be compared to anything. are you on 0.4 ? --~--~-~--~~~---~--~~ 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: generate_series?
On Apr 25, 2008, at 9:04 AM, Luke Iannini wrote: Hi all, Is there a way to use generate_series with SQLAlchemy? http://www.postgresql.org/docs/8.2/interactive/functions-srf.html generate_series = select([column('i')], from_obj=[func.generate_series(bindparam('start'), bindparam('end'))]) zrows = select([generate_series.params(start=1, end=20).c.i]).label('series') is the best stab I've made at it, but I don't actually understand the syntax in the PGSQL docs: select current_date + s.a as dates from generate_series(0,14,7) as s(a); that particular syntax is an aliasing syntax that we plan on supporting in the near future, so the above would look possibly like s = func.generate_series(4,5,6).alias(cols=['a']) select([func.current_date() + s.c.a]) you can hardwire this stuff using text right now: select([(func.current_date() + literal_column (s.a)).label(dates)]).select_from(generate_series(0, 14, 7) as s(a)) I just noticed that the text() construct, which would allow the bindparams to happen, is not being accepted into select_from() so i've added ticket #1014 for that. As a side question, how would I add static columns to a select statement? e.g. based on the pseudocode above: zrows = select([generate_series.params(start=1, end=20).c.i], 0, 0, 0).label('series') to add 3 columns of 0 value to each row generated. you should be able to put plain strings in the columns clause: select([foo, bar, bat]) this is shorthand for using the literal_column() construct which you can use anywhere in a column expression to produce textual SQL expressions. --~--~-~--~~~---~--~~ 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] Getting the table name that a mapped object came from
Hi, does anyone know a way to get the underlying table name from the DB for a mapped object? foo = session.Query(Foo).filter_by(a=x) I'd like to now find out what table name foo came from. 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: Getting the table name that a mapped object came from
On Fri, Apr 25, 2008 at 2:34 PM, TP [EMAIL PROTECTED] wrote: Hi, does anyone know a way to get the underlying table name from the DB for a mapped object? foo = session.Query(Foo).filter_by(a=x) I'd like to now find out what table name foo came from. You'd want sqlalchemy.orm.object_mapper(foo).local_table.name -- david bonner [EMAIL PROTECTED] --~--~-~--~~~---~--~~ 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: what happens on save?
On Fri, Apr 25, 2008 at 5:55 PM, Michael Bayer [EMAIL PROTECTED] wrote: On Apr 25, 2008, at 11:37 AM, Eric Lemoine wrote: Hello I have the following code in my pylons app: refugee = Refugee(value, geometry) model.Session.save(refugee) model.Session.commit() Refugee is the class mapped to my Table object (refugees_table). geometry is an instance of a custom type, for which I created a Geometry(TypeEngine) class. In commit(), SQLAlchemy compares the geometry object to some other geometry object (yes, my Geometry class defines the compare_values method). I'd just like to know what object my geometry object is compared to? I'm just saving a new object in the db table so why there's a need to compare it to something else? actually, it shouldnt be compared to anything. are you on 0.4 ? It does compare something, AFICT. I'm on 0.4.5. -- Eric --~--~-~--~~~---~--~~ 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: Getting the table name that a mapped object came from
Thanks! On Apr 25, 2:44 pm, David Bonner [EMAIL PROTECTED] wrote: On Fri, Apr 25, 2008 at 2:34 PM, TP [EMAIL PROTECTED] wrote: Hi, does anyone know a way to get the underlying table name from the DB for a mapped object? foo = session.Query(Foo).filter_by(a=x) I'd like to now find out what table name foo came from. You'd want sqlalchemy.orm.object_mapper(foo).local_table.name -- david bonner [EMAIL PROTECTED] --~--~-~--~~~---~--~~ 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: what happens on save?
On Fri, Apr 25, 2008 at 8:48 PM, Eric Lemoine [EMAIL PROTECTED] wrote: On Fri, Apr 25, 2008 at 5:55 PM, Michael Bayer [EMAIL PROTECTED] wrote: On Apr 25, 2008, at 11:37 AM, Eric Lemoine wrote: Hello I have the following code in my pylons app: refugee = Refugee(value, geometry) model.Session.save(refugee) model.Session.commit() Refugee is the class mapped to my Table object (refugees_table). geometry is an instance of a custom type, for which I created a Geometry(TypeEngine) class. In commit(), SQLAlchemy compares the geometry object to some other geometry object (yes, my Geometry class defines the compare_values method). I'd just like to know what object my geometry object is compared to? I'm just saving a new object in the db table so why there's a need to compare it to something else? actually, it shouldnt be compared to anything. are you on 0.4 ? It does compare something, AFICT. I'm on 0.4.5. Here is the stack trace: Module unhcr.controllers.refugees:80 in post model.Session.commit() Module sqlalchemy.orm.scoping:98 in do return getattr(self.registry(), name)(*args, **kwargs) Module sqlalchemy.orm.session:544 in commit self.transaction.commit() Module sqlalchemy.orm.session:250 in commit self._prepare_impl() Module sqlalchemy.orm.session:234 in _prepare_impl self.session.flush() Module sqlalchemy.orm.session:757 in flush self.uow.flush(self, objects) Module sqlalchemy.orm.unitofwork:233 in flush flush_context.execute() Module sqlalchemy.orm.unitofwork:445 in execute UOWExecutor().execute(self, tasks) Module sqlalchemy.orm.unitofwork:930 in execute self.execute_save_steps(trans, task) Module sqlalchemy.orm.unitofwork:945 in execute_save_steps self.save_objects(trans, task) Module sqlalchemy.orm.unitofwork:936 in save_objects task.mapper._save_obj(task.polymorphic_tosave_objects, trans) Module sqlalchemy.orm.mapper:1158 in _save_obj mapper._postfetch(uowtransaction, connection, table, state, c, c.last_inserted_params(), value_params) Module sqlalchemy.orm.mapper:1198 in _postfetch elif not c.primary_key and c.key in params and self._get_state_attr_by_column(state, c) != params[c.key]: Module shapely.geometry.base:255 in __ne__ return not self.equals(other) Module shapely.predicates:30 in __call__ raise RuntimeError() # breakpoint FIXME As you can see, the __ne__ method of my object does get called. -- Eric --~--~-~--~~~---~--~~ 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 I get some help with this?
On Apr 25, 2008, at 4:20 PM, juju wrote: If this is the relation with its constraints: CREATE TABLE Orders (o_num INTEGER NOT NULL PRIMARY KEY, c_num INTEGER NOT NULL, s_num INTEGER DEFAULT 0 NOT NULL, o_date DATE NOT NULL, o_filled o_filled, CONSTRAINT fk_cnum FOREIGN KEY (c_num) REFERENCES Customers (c_num) ON UPDATE CASCADE ON DELETE CASCADE); Where do I put the domain def: CREATE DOMAIN o_filled AS VARCHAR (5) DEFAULT 'false' CHECK (VALUE= 'true' OR VALUE='false'); if I try to created the domain thingy separate i get an error about an empy string. If how does the relation reference it (domain) as a constraint? we have a construct called DDL() that might be able to help here. Although the specific SQL for the o_filled column within the table, we dont support that in a nice way at this timeperhaps creating a custom TypeEngine subclass would do it. The docs have examples of custom TypeEngines. The CREATE DOMAIN SQL, you can definitely issue that separately beforehand; we have unit tests which do it. --~--~-~--~~~---~--~~ 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: what happens on save?
On Apr 25, 2008, at 4:21 PM, Eric Lemoine wrote: Module sqlalchemy.orm.mapper:1198 in _postfetch elif not c.primary_key and c.key in params and self._get_state_attr_by_column(state, c) != params[c.key]: Module shapely.geometry.base:255 in __ne__ return not self.equals(other) Module shapely.predicates:30 in __call__ raise RuntimeError() # breakpoint FIXME As you can see, the __ne__ method of my object does get called. this occurs well after any attribute history detection has happened (which is where comparsions are supposed to happen, if needed). The mapper has inserted the row, then it goes through the list of parameters which were inserted into the row and compares them to what is present on the object, so that it can detect Column-level defaults and other auto-generated values which need to be placed on the instance. This methodology is out of date since nowadays we have an explicit listing of which columns were auto generated - so try out the attached patch which refines the methodology in that section and should solve the issue. The patch is also ticket #1015 which needs test coverage before it can be committed (but is high priority for 0.4.6). --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~--- dont_compare_in_postfetch.patch Description: Binary data
[sqlalchemy] problems with py2app
Hi folks, I seem to be having a problem with sqlalchemy and py2app, but I am very new to OS X and py2app, so I could be doing something stupid. When we try to build the app we get this: ImportError: No module named logging Traceback (most recent call last): File /Users/bear/iain/booking-wx/dist/booking_main.app/Contents/Resources/__boot__.py, line 137, in module _run('booking_main.py') File /Users/bear/iain/booking-wx/dist/booking_main.app/Contents/Resources/__boot__.py, line 134, in _run execfile(path, globals(), globals()) File /Users/bear/iain/booking-wx/dist/booking_main.app/Contents/Resources/booking_main.py, line 10, in module from model_extern import * File model_extern.pyc, line 15, in module File sqlalchemy/__init__.pyc, line 29, in module File sqlalchemy/engine/__init__.pyc, line 54, in module File sqlalchemy/engine/base.pyc, line 16, in module File sqlalchemy/logging.pyc, line 35, in module ImportError: No module named logging 2008-04-25 22:43:27.066 booking_main[457] booking_main Error 2008-04-25 22:43:27.067 booking_main[457] booking_main Error An unexpected error has occurred during execution of the main script I'm not import logging, and the only other libraries being used are wxPython and formencode. wx is working ok. Any tips or even stories of success/failure would be much appreciated! Thanks Iain --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---