Skip to content

Instantly share code, notes, and snippets.

@seeschloss seeschloss/sql.sh
Created Jun 3, 2015

Embed
What would you like to do?
#!/usr/bin/env bash
FILE="$(mktemp)"
trap "rm $FILE; exit" EXIT
DEBUG=0
if test "$1" = "-d"; then
DEBUG=1
shift 1
fi
SQLFILE="$1"
function mysql2sqlite() {
fgrep -v 'CREATE DATABASE' \
| grep -v '^USE' \
| grep -v '^SET' \
| sed 's/AUTO_INCREMENT//I' \
| sed 's/collate [^ ,]*//I' \
| fgrep -v 'KEY' \
| fgrep -v 'LOCK' \
| sed -e ':a' -e 'N' -e '$!ba' -e 's/,\n)/)/g' \
| sed 's/ENGINE=.*;/;/' \
| sed 's/unsigned//I' \
| sed "s/\\\'/''/g" \
| sed 's/enum([^)]*)/TEXT/' \
| sed 's/INT([0-9]*)//'
}
if test "$DEBUG" = 1; then
cat "$SQLFILE" | mysql2sqlite
else
cat "$SQLFILE" | mysql2sqlite | sqlite3 "$FILE"
sqlite3 -csv "$FILE"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.