convert Dbase (.dbf) files to SQLite databases

Discussion in 'Python' started by Helmut Jarausch, Jul 15, 2009.

  1. Hi,

    I have a lot of old Dbase files (.dbf) and I'll like to convert these
    to SQLite databases as automatically as possible.
    Does anybody know a tool/Python script to do so?

    I know, I could use dbfpy and create the SQLite table and import all
    data. But is there something easier?

    Many thanks for a hint,

    Helmut.

    --
    Helmut Jarausch

    Lehrstuhl fuer Numerische Mathematik
    RWTH - Aachen University
    D 52056 Aachen, Germany
     
    Helmut Jarausch, Jul 15, 2009
    #1
    1. Advertising

  2. Helmut Jarausch

    David Lyon Guest

    On Wed, 15 Jul 2009 11:53:28 +0200, Helmut Jarausch
    <-aachen.de> wrote:
    > Hi,
    >
    > I have a lot of old Dbase files (.dbf) and I'll like to convert these
    > to SQLite databases as automatically as possible.
    > Does anybody know a tool/Python script to do so?
    >
    > I know, I could use dbfpy and create the SQLite table and import all
    > data. But is there something easier?


    yes...

    Use OpenOffice-Scalc or MS-Office-Excel to open the table...

    Export to csv....

    Use SQLite Manager (https://addons.mozilla.org/en-US/firefox/addon/5817)

    and use the import wizard to import your data....

    It shouldn't take too long...

    David
     
    David Lyon, Jul 15, 2009
    #2
    1. Advertising

  3. Helmut Jarausch

    Ethan Furman Guest

    Helmut Jarausch wrote:
    > Hi,
    >
    > I have a lot of old Dbase files (.dbf) and I'll like to convert these
    > to SQLite databases as automatically as possible.
    > Does anybody know a tool/Python script to do so?
    >
    > I know, I could use dbfpy and create the SQLite table and import all
    > data. But is there something easier?
    >
    > Many thanks for a hint,
    >
    > Helmut.
    >


    Greetings!

    If your tables are either dBase III or Visual Foxpro 6 (may work with
    other VFP versions...) you can try
    http://groups.google.com/group/python-dbase

    #open table
    import dbf
    table = dbf.Table('/path/to/old/dbf')

    #generate .csv file
    table.export() # defaults to same name with csv extension

    #access records
    for rec in table:
    tups = tuple(rec)
    lst = list(rec)
    dct = rec.scatter_fields()

    I haven't used SQlite, so I'm unable to provide samples for that portion
    of the conversion.

    Hope this helps.

    ~Ethan~
     
    Ethan Furman, Jul 15, 2009
    #3
  4. Helmut Jarausch

    John Machin Guest

    On Jul 15, 8:39 pm, David Lyon <> wrote:
    > On Wed, 15 Jul 2009 11:53:28 +0200, Helmut Jarausch
    >
    > <-aachen.de> wrote:
    > > Hi,

    >
    > > I have a lot of old Dbase files (.dbf) and I'll like to convert these
    > > to SQLite databases as automatically as possible.
    > > Does anybody know a tool/Python script to do so?

    >
    > > I know, I could use dbfpy and create the SQLite table and import all
    > > data. But is there something easier?

    >
    > yes...
    >
    > Use OpenOffice-Scalc or MS-Office-Excel to open the table...


    Max 64K rows for Scalc and Excel 2003; 2007 can take 2**20 rows.
    Only old dBase (not dBase 7). Memo fields not handled. Visual FoxPro
    DBFs not supported by Excel even tho' VFP is an MS product.


    > Export to csv....


    Yuk.

    >
    > Use SQLite Manager (https://addons.mozilla.org/en-US/firefox/addon/5817)
    >
    > and use the import wizard to import your data....
    >
    > It shouldn't take too long...


    .... before you get sick of the error-prone manual tasks.

    I'd write a script that took a DBF file, analysed the field
    descriptions, made a CREATE TABLE statement, executed it, and then
    started doing inserts. Fairly easy to write. Scripts have the great
    benefit that you can fix them and re-run a whole lot easier than
    redoing manual steps.

    If dbfpy can't handle any new-fangled stuff you may have in your
    files, drop me a line ... I have a soon-to-be released DBF module that
    should be able to read the "new" stuff up to dBase7 and VFP9,
    including memo files, conversion from whatever to Unicode if
    needed, ...

    Cheers,
    John
     
    John Machin, Jul 15, 2009
    #4
  5. Helmut Jarausch

    Ethan Furman Guest

    John Machin wrote:

    > If dbfpy can't handle any new-fangled stuff you may have in your
    > files, drop me a line ... I have a soon-to-be released DBF module that
    > should be able to read the "new" stuff up to dBase7 and VFP9,
    > including memo files, conversion from whatever to Unicode if
    > needed, ...
    >
    > Cheers,
    > John


    Cool! I'm looking forward to it!

    ~Ethan~
     
    Ethan Furman, Jul 15, 2009
    #5
    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. Aurelio
    Replies:
    0
    Views:
    2,726
    Aurelio
    Jan 2, 2006
  2. Ken North
    Replies:
    0
    Views:
    604
    Ken North
    Jul 14, 2005
  3. afandi
    Replies:
    6
    Views:
    1,201
    afandi
    Apr 21, 2008
  4. Ethan Furman

    dBase III files and Visual Foxpro 6 files

    Ethan Furman, Dec 8, 2008, in forum: Python
    Replies:
    4
    Views:
    882
    imageguy
    Dec 9, 2008
  5. Ethan Furman

    ANN: dbf (aka Python dBase)

    Ethan Furman, Mar 1, 2013, in forum: Python
    Replies:
    0
    Views:
    164
    Ethan Furman
    Mar 1, 2013
Loading...

Share This Page