Last active
October 22, 2021 20:19
-
-
Save Siniinik/177e7c45a8fd785b7c4c to your computer and use it in GitHub Desktop.
mdbtools encoding UTF-8 and type InnoDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/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/ | |
# -*- coding: utf-8 -*- | |
import sys | |
import subprocess | |
import os | |
PATH = os.path.dirname(os.path.realpath(__file__)) | |
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" | |
def generated_schema(type_name): | |
with open(PATH + '/schema2.sql', 'r') as f: | |
schema = f.read() | |
schema = schema.replace('@TYPE@', type_name) | |
return schema | |
table_names = subprocess.Popen( | |
['mdb-tables', '-1', DATABASE], | |
stdout=subprocess.PIPE | |
).communicate()[0] | |
tables = table_names.splitlines() | |
# print tables | |
print generated_schema(tables[0]) | |
# sys.stdout.flush() | |
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment