trim white lines after PostgreSQL error message

This commit is contained in:
Tomasz Sowa 2022-05-24 20:06:06 +02:00
parent 56cbebad4f
commit 1ad4cb4fbd
2 changed files with 25 additions and 7 deletions

View File

@ -119,15 +119,15 @@ bool PostgreSQLConnector::do_query(const char * query_str, PostgreSQLQueryResult
if( err_msg )
{
pt::utf8_to_wide(err_msg, psql_result->error_msg);
prepare_error_msg(err_msg, psql_result->error_msg);
}
if( log )
{
(*log) << pt::Log::log1 << "Morm: Problem with this query: \"" << query_str << '\"' << pt::Log::logend;
if( err_msg )
(*log) << pt::Log::log1 << "Morm: " << err_msg << pt::Log::logend;
if( !psql_result->error_msg.empty() )
(*log) << pt::Log::log1 << "Morm: " << psql_result->error_msg << pt::Log::logend;
}
}
else
@ -180,8 +180,21 @@ const char * PostgreSQLConnector::query_last_sequence(const wchar_t * sequence_t
{
if( pg_conn && log )
{
(*log) << pt::Log::log1 << "Morm: error (currval) for table: " << sequence_table_name << ", "
<< PQerrorMessage(pg_conn) << pt::Log::logend;
const char * err_msg = PQerrorMessage(pg_conn);
if( err_msg )
{
prepare_error_msg(err_msg, psql_result.error_msg);
}
(*log) << pt::Log::log1 << "Morm: error (currval) for table: " << sequence_table_name;
if( !psql_result.error_msg.empty() )
{
(*log) << ", " << psql_result.error_msg;
}
(*log) << pt::Log::logend;
}
}
}
@ -289,8 +302,11 @@ bool PostgreSQLConnector::query_remove(const pt::TextStream & stream, QueryResul
}
void PostgreSQLConnector::prepare_error_msg(const char * msg_in, std::wstring & msg_out)
{
pt::utf8_to_wide(msg_in, msg_out);
pt::trim_last_white(msg_out, true, true);
}

View File

@ -158,6 +158,8 @@ protected:
void unescape_bin_string(const char * str, std::string & out);
void unescape_bin_string(const char * str, std::wstring & out);
void prepare_error_msg(const char * msg_in, std::wstring & msg_out);
};
}