• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MerginMaps / geodiff / 20364107471

19 Dec 2025 08:18AM UTC coverage: 88.063% (+0.04%) from 88.019%
20364107471

push

github

wonder-sk
Improve Postgres constraint error handling

3 of 9 new or added lines in 3 files covered. (33.33%)

148 existing lines in 5 files now uncovered.

3637 of 4130 relevant lines covered (88.06%)

573.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

69.44
/geodiff/src/drivers/postgresutils.cpp
1
/*
2
 GEODIFF - MIT License
3
 Copyright (C) 2020 Martin Dobias
4
*/
5

6
#include "postgresutils.h"
7
#include "geodiff.h"
8
#include "geodiffutils.hpp"
9

10
GeoDiffPostgresException::GeoDiffPostgresException( PGresult *res, const std::string &sql )
1✔
11
  : GeoDiffPostgresException( PostgresResult( res ), sql ) {}
1✔
12

13
GeoDiffPostgresException::GeoDiffPostgresException( PostgresResult res, const std::string &sql )
1✔
14
  : GeoDiffException( "postgres cmd error(" + res.sqlState() +
2✔
15
                      "): " + res.statusErrorMessage() +
4✔
16
                      ( sql.size() ? "\n\nSQL:\n" + sql : "" ) ),
2✔
17
    mSql( sql ), mRes( std::move( res ) ) {}
3✔
18

19
const PostgresResult &GeoDiffPostgresException::result() const
1✔
20
{
21
  return mRes;
1✔
22
}
23

NEW
24
int GeoDiffPostgresException::errorCode() const
×
25
{
NEW
26
  if ( mRes.isIntegrityError() )
×
NEW
27
    return GEODIFF_CONFLICTS;
×
28
  else
NEW
29
    return GEODIFF_ERROR;
×
30
}
31

32
PostgresResult execSql( PGconn *c, const std::string &sql )
1,197✔
33
{
34
  PGresult *res = ::PQexec( c, sql.c_str() );
1,197✔
35

36
  if ( res && ::PQstatus( c ) == CONNECTION_OK )
1,197✔
37
  {
38
    int errorStatus = PQresultStatus( res );
1,197✔
39
    if ( errorStatus != PGRES_COMMAND_OK && errorStatus != PGRES_TUPLES_OK )
1,197✔
40
    {
41
      throw GeoDiffPostgresException( res, sql );
1✔
42
    }
43

44
    return PostgresResult( res );
1,196✔
45
  }
46
  if ( PQstatus( c ) != CONNECTION_OK )
×
47
  {
48
    if ( res )
×
49
      PQclear( res );
×
50
    throw GeoDiffException( "postgres conn error: " + std::string( PQerrorMessage( c ) ) );
×
51
  }
52
  else
53
  {
54
    throw GeoDiffException( "postgres error: out of memory" );
×
55
  }
56

57
  return PostgresResult( nullptr );
58
}
59

60
std::string quotedIdentifier( const std::string &ident )
1,990✔
61
{
62
  std::string result = replace( ident, "\"", "\"\"" );
5,970✔
63
  return "\"" + result + "\"";
3,980✔
64
}
1,990✔
65

66
std::string quotedString( const std::string &value )
935✔
67
{
68
  std::string result = replace( value, "'", "''" );
2,805✔
69
  if ( result.find( '\\' ) != std::string::npos )
935✔
70
  {
71
    result = replace( result, "\\", "\\\\" );
×
72
    return "E'" + result + "'";
×
73
  }
74
  else
75
    return "'" +  result + "'";
935✔
76
}
935✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc