@@ -144,6 +144,11 @@ bool ImportData::create_table() const
144144{
145145 if (g_db->exist_table (m_tablename))
146146 {
147+ if (mopt_append_data)
148+ {
149+ OUT (" Table \" " << m_tablename << " \" exists. Appending data." );
150+ return true ;
151+ }
147152 OUT (" Table \" " << m_tablename << " \" exists. Replacing data." );
148153
149154 std::ostringstream cmd;
@@ -326,6 +331,7 @@ ImportData::ImportData(bool temporary_table)
326331 mopt_colnums(false ),
327332 mopt_temporary_table(temporary_table),
328333 mopt_empty_okay(false ),
334+ mopt_append_data(false ),
329335 m_total_count(0 )
330336{
331337}
@@ -335,7 +341,7 @@ enum { OPT_HELP, OPT_VERBOSE,
335341 OPT_FIRSTLINE, OPT_ALL_LINES, OPT_NO_DUPLICATE,
336342 OPT_COLUMN_NUMBERS, OPT_EMPTY_OKAY,
337343 OPT_TEMPORARY_TABLE, OPT_PERMANENT_TABLE,
338- OPT_DATABASE };
344+ OPT_DATABASE, OPT_APPEND_DATA };
339345
340346// ! define command line arguments
341347static CSimpleOpt::SOption sopt_list[] = {
@@ -350,6 +356,7 @@ static CSimpleOpt::SOption sopt_list[] = {
350356 { OPT_TEMPORARY_TABLE, " -T" , SO_NONE },
351357 { OPT_PERMANENT_TABLE, " -P" , SO_NONE },
352358 { OPT_DATABASE, " -D" , SO_REQ_SEP },
359+ { OPT_APPEND_DATA, " -A" , SO_NONE },
353360 SO_END_OF_OPTIONS
354361};
355362
@@ -366,6 +373,7 @@ int ImportData::print_usage(const std::string& progname)
366373 " -d Eliminate duplicate RESULT lines." << std::endl <<
367374 " -T Import into TEMPORARY table (for in-file processing)." << std::endl <<
368375 " -P Import into non-TEMPORARY table (reverts the default -T)." << std::endl <<
376+ " -A Append rows if the table already exists (schema must match)." << std::endl <<
369377 " -v Increase verbosity." << std::endl);
370378
371379 return EXIT_FAILURE;
@@ -429,6 +437,10 @@ int ImportData::main(int argc, char* argv[])
429437 case OPT_DATABASE:
430438 opt_db_conninfo = args.OptionArg ();
431439 break ;
440+
441+ case OPT_APPEND_DATA:
442+ mopt_append_data = true ;
443+ break ;
432444 }
433445 }
434446
0 commit comments