Thread: [SQLObject] Executing arbitrary SQL commands
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Jorge G. <go...@ie...> - 2005-10-13 22:57:24
|
Hi! Is there any recommended (if it is possible) way to execute arbitrary SQL commands? For example, in one application I had this 'start' block: query = QSqlQuery('BEGIN') query = QSqlQuery('SET CONSTRAINTS amostras_exames_amostra_id_fkey DEFERRED') query = QSqlQuery('SET CONSTRAINTS amostras_toxicologia_amostra_id_fkey DEFERRED') How could I issue the 'SET CONSTRAINTS' commands? (The begin I'd do with the corresponding transaction command.) TIA, -- Jorge Godoy <go...@ie...> |
From: Sam N. <li...@se...> - 2005-10-14 00:05:05
|
Jorge Godoy wrote: > Hi! > > > Is there any recommended (if it is possible) way to execute arbitrary SQL > commands? For example, in one application I had this 'start' block: > > query = QSqlQuery('BEGIN') > query = QSqlQuery('SET CONSTRAINTS amostras_exames_amostra_id_fkey DEFERRED') > query = QSqlQuery('SET CONSTRAINTS amostras_toxicologia_amostra_id_fkey DEFERRED') > > How could I issue the 'SET CONSTRAINTS' commands? (The begin I'd do with the > corresponding transaction command.) > > > TIA, I use my sqlobject class' _connection object to get a cursor and then I use that to issue queries. Of course this won't play nice with sqlobject's caching, so care must be taken. - Sam |
From: Jorge G. <go...@ie...> - 2005-10-14 00:29:54
|
Sam Nilsson <li...@se...> writes: > Jorge Godoy wrote: >> Hi! >> Is there any recommended (if it is possible) way to execute arbitrary SQL >> commands? For example, in one application I had this 'start' block: >> query = QSqlQuery('BEGIN') >> query = QSqlQuery('SET CONSTRAINTS amostras_exames_amostra_id_fkey DEFERRED') >> query = QSqlQuery('SET CONSTRAINTS amostras_toxicologia_amostra_id_fkey DEFERRED') >> How could I issue the 'SET CONSTRAINTS' commands? (The begin I'd do with the >> corresponding transaction command.) >> TIA, > > I use my sqlobject class' _connection object to get a cursor and then I > use that to issue queries. Of course this won't play nice with > sqlobject's caching, so care must be taken. How can I ensure, then, that these will all be in the same transaction? I'll have to run the queries by hand (SELECT, INSERT, UPDATE) as well after I setup the environment? Because there might be concurrent transactions happening... -- Jorge Godoy <go...@ie...> |
From: Sam N. <li...@se...> - 2005-10-14 00:47:04
|
Jorge Godoy wrote: > Sam Nilsson <li...@se...> writes: > >> Jorge Godoy wrote: >>> Hi! >>> Is there any recommended (if it is possible) way to execute arbitrary SQL >>> commands? For example, in one application I had this 'start' block: >>> query = QSqlQuery('BEGIN') >>> query = QSqlQuery('SET CONSTRAINTS amostras_exames_amostra_id_fkey DEFERRED') >>> query = QSqlQuery('SET CONSTRAINTS amostras_toxicologia_amostra_id_fkey DEFERRED') >>> How could I issue the 'SET CONSTRAINTS' commands? (The begin I'd do with the >>> corresponding transaction command.) >>> TIA, >> I use my sqlobject class' _connection object to get a cursor and then I >> use that to issue queries. Of course this won't play nice with >> sqlobject's caching, so care must be taken. > > How can I ensure, then, that these will all be in the same transaction? I'll > have to run the queries by hand (SELECT, INSERT, UPDATE) as well after I setup > the environment? Because there might be concurrent transactions happening... > I don't and haven't used transactions with SQLObject, so I won't be very helpful with that. However, this looks like what you need to do: -- http://sqlobject.org/SQLObject.html#transactions |
From: Jorge G. <go...@ie...> - 2005-10-14 01:05:18
|
Sam Nilsson <li...@se...> writes: > I don't and haven't used transactions with SQLObject, so I won't be very > helpful with that. However, this looks like what you need to do: > > -- http://sqlobject.org/SQLObject.html#transactions Yep, I read that. That's why I said that for the "BEGIN" part there was no problem and I'd use transactions from SQLObject, but with your suggestion of using the "connection" to send raw SQL commands, I'd have to check if I can specify the connection the same way as in the example shown in the URL above. -- Jorge Godoy <go...@ie...> |
From: Rick F. <rf...@im...> - 2005-10-14 01:27:26
|
I think something like this will work for you... conn = DBConnection.PostgresConnection('yada') trans = conn.transaction() try: trans.query('blah') except: trans.rollback() else: trans.commit() On Thu, 13 Oct 2005, Jorge Godoy wrote: > Sam Nilsson <li...@se...> writes: > >> I don't and haven't used transactions with SQLObject, so I won't be very >> helpful with that. However, this looks like what you need to do: >> >> -- http://sqlobject.org/SQLObject.html#transactions > > Yep, I read that. That's why I said that for the "BEGIN" part there was no > problem and I'd use transactions from SQLObject, but with your suggestion of > using the "connection" to send raw SQL commands, I'd have to check if I can > specify the connection the same way as in the example shown in the URL above. > > |
From: Jorge G. <go...@ie...> - 2005-10-14 01:47:37
|
Rick Flosi <rf...@im...> writes: > I think something like this will work for you... > > conn = DBConnection.PostgresConnection('yada') > trans = conn.transaction() > try: > trans.query('blah') > except: > trans.rollback() > else: > trans.commit() Yep! Thanks! I'll add this to the docs too... -- Jorge Godoy <go...@ie...> |