#!/usr/bin/env sh
# prerequisite https://github.com/brianb/mdbtools
#
# if your mdb is encoded in certain character set
# do something like this
# export MDB_ICONV="Big-5"
# export MDB_JET3_CHARSET="Big-5"
#
# under zsh
# for f (**/*.mdb) {~/dump.sh $f}
#
python ~/AccessDump.py $1 | sqlite3 $1.sqlite
for x in `mdb-tables -1 $1`; do mdb-export $1 $x >> $1.$x.csv ; done
#!/usr/bin/env python
#
# AccessDump.py
# A simple script to dump the contents of a Microsoft Access Database.
# It depends upon the mdbtools suite:
# http://sourceforge.net/projects/mdbtools/
import sys, subprocess, os
DATABASE = sys.argv[1]
# Dump the schema for the DB
subprocess.call(["mdb-schema", DATABASE, "mysql"])
# Get the list of table names with "mdb-tables"
table_names = subprocess.Popen(["mdb-tables", "-1", DATABASE],
stdout=subprocess.PIPE).communicate()[0]
tables = table_names.splitlines()
print "BEGIN;" # start a transaction, speeds things up when importing
sys.stdout.flush()
# Dump each table as a CSV file using "mdb-export",
# converting " " in table names to "_" for the CSV filenames.
for table in tables:
if table != '':
subprocess.call(["mdb-export", "-I", "mysql", DATABASE, table])
print "COMMIT;" # end the transaction
sys.stdout.flush()