Re: [DB-SIG] Reading DB2 on AIX in Python scripts
On 2007-10-24 06:03, James Briggs wrote: > Hi, > > I have been using pyodbc to connect to DB2 on an AS400. > Different beast I know but this is successful provided you have the correct > ODBC drivers installed for the flavour of DB2 on your PC. > > An example from my code, which returns a database connection: > > import pyodbc > > def connect_to_db2(): > """ > quick and dirty connect to db2 > """ > s='DRIVER={iSeries access ODBC Driver};SYSTEM=10.3.36.150;UID=%s;PWD=%s' > return > connect_to_db(connect_str=s%('myuser','mypassword'),autocommit=True) > > db=connect_to_db2() > c=db.cursor() > # > # insert working code here > # > c.close() > db.close() > > I found the autocommit needs to be true for our flavour of DB2, this may not > be the case with DB2 on AIX which has proper rollbacks and commits. Not sure why you would need auto commit to be true. In fact, you only rarely want to *not* use transactions with a database (it's one of the most important features in database programming). You will also want to define a system data source on the machine your running the above code on, instead of passing the driver details to the Windows ODBC Manager directly. This makes your code both more portable and creates fewer issues with Windows permission management. With mxODBC you can connect to a DB2 running on AS400 using this driver for Windows: http://www-03.ibm.com/systems/i/software/access/windows/ Or this driver if you want to connect from Linux: http://www-03.ibm.com/systems/i/software/access/linux/ Both work reliably with transactions and have been in use for many years by quite a few mxODBC users. However, David was looking for a solution that runs on AIX, so all this doesn't really help him :-) Then again, mxODBC works on AIX as well... http://www.egenix.com/products/python/mxODBC/ -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Oct 24 2007) >>> Python/Zope Consulting and Support ...http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/ Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 ___ DB-SIG maillist - DB-SIG@python.org http://mail.python.org/mailman/listinfo/db-sig
[DB-SIG] DSN or not
>> An example from my code, which returns a database connection: >> >> import pyodbc >> >> def connect_to_db2(): >> """ >> quick and dirty connect to db2 >> """ >> s='DRIVER={iSeries access ODBC Driver};SYSTEM=10.3.36.150;UID=%s;PWD=%s' >> return >> connect_to_db(connect_str=s%('myuser','mypassword'),autocommit=True) >> >> db=connect_to_db2() >> c=db.cursor() >> # >> # insert working code here >> # >> c.close() >> db.close() >> > > You will also want to define a system data source on the machine > your running the above code on, instead of passing the driver > details to the Windows ODBC Manager directly. This makes your > code both more portable and creates fewer issues with Windows > permission management. I disagree with the "DSN is best" generalization. They both have their places, and it is up to the developer to chose which is best for a given situation. In the case of sample code being posted to a mail list, I think DSNs just confuse things, as where a DSNless connection string makes it clear exactly what options are being set. I will agree that for production code, DSNs have something to offer, but even then there are cases where they aren't needed. Carl K ___ DB-SIG maillist - DB-SIG@python.org http://mail.python.org/mailman/listinfo/db-sig
Re: [DB-SIG] DSN or not
Carl Karsten wrote: >>> An example from my code, which returns a database connection: >>> >>> import pyodbc >>> >>> def connect_to_db2(): >>> """ >>> quick and dirty connect to db2 >>> """ >>> s='DRIVER={iSeries access ODBC Driver};SYSTEM=10.3.36.150;UID=%s;PWD=%s' >>> return >>> connect_to_db(connect_str=s%('myuser','mypassword'),autocommit=True) >>> >>> db=connect_to_db2() >>> c=db.cursor() >>> # >>> # insert working code here >>> # >>> c.close() >>> db.close() >>> >> You will also want to define a system data source on the machine >> your running the above code on, instead of passing the driver >> details to the Windows ODBC Manager directly. This makes your >> code both more portable and creates fewer issues with Windows >> permission management. > > I disagree with the "DSN is best" generalization. They both have their > places, > and it is up to the developer to chose which is best for a given situation. > In > the case of sample code being posted to a mail list, I think DSNs just > confuse > things, as where a DSNless connection string makes it clear exactly what > options > are being set. > > I will agree that for production code, DSNs have something to offer, but even > then there are cases where they aren't needed. I'm happy to agree that we disagree :-) Data source details are part of the system configuration and as such shouldn't be part of application code. Even if you post code as example, the developer will have to install the ODBC driver and it's usually easier to setup a data source using the GUI tools available for the drivers right along with it, than trying to find the right option syntax for the DSN keywords. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Oct 24 2007) >>> Python/Zope Consulting and Support ...http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/ Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 ___ DB-SIG maillist - DB-SIG@python.org http://mail.python.org/mailman/listinfo/db-sig
[DB-SIG] [SOLVED]Re: no-error error
On 10/19/07, Lukasz Szybalski <[EMAIL PROTECTED]> wrote: > Hello, > I have a python program that converts some data and writes it via ODBC driver. > I am using a win32 dbi,odbc to do that. (none of the free other ones work) > > I just upgraded my ODBC driver to a newer version that supposedly is a > 2.0 compatible. > > Now I am getting a: > dbi.no-error: [SoftVelocity Inc.][TopSpeed ODBC Driver]String or > binary data would be truncated in EXEC > This error means that truncation would have to happen, so instead of truncating the data the odbc driver decided to throw an error and exit the program. Are truncation errors suppose to stop the write of data per API 2.0 specifications? I have tried the ceODBC and the new version that will come out will support the TopSpeed ODBC Driver 5.0 for tps data files. Also, as a side not. If you ever come around a "Driver not capable" error you need to set the autocommit=True. c = ceODBC.Connection("DSN=MYDATASOURCE", autocommit = True) > What I noticed is that dbi.no-error has given me this error. How do I > except a 'no-error' error? And if you need to except any errors from database: except ceODBC.DatabaseError, e: print e #do stuff Thanks, Lucas -- -- Vim auto completion for python http://lucasmanual.com/mywiki/FrontPage#head-8ce19b13e89893059e126b719bebe4ee32fe103c TurboGears from start to finish: http://www.lucasmanual.com/mywiki/TurboGears ___ DB-SIG maillist - DB-SIG@python.org http://mail.python.org/mailman/listinfo/db-sig