diff --git a/mysqlloadcsv b/mysqlloadcsv index c8424e4..d567b9e 100755 --- a/mysqlloadcsv +++ b/mysqlloadcsv @@ -67,6 +67,9 @@ OPTIONS Nombre de lignes à sauter dans le fichier en entrée -n, --fake Ne pas effectuer l'opération. Afficher simplement la commande SQL. + --prefix PREFIX + Spécifier un ensemble de requêtes SQL à exécuter ou à afficher avant les + requêtes générées automatiquement. --run Forcer le lancement de l'opération. Utiliser cette option avec -A pour créer la table avec les paramètres analysés. @@ -206,6 +209,7 @@ profile= input= auto_db= skip_lines= +prefix= truncate= fake= method=load @@ -224,6 +228,7 @@ parse_opts "${PRETTYOPTS[@]}" \ -s:,--skip-lines: skip_lines= \ -n,--fake fake=1 \ --run fake= \ + --prefix: prefix= \ -T,--truncate truncate=1 \ -L,--load-data method=load \ -I,--insert-data method=insert \ @@ -328,7 +333,10 @@ if [ "$method" == load ]; then skip_lines=$(($skip_lines + 1)) loadcsv="load data local infile '$input' into table \`$table\` character set 'utf8' fields terminated by ',' optionally enclosed by '\\\"' escaped by '\\\\' lines terminated by '\\n' starting by '' ignore $skip_lines lines ($cfields);" mysqlargs=("${mysqlargs[@]}" - "$truncate$loadcsv" + "\ +$prefix +$truncate +$loadcsv" -- --local-infile=1 ) @@ -337,6 +345,7 @@ if [ "$method" == load ]; then r=0 if [ -n "$fake" ]; then echo "-- Requêtes SQL:" + [ -n "$prefix" ] && echo "$prefix" [ -n "$truncate" ] && echo "$truncate" echo "$loadcsv" echo "-- Commande à lancer pour importer la table dans MySQL:" @@ -349,6 +358,7 @@ if [ "$method" == load ]; then elif [ "$method" == insert ]; then ac_set_tmpfile inserts + [ -n "$prefix" ] && echo "$prefix" >>"$inserts" [ -n "$truncate" ] && echo "$truncate" >>"$inserts" awkcsv <"$input" >>"$inserts" -s "$skip_lines" -v table="$table" \ -v null_value="$null_value" -v types[@] -a "$__AWK_MYSQLFUNCS"'{ @@ -382,6 +392,7 @@ elif [ "$method" == update ]; then array_contains fields "$update_key" || die "$update_key: ce champ n'existe pas dans la source" ac_set_tmpfile updates + [ -n "$prefix" ] && echo "$prefix" >>"$updates" [ -n "$truncate" ] && echo "$truncate" >>"$updates" awkcsv <"$input" >>"$updates" -s "$skip_lines" \ -v table="$table" -v update_key="$update_key" \ @@ -416,7 +427,8 @@ END { elif [ "$method" == analyse ]; then ac_set_tmpfile create - awkcsv <"$input" >"$create" -s "$skip_lines" -v table="$table" \ + [ -n "$prefix" ] && echo "$prefix" >>"$create" + awkcsv <"$input" >>"$create" -s "$skip_lines" -v table="$table" \ -v null_value="$null_value" -v types[@] -a "$__AWK_MYSQLFUNCS"' function set_integer(i) { if (COL_TYPES[i] == "" || COL_TYPES[i] == "integer") {