ODBC & DbiData problem

M.-A. Lemburg mal at lemburg.com
Sun Aug 3 15:16:31 EDT 2003


Wedrowiec wrote:
> I have a problem for experienced programmers. The following code
> should copy data between two different databases:
> 
> import dbi,odbc
> conn1=odbc.odbc('mysql'); conn2=odbc.odbc('sqlite')
> c1 = conn1.cursor(); c2 = conn2.cursor()
> 
> c1.execute("SELECT field1, field2  FROM table1")
> rows = c1.fetchall()
> c2.executemany('INSERT INTO table1 (field1=%s,field2=%s)', rows)
> 
> c1.close();c1=None; c2.close();c1=None;
> conn1.close();conn1=None; conn2.close();conn2=None
> 
> The problem is: field 'field2' is DATE type and after fetchmany()
> method I got DbiDate object instead of string 'YYYY-MM-DD 
> HH:MM:SS'. So my  code breaks because Python cannot 
> insert such object to another database.

FWIW, with mxODBC you shouldn't have a problem with this
at all. You can even tell it to return all dates as strings.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Software directly from the Source  (#1, Aug 03 2003)
 >>> Python/Zope Products & Consulting ...         http://www.egenix.com/
 >>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________






More information about the Python-list mailing list