Skip to content

Commit

Permalink
ClickHouse raw_errors fixes. (#42)
Browse files Browse the repository at this point in the history
* Fixed bug converting error message in flat error records to string suitable for inserting into a database.
  • Loading branch information
mfellows authored Jul 30, 2024
1 parent 84ed904 commit 09e2362
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Source/moja.modules.cbm/src/flatrecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ namespace cbm {
std::string valueStr = firstItem ? "" : ",";
firstItem = false;
if (!value.isNull()) {
valueStr += (boost::format("%1%%2%%3%") % quote % value % quote).str();
std::string currentValue = value;
if (!csvFormat) {
boost::replace_all(currentValue, "'", "''");
}

valueStr += (boost::format("%1%%2%%3%") % quote % currentValue % quote).str();
} else {
valueStr += "NULL";
}
Expand Down Expand Up @@ -281,10 +286,17 @@ namespace cbm {
static const std::string dbRecord = "%1%,%2%,'%3%','%4%',%5%";

auto classifierStr = FlatRecordHelper::BuildClassifierValueString(_classifierValues, csvFormat);
auto errorStr = _error;
std::string errorStr = _error;

boost::replace_all(errorStr, "\r", " ");
boost::replace_all(errorStr, "\n", " ");
boost::replace_all(errorStr, "\\", "\\\\");

if (csvFormat) {
boost::replace_all(errorStr, "\"", "'");
} else {
boost::replace_all(errorStr, "&", "\\&");
boost::replace_all(errorStr, "'", "\\'");
}

return (boost::format(csvFormat ? csvRecord : dbRecord)
Expand Down

0 comments on commit 09e2362

Please sign in to comment.