Skip to content

Commit

Permalink
dbcopy: sort columns always in lower case
Browse files Browse the repository at this point in the history
- column names have to compared in lower case letters
- move ToLowerCase to util.cc
  • Loading branch information
franku committed Feb 27, 2020
1 parent 954f8ef commit 6766a68
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
5 changes: 4 additions & 1 deletion core/src/dird/dbcopy/database_column_descriptions.cc
Expand Up @@ -23,6 +23,7 @@
#include "include/make_unique.h"
#include "cats/cats.h"
#include "dird/dbcopy/database_column_descriptions.h"
#include "lib/util.h"

#include <algorithm>
#include <iostream>
Expand All @@ -43,7 +44,9 @@ void DatabaseColumnDescriptions::SelectColumnDescriptions(
std::sort(column_descriptions.begin(), column_descriptions.end(),
[](const std::unique_ptr<ColumnDescription>& v1,
const std::unique_ptr<ColumnDescription>& v2) {
return v1->column_name < v2->column_name;
std::string l1, l2;
ToLowerCase(v1->column_name, v2->column_name, l1, l2);
return l1 < l2;
});
}

Expand Down
12 changes: 1 addition & 11 deletions core/src/dird/dbcopy/database_table_descriptions.cc
Expand Up @@ -23,6 +23,7 @@
#include "database_table_descriptions.h"
#include "dird/dbcopy/database_column_descriptions.h"
#include "cats/cats.h"
#include "lib/util.h"

#include <algorithm>
#include <iostream>
Expand Down Expand Up @@ -88,17 +89,6 @@ DatabaseTablesMysql::DatabaseTablesMysql(BareosDb* db)
}
}

static void ToLowerCase(const std::string& i1,
const std::string& i2,
std::string& o1,
std::string& o2)
{
o1.clear();
o2.clear();
std::transform(i1.cbegin(), i1.cend(), std::back_inserter(o1), ::tolower);
std::transform(i2.cbegin(), i2.cend(), std::back_inserter(o2), ::tolower);
}

const DatabaseTableDescriptions::TableDescription*
DatabaseTableDescriptions::GetTableDescription(
const std::string& table_name) const
Expand Down
11 changes: 11 additions & 0 deletions core/src/lib/util.cc
Expand Up @@ -1110,3 +1110,14 @@ std::string getenv_std_string(std::string env_var)
const char* v = (std::getenv(env_var.c_str()));
return v ? std::string(v) : std::string();
}

void ToLowerCase(const std::string& i1,
const std::string& i2,
std::string& o1,
std::string& o2)
{
o1.clear();
o2.clear();
std::transform(i1.cbegin(), i1.cend(), std::back_inserter(o1), ::tolower);
std::transform(i2.cbegin(), i2.cend(), std::back_inserter(o2), ::tolower);
}
4 changes: 4 additions & 0 deletions core/src/lib/util.h
Expand Up @@ -68,5 +68,9 @@ void SetWorkingDirectory(const char* wd);
const char* last_path_separator(const char* str);
void SortCaseInsensitive(std::vector<std::string>& v);
std::string getenv_std_string(std::string env_var);
void ToLowerCase(const std::string& i1,
const std::string& i2,
std::string& o1,
std::string& o2);

#endif // BAREOS_LIB_UTIL_H_

0 comments on commit 6766a68

Please sign in to comment.