Skip to content

Commit d5a303f

Browse files
committed
Merge branch 'lorenzhs-append-rows'
2 parents 649af5e + e13d688 commit d5a303f

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/importdata.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
341347
static 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

src/importdata.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ class ImportData
5555
//! allow empty tables and globs matching no files
5656
bool mopt_empty_okay;
5757

58+
//! append rows to table instead of clearing all data
59+
bool mopt_append_data;
60+
5861
//! table imported
5962
std::string m_tablename;
6063

0 commit comments

Comments
 (0)