Skip to main content
Adopted the script so it really works under the conditions I asked for.
Source Link

This should work:

#!/usr/bin/env##Database=group
##Access.mdb pythonto SqLite=name
##inputmdb= input file
##outputsqlite = output file

import sys, subprocess, os, sqlite3 as sql

mdb_name = sys.argv[1]inputmdb
sql_name = sys.argv[2]outputsqlite

try:
    print "\nopening db"
    conn = sql.connect(sql_name)
    curs = conn.cursor()
    
    print "\ncreating schema"
    cmds = subprocess.Popen(["mdb-schema", mdb_name, "mysql"], stdout=subprocess.PIPE).communicate()[0]
    curs.executescript(cmds)
    conn.commit()
    
    print "\nfetching table names"
    table_names = subprocess.Popen(["mdb-tables", "-1", mdb_name], stdout=subprocess.PIPE).communicate()[0]
    tables = table_names.splitlines()
    
    print "\npopulate tables"
    for table in tables:
        if table != '':
            cmds = subprocess.Popen(["mdb-export", "-I", "mysql", mdb_name, table], stdout=subprocess.PIPE).communicate()[0]
            curs.executescript("BEGIN;" + cmds + "COMMIT;")
    conn.commit()
    print "\nhoooray"

except Exception, e:
    print "oh noes:"
    print e
finally:    
    print "\nclosing DB"
    conn.close()

python mdb2sqlite.py testdb.mdb dump.db

This should work:

#!/usr/bin/env python
import sys, subprocess, os, sqlite3 as sql

mdb_name = sys.argv[1]
sql_name = sys.argv[2]

try:
    print "\nopening db"
    conn = sql.connect(sql_name)
    curs = conn.cursor()
    
    print "\ncreating schema"
    cmds = subprocess.Popen(["mdb-schema", mdb_name, "mysql"], stdout=subprocess.PIPE).communicate()[0]
    curs.executescript(cmds)
    conn.commit()
    
    print "\nfetching table names"
    table_names = subprocess.Popen(["mdb-tables", "-1", mdb_name], stdout=subprocess.PIPE).communicate()[0]
    tables = table_names.splitlines()
    
    print "\npopulate tables"
    for table in tables:
        if table != '':
            cmds = subprocess.Popen(["mdb-export", "-I", "mysql", mdb_name, table], stdout=subprocess.PIPE).communicate()[0]
            curs.executescript("BEGIN;" + cmds + "COMMIT;")
    conn.commit()
    print "\nhoooray"

except Exception, e:
    print "oh noes:"
    print e
finally:    
    print "\nclosing DB"
    conn.close()

python mdb2sqlite.py testdb.mdb dump.db

This should work:

##Database=group
##Access.mdb to SqLite=name
##inputmdb= input file
##outputsqlite = output file

import sys, subprocess, os, sqlite3 as sql

mdb_name = inputmdb
sql_name = outputsqlite

try:
    print "\nopening db"
    conn = sql.connect(sql_name)
    curs = conn.cursor()
    
    print "\ncreating schema"
    cmds = subprocess.Popen(["mdb-schema", mdb_name, "mysql"], stdout=subprocess.PIPE).communicate()[0]
    curs.executescript(cmds)
    conn.commit()
    
    print "\nfetching table names"
    table_names = subprocess.Popen(["mdb-tables", "-1", mdb_name], stdout=subprocess.PIPE).communicate()[0]
    tables = table_names.splitlines()
    
    print "\npopulate tables"
    for table in tables:
        if table != '':
            cmds = subprocess.Popen(["mdb-export", "-I", "mysql", mdb_name, table], stdout=subprocess.PIPE).communicate()[0]
            curs.executescript("BEGIN;" + cmds + "COMMIT;")
    conn.commit()
    print "\nhoooray"

except Exception, e:
    print "oh noes:"
    print e
finally:    
    print "\nclosing DB"
    conn.close()
Source Link
ymirsson
  • 884
  • 6
  • 9

This should work:

#!/usr/bin/env python
import sys, subprocess, os, sqlite3 as sql

mdb_name = sys.argv[1]
sql_name = sys.argv[2]

try:
    print "\nopening db"
    conn = sql.connect(sql_name)
    curs = conn.cursor()
    
    print "\ncreating schema"
    cmds = subprocess.Popen(["mdb-schema", mdb_name, "mysql"], stdout=subprocess.PIPE).communicate()[0]
    curs.executescript(cmds)
    conn.commit()
    
    print "\nfetching table names"
    table_names = subprocess.Popen(["mdb-tables", "-1", mdb_name], stdout=subprocess.PIPE).communicate()[0]
    tables = table_names.splitlines()
    
    print "\npopulate tables"
    for table in tables:
        if table != '':
            cmds = subprocess.Popen(["mdb-export", "-I", "mysql", mdb_name, table], stdout=subprocess.PIPE).communicate()[0]
            curs.executescript("BEGIN;" + cmds + "COMMIT;")
    conn.commit()
    print "\nhoooray"

except Exception, e:
    print "oh noes:"
    print e
finally:    
    print "\nclosing DB"
    conn.close()

python mdb2sqlite.py testdb.mdb dump.db