@@ -709,10 +709,22 @@ lease_upload() {
709
709
exit 1
710
710
fi
711
711
712
- # Invoke LFC on the input file.
713
- log_info " Looking at ${input_file_line_length} lines of CSV in ${input_file} ..."
712
+ if test " ${backend} " = ' mysql' ; then
713
+ function_call=" CALL lease${dhcp_version} "
714
+ elif test " ${backend} " = ' pgsql' ; then
715
+ function_call=" SELECT lease${dhcp_version} "
716
+ else
717
+ log_error " lease-upload not implemented for ${backend} "
718
+ exit 1
719
+ fi
720
+
714
721
cleaned_up_csv=" /tmp/$( basename " ${input_file} " ) .tmp"
715
722
check_file_overwrite " ${cleaned_up_csv} "
723
+ sql_statement_file=" /tmp/$( basename " ${input_file} " ) .sql.tmp"
724
+ check_file_overwrite " ${sql_statement_file} "
725
+
726
+ # Invoke LFC on the input file.
727
+ log_info " Looking at ${input_file_line_length} lines of CSV in ${input_file} ..."
716
728
cp " ${input_file} " " ${cleaned_up_csv} "
717
729
" ${KEA_LFC} " " -${dhcp_version} " -x " ${cleaned_up_csv} " \
718
730
-i " ${cleaned_up_csv} .1" -o " ${cleaned_up_csv} .output" \
@@ -738,37 +750,31 @@ lease_upload() {
738
750
739
751
# Construct the SQL insert statements.
740
752
header_parsed=false
741
- sql_statement= ' START TRANSACTION;'
753
+ echo ' START TRANSACTION;' > " ${sql_statement_file} "
742
754
while read -r line; do
743
- if " ${header_parsed} " ; then
744
- line=$( stringify_positions_in_line " ${string_positions} " " ${line} " )
745
- if test " ${backend} " = ' mysql' ; then
746
- sql_statement=" ${sql_statement} CALL lease${dhcp_version} Upload(${line} ); "
747
- elif test " ${backend} " = ' pgsql' ; then
748
- sql_statement=" ${sql_statement} SELECT lease${dhcp_version} Upload(${line} ); "
749
- else
750
- log_error " lease-upload not implemented for ${backend} "
751
- exit 1
752
- fi
753
- else
755
+ if ! " ${header_parsed} " ; then
754
756
header_parsed=true
757
+ continue
755
758
fi
759
+ line=$( stringify_positions_in_line " ${string_positions} " " ${line} " )
760
+ echo " ${function_call} Upload(${line} );" >> " ${sql_statement_file} "
756
761
done < " ${cleaned_up_csv} "
757
- sql_statement= " ${sql_statement} COMMIT; "
762
+ echo ' COMMIT; ' >> " ${sql_statement_file} "
758
763
759
764
# Execute the SQL insert statements.
760
765
if test " ${backend} " = ' mysql' ; then
761
- output=" $( mysql_execute " ${sql_statement } " ) "
766
+ output=" $( mysql_execute_script " ${sql_statement_file } " ) "
762
767
elif test " ${backend} " = ' pgsql' ; then
763
- output=" $( pgsql_execute " ${sql_statement } " ) "
768
+ output=" $( pgsql_execute_script " ${sql_statement_file } " ) "
764
769
else
765
770
log_error " lease-upload not implemented for ${backend} "
766
771
exit 1
767
772
fi
768
773
769
774
# Clean up the temporary CSV.
770
775
rm -f " ${cleaned_up_csv} "
771
- log_info " Removed temporary file ${cleaned_up_csv} ."
776
+ rm -f " ${sql_statement_file} "
777
+ log_info " Removed temporary files: ${cleaned_up_csv} , ${sql_statement_file} ."
772
778
773
779
# Print a confirmation message.
774
780
log_info " Successfully updated table lease${dhcp_version} ."
0 commit comments