LCOV - code coverage report
Current view: directory - ogr/ogrsf_frmts/pg - ogrpgutility.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 22 20 90.9 %
Date: 2012-04-28 Functions: 1 1 100.0 %

       1                 : /******************************************************************************
       2                 :  * $Id: ogrpgutility.cpp 22919 2011-08-10 18:12:05Z rouault $
       3                 :  *
       4                 :  * Project:  OpenGIS Simple Features Reference Implementation
       5                 :  * Purpose:  Utility methods
       6                 :  * Author:   Even Rouault, <even dot rouault at mines dash paris dot org>
       7                 :  *
       8                 :  ******************************************************************************
       9                 :  * Copyright (c) 2009, Even Rouault
      10                 :  *
      11                 :  * Permission is hereby granted, free of charge, to any person obtaining a
      12                 :  * copy of this software and associated documentation files (the "Software"),
      13                 :  * to deal in the Software without restriction, including without limitation
      14                 :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      15                 :  * and/or sell copies of the Software, and to permit persons to whom the
      16                 :  * Software is furnished to do so, subject to the following conditions:
      17                 :  *
      18                 :  * The above copyright notice and this permission notice shall be included
      19                 :  * in all copies or substantial portions of the Software.
      20                 :  *
      21                 :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      22                 :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      23                 :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      24                 :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      25                 :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      26                 :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      27                 :  * DEALINGS IN THE SOFTWARE.
      28                 :  ****************************************************************************/
      29                 : 
      30                 : #include "ogr_pg.h"
      31                 : #include "cpl_conv.h"
      32                 : 
      33                 : CPL_CVSID("$Id: ogrpgutility.cpp 22919 2011-08-10 18:12:05Z rouault $");
      34                 : 
      35                 : /************************************************************************/
      36                 : /*                         OGRPG_PQexec()                               */
      37                 : /************************************************************************/
      38                 : 
      39           24554 : PGresult *OGRPG_PQexec(PGconn *conn, const char *query, int bMultipleCommandAllowed)
      40                 : {
      41                 :     PGresult* hResult;
      42                 : #if defined(PG_PRE74)
      43                 :     /* PQexecParams introduced in PG >= 7.4 */
      44                 :     hResult = PQexec(conn, query);
      45                 : #else
      46           24554 :     if (bMultipleCommandAllowed)
      47             346 :         hResult = PQexec(conn, query);
      48                 :     else
      49           24208 :         hResult = PQexecParams(conn, query, 0, NULL, NULL, NULL, NULL, 0);
      50                 : #endif
      51                 : 
      52                 : #ifdef DEBUG
      53           24554 :     const char* pszRetCode = "UNKNOWN";
      54                 :     char szNTuples[32];
      55           24554 :     szNTuples[0] = '\0';
      56           24554 :     if (hResult)
      57                 :     {
      58           24554 :         switch(PQresultStatus(hResult))
      59                 :         {
      60                 :             case PGRES_TUPLES_OK:
      61           10524 :                 pszRetCode = "PGRES_TUPLES_OK";
      62           10524 :                 sprintf(szNTuples, ", ntuples = %d", PQntuples(hResult));
      63           10524 :                 break;
      64                 :             case PGRES_COMMAND_OK:
      65           13884 :                 pszRetCode = "PGRES_COMMAND_OK";
      66           13884 :                 break;
      67                 :             case PGRES_NONFATAL_ERROR:
      68               0 :                 pszRetCode = "PGRES_NONFATAL_ERROR";
      69               0 :                 break;
      70                 :             case PGRES_FATAL_ERROR:
      71             126 :                 pszRetCode = "PGRES_FATAL_ERROR";
      72                 :                 break;
      73                 :             default: break;
      74                 :         }
      75                 :     }
      76           24554 :     if (bMultipleCommandAllowed)
      77             346 :         CPLDebug("PG", "PQexec(%s) = %s%s", query, pszRetCode, szNTuples);
      78                 :     else
      79           24208 :         CPLDebug("PG", "PQexecParams(%s) = %s%s", query, pszRetCode, szNTuples);
      80                 : 
      81                 : /* -------------------------------------------------------------------- */
      82                 : /*      Generate an error report if an error occured.                   */
      83                 : /* -------------------------------------------------------------------- */
      84           24554 :     if ( !hResult || (PQresultStatus(hResult) == PGRES_NONFATAL_ERROR ||
      85                 :                       PQresultStatus(hResult) == PGRES_FATAL_ERROR ) )
      86                 :     {
      87             126 :         CPLDebug( "PG", "%s", PQerrorMessage( conn ) );
      88                 :     }
      89                 : #endif
      90                 : 
      91           24554 :     return hResult;
      92                 : }

Generated by: LCOV version 1.7