-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmdbwrapper
More file actions
executable file
·47 lines (37 loc) · 1.32 KB
/
mdbwrapper
File metadata and controls
executable file
·47 lines (37 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
# Inspired by:
# http://nialldonegan.me/2007/03/10/converting-microsoft-access-mdb-into-csv-or-mysql-in-linux/
# http://cltb.ojuba.org/en/articles/mdb2sqlite.html
# Use temporary files for sql statements to ease debugging if something goes wrong
# Export schema from mdb:
# mdb-schema $1 sqlite \
# | sed "s/Int8/INTEGER(8)/" \
# | sed "s/Int4/INTEGER(4)/" \
# | sed "s/Float8/FLOAT(8)/" \
# | sed "s/Float4/FLOAT(4)/" \
# | sed "s/Bool/BOOLEAN/" \
# | sed "s/Char /VARCHAR/" \
# | sed "s/DROP TABLE/DROP TABLE IF EXISTS/" \
# | grep -v "^--" \
# > create.sql
mdb-schema $1 sqlite > create.sql
# Import schema to sqlite3
sqlite3 $2< create.sql
# Delete old import data (adding to exising file later)
# Vast speed improvement with BEGIN..COMMIT
echo "BEGIN;" > import-data.sql
# Export each table and replace nan and inf with NULL
for table in `mdb-tables $1`; do
echo $table
MDB_JET3_CHARSET=cp1256 mdb-export -R ";\n" -I sqlite $1 $table >> import-data.sql
# mdb-export -I sqlite $1 $table \
# | sed -e 's/)$/)\;/'\
# | sed "s/-inf/NULL/mg" \
# | sed "s/inf/NULL/mg" \
# | sed "s/-nan/NULL/mg" \
# | sed "s/nan/NULL/mg" \
# >> import-data.sql
done
echo "COMMIT;" >> import-data.sql
# Import data to sqlite3
sqlite3 $2 < import-data.sql