Bottom Page

Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Is there a standard for autocommit In PEP 249
#1
I tried reading PEP 249 and I could not locate any mentioning as a parameter to the connect() except in the commit method:
----------------------------
.commit()
Commit any pending transaction to the database.

Note that if the database supports an auto-commit feature, this must be initially off. An interface method may be provided to turn it back on.

Database modules that do not support transactions should implement this method with void functionality.
----------------------------
Other languages do supply that as an option. Is there anything special in Python that obviate the need to set this option, either in the connect or elsewhere?

Thanks
ZA

Could somebody help me. This need to be moved to 'general coding help' and I do not know how to do it
Thank you
Quote
#2
Don't know what you're reading, PEP 249 has a huge section labeled 'Connection Objects'
Quote
#3
This DOES NOT answer the question!

1. The description of 'commit()' in my original post is the second item in the 'connection objects' section, so obviously, I read PEP 249 and specifically, the recommended section.

2. Nowhere in that section or anywhere else, there is any reference for a standard way to provide the autocommit option! At least not any reference that is obvious.

Autocommit is a standard feature in Perl's DBI, Java's JDBC and ODBC for example. So, either the Python guys believe that they know better than the rest of the world (I doubt that they believe it and I doubt that they are), or, I miss something... and I asked to point me where is that feature mentioned.


Thank you
ZA
Quote
#4
(Feb-05-2019, 06:38 PM)zatlas1 Wrote: I tried reading PEP 249 and I could not locate any mentioning as a parameter to the connect()

I am not familiar with the subject but I read following mentioning of connect parameters from PEP 249:

Quote:As a guideline the connection constructor parameters should be implemented as keyword parameters for more intuitive use and follow this order of parameters:

Parameter Meaning
dsn Data source name as string
user User name as string (optional)
password Password as string (optional)
host Hostname (optional)
database Database name (optional)
E.g. a connect could look like this:

connect(dsn='myhost:MYDB', user='guido', password='234$')
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Life of Brian: Conjugate the verb, "to go" !
Quote
#5
You are right that there isn't a lot about autocommit.
I did find one reference that states it is done by appending autocommit to the connection:

conn = MySQLdb.connect(...)
conn.autocommit(True)
Quote
#6
Almost all databases support auto-commit,just that is off bye default in most cases for Python,as mention in 249.
PEP 249 Wrote:Note that if the database supports an auto-commit feature, this must be initially off. An interface method may be provided to turn it back on.
There is a reason behind this from mailing list,long time ago:
Quote:Auto commit is a bad thing and a pretty evil invention of ODBC.
While it does make writing ODBC drivers simpler (ones which don't support transactions that is),
it is potentially dangerous at times, e.g. take a crashing program: there is no way to recover from errors because the database has no way of knowing which data is valid and which is not.
No commercial application handling "mission critical" (I love that term ;-) data would ever want to run in auto-commit mode.
Quote:ANY serious application MUST manage its own transactions, as otherwise you can't ever hope to control failure modes.
Python developers took this sort of information into consideration and decided the benefit of having auto-commit off by default (easier error handling and reversing).

That said it's very easy to turn on in almost all cases.
# PostgreSQL
conn.set_session(readonly=True, autocommit=True)

# For Flask-SQLAlchemy(what i use most)
db = SQLAlchemy(app, session_options={'autocommit': True})
SQLAlchemy Python biggest ORM,dos implements it's own auto-commit.
Understanding Autocommit
Quote:SQLAlchemy implements its own “autocommit” feature which works completely consistently across all backends
micseydel and buran like this post
Quote
#7
There is a fundamental issue with PEP 249 regarding this common feature. I truly expected without any prejudice, that I would find a reference to autocommit in the PEP. Something like this imaginary paragraph:
Quote:autocommit is an attribute that means bla bla bla. By default it should be set to false because of bla bla bla. You could set it to whatever you want in connection time or dynamically later, by specifying:
whatefer.autocommit(true) or something else...
[as you see above in the thread, there were two non-standard flavors mentioned (MySQL and Postgress) and who knows how many other flavors are out there. So I would expect the standard to specify one of them as the choice flavor whatever the standard bearer have decided is best.]
The authors of the standard chose to leave that out of the standard altogether and allow a wild west of options. In my case I have to do connections to Oracle, Sybase ASE, Sybase Anywhere, Postgress and potentially SQL Server and a couple of other databases, and many times more than one or two concurrently. So the poor programmer who wants to set autocommit on or off. has to remember five different non-standard ways of doing so.
What could I say (with a lot of sarcasm), what a great design or lack of it thereof!
Quote
#8
(Feb-06-2019, 02:56 PM)zatlas1 Wrote: that I would find a reference to autocommit in the PEP.
There is a reference as i posted over,the default for Python is auto-commit off.
If database authors follow this Python standard is up to them.
They can have there own reason not to,then it should be clear in there documentation.
PEP 249 Wrote:Note that if the database supports an auto-commit feature,this must be initially off. An interface method may be provided to turn it back on.
Quote
#9
Don't misunderstand me, I will follow all my vendors' documentation, deal with it, and hide that from my users' (I am writing a common connect/interface class), but I still think that there should have been a common way to express autocommit (regardless of the choice of default), akin to other languages' API's.
Now I know that the Python guys believe that they are better than anybody else. Such hubris is in the eyes of the beholder.
Quote
#10
(Feb-06-2019, 03:55 PM)zatlas1 Wrote: Now I know that the Python guys believe that they are better than anybody else
I have always though that C++ people hold that merit Wink
As i been told many times in the past to use a real programming language.
Quote:Yes, we C++ programmers look down on all others as lesser beings.
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)