SAP DB:ODBC Przewodnik Instalacji Strona 112

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 225
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 111
mxODBC - Python ODBC Database Interface
6.4.2 Errors due to missing Transaction Support
If you get an exception during connect telling you that the driver is not capable or
does not support transactions, e.g.
mxODBC.NotSupportedError: ('S1C00',
84, '[Microsoft][ODBC Excel Driver]Driver not capable ', 4226)
, try
to connect with
clear_auto_commit set to 0. mxODBC will then keep auto-
commit switched on and the connection will operate in auto-commit mode.
6.5 Connection objects as context managers
6.5.1 Introduction to Context Managers
Python 2.5 introduced the new concept of context manager to Python. Context
managers are Python objects implementing the context manager API based on the
methods .__enter__() and .__exit__().
The context managers can be used together with the Python with-statement to
wrap sections of a program into a block (the context) that is entered and exited in
a controlled way:
with context_manager as context:
context.do_something()
When entering the block, the context_manager's .__enter__() method is
called and the returned object assigned to
context. When exiting the block, the
context.__exit__() is called, either with the exception that caused the block to
be left or without exception in case the block was left normally.
6.5.2 Using connection objects as context object
Connection objects implement this API and use it to automatically commit or roll
back the current transaction.
from mx.ODBC.Manager import DriverConnect
connection = DriverConnect(…)
with connection:
cursor = connection.cursor()
cursor.execute('INSERT INTO table VALUES (?, ?)', (1, 2))
… other tasks …
cursor.close()
This code will automatically commit the INSERT to the database backend in cae
the with-block is left without exception. If the other tasks trigger an unhandled
transaction, the connection is rolled back when leaving the block.
For code which doesn't have to do more complex error handling, using the with-
statement block can greatly simplify the resulting code. It also gives the
transaction section a visible resemblance in the code.
90
Przeglądanie stron 111
1 2 ... 107 108 109 110 111 112 113 114 115 116 117 ... 224 225

Komentarze do niniejszej Instrukcji

Brak uwag

Simplicity S210 Handbücher

Bedienungsanleitungen und Benutzerhandbücher für Nähmaschinen Simplicity S210.
Wir stellen 1 PDF-Handbücher Simplicity S210 zum kostenlosen herunterladen nach Dokumenttypen zur Verfügung Bedienerhandbuch






Weitere Produkte und Handbücher für Nähmaschinen Simplicity

Modelle Dokumententyp
SA200 Bedienungsanleitung   LE Parts Tutorial Guide, 18 Seiten
Serge Pro SW432 Bedienerhandbuch   Simplicity Serge Pro SW432 Instruction manual [en] , 54 Seiten
sw210 Bedienungsanleitung   Occupational Therapy intervention, 32 Seiten
SA2200 Bedienerhandbuch   Simplicity SA2200 Instruction manual, 35 Seiten
SA200 Bedienungsanleitung   Simplicity SA200 User Manual, 27 Seiten
sw210 Bedienungsanleitung   Simplicity sw210 User Manual, 35 Seiten