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
|
||||
dans la section [sqlmig] du fichier my.cnf ou avec la variable SUFFIX
|
||||
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
|
||||
-P, --prod
|
||||
|
@ -304,6 +310,13 @@ function set_dbdirs() {
|
|||
fi
|
||||
}
|
||||
|
||||
function fix_csv_null() {
|
||||
case "$csv_null" in
|
||||
mysql) csv_null='\N';;
|
||||
upper) csv_null=NULL;;
|
||||
esac
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# MySQL
|
||||
|
||||
|
@ -441,42 +454,43 @@ function mysql_set_adminargs() {
|
|||
fi
|
||||
[ ${#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() {
|
||||
local dir="$1" dbname="$2" defaults set_suffix tmpsuffix
|
||||
local dir="$1" dbname="$2" defaults
|
||||
local set_suffix set_csv_null
|
||||
userargs=()
|
||||
setx defaults=mysql_get_defaults "$dir"
|
||||
[ -z "$suffix" ] && set_suffix=1
|
||||
[ -z "$csv_null" ] && set_csv_null=1
|
||||
if [ -f "$defaults" ]; then
|
||||
array_add userargs --defaults-file="$defaults"
|
||||
if [ -n "$set_suffix" ]; then
|
||||
setx tmpsuffix=mconf_get "$defaults" sqlmig suffix
|
||||
[ -n "$tmpsuffix" ] && suffix="$tmpsuffix"
|
||||
fi
|
||||
mysql__mconf_get "$defaults"
|
||||
if [ -n "$userdefaults" ]; then
|
||||
array_add userargs --defaults-extra-file="$userdefaults"
|
||||
if [ -n "$set_suffix" ]; then
|
||||
setx tmpsuffix=mconf_get "$userdefaults" sqlmig suffix
|
||||
[ -n "$tmpsuffix" ] && suffix="$tmpsuffix"
|
||||
fi
|
||||
mysql__mconf_get "$userdefaults"
|
||||
elif [ -f "$dir/my-${dbname}.cnf" ]; then
|
||||
array_add userargs --defaults-extra-file="$dir/my-${dbname}.cnf"
|
||||
if [ -n "$set_suffix" ]; then
|
||||
setx tmpsuffix=mconf_get "$dir/my-${dbname}.cnf" sqlmig suffix
|
||||
[ -n "$tmpsuffix" ] && suffix="$tmpsuffix"
|
||||
fi
|
||||
mysql__mconf_get "$dir/my-${dbname}.cnf"
|
||||
fi
|
||||
elif [ -n "$userdefaults" ]; then
|
||||
array_add userargs --defaults-file="$userdefaults"
|
||||
if [ -n "$set_suffix" ]; then
|
||||
setx tmpsuffix=mconf_get "$userdefaults" sqlmig suffix
|
||||
[ -n "$tmpsuffix" ] && suffix="$tmpsuffix"
|
||||
fi
|
||||
mysql__mconf_get "$userdefaults"
|
||||
elif [ -f "$dir/my-${dbname}.cnf" ]; then
|
||||
array_add userargs --defaults-file="$dir/my-${dbname}.cnf"
|
||||
if [ -n "$set_suffix" ]; then
|
||||
setx tmpsuffix=mconf_get "$dir/my-${dbname}.cnf" sqlmig suffix
|
||||
[ -n "$tmpsuffix" ] && suffix="$tmpsuffix"
|
||||
fi
|
||||
mysql__mconf_get "$dir/my-${dbname}.cnf"
|
||||
fi
|
||||
[ ${#userargs[*]} -gt 0 ] || array_add userargs --default-character-set utf8
|
||||
}
|
||||
|
@ -797,7 +811,7 @@ function oracle_source_adminconf() {
|
|||
}
|
||||
function oracle_source_userconf() {
|
||||
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"
|
||||
[ -f "$defaults" ] && source "$defaults"
|
||||
[ -f "$dir/ora-${dbname}.conf" ] && source "$dir/ora-${dbname}.conf"
|
||||
|
@ -821,6 +835,10 @@ function oracle_source_userconf() {
|
|||
fi
|
||||
[ -n "$SQLMIGLOG" ] || SQLMIGLOG="/tmp/sqlmig-${ORACLE_SID}-${dbname}.log"
|
||||
[ -z "$suffix" ] && suffix="$SUFFIX"
|
||||
[ -z "$csv_null" ] && {
|
||||
csv_null="$CSV_NULL"
|
||||
fix_csv_null
|
||||
}
|
||||
}
|
||||
ORACLE_ADMIN_CONF_DONE=
|
||||
function oracle_admin_update() {
|
||||
|
@ -884,6 +902,7 @@ charset=
|
|||
oracle_sid=
|
||||
nls_lang=
|
||||
suffix=
|
||||
csv_null=
|
||||
profile=
|
||||
type=auto
|
||||
action=update
|
||||
|
@ -911,6 +930,9 @@ args=(
|
|||
-s:,--oracle-sid: oracle_sid=
|
||||
--nls-lang: nls_lang=
|
||||
--suffix: suffix=
|
||||
--csv-null: csv_null=
|
||||
--csv-null-mysql csv_null='\N'
|
||||
--csv-null-upper csv_null=NULL
|
||||
--profile: profile=
|
||||
-P,--prod profile=prod
|
||||
-T,--test profile=test
|
||||
|
@ -1005,7 +1027,11 @@ create database @@database@@;"
|
|||
#socket=/var/run/mysqld/mysqld.sock
|
||||
|
||||
[mysql]
|
||||
default-character-set=utf8"
|
||||
default-character-set=utf8
|
||||
|
||||
[sqlmig]
|
||||
#suffix=
|
||||
csv_null="
|
||||
fi
|
||||
|
||||
if [ ! -f "$dbdir/my-${dbname}.cnf" ]; then
|
||||
|
@ -1051,7 +1077,10 @@ ADMINCONNECT=
|
|||
# paramètres de connexion pour les mises à jour utilisateur
|
||||
USERCONNECT=$dbname/password
|
||||
# logs des mises à jour
|
||||
SQLMIGLOG=\"/tmp/sqlmig-\${ORACLE_SID}-${dbname}.log\""
|
||||
SQLMIGLOG=\"/tmp/sqlmig-\${ORACLE_SID}-${dbname}.log\"
|
||||
# divers
|
||||
#SUFFIX=
|
||||
#CSV_NULL="
|
||||
fi
|
||||
|
||||
else
|
||||
|
@ -1239,7 +1268,7 @@ for dbdir in "${dbdirs[@]}"; do
|
|||
gsub(/'\''/, "'\'\\\\\'\''")
|
||||
print "table='\''" $0 "'\''"
|
||||
}' <<<"$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
|
||||
eend; eclearp
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue