[sqlalchemy] [SQLAlchemy RD] Working of Session in thread
Could someone please explain, Howto sqlalchemy creating new Session and connection inside the thread. Please check the attached programme and output. I went through the doc http://docs.sqlalchemy.org/en/latest/orm/session.html#thread-local-scope and find that sqlalchemy using threading.local() to do this magic, but I could not seen any thing in threading.local() (see output of the programme) *### Test Code and Output ###* from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() e = create_engine(mysql://root: x@localhost/x) Session = scoped_session(sessionmaker(e)) import threading from functools import wraps def find_connection_id_deco(func): @wraps(func) def wrap1(*args, **kwargs): gls = func.__globals__ _DBSession = gls.get(Session) if _DBSession: res1 = _DBSession.connection().execute(SELECT connection_id()) if res1: conn_id = res1.fetchone()[0] print %s===%s()===conn_id_1===%s===%s===%s===%s=== \ %(func.func_code.co_filename, func.__name__, conn_id, vars(threading.local()),\ threading.currentThread().getName(), threading.currentThread().ident) return func(*args, **kwargs) return wrap1 @find_connection_id_deco def test1(): print test1 @find_connection_id_deco def test2(): print test2 from threading import Thread test1() thread = Thread(target=test2) thread.start() *OUTPUT ###* cvt_test_script.py===test1()===conn_id_1===661==={}===MainThread===139917239523072=== test1 cvt_test_script.py===test2()===conn_id_1===662==={}===Thread-1===139917193123584=== test2 -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/groups/opt_out.
[sqlalchemy] How to update PickleType column using DBSession.execute()
How to update PickleType column using DBSession.execute() class MyTable(DeclarativeBase): __tablename__ = 'mytable' context = Column(PickleType) *Attempt 1 * context = {k1:{n1:bbla}, k2:{n2:bbla}} context = pickle.dumps(context) DBSession.execute(update mytable set context='%s' where t_id=%s; %(context, id)) DBSession.execute(commit;) *Error * ProgrammingError: (ProgrammingError) (1064, You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'shortD'\np1\nS'bla bla bla%s'\np2\nsS'child'\np3\n(dp4\nS'im' at line 1) uupdate mytable set context='(dp0\nS'shortD'\np1\nS'blabla %%s'\np2\nsS'child'\np3\n(dp4\nS'import_disk'\np5\n(dp6\nS't_id'\np7\nL11092L\nsssS'shortDP'\np8\n(V2\np9\ntp10\nsS'description'\np11\ng2\nsS'descParams'\np12\n(V2\np13\ntp14\ns.' where t_id=11091; *Attempt 2 * context = {k1:{n1:bbla}, k2:{n2:bbla}} context = re.escape(str(context)) context = pickle.dumps(context) DBSession.execute(update mytable set context='%s' where t_id=%s; %(context, id)) DBSession.execute(commit;) * Error * ProgrammingError: (ProgrammingError) (1064, You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'shortDesc': 'bla bla bla %s', 'child_' at line 1) u'update mytable set context=\'S{\'shortD\': \'bla bla bla %%s\', \'child_s\': {\'import_disk\': {\'t_id\': 11145L}}, \'shortDP\': (u\'2\',), \'description\': \'bla Virtual bla %%s\', \'descP\': (u\'2\',)}\np0\n.\' where t_id=11144;' *Note: =* * I want to use only DBSession.execute(). * I know that following code will works, But i want to use DBSession.execute(). DBSession.query(MyTable).filter(MyTable.t_id==id).update(values=dict(context=context)) -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: [sqlalchemy] How to change polymorphic_identity dynamically
Hi Michael Bayer, 1) I tried your suggestion, but it not updating the value of type column in the database. instance_of_B.__class__ = C_Class instance_of_B.type = type_c 2) * So, i tried like this, and it updating he value of type column in the database. * What you think?, is it a good way to solve this issue ? zope transaction begin Some DBSession query and add statements DBSession.execute(update my_table set type='%s' where id='%s'; %(new_type, id)) DBSession.execute(commit;) Some DBSession query and add statements zope transaction commit Thanks, -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
[sqlalchemy] How to change polymorphic_identity dynamically
Hi, * I have a table A with __mapper_args__ = {'polymorphic_on': type} * Table B C and D are inherited from A with polymorphic_identity type_b, type_c and type_d respectively I want to change the value of polymorphic_identity for an instance of class B, how do it ?? I tried like this, but not working instance_of_B.type = type_c DBSession.add(instance_of_B) transaction.commit(); I want to change the class of instance_of_B to C dynamically. Thanks, -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
[sqlalchemy] Re: How to change polymorphic_identity dynamically
Hi, I also tried like this, But not working instance_of_B.__mapper_args__[polymorphic_identity] = type_c DBSession.add(instance_of_B) transaction.commit(); and instance_of_B.__mapper__.polymorphic_identity = type_c DBSession.add(instance_of_B) transaction.commit(); Thanks, -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: [sqlalchemy] How to get update done by one transaction in another transaction
Hi Michael Bayer, I tried with execution_options, but getting *AttributeError: 'ScopedSession' object has no attribute 'execution_options'.* Note, In my code, I don't have access to create_engine and connection object, since they are defined at lower level. But I can access DBSession, since it defined as module level variable in model.__init_.py like DBSession = scoped_session(maker) So I am searching for the fix which can do with DBSession. === Code 1) Set Session isolation_level to READ-COMMITTED DBSession.execution_options(isolation_level='READ-COMMITTED') 2) Query and get changes committed by other transactions 3) Set Session isolation_level back to REPEATABLE-READ DBSession.execution_options(isolation_level='REPEATABLE-READ') Thanks, -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: [sqlalchemy] How to get update done by one transaction in another transaction
Hi Michael Bayer, I am getting following errors 1) engine = DBSession.bind DBSession.commit() assert self.transaction_manager.get().status == ZopeStatus.COMMITTING, Transaction must be committed using the transaction manager *AssertionError: Transaction must be committed using the transaction manager * 2) conn = engine.connect().execution_options(isolation_level='SERIALIZABLE') conn = engine.connect().execution_options(isolation_level='SERIALIZABLE') *AttributeError: 'Connection' object has no attribute 'execution_options'* a) Sqlalchemy version sqlalchemy.__version__ '0.5.6' b) dir(engine.connect())== ['_Connection__branch', '_Connection__close_with_result', '_Connection__connection', '_Connection__create_execution_context', '_Connection__distill_params', '_Connection__execute_context', '_Connection__invalid', '_Connection__savepoint_seq', '_Connection__transaction', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_autorollback', '_begin_impl', '_begin_twophase_impl', '_branch', '_commit_impl', '_commit_twophase_impl', '_cursor_execute', '_cursor_executemany', '_execute_clauseelement', '_execute_compiled', '_execute_ddl', '_execute_default', '_execute_function', '_execute_text', '_handle_dbapi_exception', '_prepare_twophase_impl', '_release_savepoint_impl', '_rollback_impl', '_rollback_to_savepoint_impl', '_rollback_twophase_impl', '_savepoint_impl', 'begin', 'begin_nested', 'begin_twophase', 'close', 'closed', 'commit_prepared', 'connect', 'connection', 'contextual_connect', 'create', 'default_schema_name', 'detach', 'dialect', 'drop', 'engine', 'execute', 'executors', 'in_transaction', 'info', 'invalidate', 'invalidated', 'recover_twophase', 'reflecttable', 'rollback_prepared', 'run_callable', 'scalar', 'should_close_with_result', 'statement_compiler'] Thanks, -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: [sqlalchemy] How to get update done by one transaction in another transaction
Hi Michael Bayer, I can't set isolation_level='SERIALIZABLE' at global level, since it affect behaviour of other existing operations of my application. So I done following changes where-ever I want to get changes committed by other transactions 1) Set Session isolation_level to READ-COMMITTED DBSession.execute(SET SESSION tx_isolation='READ-COMMITTED'); 2) Query and get changes committed by other transactions 3) Set Session isolation_level back to REPEATABLE-READ DBSession.execute(SET SESSION tx_isolation='REPEATABLE-READ'); * Unfortunately, It is not working as expected. Is there any other way to do it ?? Thanks, -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: [sqlalchemy] How to get update done by one transaction in another transaction
Hi Michael Bayer, Is there any way to dynamically change Transaction Isolation Level ?? I want to do it only for a particular operation. So I can't set it at Engine or Connection Level, right ?? I am using turbogears + Sqlalchemy with default isolation_level. What is the default isolation_level ?? = Also tried DBSession.expire_all() and DBSession.expunge_all(), but not getting Updated row in waiting transaction. http://docs.sqlalchemy.org/en/rel_0_8/orm/session.html#sqlalchemy.orm.session.Session.expire_all http://docs.sqlalchemy.org/en/rel_0_8/orm/session.html#sqlalchemy.orm.session.Session.expunge_all Thanks, -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
[sqlalchemy] How to get update done by one transaction in another transaction
Hi, Suppose we have two transactions T1 and T2. Both transactions trying to update same row ROW1. Suppose both transactions are started simultaneously. T1 first updated ROW1 and commit it. In my case T2 not getting the update done by T1. If run commit in T2 and query ROW1 again, then I can see the commit done by T1. In a transaction, do we need to run commit and query again to get change done by another transaction ??? Any other way to sync these transactions ?? Thanks, -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
[sqlalchemy] How to release sqlalchemy with_lock
Hi, I have a locking system like this class LockManager: def get_lock(self, id): lock_m=DBSession.query(Locker).with_lockmode(update).\ filter(Locker.id==id).all() if len(lock_m) == 0: lm=Locker(id) DBSession.add(lm) def release_lock(self): transaction.commit() * Issues ===* *1)* I can't use this in nested form, since release of inner transaction will release outer transaction also, since release using transaction.commit() Example: ##Outer lock start LockManager.get_lock(1) //Do something ##Inner lock start LockManager.get_lock(2) //Do something ##Inner lock release(Issue:This will release outer lock also) LockManager.release_lock() ##Outer lock release LockManager.release_lock() *How to solve this issue ???* Thanks, -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: [sqlalchemy] Re: ObjectDeletedError: Instance 'xxx' has been deleted
Hi, Michael Bayer. Thanks, that example is really helpful. In your example I used *Session.object_session*http://docs.sqlalchemy.org/en/latest/orm/session.html#sqlalchemy.orm.session.Session.object_sessionmethod to verify that main_method and method1 running in two different sessions. But my test result showing that main_method and method1 running in same session. I think, we can check this using method *Session.object_session** *, I am not sure about that. * added following code in main_method s1 = Session.object_session(db_obj1) print ===main_methodsession=, vars(s1) * added following code in method1 s2 = Session.object_session(db_obj2) print ===method1session=, vars(s2) *Result =* *===main_methodsession=* {'autocommit': False, 'autoflush': True, 'transaction': sqlalchemy.orm.session.SessionTransaction object at 0x22a5f90, *'hash_key': 36330896*, 'expire_on_commit': True, '_new': {}, 'bind': Engine(mysql://root:cvt@localhost/cvt_ee), '_deleted': {}, '_flushing': False, 'identity_map': {(class '__main__.A', (1L,)): sqlalchemy.orm.state.InstanceState object at 0x22a5c90}, '_enable_transaction_accounting': True, 'extensions': [], '_identity_cls': class 'sqlalchemy.orm.identity.WeakInstanceDict', 'twophase': False, '_Session__binds': {}, '_query_cls': class 'sqlalchemy.orm.query.Query', '_mapper_flush_opts': {}} ===method1session= {'autocommit': False, 'autoflush': True, 'transaction': sqlalchemy.orm.session.SessionTransaction object at 0x2073190,* 'hash_key': 36330896,* 'expire_on_commit': True, '_new': {}, 'bind': Engine(mysql://root:cvt@localhost/cvt_ee), '_deleted': {}, '_flushing': False, 'identity_map': {(class '__main__.A', (2L,)): sqlalchemy.orm.state.InstanceState object at 0x2073550, (class '__main__.A', (1L,)): sqlalchemy.orm.state.InstanceState object at 0x22a5c90}, '_enable_transaction_accounting': True, 'extensions': [], '_identity_cls': class 'sqlalchemy.orm.identity.WeakInstanceDict', 'twophase': False, '_Session__binds': {}, '_query_cls': class 'sqlalchemy.orm.query.Query', '_mapper_flush_opts': {}} -- 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/-/qzSbUaBu8UoJ. 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] how to implement nested scoped_session
Hi, Getting error when nesting scoped_session http://stackoverflow.com/questions/13330245/how-to-use-nested-transaction-with-scoped-session-in-sqlalchemy https://groups.google.com/forum/?fromgroups=#!topic/sqlalchemy/E8QEtj35TEY Thanks -- 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/-/MYI9cgxPC2AJ. 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] ObjectDeletedError: Instance 'xxx' has been deleted
The code bellow throwing error ObjectDeletedError: Instance 'xxx' has been deleted. when an exception throwing from method1. How fix this issue. def main_method(): DBSession.add(db_obj1) DBSession.fush() for x in lst: method1(db_obj1.id) def method1(id): try: s1 = DBSession() s1.begin_nested() db_obj2 = create_new_obj(id) DBSession.add(db_obj1) DBSession.fush() if some-codition: raise Exception(Failedd) s1.commit() except Exception, ex: s1.rollback() raise ex -- 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/-/VGUXlX9cevoJ. 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: ObjectDeletedError: Instance 'xxx' has been deleted
The code bellow throwing error ObjectDeletedError: Instance 'xxx' has been deleted. when a exception throwing from method1. Eroor in line method1(db_obj1.id), db_obj1.id failing. How fix this issue. def main_method(): DBSession.add(db_obj1) DBSession.fush() for x in lst: try: method1(db_obj1.id) excpt Exception, ex: pass def method1(id): try: s1 = DBSession() s1.begin_nested() db_obj2 = create_new_obj(id) DBSession.add(db_obj1) DBSession.fush() if some-codition: raise Exception(Failedd) s1.commit() except Exception, ex: s1.rollback() raise ex -- 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/-/ya-rKw3XinwJ. 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: ObjectDeletedError: Instance 'xxx' has been deleted
H, Michael Bayer Thanks You are correct, the rollback in method1 rollbacking transaction in main_method. I want to isolate transaction in main_method from rollback in method1. I attached more code. from sqlalchemy.orm import scoped_session, sessionmaker maker = sessionmaker(autoflush=True, autocommit=False,expire_on_commit=False, extension=ZopeTransactionExtension()) zopelessmaker = sessionmaker(autoflush=True, \ autocommit=False, \ expire_on_commit=False) DBSession = scoped_session(maker) def main_method(): db_obj1 = DBModelclass1(Hello) DBSession.add(db_obj1) DBSession.fush() for x in lst: try: method1(db_obj1.id) excpt Exception, ex: pass def method1(id): try: s1 = DBSession() s1.begin_nested() db_obj2 = DBModelclass2(Test) db_obj2.refname = name_%s %(id) DBSession.add(db_obj2) DBSession.fush() if some-codition: raise Exception(Failedd) s1.commit() except Exception, ex: s1.rollback() raise ex -- 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/-/uIJwy6KOAdsJ. 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] sqlalchemy.exc.NotSupportedError: (NotSupportedError) (1286, Unknown table engine 'InnoDB') set storage_engine='InnoDB' ()
Hi, Getting following error while doing setup-app Running setup_config() from site.websetup Creating tables check if database exists create database Traceback (most recent call last): File /home/sa/cms/tg2env/bin/paster, line 8, in module load_entry_point('PasteScript==1.7.3', 'console_scripts', 'paster') () File /home/sa/cms/tg2env/lib/python2.6/site-packages/ PasteScript-1.7.3-py2.6.egg/paste/script/command.py, line 84, in run invoke(command, command_name, options, args[1:]) File /home/sa/cms/tg2env/lib/python2.6/site-packages/ PasteScript-1.7.3-py2.6.egg/paste/script/command.py, line 123, in invoke exit_code = runner.run(args) File /home/sa/cms/tg2env/lib/python2.6/site-packages/ PasteScript-1.7.3-py2.6.egg/paste/script/appinstall.py, line 68, in run return super(AbstractInstallCommand, self).run(new_args) File /home/sa/cms/tg2env/lib/python2.6/site-packages/ PasteScript-1.7.3-py2.6.egg/paste/script/command.py, line 218, in run result = self.command() File /home/sa/cms/tg2env/lib/python2.6/site-packages/ PasteScript-1.7.3-py2.6.egg/paste/script/appinstall.py, line 456, in command self, config_file, section, self.sysconfig_install_vars(installer)) File /home/sa/cms/tg2env/lib/python2.6/site-packages/ PasteScript-1.7.3-py2.6.egg/paste/script/appinstall.py, line 598, in setup_config mod.setup_app, command, filename, section, vars) File /home/sa/cms/tg2env/lib/python2.6/site-packages/ PasteScript-1.7.3-py2.6.egg/paste/script/appinstall.py, line 612, in _call_setup_app func(command, conf, vars) File ./cms/src/site/web/site/site/websetup.py, line 123, in setup_app File /home/sa/cms/tg2env/lib/python2.6/site-packages/ SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/engine/base.py, line 1202, in execute return connection.execute(statement, *multiparams, **params) File /home/sa/cms/tg2env/lib/python2.6/site-packages/ SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/engine/base.py, line 824, in execute return Connection.executors[c](self, object, multiparams, params) File /home/sa/cms/tg2env/lib/python2.6/site-packages/ SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/engine/base.py, line 888, in _execute_text return self.__execute_context(context) File /home/sa/cms/tg2env/lib/python2.6/site-packages/ SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/engine/base.py, line 896, in __execute_context self._cursor_execute(context.cursor, context.statement, context.parameters[0], context=context) File /home/sa/cms/tg2env/lib/python2.6/site-packages/ SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/engine/base.py, line 950, in _cursor_execute self._handle_dbapi_exception(e, statement, parameters, cursor, context) File /home/sa/cms/tg2env/lib/python2.6/site-packages/ SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/engine/base.py, line 931, in _handle_dbapi_exception raise exc.DBAPIError.instance(statement, parameters, e, connection_invalidated=is_disconnect) sqlalchemy.exc.NotSupportedError: (NotSupportedError) (1286, Unknown table engine 'InnoDB') set storage_engine='InnoDB' () -- 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: howto Sqlalchemy atomic transaction ??
Model class VDCTemplates(DeclarativeBase): __tablename__='cd_vdc_templates' id = Column(Unicode(50), primary_key=True) vdc_id=Column(Unicode(50), ForeignKey('cd_vdc.id', ondelete=CASCADE)) template_id=Column(Unicode(50), ForeignKey('cd_account_templates.id', ondelete=CASCADE)) account_id=Column(Unicode(50), ForeignKey('cd_accounts.id', ondelete=CASCADE)) code == acc_template=self.create_template_data() DBSession.add(acc_template) vdc_template = VDCTemplates() vdc_template.account_id = account_id vdc_template.vdc_id = vdc_id vdc_template.template_id = acc_template.id DBSession.add(vdc_template) * Getting IntegrityError error (IntegrityError) (1452, 'Cannot add or update a child row: a foreign key constraint fails (`my_cms_ee/cd_vdc_templates`, CONSTRAINT `cd_vdc_templates_ibfk_1` FOREIGN KEY (`template_id`) REFERENCES `cd_account_templates` (`id`) ON DELETE CASCADE)') u'INSERT INTO cd_vdc_templates (id, vdc_id, template_id, account_id) VALUES (%s, %s, %s, %s)' ['6ae8e571-ebce-6977-150d-09f7127acb5b', 'ab977753- de54-6e3b-3d7c-644d12f66d63', '8e0ce099-4ba7-2e01-304c-edc18803fbce', 'b56bc9e3-288b-a98f-a974-b67f90970122'] * Its working, if i put transaction.commit() after DBSession.add(acc_template), but that not atomic. * Have any way to make it atomic ??? -- 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] howto Sqlalchemy atomic transaction ??
Hi, http://dpaste.com/659618/ -- 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] Join query with MAX
i have a join query that using aggregate function MAX and its output look like (103,) or (None, ), How check that out of that query is not None. ?? saju_m i know we can not use -- if result:, only option is i think --- if result[0]: , Any other way ? -- 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] sqlalchemy check select query execution time
How check select query execution time using sqlalchemy. -- 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] SQLAlchemy subquery to find variance
DBSession.query(func.length(class_name.cpu_util), (DBSession.query(func.variance(class_name.util)).\ filter(class_name.entity_id==entity_id).filter(class_name.metric_type==metric_type). \ filter(class_name.cdate=from_date).filter(class_name.cdate=to_date).all()), \ func.avg(class_name.m_util)).\ filter(class_name.entity_id==entity_id).filter(class_name.metric_type==metric_type). \ filter(class_name.cdate=from_date).filter(class_name.cdate=to_date).all() ERROR == File /root/tg2env/lib/python2.4/site-packages/SQLAlchemy-0.5.6- py2.4.egg/sqlalchemy/orm/scoping.py, line 123, in do return getattr(self.registry(), name)(*args, **kwargs) File /root/tg2env/lib/python2.4/site-packages/SQLAlchemy-0.5.6- py2.4.egg/sqlalchemy/orm/session.py, line 895, in query return self._query_cls(entities, self, **kwargs) File /root/tg2env/lib/python2.4/site-packages/SQLAlchemy-0.5.6- py2.4.egg/sqlalchemy/orm/query.py, line 92, in __init__ self._set_entities(entities) File /root/tg2env/lib/python2.4/site-packages/SQLAlchemy-0.5.6- py2.4.egg/sqlalchemy/orm/query.py, line 99, in _set_entities entity_wrapper(self, ent) File /root/tg2env/lib/python2.4/site-packages/SQLAlchemy-0.5.6- py2.4.egg/sqlalchemy/orm/query.py, line 2099, in __init__ raise sa_exc.InvalidRequestError( InvalidRequestError: SQL expression, column, or mapped entity expected - got '[(0.0,)]' Here i am using a subquery to find variance. How give a name to subquery result column. (DBSession.query(func.variance(class_name.util)).\ filter(class_name.entity_id==entity_id).filter(class_name.metric_type==metric_type). \ filter(class_name.cdate=from_date).filter(class_name.cdate=to_date).all()) -- 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] func.variance() in sqllalchemy
How calculate variance in sqlalchemy No function func.variance() in sqllalchemy -- 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.