odbc script

Steve Holden steve at holdenweb.com
Tue Dec 21 07:56:27 EST 2004


Chris wrote:

> Thanks Benji,
>                       I took your advice and added in the conn.commit() into 
> the script but still had the same problem.  I did some digging around the 
> odbc documentation and found this bug:
> **************************************************************************************************************
> 4. Hirendra Hindocha also reports: inserting a single row into a table 
> doesn't work properly unless one specifically deallocates the cursor.
> for example the following code snippet -
> conn = odbc.odbc(str)
> cur = conn.cursor()
> sql = 'insert into abc_table values(1,2,'abc')
> cur.execute(sql)
> conn.commit()
> cur.close()
> conn.close()doesn't work, unless you add the following lines
> 
> cur = None
> conn = None at the end of the above code snippet. Tracing with ODBC and a 
> look into odbc.cpp shows that sqlfreestmt is not being called until the 
> explicit deallocation is done. [Note however, Bill Tutt seems to think that 
> this problem implies a problem with the specific ODBC driver, rather than 
> with the ODBC implementation of Python. I haven't a clue!]
> 
> *****************************************************************************************************************
> I figured what the heck and added in the 2 lines specified:
> cur = None
> conn = None
> and sure enough it worked after that!  I am not sure why but figure that 
> when the last loop goes through it is as if it is updating 1 single row?????
> Either way it works now.  Thanks for the help as I am sure I needed the 
> conn.commit() as well.
> 
> Chris
> 
> "Benji York" <benji at benjiyork.com> wrote in message 
> news:mailman.8037.1103465926.5135.python-list at python.org...
> 
>>Chris wrote:
>>
>>>what ever is the last loop through doesn't seem to update the
>>>database?
>>
>>Try a conn.commit() after your loop.
>>--
>>Benji York 
> 
> 
> 
Chris:

Please note that the odbc module is a bit long in the totth now, though 
it surely is convenient to get it with win32all. If this work is being 
done for personal use you might want to look at www.egenix.com and think 
about installing the mxODBC module, which I have used with very good 
results.

regards
  Steve
-- 
Steve Holden               http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC      +1 703 861 4237  +1 800 494 3119



More information about the Python-list mailing list