sqlmig: possibilité de spécifier csv_null pour la conversion des fichiers csv
This commit is contained in:
parent
6f1b8b4926
commit
e621a5671e
79
sqlmig
79
sqlmig
|
@ -76,6 +76,12 @@ OPTIONS
|
||||||
spécifié au nom de la base de données. Cette valeur peut être spécifiée
|
spécifié au nom de la base de données. Cette valeur peut être spécifiée
|
||||||
dans la section [sqlmig] du fichier my.cnf ou avec la variable SUFFIX
|
dans la section [sqlmig] du fichier my.cnf ou avec la variable SUFFIX
|
||||||
pour ora.conf
|
pour ora.conf
|
||||||
|
--csv-null VALUE
|
||||||
|
Lors de la conversion des fichiers .csv en .sql, considérer que VALUE
|
||||||
|
représente la valeur NULL. Par défaut, utiliser la chaine vide
|
||||||
|
--csv-null-mysql
|
||||||
|
--csv-null-upper
|
||||||
|
Aliases pour --csv-null '\\N' et --csv-null NULL respectivement
|
||||||
|
|
||||||
--profile PROFILE
|
--profile PROFILE
|
||||||
-P, --prod
|
-P, --prod
|
||||||
|
@ -304,6 +310,13 @@ function set_dbdirs() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function fix_csv_null() {
|
||||||
|
case "$csv_null" in
|
||||||
|
mysql) csv_null='\N';;
|
||||||
|
upper) csv_null=NULL;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# MySQL
|
# MySQL
|
||||||
|
|
||||||
|
@ -441,42 +454,43 @@ function mysql_set_adminargs() {
|
||||||
fi
|
fi
|
||||||
[ ${#adminargs[*]} -gt 0 ] || array_add adminargs --default-character-set utf8
|
[ ${#adminargs[*]} -gt 0 ] || array_add adminargs --default-character-set utf8
|
||||||
}
|
}
|
||||||
|
function mysql__mconf_get() {
|
||||||
|
local defaults="$1" tmp
|
||||||
|
if [ -n "$set_suffix" ]; then
|
||||||
|
setx tmp=mconf_get "$defaults" sqlmig suffix
|
||||||
|
[ -n "$tmp" ] && suffix="$tmp"
|
||||||
|
fi
|
||||||
|
if [ -n "$set_csv_null" ]; then
|
||||||
|
setx tmp=mconf_get "$defaults" sqlmig csv_null
|
||||||
|
[ -n "$tmp" ] && {
|
||||||
|
csv_null="$tmp"
|
||||||
|
fix_csv_null
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
}
|
||||||
function mysql_set_userargs() {
|
function mysql_set_userargs() {
|
||||||
local dir="$1" dbname="$2" defaults set_suffix tmpsuffix
|
local dir="$1" dbname="$2" defaults
|
||||||
|
local set_suffix set_csv_null
|
||||||
userargs=()
|
userargs=()
|
||||||
setx defaults=mysql_get_defaults "$dir"
|
setx defaults=mysql_get_defaults "$dir"
|
||||||
[ -z "$suffix" ] && set_suffix=1
|
[ -z "$suffix" ] && set_suffix=1
|
||||||
|
[ -z "$csv_null" ] && set_csv_null=1
|
||||||
if [ -f "$defaults" ]; then
|
if [ -f "$defaults" ]; then
|
||||||
array_add userargs --defaults-file="$defaults"
|
array_add userargs --defaults-file="$defaults"
|
||||||
if [ -n "$set_suffix" ]; then
|
mysql__mconf_get "$defaults"
|
||||||
setx tmpsuffix=mconf_get "$defaults" sqlmig suffix
|
|
||||||
[ -n "$tmpsuffix" ] && suffix="$tmpsuffix"
|
|
||||||
fi
|
|
||||||
if [ -n "$userdefaults" ]; then
|
if [ -n "$userdefaults" ]; then
|
||||||
array_add userargs --defaults-extra-file="$userdefaults"
|
array_add userargs --defaults-extra-file="$userdefaults"
|
||||||
if [ -n "$set_suffix" ]; then
|
mysql__mconf_get "$userdefaults"
|
||||||
setx tmpsuffix=mconf_get "$userdefaults" sqlmig suffix
|
|
||||||
[ -n "$tmpsuffix" ] && suffix="$tmpsuffix"
|
|
||||||
fi
|
|
||||||
elif [ -f "$dir/my-${dbname}.cnf" ]; then
|
elif [ -f "$dir/my-${dbname}.cnf" ]; then
|
||||||
array_add userargs --defaults-extra-file="$dir/my-${dbname}.cnf"
|
array_add userargs --defaults-extra-file="$dir/my-${dbname}.cnf"
|
||||||
if [ -n "$set_suffix" ]; then
|
mysql__mconf_get "$dir/my-${dbname}.cnf"
|
||||||
setx tmpsuffix=mconf_get "$dir/my-${dbname}.cnf" sqlmig suffix
|
|
||||||
[ -n "$tmpsuffix" ] && suffix="$tmpsuffix"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
elif [ -n "$userdefaults" ]; then
|
elif [ -n "$userdefaults" ]; then
|
||||||
array_add userargs --defaults-file="$userdefaults"
|
array_add userargs --defaults-file="$userdefaults"
|
||||||
if [ -n "$set_suffix" ]; then
|
mysql__mconf_get "$userdefaults"
|
||||||
setx tmpsuffix=mconf_get "$userdefaults" sqlmig suffix
|
|
||||||
[ -n "$tmpsuffix" ] && suffix="$tmpsuffix"
|
|
||||||
fi
|
|
||||||
elif [ -f "$dir/my-${dbname}.cnf" ]; then
|
elif [ -f "$dir/my-${dbname}.cnf" ]; then
|
||||||
array_add userargs --defaults-file="$dir/my-${dbname}.cnf"
|
array_add userargs --defaults-file="$dir/my-${dbname}.cnf"
|
||||||
if [ -n "$set_suffix" ]; then
|
mysql__mconf_get "$dir/my-${dbname}.cnf"
|
||||||
setx tmpsuffix=mconf_get "$dir/my-${dbname}.cnf" sqlmig suffix
|
|
||||||
[ -n "$tmpsuffix" ] && suffix="$tmpsuffix"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
[ ${#userargs[*]} -gt 0 ] || array_add userargs --default-character-set utf8
|
[ ${#userargs[*]} -gt 0 ] || array_add userargs --default-character-set utf8
|
||||||
}
|
}
|
||||||
|
@ -797,7 +811,7 @@ function oracle_source_adminconf() {
|
||||||
}
|
}
|
||||||
function oracle_source_userconf() {
|
function oracle_source_userconf() {
|
||||||
local dir="$1" dbname="$2"
|
local dir="$1" dbname="$2"
|
||||||
unset ORACLE_SID NLS_LANG ADMINCONNECT USERCONNECT SQLMIGLOG SUFFIX
|
unset ORACLE_SID NLS_LANG ADMINCONNECT USERCONNECT SQLMIGLOG SUFFIX CSV_NULL
|
||||||
setx defaults=oracle_get_defaults "$dir"
|
setx defaults=oracle_get_defaults "$dir"
|
||||||
[ -f "$defaults" ] && source "$defaults"
|
[ -f "$defaults" ] && source "$defaults"
|
||||||
[ -f "$dir/ora-${dbname}.conf" ] && source "$dir/ora-${dbname}.conf"
|
[ -f "$dir/ora-${dbname}.conf" ] && source "$dir/ora-${dbname}.conf"
|
||||||
|
@ -821,6 +835,10 @@ function oracle_source_userconf() {
|
||||||
fi
|
fi
|
||||||
[ -n "$SQLMIGLOG" ] || SQLMIGLOG="/tmp/sqlmig-${ORACLE_SID}-${dbname}.log"
|
[ -n "$SQLMIGLOG" ] || SQLMIGLOG="/tmp/sqlmig-${ORACLE_SID}-${dbname}.log"
|
||||||
[ -z "$suffix" ] && suffix="$SUFFIX"
|
[ -z "$suffix" ] && suffix="$SUFFIX"
|
||||||
|
[ -z "$csv_null" ] && {
|
||||||
|
csv_null="$CSV_NULL"
|
||||||
|
fix_csv_null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ORACLE_ADMIN_CONF_DONE=
|
ORACLE_ADMIN_CONF_DONE=
|
||||||
function oracle_admin_update() {
|
function oracle_admin_update() {
|
||||||
|
@ -884,6 +902,7 @@ charset=
|
||||||
oracle_sid=
|
oracle_sid=
|
||||||
nls_lang=
|
nls_lang=
|
||||||
suffix=
|
suffix=
|
||||||
|
csv_null=
|
||||||
profile=
|
profile=
|
||||||
type=auto
|
type=auto
|
||||||
action=update
|
action=update
|
||||||
|
@ -911,6 +930,9 @@ args=(
|
||||||
-s:,--oracle-sid: oracle_sid=
|
-s:,--oracle-sid: oracle_sid=
|
||||||
--nls-lang: nls_lang=
|
--nls-lang: nls_lang=
|
||||||
--suffix: suffix=
|
--suffix: suffix=
|
||||||
|
--csv-null: csv_null=
|
||||||
|
--csv-null-mysql csv_null='\N'
|
||||||
|
--csv-null-upper csv_null=NULL
|
||||||
--profile: profile=
|
--profile: profile=
|
||||||
-P,--prod profile=prod
|
-P,--prod profile=prod
|
||||||
-T,--test profile=test
|
-T,--test profile=test
|
||||||
|
@ -1005,7 +1027,11 @@ create database @@database@@;"
|
||||||
#socket=/var/run/mysqld/mysqld.sock
|
#socket=/var/run/mysqld/mysqld.sock
|
||||||
|
|
||||||
[mysql]
|
[mysql]
|
||||||
default-character-set=utf8"
|
default-character-set=utf8
|
||||||
|
|
||||||
|
[sqlmig]
|
||||||
|
#suffix=
|
||||||
|
csv_null="
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -f "$dbdir/my-${dbname}.cnf" ]; then
|
if [ ! -f "$dbdir/my-${dbname}.cnf" ]; then
|
||||||
|
@ -1051,7 +1077,10 @@ ADMINCONNECT=
|
||||||
# paramètres de connexion pour les mises à jour utilisateur
|
# paramètres de connexion pour les mises à jour utilisateur
|
||||||
USERCONNECT=$dbname/password
|
USERCONNECT=$dbname/password
|
||||||
# logs des mises à jour
|
# logs des mises à jour
|
||||||
SQLMIGLOG=\"/tmp/sqlmig-\${ORACLE_SID}-${dbname}.log\""
|
SQLMIGLOG=\"/tmp/sqlmig-\${ORACLE_SID}-${dbname}.log\"
|
||||||
|
# divers
|
||||||
|
#SUFFIX=
|
||||||
|
#CSV_NULL="
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
|
@ -1239,7 +1268,7 @@ for dbdir in "${dbdirs[@]}"; do
|
||||||
gsub(/'\''/, "'\'\\\\\'\''")
|
gsub(/'\''/, "'\'\\\\\'\''")
|
||||||
print "table='\''" $0 "'\''"
|
print "table='\''" $0 "'\''"
|
||||||
}' <<<"$csvname")" #"
|
}' <<<"$csvname")" #"
|
||||||
"$scriptdir/mysqlloadcsv" >"$sql" ${truncate:+-T} -nIf "$csv" "$table" --prefix "-- -*- coding: utf-8 mode: sql -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8"
|
"$scriptdir/mysqlloadcsv" >"$sql" ${truncate:+-T} -Z "$csv_null" -nIf "$csv" "$table" --prefix "-- -*- coding: utf-8 mode: sql -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8"
|
||||||
done
|
done
|
||||||
eend; eclearp
|
eend; eclearp
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue