Ticket #661: 0001-ticket-661-fix-compilation-with-PG-9.patch

File 0001-ticket-661-fix-compilation-with-PG-9.patch, 4.5 KB (added by Dimitar Misev, 11 years ago)

patch

  • applications/rasgeo/RasdamanHelper2.cc

    From eff159c3b9a4ea250e20a413b5919efbea36be2e Mon Sep 17 00:00:00 2001
    From: Dimitar Misev <misev@rasdaman.com>
    Date: Fri, 21 Feb 2014 10:29:13 +0100
    Subject: [PATCH] ticket:661 - fix compilation with PG < 9
    
    ---
     applications/rasgeo/RasdamanHelper2.cc |   49 ++++++++++++++++++++++++++++----
     applications/rasgeo/RasdamanHelper2.hh |    7 +++++
     2 files changed, 51 insertions(+), 5 deletions(-)
    
    diff --git a/applications/rasgeo/RasdamanHelper2.cc b/applications/rasgeo/RasdamanHelper2.cc
    index 8ba0957..2ca2804 100644
    a b  
    4545#include "gdal_priv.h"
    4646#include "gdal_rat.h"
    4747
     48#include <pg_config.h>
     49#include <postgresql/libpq-fe.h>
     50
    4851// some string constants
    4952#define PSPREFIX "ps"
    5053#define crsURIprefix "%SECORE_URL%/crs/"
    RasdamanHelper2::writeExtraMetadata(long oid,  
    15771580        query.str("");
    15781581        PQclear(res);
    15791582
    1580         char* litstr = PQescapeLiteral(const_cast<PGconn*>(petaconn),
     1583        char* litstr = escapeLiteral(const_cast<PGconn*>(petaconn),
    15811584                values[k].c_str(), values[k].size());
    15821585
    15831586        // write the name of the table into the ps_extra_metadata table
    RasdamanHelper2::queryImageOIDs(const std::string& kvp)  
    17381741    query << "select distinct k0.oid from ";
    17391742    for (int k=0; k < availkeys.size(); ++k)
    17401743    {
    1741         char* key = PQescapeLiteral(conn, availkeys[k].c_str(), availkeys[k].size());
    1742         char* val = PQescapeLiteral(conn, availvals[k].c_str(), availvals[k].size());
     1744        char* key = escapeLiteral(conn, availkeys[k].c_str(), availkeys[k].size());
     1745        char* val = escapeLiteral(conn, availvals[k].c_str(), availvals[k].size());
    17431746
    17441747        if (k > 0)
    17451748        {
    RasdamanHelper2::writeRAT(const std::string& filename,  
    22612264    for (c=0; c < ncols; c++)
    22622265    {
    22632266        std::string gdalcolname = pRAT->GetNameOfCol(c);
    2264         char* colname = PQescapeIdentifier(const_cast<PGconn*>(conn),
     2267        char* colname = escapeIdentifier(const_cast<PGconn*>(conn),
    22652268                gdalcolname.c_str(), gdalcolname.size());
    22662269
    22672270        coltypes.push_back(pRAT->GetTypeOfCol(c));
    RasdamanHelper2::writeRAT(const std::string& filename,  
    23202323            case GFT_String:
    23212324                {
    23222325                    std::string valstr = pRAT->GetValueAsString(r,c);
    2323                     char* litstr = PQescapeLiteral(const_cast<PGconn*>(conn),
     2326                    char* litstr = escapeLiteral(const_cast<PGconn*>(conn),
    23242327                                valstr.c_str(), valstr.size());
    23252328                    query << litstr;
    23262329                    PQfreemem((void*)litstr);
    RasdamanHelper2::getDataTypeString(r_Type::r_Type_Id type)  
    36723675    }
    36733676    return stype;
    36743677}
     3678
     3679char*
     3680RasdamanHelper2::escapeLiteral(PGconn* conn, char* str, size_t strsize) throw (r_Error)
     3681{
     3682#if PG_VERSION_NUM >= 90000
     3683    return PQescapeLiteral(conn, str, strsize);
     3684#elif PG_VERSION_NUM >= 80000
     3685    char* to = (char*) malloc(strsize * 2 + 1);
     3686    if (to)
     3687    {
     3688        int error;
     3689        PQescapeStringConn(conn, to, str, strsize, &error);
     3690        if (error)
     3691        {
     3692            std::cerr << "RasdamanHelper2::escapeLiteral - failed escaping string." << std::endl;
     3693            throw r_Error(r_Error::r_Error_General);
     3694        }
     3695    }
     3696    else
     3697    {
     3698        std::cerr << "RasdamanHelper2::escapeLiteral - failed allocating memory." << std::endl;
     3699        throw r_Error(r_Error::r_Error_MemoryAllocation);
     3700    }
     3701    return to;
     3702#endif
     3703}
     3704
     3705char*
     3706RasdamanHelper2::escapeIdentifier(PGconn* conn, char* str, size_t strsize) throw (r_Error)
     3707{
     3708#if PG_VERSION_NUM >= 90000
     3709    return PQescapeIdentifier(conn, str, strsize);
     3710#elif PG_VERSION_NUM >= 80000
     3711    return escapeLiteral(conn, str, strsize);
     3712#endif
     3713}
     3714 No newline at end of file
  • applications/rasgeo/RasdamanHelper2.hh

    diff --git a/applications/rasgeo/RasdamanHelper2.hh b/applications/rasgeo/RasdamanHelper2.hh
    index 53cecb4..6698f34 100644
    a b protected:  
    445445    /* just to make PG-heavy code a little bit easier to read ...*/
    446446    bool PGDATAFAILED(std::string fun, std::string msg, PGresult* res);
    447447    bool PGFAILED(std::string fun, std::string msg, PGresult* res);
     448   
     449private:
     450    /// proxy to PQEscapeLiteral
     451    char* escapeLiteral(PGconn* conn, char* str, size_t strsize) throw (r_Error);
     452   
     453    /// proxy to PQEscapeIdentifier
     454    char* escapeIdentifier(PGconn* conn, char* str, size_t strsize) throw (r_Error);
    448455
    449456};
    450457