ODBC & DbiData problem

Discussion in 'Python' started by Wedrowiec, Aug 2, 2003.

  1. Wedrowiec

    Wedrowiec Guest

    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.

    I know how to convert this object to the correct string
    (http://www.python.org/windows/OdbcHints.html) but it must be done for
    every field in every row. :( So my question is: Is it possible to make
    odbc module to *automatically convert* this field from DbiDate object
    to string? Maybe is there any special parameter to set up? I do not
    want to write special code to convert all such fields. It suppose, it
    can be done more automatically by odbc module, bu I do not know
    how....
     
    Wedrowiec, Aug 2, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. HB

    ODBC problem

    HB, Dec 11, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    957
    Alex Papadimoulis
    Dec 11, 2003
  2. TomislaW

    problem with odbc

    TomislaW, Jul 23, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,326
    Martin Marinov
    Jul 23, 2004
  3. yefei
    Replies:
    0
    Views:
    420
    yefei
    Mar 30, 2006
  4. goli

    JDBC / ODBC problem

    goli, Apr 7, 2005, in forum: Java
    Replies:
    3
    Views:
    458
    AlexKay
    Apr 8, 2005
  5. Wes Gamble
    Replies:
    1
    Views:
    176
    Gerardo Santana Gómez Garrido
    Apr 5, 2006
Loading...

Share This Page