Skip to content

Commit

Permalink
Revert "return finished strings from EscapeString"
Browse files Browse the repository at this point in the history
This reverts commit b0db34c.
  • Loading branch information
lampajr committed Feb 21, 2024
1 parent 9d467de commit 53bcfb3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ml_metadata/metadata_store/mysql_metadata_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ std::string MySqlMetadataSource::EscapeString(absl::string_view value) const {
CHECK(mysql_real_escape_string(db_, buffer, value.data(), value.length()) !=
-1UL)
<< "NO_BACKSLASH_ESCAPES SQL mode should not be enabled.";
std::string result = absl::StrCat("'", buffer, "'");
std::string result(buffer);
delete[] buffer;
return result;
}
Expand Down
6 changes: 5 additions & 1 deletion ml_metadata/metadata_store/postgresql_metadata_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,12 @@ std::string PostgreSQLMetadataSource::EscapeString(

char* escaped_str = PQescapeLiteral(conn_, value.data(), value.size());
std::string result{escaped_str};
// PQescapeLiteral will wrap the escaped string in '', which is redundant to
// the existing MLMD syntax. Therefore stripping the outer '' from the escaped
// string.
std::string substring = result.substr(1, std::strlen(result.data()) - 2);
PQfreemem(escaped_str);
return result;
return substring;
}

std::string PostgreSQLMetadataSource::EncodeBytes(
Expand Down
8 changes: 4 additions & 4 deletions ml_metadata/metadata_store/postgresql_query_executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,10 @@ absl::Status PostgreSQLQueryExecutor::DowngradeMetadataSource(
return absl::OkStatus();
}
std::string PostgreSQLQueryExecutor::Bind(const char* value) {
return metadata_source_->EscapeString(value);
return absl::StrCat("'", metadata_source_->EscapeString(value), "'");
}
std::string PostgreSQLQueryExecutor::Bind(absl::string_view value) {
return metadata_source_->EscapeString(value);
return absl::StrCat("'", metadata_source_->EscapeString(value), "'");
}
std::string PostgreSQLQueryExecutor::Bind(int value) {
return std::to_string(value);
Expand All @@ -390,10 +390,10 @@ std::string PostgreSQLQueryExecutor::Bind(double value) {
}
std::string PostgreSQLQueryExecutor::Bind(const google::protobuf::Any& value) {
return absl::StrCat(
"decode(",
"decode('",
metadata_source_->EscapeString(
metadata_source_->EncodeBytes(value.SerializeAsString())),
", 'base64')");
"', 'base64')");
}
std::string PostgreSQLQueryExecutor::Bind(bool value) {
return value ? "TRUE" : "FALSE";
Expand Down
4 changes: 2 additions & 2 deletions ml_metadata/metadata_store/query_config_executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,11 @@ absl::Status QueryConfigExecutor::DowngradeMetadataSource(
}

std::string QueryConfigExecutor::Bind(const char* value) {
return metadata_source_->EscapeString(value);
return absl::StrCat("'", metadata_source_->EscapeString(value), "'");
}

std::string QueryConfigExecutor::Bind(absl::string_view value) {
return metadata_source_->EscapeString(value);
return absl::StrCat("'", metadata_source_->EscapeString(value), "'");
}

std::string QueryConfigExecutor::Bind(int value) {
Expand Down

0 comments on commit 53bcfb3

Please sign in to comment.