From chris.wood at bookitnow.ca Sat Oct 4 00:00:59 2008 From: chris.wood at bookitnow.ca (Chris Wood) Date: Fri, 3 Oct 2008 18:00:59 -0400 Subject: [DB-SIG] newbie question on trapping a DB error message using psycopg2 / DB-API Message-ID: <84d154660810031500oc148316ve2ff138515ae651f@mail.gmail.com> If I run a python program that calls a stored procedure without a "try:" , I see a descriptive message in the error that is returned (highlighted inyellowbelow): >>> cur.execute("select * from f_test_return_error2('normon')") Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.4/site-packages/psycopg2/extras.py", line 48, in execute return _cursor.execute(self, query, vars, async) psycopg2.ProgrammingError: Error. Party name normon not found in the party table. but if I put the "cur.execute" in a "try:" / "except:" I cannot figure out where to get the error text that I need, can anyone help please?? I know it is possible because a friend of mine can get it back from SQLAlchemy and SQLAlchemy uses psycopg2. thanks, - chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From carsten.haese at gmail.com Sat Oct 4 01:43:30 2008 From: carsten.haese at gmail.com (Carsten Haese) Date: Fri, 3 Oct 2008 19:43:30 -0400 Subject: [DB-SIG] newbie question on trapping a DB error message using psycopg2 / DB-API In-Reply-To: <84d154660810031500oc148316ve2ff138515ae651f@mail.gmail.com> References: <84d154660810031500oc148316ve2ff138515ae651f@mail.gmail.com> Message-ID: <5fbcfcff0810031643v1c8f7d62lbf95105f6000dfe4@mail.gmail.com> 2008/10/3 Chris Wood > If I run a python program that calls a stored procedure without a "try:" , > I see a descriptive message in the error that is returned (highlighted inyellowbelow): > > >>> cur.execute("select * from f_test_return_error2('normon')") > Traceback (most recent call last): > File "", line 1, in ? > File "/usr/lib/python2.4/site-packages/psycopg2/extras.py", line 48, in > execute > return _cursor.execute(self, query, vars, async) > psycopg2.ProgrammingError: Error. Party name normon not found in the > party table. > > but if I put the "cur.execute" in a "try:" / "except:" I cannot figure out > where to get the error text that I need, > can anyone help please?? > I don't have a PostgreSQL server handy, so this is not tested: try: cur.execute(...) except psycopg2.ProgrammingError, e: print e.message Hope this helps, -- Carsten Haese http://informixdb.sourceforge.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From info at egenix.com Wed Oct 15 17:42:38 2008 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Wed, 15 Oct 2008 17:42:38 +0200 Subject: [DB-SIG] ANN: eGenix mxODBC - ODBC Database Interface for Python 3.0.2 Message-ID: <48F60F6E.2010207@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com mxODBC - ODBC Database Interface for Python Version 3.0.2 mxODBC is our commercially supported Python extension providing ODBC database connectivity to Python applications on Windows and Unix platforms This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-mxODBC-3.0.2-GA.html ________________________________________________________________________ INTRODUCTION mxODBC provides an easy-to-use, high-performance, reliable and robust Python interface to ODBC compatible databases such as MS SQL Server, MS Access, Oracle Database, IBM DB2 and Informix , Sybase ASE and Sybase Anywhere, MySQL, PostgreSQL, SAP MaxDB and many more. The "eGenix mxODBC - ODBC Database Interface for Python" product is a commercial extension to our open-source eGenix mx Base Distribution. * About Python: Python is an object-oriented Open Source programming language which runs on all modern platforms (http://www.python.org/). By integrating ease-of-use, clarity in coding, enterprise application connectivity and rapid application design, Python establishes an ideal programming platform for todays IT challenges. * About eGenix: eGenix is a consulting and software product company focused on providing professional quality services and products to Python users and developers (http://www.egenix.com/). ________________________________________________________________________ NEWS mxODBC 3.0.2 is a patch-level release and includes the following updates: * Python 2.6 support mxODBC 3.0.2 is now available for Python 2.6, compiled with the same MS VS 2008 edition used by the Python developers to build Python 2.6 binaries for enhanced compatibility. * Enhanced support for using TEXT and VARCHAR columns with binary data ODBC drivers which need the Python type binding, like e.g. the FreeTDS ODBC driver, will now be able to pass binary data to text columns in most cases. * Updated work-arounds for various ODBC drivers eGenix always aims to make using mxODBC as easy and robust as possible. For this reason, we regularly add or update work-arounds for problems found in recent ODBC driver versions. This release includes updated or new work-arounds for the MySQL ODBC driver, the Informix ODBC driver and the SQL Server 2005 ODBC driver. * Enhanced Python datetime module support mxODBC 3.0 already supports the datetime module found in Python 2.4 and later. With this release, we have additionally added support for the datetime module found in Python 2.3. For the full set of changes please check the mxODBC change log: http://www.egenix.com/products/python/mxODBC/changelog.html ________________________________________________________________________ DOWNLOADS The download archives and instructions for installing the package can be found at: http://www.egenix.com/products/python/mxODBC/ In order to use the eGenix mxODBC package you will first need to install the eGenix mx Base package: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ UPGRADING You are encouraged to upgrade to this latest mxODBC release, especially if you are using MS SQL Server or Informix as database server. Customers who have purchased mxODBC 3.0 licenses can download and install this patch-level release on top of their existing installations. The licenses will continue to work with version 3.0.2. Users of mxODBC 2.0 will have to purchase new licenses from our online shop in order to upgrade to mxODBC 3.0.2. You can request 30-day evaluation licenses by visiting our web-site at http://www.egenix.com/products/python/mxODBC/#Evaluation or writing to sales at egenix.com, stating your name (or the name of the company) and the number of eval licenses that you need. _______________________________________________________________________ SUPPORT Commercial support for this product is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Oct 15 2008) >>> 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 From andy47 at halfcooked.com Sat Oct 4 07:01:27 2008 From: andy47 at halfcooked.com (Andy Todd) Date: Sat, 04 Oct 2008 15:01:27 +1000 Subject: [DB-SIG] newbie question on trapping a DB error message using psycopg2 / DB-API In-Reply-To: <84d154660810031500oc148316ve2ff138515ae651f@mail.gmail.com> References: <84d154660810031500oc148316ve2ff138515ae651f@mail.gmail.com> Message-ID: <48E6F8A7.7080009@halfcooked.com> Chris Wood wrote: > If I run a python program that calls a stored procedure without a "try:" , > I see a descriptive message in the error that is returned (highlighted > in yellow below): > > >>> cur.execute("select * from f_test_return_error2('normon')") > Traceback (most recent call last): > File "", line 1, in ? > File "/usr/lib/python2.4/site-packages/psycopg2/extras.py", line 48, > in execute > return _cursor.execute(self, query, vars, async) > psycopg2.ProgrammingError: Error. Party name normon not found in the > party table. > > but if I put the "cur.execute" in a "try:" / "except:" I cannot figure > out where to get the error text that I need, > can anyone help please?? > > I know it is possible because a friend of mine can get it back from > SQLAlchemy and SQLAlchemy uses psycopg2. > > thanks, > - chris > > When asking questions on this list it is good practice to list which database you are using and which Python DB-API module you are using to access it. In this case it looks like PostgreSQL and psycopg2. However, I think the answer to your question lies in standard Python and I'd like to direct your attention to Chapter 8 of the Python tutorial (which can be found online here - http://www.python.org/doc/2.5.2/tut/node10.html), and in particular this extract from section 8.3: """ When an exception occurs, it may have an associated value, also known as the exception's argument. The presence and type of the argument depend on the exception type. The except clause may specify a variable after the exception name (or tuple). The variable is bound to an exception instance with the arguments stored in instance.args. For convenience, the exception instance defines __getitem__ and __str__ so the arguments can be accessed or printed directly without having to reference .args. But use of .args is discouraged. Instead, the preferred use is to pass a single argument to an exception (which can be a tuple if multiple arguments are needed) and have it bound to the message attribute. One may also instantiate an exception first before raising it and add any attributes to it as desired. >>> try: ... raise Exception('spam', 'eggs') ... except Exception, inst: ... print type(inst) # the exception instance ... print inst.args # arguments stored in .args ... print inst # __str__ allows args to printed directly ... x, y = inst # __getitem__ allows args to be unpacked directly ... print 'x =', x ... print 'y =', y ... ('spam', 'eggs') ('spam', 'eggs') x = spam y = eggs If an exception has an argument, it is printed as the last part (`detail') of the message for unhandled exceptions. """ Which would lead to your code looking something like this: >>> try: ... cur.execute("select * from f_test_return_error2('normon')") ... except ProgrammingError, msg: ... print msg Regards Andy -- From the desk of Andrew J Todd esq - http://www.halfcooked.com/ From peter at machell.net Fri Oct 17 02:55:32 2008 From: peter at machell.net (Peter Machell) Date: Fri, 17 Oct 2008 10:55:32 +1000 Subject: [DB-SIG] Simple? ODBC connection issue Message-ID: <26B1C4C2-928B-449D-9CF9-5A138E1A85CF@machell.net> I'm using pyodbc to connect to several databases. On one of them, the database password needs to be a variable. If I hard code the password, the connection works fine: cnxn = pyodbc.connect("DSN=test;UID=test;PWD=test") However substituting a variable fails: passwd='test' connectstring='pyodbc.connect("DSN=test;UID=test;PWD='+passwd+'")' cnxn = connectstring I get an ODBC login failed error. Sorry if I'm just having a Friday brain problem but I just can't get this to work, can anyone help? regards, Peter. From Chris.Clark at ingres.com Fri Oct 17 03:21:48 2008 From: Chris.Clark at ingres.com (Chris Clark) Date: Thu, 16 Oct 2008 18:21:48 -0700 Subject: [DB-SIG] Simple? ODBC connection issue In-Reply-To: <26B1C4C2-928B-449D-9CF9-5A138E1A85CF@machell.net> References: <26B1C4C2-928B-449D-9CF9-5A138E1A85CF@machell.net> Message-ID: <48F7E8AC.4020109@ingres.com> On 10/16/2008 5:55 PM, Peter Machell wrote: > ...If I hard code the password, the connection works fine: > > cnxn = pyodbc.connect("DSN=test;UID=test;PWD=test") > > However substituting a variable fails: > > passwd='test' > connectstring='pyodbc.connect("DSN=test;UID=test;PWD='+passwd+'")' > cnxn = connectstring > ... Try printing the string to screen first :-) You have single quotes embedded in the variables based so the variable is never in place. Use % markers instead and make your life easier :-) From vernondcole at gmail.com Fri Oct 17 04:39:54 2008 From: vernondcole at gmail.com (Vernon Cole) Date: Thu, 16 Oct 2008 20:39:54 -0600 Subject: [DB-SIG] Simple? ODBC connection issue In-Reply-To: <48F7E8AC.4020109@ingres.com> References: <26B1C4C2-928B-449D-9CF9-5A138E1A85CF@machell.net> <48F7E8AC.4020109@ingres.com> Message-ID: Chris is correct. > passwd='test' > connectstring="DSN=test;UID=test;PWD=%s" > cnxn = pyodbc.connect(connectstring % passwd) > is much more readable. -- Vernon On Thu, Oct 16, 2008 at 7:21 PM, Chris Clark wrote: > On 10/16/2008 5:55 PM, Peter Machell wrote: > >> ...If I hard code the password, the connection works fine: >> >> cnxn = pyodbc.connect("DSN=test;UID=test;PWD=test") >> >> However substituting a variable fails: >> >> >> ... >> > > > Try printing the string to screen first :-) > > You have single quotes embedded in the variables based so the variable is > never in place. Use % markers instead and make your life easier :-) > > > > > _______________________________________________ > DB-SIG maillist - DB-SIG at python.org > http://mail.python.org/mailman/listinfo/db-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aprotin at research.att.com Fri Oct 17 16:29:49 2008 From: aprotin at research.att.com (Art Protin) Date: Fri, 17 Oct 2008 10:29:49 -0400 Subject: [DB-SIG] Simple? ODBC connection issue In-Reply-To: <48F7E8AC.4020109@ingres.com> References: <26B1C4C2-928B-449D-9CF9-5A138E1A85CF@machell.net> <48F7E8AC.4020109@ingres.com> Message-ID: <48F8A15D.6090405@research.att.com> Dear folks, I read the code and think I see the problem. Chris Clark wrote: > On 10/16/2008 5:55 PM, Peter Machell wrote: > >> ...If I hard code the password, the connection works fine: >> >> cnxn = pyodbc.connect("DSN=test;UID=test;PWD=test") >> >> However substituting a variable fails: >> >> passwd='test' >> connectstring='pyodbc.connect("DSN=test;UID=test;PWD='+passwd+'")' >> cnxn = connectstring >> ... > I would expect that if one were to follow this code with print cnxn one would get the string 'pyodbc.connect("DSN=test;UID=test;PWD=test")' and not some reference to a connection object. To do what he seemed to have been trying would take: passwd='test' connectstring='DSN=test;UID=test;PWD=' + passwd cnxn = pyodbc.connect(connectstring) But I agreee that Vernon Cole's code is better. Or how about cnxn = pyodbc.connect('DSN=test;UID=test;PWD=' + passwd) or cnxn = pyodbc.connect('DSN=test;UID=test;PWD=%s' % passwd) > > > Try printing the string to screen first :-) > > You have single quotes embedded in the variables based so the variable > is never in place. I think this analysis by Chris Clark is not correct. > Use % markers instead and make your life easier :-) > > > > _______________________________________________ > DB-SIG maillist - DB-SIG at python.org > http://mail.python.org/mailman/listinfo/db-sig Thank you all, Art Protin From Dennis.Benzinger at gmx.net Fri Oct 17 17:25:31 2008 From: Dennis.Benzinger at gmx.net (Dennis Benzinger) Date: Fri, 17 Oct 2008 17:25:31 +0200 Subject: [DB-SIG] Simple? ODBC connection issue In-Reply-To: <26B1C4C2-928B-449D-9CF9-5A138E1A85CF@machell.net> References: <26B1C4C2-928B-449D-9CF9-5A138E1A85CF@machell.net> Message-ID: <48F8AE6B.1070900@gmx.net> Hi! Am 17.10.2008 02:55, Peter Machell schrieb: > I'm using pyodbc to connect to several databases. > > On one of them, the database password needs to be a variable. > > If I hard code the password, the connection works fine: > > cnxn = pyodbc.connect("DSN=test;UID=test;PWD=test") > > However substituting a variable fails: > > passwd='test' > connectstring='pyodbc.connect("DSN=test;UID=test;PWD='+passwd+'")' > cnxn = connectstring > [...] You have to many quotes in your code. Your second line creates a string but does not call the connect function. You can either use passwd='test' connectstring='DSN=test;UID=test;PWD='+passwd cnxn = pyodbc.connect(connectstring) if you need the connectstring variable. Or simply passwd='test' cnxn=pyodbc.connect("DSN=test;UID=test;PWD="+passwd) HTH, Dennis Benzinger From gslindstrom at gmail.com Sat Oct 18 16:58:10 2008 From: gslindstrom at gmail.com (Greg Lindstrom) Date: Sat, 18 Oct 2008 09:58:10 -0500 Subject: [DB-SIG] PyCon 2009 (US) - Call for Tutorials Message-ID: The period for submitting tutorial proposals for Pycon 2009 (US) is open and will continue through Friday, October 31th. This year features two "pre-conference" days devoted to tutorials on Wednesday March 25 & Thursday March 26 in Chicago. This allows for more classes than ever. Tutorials are 3-hours long on a specific topic of your choice. Last year we featured classes on Learning Python, Web Development, Scientific Computing, and many more. Class size varied from 10 to over 60 students. The extended time spent in class allows teachers to cover a lot of material while allowing for interaction with students. The full Call for Tutorial Proposals, including submission details, an example proposal as well as a template, is available at . Tutorial selections will be announced in early December to give you time to prepare your class and PyCon will compensate instructors US$1,500 per tutorial. If you have any questions, please contact pycon-tutorials at python.org. Greg Lindstrom Tutorial Coordinator, PyCon 2009 (US) -------------- next part -------------- An HTML attachment was scrubbed... URL: From anthony.tuininga at gmail.com Wed Oct 29 18:06:53 2008 From: anthony.tuininga at gmail.com (Anthony Tuininga) Date: Wed, 29 Oct 2008 11:06:53 -0600 Subject: [DB-SIG] cx_Oracle 4.4.1 Message-ID: <703ae56b0810291006g5fe4bf69qa48b6427f85a8eeb@mail.gmail.com> What is cx_Oracle? cx_Oracle is a Python extension module that allows access to Oracle and conforms to the Python database API 2.0 specifications with a few exceptions. Where do I get it? http://cx-oracle.sourceforge.net What's new? 1) Make the bind variables and fetch variables accessible although they need to be treated carefully since they are used internally; support added for forward compatibility with version 5.x. 2) Include the "cannot insert null value" in the list of errors that are treated as integrity errors as requested by Matt Boersma. 3) Use a cx_Oracle.Error instance rather than a string to hold the error when truncation (ORA-1406) takes place as requested by Helge Tesdal. 4) Added support for fixed char, old style varchar and timestamp attribute values in objects. 5) Tweaked setup.py to check for the Oracle version up front rather than during the build in order to produce more meaningful errors and simplify the code. 6) In setup.py added proper detection for the instant client on Mac OS X as recommended by Martijn Pieters. 7) In setup.py, avoided resetting the extraLinkArgs on Mac OS X as doing so prevents simple modification where desired as expressed by Christian Zagrodnick. 8) Added documentation on exception handling as requested by Andreas Mock, who also graciously provided an initial patch. 9) Modified documentation indicating that the password attribute on connection objects can be written. 10) Added documentation warning that parameters not passed in during subsequent executions of a statement will retain their original values as requested by Harald Armin Massa. 11) Added comments indicating that an Oracle client is required since so many people find this surprising. 12) Removed all references to Oracle 8i from the documentation and version 5.x will eliminate all vestiges of support for this version of the Oracle client. 13) Added additional link arguments for Cygwin as requested by Rob Gillen. Anthony Tuininga