Path: csiph.com!news.mixmin.net!newsreader4.netcologne.de!news.netcologne.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Israel Brewster Newsgroups: comp.lang.python Subject: Handling transactions in Python DBI module Date: Wed, 10 Feb 2016 14:33:56 -0900 Lines: 37 Message-ID: Mime-Version: 1.0 (Mac OS X Mail 9.1 \(3096.5\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de Q0sfQ5CB6b4l+cCZWcMT/Q80JAhT29UBRQD5m1AMEkzA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'modify': 0.04; 'subject:Python': 0.05; 'api': 0.09; 'cursor': 0.09; 'statements': 0.09; 'subject:module': 0.09; 'python': 0.10; 'appropriate': 0.14; 'explicitly': 0.15; 'helvetica;': 0.15; 'break-word;': 0.16; 'confusion': 0.16; 'modules,': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'space;': 0.16; 'word-wrap:': 0.16; 'implementing': 0.18; 'module,': 0.18; 'library': 0.20; '(the': 0.22; 'commands,': 0.22; 'implicit': 0.22; '(or': 0.23; 'this:': 0.23; 'skip:- 40': 0.25; "doesn't": 0.26; 'handling': 0.27; 'least': 0.27; '12px;': 0.27; 'finally,': 0.27; 'object,': 0.27; 'tech': 0.27; 'flying': 0.29; 'issuing': 0.29; "i'm": 0.30; 'connection': 0.30; 'transaction': 0.30; 'primary': 0.31; 'statement': 0.32; 'open': 0.33; 'skip:- 10': 0.34; '0);': 0.34; 'on,': 0.35; 'to:addr:python-list': 0.36; 'received:10': 0.37; 'thanks': 0.37; 'charset:us-ascii': 0.37; 'skip:- 20': 0.39; 'goes': 0.39; 'does': 0.39; 'to:addr:python.org': 0.40; 'called': 0.40; 'some': 0.40; 'close': 0.61; 'header:Message-Id:1': 0.61; 'received:10.9': 0.66; 'statement,': 0.66; 'connection,': 0.72; 'connection.': 0.76; 'hoping': 0.77; 'received:12': 0.81; 'skip:4 60': 0.84; 'to:name:python': 0.84; '0px;">': 0.91; 'alaska': 0.91; 'start;': 0.91 X-Warning: RFC compliance checks disabled due to whitelist X-Warning: Reverse-Path DNS check skipped due to whitelist X-Warning: Maximum message size check skipped due to whitelist X-Warning: Realtime Block Lists skipped due to whitelist X-Warning: System filters skipped due to whitelist X-Warning: Domain filters skipped due to whitelist X-Warning: User filters skipped due to whitelist X-Warning: Anti-Spam check skipped due to whitelist X-Whitelist: 2147483645 X-Envelope-From: israel@ravnalaska.net X-Envelope-To: python-list@python.org X-Mailer: Apple Mail (2.3096.5) X-Content-Filtered-By: Mailman/MimeDel 2.1.21rc2 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21rc2 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:102777 I am working on implementing a Python DB API module, and am hoping I can = get some help with figuring out the workflow of handling transactions. = In my experience (primarily with psycopg2) the workflow goes like this: - When you open a connection (or is it when you get a cursor? I *think* = it is on opening a connection), a new transaction is started - When you close a connection, an implicit ROLLBACK is performed - After issuing SQL statements that modify the database, you call = commit() on the CONNECTION object, not the cursor. My primary confusion is that at least for the DB I am working on, to = start/rollback/commit a transaction, you execute the appropriate SQL = statement (the c library I'm using doesn't have any transactional = commands, not that it should). However, to execute the statement, you = need a cursor. So how is this *typically* handled? Does the connection = object keep an internal cursor that it uses to manage transactions? I'm assuming, since it is called on the connection, not the cursor, that = any COMMIT/ROLLBACK commands called affect all cursors on that = connection. Is that correct? Or is this DB specific? Finally, how do other DB API modules, like psycopg2, ensure that = ROLLBACK is called if the user never explicitly calls close()? Thanks for any assistance that can be provided. ----------------------------------------------- Israel Brewster Systems Analyst II Ravn Alaska 5245 Airport Industrial Rd Fairbanks, AK 99709 (907) 450-7293 -----------------------------------------------