#!/bin/bash
# this script is only working with linux.
# the purpose is that this scrip export all files from the mdb database as CSV
# The option I use
#a) Only data files are exported.
#b) Date are exported in year month day style for using in HSQLDB style
#c) Numbers are exported with a point as decimal separator
#
#The script take care all MDB files are exported as a CSV.
#For each MDB file there is made a new MAP.
#
#I have select this method there it was the most easy way to import data in CALC.
#When you still have MS Acces use MS Acces for exporting dat to a CSV. I think this is the best method.


# start this script up from the place where the MDB files are. Then the files are stored in the same map.
# It is not important where this script is.

# Set the field separator to one line
IFS=$'\n'

for database in $(ls -1 *.mdb )
	do
		DirNaam="${database%*.mdb}" # Strip MDB from the file name and make the map name
		test -d "${DirNaam}" || mkdir "${DirNaam}" 
	
		for tabel in $(mdb-tables -1 "${database}")
			do
			#echo "Ik werk aan deze : $database  $tabel"
			echo "Processing this : $database  $tabel"
# There are three lines in this script select the line you need
# American   month day year
# Europe       day month year
# HSQLDB   year  month  day
#		 	mdb-export -D "%m-%d-%y" "${database}" "$tabel" >"${DirNaam}/${tabel}.csv"
#		 	mdb-export -D "%d-%m-%y" "${database}" "$tabel" >"${DirNaam}/${tabel}.csv"
		 	mdb-export -D "%Y-%m-%d" "${database}" "$tabel" >"${DirNaam}/${tabel}.csv"
			done
	done
