LCOV - differential code coverage report
Current view: top level - src/interfaces/ecpg/ecpglib - execute.c (source / functions) Coverage Total Hit UNC LBC UBC GNC CBC DUB DCB
Current: bed3ffbf9d952be6c7d739d068cdce44c046dfb7 vs 574581b50ac9c63dd9e4abebb731a3b67e5b50f6 Lines: 67.5 % 1132 764 9 1 358 24 740 3 22
Current Date: 2026-05-05 10:23:31 +0900 Functions: 91.7 % 24 22 2 8 14 2
Baseline: lcov-20260505-025707-baseline Branches: 61.1 % 736 450 9 4 273 9 441 6 6
Baseline Date: 2026-05-05 10:27:06 +0900 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(30,360] days: 72.7 % 33 24 9 24
(360..) days: 67.3 % 1099 740 1 358 740
Function coverage date bins:
(30,360] days: 100.0 % 2 2 2
(360..) days: 90.9 % 22 20 2 6 14
Branch coverage date bins:
(30,360] days: 50.0 % 18 9 9 9
(360..) days: 61.4 % 718 441 4 273 441

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /* src/interfaces/ecpg/ecpglib/execute.c */
                                  2                 :                : 
                                  3                 :                : /*
                                  4                 :                :  * The aim is to get a simpler interface to the database routines.
                                  5                 :                :  * All the tedious messing around with tuples is supposed to be hidden
                                  6                 :                :  * by this function.
                                  7                 :                :  */
                                  8                 :                : /* Author: Linus Tolke
                                  9                 :                :    (actually most if the code is "borrowed" from the distribution and just
                                 10                 :                :    slightly modified)
                                 11                 :                :  */
                                 12                 :                : 
                                 13                 :                : /* Taken over as part of PostgreSQL by Michael Meskes <meskes@postgresql.org>
                                 14                 :                :    on Feb. 5th, 1998 */
                                 15                 :                : 
                                 16                 :                : #define POSTGRES_ECPG_INTERNAL
                                 17                 :                : #include "postgres_fe.h"
                                 18                 :                : 
                                 19                 :                : #include <math.h>
                                 20                 :                : 
                                 21                 :                : #include "catalog/pg_type_d.h"
                                 22                 :                : #include "ecpgerrno.h"
                                 23                 :                : #include "ecpglib.h"
                                 24                 :                : #include "ecpglib_extern.h"
                                 25                 :                : #include "ecpgtype.h"
                                 26                 :                : #include "pgtypes_date.h"
                                 27                 :                : #include "pgtypes_interval.h"
                                 28                 :                : #include "pgtypes_numeric.h"
                                 29                 :                : #include "pgtypes_timestamp.h"
                                 30                 :                : #include "sql3types.h"
                                 31                 :                : #include "sqlca.h"
                                 32                 :                : #include "sqlda-compat.h"
                                 33                 :                : #include "sqlda-native.h"
                                 34                 :                : 
                                 35                 :                : /*
                                 36                 :                :  *  This function returns a newly malloced string that has ' and \
                                 37                 :                :  *  escaped.
                                 38                 :                :  */
                                 39                 :                : static char *
 7195 meskes@postgresql.or       40                 :CBC         570 : quote_postgres(char *arg, bool quote, int lineno)
                                 41                 :                : {
                                 42                 :                :     char       *res;
                                 43                 :                :     size_t      length;
                                 44                 :                :     size_t      escaped_len;
                                 45                 :                :     size_t      buffer_len;
                                 46                 :                : 
                                 47                 :                :     /*
                                 48                 :                :      * if quote is false we just need to store things in a descriptor they
                                 49                 :                :      * will be quoted once they are inserted in a statement
                                 50                 :                :      */
                                 51         [ +  - ]:            570 :     if (!quote)
 6903                            52                 :            570 :         return arg;
                                 53                 :                :     else
                                 54                 :                :     {
 7023 meskes@postgresql.or       55                 :UBC           0 :         length = strlen(arg);
                                 56                 :              0 :         buffer_len = 2 * length + 1;
  154 peter@eisentraut.org       57                 :UNC           0 :         res = ecpg_alloc(buffer_len + 3, lineno);
 7195 meskes@postgresql.or       58         [ #  # ]:UBC           0 :         if (!res)
 3183 peter_e@gmx.net            59                 :              0 :             return res;
 6746 bruce@momjian.us           60                 :              0 :         escaped_len = PQescapeString(res + 1, arg, buffer_len);
 7023 meskes@postgresql.or       61         [ #  # ]:              0 :         if (length == escaped_len)
                                 62                 :                :         {
 6746 bruce@momjian.us           63                 :              0 :             res[0] = res[escaped_len + 1] = '\'';
                                 64                 :              0 :             res[escaped_len + 2] = '\0';
                                 65                 :                :         }
                                 66                 :                :         else
                                 67                 :                :         {
                                 68                 :                :             /*
                                 69                 :                :              * We don't know if the target database is using
                                 70                 :                :              * standard_conforming_strings, so we always use E'' strings.
                                 71                 :                :              */
                                 72                 :              0 :             memmove(res + 2, res + 1, escaped_len);
 7023 meskes@postgresql.or       73                 :              0 :             res[0] = ESCAPE_STRING_SYNTAX;
 6746 bruce@momjian.us           74                 :              0 :             res[1] = res[escaped_len + 2] = '\'';
                                 75                 :              0 :             res[escaped_len + 3] = '\0';
                                 76                 :                :         }
 6789 meskes@postgresql.or       77                 :              0 :         ecpg_free(arg);
 7195                            78                 :              0 :         return res;
                                 79                 :                :     }
                                 80                 :                : }
                                 81                 :                : 
                                 82                 :                : static void
 3240 tgl@sss.pgh.pa.us          83                 :CBC        5350 : free_variable(struct variable *var)
                                 84                 :                : {
                                 85                 :                :     struct variable *var_next;
                                 86                 :                : 
 4543 meskes@postgresql.or       87         [ +  + ]:           8507 :     while (var)
                                 88                 :                :     {
 8451                            89                 :           3157 :         var_next = var->next;
 6789                            90                 :           3157 :         ecpg_free(var);
 4543                            91                 :           3157 :         var = var_next;
                                 92                 :                :     }
 8451                            93                 :           5350 : }
                                 94                 :                : 
                                 95                 :                : static void
 3240 tgl@sss.pgh.pa.us          96                 :           2675 : free_statement(struct statement *stmt)
                                 97                 :                : {
 8154 neilc@samurai.com          98         [ -  + ]:           2675 :     if (stmt == NULL)
 8451 meskes@postgresql.or       99                 :UBC           0 :         return;
 8451 meskes@postgresql.or      100                 :CBC        2675 :     free_variable(stmt->inlist);
                                101                 :           2675 :     free_variable(stmt->outlist);
 6789                           102                 :           2675 :     ecpg_free(stmt->command);
                                103                 :           2675 :     ecpg_free(stmt->name);
                                104                 :                : #ifndef HAVE_USELOCALE
                                105                 :                :     ecpg_free(stmt->oldlocale);
                                106                 :                : #endif
                                107                 :           2675 :     ecpg_free(stmt);
                                108                 :                : }
                                109                 :                : 
                                110                 :                : static int
 3113                           111                 :           4511 : next_insert(char *text, int pos, bool questionmarks, bool std_strings)
                                112                 :                : {
 8451                           113                 :           4511 :     bool        string = false;
 6746 bruce@momjian.us          114                 :           4511 :     int         p = pos;
                                115                 :                : 
 6839 meskes@postgresql.or      116         [ +  + ]:         121703 :     for (; text[p] != '\0'; p++)
                                117                 :                :     {
 3113                           118   [ +  +  -  +  :         119033 :         if (string && !std_strings && text[p] == '\\')  /* escape character */
                                              -  - ]
 6839 meskes@postgresql.or      119                 :LBC         (4) :             p++;
 6839 meskes@postgresql.or      120         [ +  + ]:CBC      119033 :         else if (text[p] == '\'')
 8451                           121                 :           1972 :             string = string ? false : true;
 6839                           122         [ +  + ]:         117061 :         else if (!string)
                                123                 :                :         {
 6639 tgl@sss.pgh.pa.us         124   [ +  +  +  + ]:         109534 :             if (text[p] == '$' && isdigit((unsigned char) text[p + 1]))
 6839 meskes@postgresql.or      125                 :UBC           0 :             {
                                126                 :                :                 /* this can be either a dollar quote or a variable */
                                127                 :                :                 int         i;
                                128                 :                : 
 6639 tgl@sss.pgh.pa.us         129         [ +  + ]:CBC        3683 :                 for (i = p + 1; isdigit((unsigned char) text[i]); i++)
                                130                 :                :                      /* empty loop body */ ;
                                131         [ +  - ]:           1841 :                 if (!isalpha((unsigned char) text[i]) &&
 2180                           132   [ +  -  +  - ]:           1841 :                     isascii((unsigned char) text[i]) && text[i] != '_')
                                133                 :                :                     /* not dollar delimited quote */
 6839 meskes@postgresql.or      134                 :           1841 :                     return p;
                                135                 :                :             }
 6746 bruce@momjian.us          136   [ +  +  -  + ]:         107693 :             else if (questionmarks && text[p] == '?')
                                137                 :                :             {
                                138                 :                :                 /* also allow old style placeholders */
 6839 meskes@postgresql.or      139                 :UBC           0 :                 return p;
                                140                 :                :             }
                                141                 :                :         }
                                142                 :                :     }
                                143                 :                : 
 6839 meskes@postgresql.or      144                 :CBC        2670 :     return -1;
                                145                 :                : }
                                146                 :                : 
                                147                 :                : static bool
   51 tgl@sss.pgh.pa.us         148                 :GNC        2581 : ecpg_type_infocache_push(struct ECPGtype_information_cache **cache, Oid oid, enum ARRAY_TYPE isarray, int lineno)
                                149                 :                : {
                                150                 :                :     struct ECPGtype_information_cache *new_entry
 6789 meskes@postgresql.or      151                 :CBC        2581 :     = (struct ECPGtype_information_cache *) ecpg_alloc(sizeof(struct ECPGtype_information_cache), lineno);
                                152                 :                : 
 7258                           153         [ -  + ]:           2581 :     if (new_entry == NULL)
 3183 peter_e@gmx.net           154                 :UBC           0 :         return false;
                                155                 :                : 
 8212 meskes@postgresql.or      156                 :CBC        2581 :     new_entry->oid = oid;
                                157                 :           2581 :     new_entry->isarray = isarray;
                                158                 :           2581 :     new_entry->next = *cache;
                                159                 :           2581 :     *cache = new_entry;
 3183 peter_e@gmx.net           160                 :           2581 :     return true;
                                161                 :                : }
                                162                 :                : 
                                163                 :                : static enum ARRAY_TYPE
   51 tgl@sss.pgh.pa.us         164                 :GNC        1261 : ecpg_is_type_an_array(Oid type, const struct statement *stmt, const struct variable *var)
                                165                 :                : {
                                166                 :                :     char       *array_query;
 7919 bruce@momjian.us          167                 :CBC        1261 :     enum ARRAY_TYPE isarray = ECPG_ARRAY_NOT_SET;
                                168                 :                :     PGresult   *query;
                                169                 :                :     struct ECPGtype_information_cache *cache_entry;
                                170                 :                : 
 8451 meskes@postgresql.or      171         [ +  + ]:           1261 :     if ((stmt->connection->cache_head) == NULL)
                                172                 :                :     {
                                173                 :                :         /*
                                174                 :                :          * Text like types are not an array for ecpg, but postgres counts them
                                175                 :                :          * as an array. This define reminds you to not 'correct' these values.
                                176                 :                :          */
                                177                 :                : #define not_an_array_in_ecpg ECPG_ARRAY_NONE
                                178                 :                : 
                                179                 :                :         /* populate cache with well known types to speed things up */
 6789                           180         [ -  + ]:             66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), BOOLOID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           181                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      182         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), BYTEAOID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           183                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      184         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), CHAROID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           185                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      186         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), NAMEOID, not_an_array_in_ecpg, stmt->lineno))
 3183 peter_e@gmx.net           187                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      188         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), INT8OID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           189                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      190         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), INT2OID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           191                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      192         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), INT2VECTOROID, ECPG_ARRAY_VECTOR, stmt->lineno))
 3183 peter_e@gmx.net           193                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      194         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), INT4OID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           195                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      196         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), REGPROCOID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           197                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      198         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), TEXTOID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           199                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      200         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), OIDOID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           201                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      202         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), TIDOID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           203                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      204         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), XIDOID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           205                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      206         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), CIDOID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           207                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      208         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), OIDVECTOROID, ECPG_ARRAY_VECTOR, stmt->lineno))
 3183 peter_e@gmx.net           209                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      210         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), POINTOID, ECPG_ARRAY_VECTOR, stmt->lineno))
 3183 peter_e@gmx.net           211                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      212         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), LSEGOID, ECPG_ARRAY_VECTOR, stmt->lineno))
 3183 peter_e@gmx.net           213                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      214         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), PATHOID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           215                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      216         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), BOXOID, ECPG_ARRAY_VECTOR, stmt->lineno))
 3183 peter_e@gmx.net           217                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      218         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), POLYGONOID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           219                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      220         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), LINEOID, ECPG_ARRAY_VECTOR, stmt->lineno))
 3183 peter_e@gmx.net           221                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      222         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), FLOAT4OID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           223                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      224         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), FLOAT8OID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           225                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      226         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), UNKNOWNOID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           227                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      228         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), CIRCLEOID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           229                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 2014 tgl@sss.pgh.pa.us         230         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), MONEYOID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           231                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      232         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), INETOID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           233                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      234         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), CIDROID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           235                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      236         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), BPCHAROID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           237                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      238         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), VARCHAROID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           239                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      240         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), DATEOID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           241                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      242         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), TIMEOID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           243                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      244         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), TIMESTAMPOID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           245                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      246         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), TIMESTAMPTZOID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           247                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      248         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), INTERVALOID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           249                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      250         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), TIMETZOID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           251                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 2985 tgl@sss.pgh.pa.us         252         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), BITOID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           253                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      254         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), VARBITOID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           255                 :UBC           0 :             return ECPG_ARRAY_ERROR;
 6789 meskes@postgresql.or      256         [ -  + ]:CBC          66 :         if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), NUMERICOID, ECPG_ARRAY_NONE, stmt->lineno))
 3183 peter_e@gmx.net           257                 :UBC           0 :             return ECPG_ARRAY_ERROR;
                                258                 :                :     }
                                259                 :                : 
 8212 meskes@postgresql.or      260         [ +  + ]:CBC       40061 :     for (cache_entry = (stmt->connection->cache_head); cache_entry != NULL; cache_entry = cache_entry->next)
                                261                 :                :     {
                                262         [ +  + ]:          40054 :         if (cache_entry->oid == type)
                                263                 :           1254 :             return cache_entry->isarray;
                                264                 :                :     }
                                265                 :                : 
  154 peter@eisentraut.org      266                 :GNC           7 :     array_query = ecpg_alloc(strlen("select typlen from pg_type where oid= and typelem<>0") + 11, stmt->lineno);
 7258 meskes@postgresql.or      267         [ -  + ]:CBC           7 :     if (array_query == NULL)
 3183 peter_e@gmx.net           268                 :UBC           0 :         return ECPG_ARRAY_ERROR;
                                269                 :                : 
   51 tgl@sss.pgh.pa.us         270                 :GNC           7 :     sprintf(array_query, "select typlen from pg_type where oid=%u and typelem<>0", type);
 8212 meskes@postgresql.or      271                 :CBC           7 :     query = PQexec(stmt->connection->connection, array_query);
 6789                           272                 :              7 :     ecpg_free(array_query);
                                273         [ -  + ]:              7 :     if (!ecpg_check_PQresult(query, stmt->lineno, stmt->connection->connection, stmt->compat))
 3183 peter_e@gmx.net           274                 :UBC           0 :         return ECPG_ARRAY_ERROR;
 6839 meskes@postgresql.or      275         [ +  - ]:CBC           7 :     else if (PQresultStatus(query) == PGRES_TUPLES_OK)
                                276                 :                :     {
 7919 bruce@momjian.us          277         [ +  + ]:              7 :         if (PQntuples(query) == 0)
 8212 meskes@postgresql.or      278                 :              2 :             isarray = ECPG_ARRAY_NONE;
                                279                 :                :         else
                                280                 :                :         {
  439 peter@eisentraut.org      281         [ +  - ]:              5 :             isarray = (atoi(PQgetvalue(query, 0, 0)) == -1) ? ECPG_ARRAY_ARRAY : ECPG_ARRAY_VECTOR;
 6789 meskes@postgresql.or      282   [ +  -  -  + ]:             10 :             if (ecpg_dynamic_type(type) == SQL3_CHARACTER ||
                                283                 :              5 :                 ecpg_dynamic_type(type) == SQL3_CHARACTER_VARYING)
                                284                 :                :             {
                                285                 :                :                 /*
                                286                 :                :                  * arrays of character strings are not yet implemented
                                287                 :                :                  */
 8189 meskes@postgresql.or      288                 :UBC           0 :                 isarray = ECPG_ARRAY_NONE;
                                289                 :                :             }
                                290                 :                :         }
 6839 meskes@postgresql.or      291                 :CBC           7 :         PQclear(query);
                                292                 :                :     }
                                293                 :                :     else
 3183 peter_e@gmx.net           294                 :UBC           0 :         return ECPG_ARRAY_ERROR;
                                295                 :                : 
 6789 meskes@postgresql.or      296                 :CBC           7 :     ecpg_type_infocache_push(&(stmt->connection->cache_head), type, isarray, stmt->lineno);
   51 tgl@sss.pgh.pa.us         297         [ +  + ]:GNC           9 :     ecpg_log("ecpg_is_type_an_array on line %d: type (%u); C (%d); array (%s)\n",
                                298         [ -  + ]:              9 :              stmt->lineno, type, var->type, ECPG_IS_ARRAY(isarray) ? "yes" : "no");
 8451 meskes@postgresql.or      299                 :CBC           7 :     return isarray;
                                300                 :                : }
                                301                 :                : 
                                302                 :                : 
                                303                 :                : bool
 6789                           304                 :           1261 : ecpg_store_result(const PGresult *results, int act_field,
                                305                 :                :                   const struct statement *stmt, struct variable *var)
                                306                 :                : {
                                307                 :                :     enum ARRAY_TYPE isarray;
                                308                 :                :     int         act_tuple,
 8451                           309                 :           1261 :                 ntuples = PQntuples(results);
                                310                 :           1261 :     bool        status = true;
                                311                 :                : 
 6789                           312         [ -  + ]:           1261 :     if ((isarray = ecpg_is_type_an_array(PQftype(results, act_field), stmt, var)) == ECPG_ARRAY_ERROR)
                                313                 :                :     {
 6789 meskes@postgresql.or      314                 :UBC           0 :         ecpg_raise(stmt->lineno, ECPG_OUT_OF_MEMORY, ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, NULL);
 7258                           315                 :              0 :         return false;
                                316                 :                :     }
                                317                 :                : 
 8214 meskes@postgresql.or      318         [ +  + ]:CBC        1261 :     if (isarray == ECPG_ARRAY_NONE)
                                319                 :                :     {
                                320                 :                :         /*
                                321                 :                :          * if we don't have enough space, we cannot read all tuples
                                322                 :                :          */
 8451                           323   [ +  +  +  -  :           1255 :         if ((var->arrsize > 0 && ntuples > var->arrsize) || (var->ind_arrsize > 0 && ntuples > var->ind_arrsize))
                                        +  +  -  + ]
                                324                 :                :         {
 5351 peter_e@gmx.net           325                 :UBC           0 :             ecpg_log("ecpg_store_result on line %d: incorrect number of matches; %d don't fit into array of %ld\n",
 6746 bruce@momjian.us          326                 :              0 :                      stmt->lineno, ntuples, var->arrsize);
 6789 meskes@postgresql.or      327   [ #  #  #  # ]:              0 :             ecpg_raise(stmt->lineno, INFORMIX_MODE(stmt->compat) ? ECPG_INFORMIX_SUBSELECT_NOT_ONE : ECPG_TOO_MANY_MATCHES, ECPG_SQLSTATE_CARDINALITY_VIOLATION, NULL);
 8451                           328                 :              0 :             return false;
                                329                 :                :         }
                                330                 :                :     }
                                331                 :                :     else
                                332                 :                :     {
                                333                 :                :         /*
                                334                 :                :          * since we read an array, the variable has to be an array too
                                335                 :                :          */
 8451 meskes@postgresql.or      336         [ -  + ]:CBC           6 :         if (var->arrsize == 0)
                                337                 :                :         {
 6789 meskes@postgresql.or      338                 :UBC           0 :             ecpg_raise(stmt->lineno, ECPG_NO_ARRAY, ECPG_SQLSTATE_DATATYPE_MISMATCH, NULL);
 8451                           339                 :              0 :             return false;
                                340                 :                :         }
                                341                 :                :     }
                                342                 :                : 
                                343                 :                :     /*
                                344                 :                :      * allocate memory for NULL pointers
                                345                 :                :      */
 8451 meskes@postgresql.or      346   [ +  +  +  +  :CBC        1261 :     if ((var->arrsize == 0 || var->varcharsize == 0) && var->value == NULL)
                                              +  + ]
                                347                 :                :     {
                                348                 :            826 :         int         len = 0;
                                349                 :                : 
 6172 bruce@momjian.us          350         [ +  + ]:            826 :         if (!PQfformat(results, act_field))
                                351                 :                :         {
 6301 meskes@postgresql.or      352      [ +  -  + ]:            825 :             switch (var->type)
                                353                 :                :             {
                                354                 :            821 :                 case ECPGt_char:
                                355                 :                :                 case ECPGt_unsigned_char:
                                356                 :                :                 case ECPGt_string:
                                357   [ +  -  +  + ]:            821 :                     if (!var->varcharsize && !var->arrsize)
                                358                 :                :                     {
                                359                 :                :                         /* special mode for handling char**foo=0 */
                                360         [ +  + ]:           1625 :                         for (act_tuple = 0; act_tuple < ntuples; act_tuple++)
                                361                 :            818 :                             len += strlen(PQgetvalue(results, act_tuple, act_field)) + 1;
 3240 tgl@sss.pgh.pa.us         362                 :            807 :                         len *= var->offset; /* should be 1, but YMNK */
 6301 meskes@postgresql.or      363                 :            807 :                         len += (ntuples + 1) * sizeof(char *);
                                364                 :                :                     }
                                365                 :                :                     else
                                366                 :                :                     {
                                367                 :             14 :                         var->varcharsize = 0;
                                368                 :                :                         /* check strlen for each tuple */
                                369         [ +  + ]:             28 :                         for (act_tuple = 0; act_tuple < ntuples; act_tuple++)
                                370                 :                :                         {
 1308 drowley@postgresql.o      371                 :             14 :                             int         slen = strlen(PQgetvalue(results, act_tuple, act_field)) + 1;
                                372                 :                : 
                                373         [ +  - ]:             14 :                             if (slen > var->varcharsize)
                                374                 :             14 :                                 var->varcharsize = slen;
                                375                 :                :                         }
 6301 meskes@postgresql.or      376                 :             14 :                         var->offset *= var->varcharsize;
                                377                 :             14 :                         len = var->offset * ntuples;
                                378                 :                :                     }
                                379                 :            821 :                     break;
 6301 meskes@postgresql.or      380                 :UBC           0 :                 case ECPGt_varchar:
                                381                 :              0 :                     len = ntuples * (var->varcharsize + sizeof(int));
                                382                 :              0 :                     break;
 6301 meskes@postgresql.or      383                 :CBC           4 :                 default:
 8451                           384                 :              4 :                     len = var->offset * ntuples;
 6301                           385                 :              4 :                     break;
                                386                 :                :             }
                                387                 :                :         }
                                388                 :                :         else
                                389                 :                :         {
 6300                           390         [ +  + ]:              2 :             for (act_tuple = 0; act_tuple < ntuples; act_tuple++)
                                391                 :              1 :                 len += PQgetlength(results, act_tuple, act_field);
                                392                 :                :         }
                                393                 :                : 
 6563 peter_e@gmx.net           394                 :            826 :         ecpg_log("ecpg_store_result on line %d: allocating memory for %d tuples\n", stmt->lineno, ntuples);
  154 peter@eisentraut.org      395                 :GNC         826 :         var->value = ecpg_auto_alloc(len, stmt->lineno);
 7258 meskes@postgresql.or      396         [ -  + ]:CBC         826 :         if (!var->value)
 7258 meskes@postgresql.or      397                 :UBC           0 :             return false;
 8451 meskes@postgresql.or      398                 :CBC         826 :         *((char **) var->pointer) = var->value;
                                399                 :                :     }
                                400                 :                : 
                                401                 :                :     /* allocate indicator variable if needed */
                                402   [ +  +  -  +  :           1261 :     if ((var->ind_arrsize == 0 || var->ind_varcharsize == 0) && var->ind_value == NULL && var->ind_pointer != NULL)
                                        +  +  +  + ]
                                403                 :                :     {
                                404                 :             10 :         int         len = var->ind_offset * ntuples;
                                405                 :                : 
  154 peter@eisentraut.org      406                 :GNC          10 :         var->ind_value = ecpg_auto_alloc(len, stmt->lineno);
 7258 meskes@postgresql.or      407         [ -  + ]:CBC          10 :         if (!var->ind_value)
 7258 meskes@postgresql.or      408                 :UBC           0 :             return false;
 8451 meskes@postgresql.or      409                 :CBC          10 :         *((char **) var->ind_pointer) = var->ind_value;
                                410                 :                :     }
                                411                 :                : 
                                412                 :                :     /* fill the variable with the tuple(s) */
                                413   [ +  +  +  + ]:           1261 :     if (!var->varcharsize && !var->arrsize &&
 6115                           414   [ -  +  -  -  :            807 :         (var->type == ECPGt_char || var->type == ECPGt_unsigned_char || var->type == ECPGt_string))
                                              -  - ]
 8451                           415                 :            807 :     {
                                416                 :                :         /* special mode for handling char**foo=0 */
                                417                 :                : 
                                418                 :                :         /* filling the array of (char*)s */
                                419                 :            807 :         char      **current_string = (char **) var->value;
                                420                 :                : 
                                421                 :                :         /* storing the data (after the last array element) */
                                422                 :            807 :         char       *current_data_location = (char *) &current_string[ntuples + 1];
                                423                 :                : 
                                424   [ +  +  +  - ]:           1625 :         for (act_tuple = 0; act_tuple < ntuples && status; act_tuple++)
                                425                 :                :         {
                                426                 :            818 :             int         len = strlen(PQgetvalue(results, act_tuple, act_field)) + 1;
                                427                 :                : 
 6789                           428         [ -  + ]:            818 :             if (!ecpg_get_data(results, act_tuple, act_field, stmt->lineno,
                                429                 :                :                                var->type, var->ind_type, current_data_location,
 6746 bruce@momjian.us          430                 :            818 :                                var->ind_value, len, 0, var->ind_offset, isarray, stmt->compat, stmt->force_indicator))
 8451 meskes@postgresql.or      431                 :UBC           0 :                 status = false;
                                432                 :                :             else
                                433                 :                :             {
 8451 meskes@postgresql.or      434                 :CBC         818 :                 *current_string = current_data_location;
                                435                 :            818 :                 current_data_location += len;
                                436                 :            818 :                 current_string++;
                                437                 :                :             }
                                438                 :                :         }
                                439                 :                : 
                                440                 :                :         /* terminate the list */
                                441                 :            807 :         *current_string = NULL;
                                442                 :                :     }
                                443                 :                :     else
                                444                 :                :     {
                                445   [ +  +  +  - ]:            992 :         for (act_tuple = 0; act_tuple < ntuples && status; act_tuple++)
                                446                 :                :         {
 6789                           447         [ +  + ]:            538 :             if (!ecpg_get_data(results, act_tuple, act_field, stmt->lineno,
 6746 bruce@momjian.us          448                 :            538 :                                var->type, var->ind_type, var->value,
                                449                 :            538 :                                var->ind_value, var->varcharsize, var->offset, var->ind_offset, isarray, stmt->compat, stmt->force_indicator))
 8451 meskes@postgresql.or      450                 :              6 :                 status = false;
                                451                 :                :         }
                                452                 :                :     }
                                453                 :           1261 :     return status;
                                454                 :                : }
                                455                 :                : 
                                456                 :                : static void
 5936                           457                 :              6 : sprintf_double_value(char *ptr, double value, const char *delim)
                                458                 :                : {
 5922                           459         [ +  + ]:              6 :     if (isnan(value))
                                460                 :              1 :         sprintf(ptr, "%s%s", "NaN", delim);
                                461         [ +  + ]:              5 :     else if (isinf(value))
                                462                 :                :     {
 5936                           463         [ +  + ]:              2 :         if (value < 0)
                                464                 :              1 :             sprintf(ptr, "%s%s", "-Infinity", delim);
                                465                 :                :         else
                                466                 :              1 :             sprintf(ptr, "%s%s", "Infinity", delim);
                                467                 :                :     }
                                468                 :                :     else
 5405                           469                 :              3 :         sprintf(ptr, "%.15g%s", value, delim);
 5936                           470                 :              6 : }
                                471                 :                : 
                                472                 :                : static void
                                473                 :              1 : sprintf_float_value(char *ptr, float value, const char *delim)
                                474                 :                : {
 5922                           475         [ -  + ]:              1 :     if (isnan(value))
 5922 meskes@postgresql.or      476                 :UBC           0 :         sprintf(ptr, "%s%s", "NaN", delim);
 5922 meskes@postgresql.or      477         [ -  + ]:CBC           1 :     else if (isinf(value))
                                478                 :                :     {
 5936 meskes@postgresql.or      479         [ #  # ]:UBC           0 :         if (value < 0)
                                480                 :              0 :             sprintf(ptr, "%s%s", "-Infinity", delim);
                                481                 :                :         else
                                482                 :              0 :             sprintf(ptr, "%s%s", "Infinity", delim);
                                483                 :                :     }
                                484                 :                :     else
 5405 meskes@postgresql.or      485                 :CBC           1 :         sprintf(ptr, "%.15g%s", value, delim);
 5936                           486                 :              1 : }
                                487                 :                : 
                                488                 :                : static char *
 2540 meskes@postgresql.or      489                 :UBC           0 : convert_bytea_to_string(char *from_data, int from_len, int lineno)
                                490                 :                : {
                                491                 :                :     char       *to_data;
      tgl@sss.pgh.pa.us         492                 :              0 :     int         to_len = ecpg_hex_enc_len(from_len) + 4 + 1;    /* backslash + 'x' +
                                493                 :                :                                                                  * quote + quote */
                                494                 :                : 
      meskes@postgresql.or      495                 :              0 :     to_data = ecpg_alloc(to_len, lineno);
                                496         [ #  # ]:              0 :     if (!to_data)
                                497                 :              0 :         return NULL;
                                498                 :                : 
                                499                 :              0 :     strcpy(to_data, "'\\x");
                                500                 :              0 :     ecpg_hex_encode(from_data, from_len, to_data + 3);
                                501                 :              0 :     strcpy(to_data + 3 + ecpg_hex_enc_len(from_len), "\'");
                                502                 :                : 
                                503                 :              0 :     return to_data;
                                504                 :                : }
                                505                 :                : 
                                506                 :                : bool
 3240 tgl@sss.pgh.pa.us         507                 :CBC        1852 : ecpg_store_input(const int lineno, const bool force_indicator, const struct variable *var,
                                508                 :                :                  char **tobeinserted_p, bool quote)
                                509                 :                : {
 8451 meskes@postgresql.or      510                 :           1852 :     char       *mallocedval = NULL;
                                511                 :           1852 :     char       *newcopy = NULL;
                                512                 :                : 
                                513                 :                :     /*
                                514                 :                :      * arrays are not possible unless the column is an array, too FIXME: we do
                                515                 :                :      * not know if the column is an array here array input to singleton column
                                516                 :                :      * will result in a runtime error
                                517                 :                :      */
                                518                 :                : 
                                519                 :                :     /*
                                520                 :                :      * Some special treatment is needed for records since we want their
                                521                 :                :      * contents to arrive in a comma-separated list on insert (I think).
                                522                 :                :      */
                                523                 :                : 
                                524                 :           1852 :     *tobeinserted_p = "";
                                525                 :                : 
                                526                 :                :     /* check for null value and set input buffer accordingly */
                                527   [ -  +  -  -  :           1852 :     switch (var->ind_type)
                                              +  + ]
                                528                 :                :     {
 8451 meskes@postgresql.or      529                 :UBC           0 :         case ECPGt_short:
                                530                 :                :         case ECPGt_unsigned_short:
                                531         [ #  # ]:              0 :             if (*(short *) var->ind_value < 0)
 6839                           532                 :              0 :                 *tobeinserted_p = NULL;
 8451                           533                 :              0 :             break;
 8451 meskes@postgresql.or      534                 :CBC           5 :         case ECPGt_int:
                                535                 :                :         case ECPGt_unsigned_int:
                                536         [ +  + ]:              5 :             if (*(int *) var->ind_value < 0)
 6839                           537                 :              3 :                 *tobeinserted_p = NULL;
 8451                           538                 :              5 :             break;
 8451 meskes@postgresql.or      539                 :UBC           0 :         case ECPGt_long:
                                540                 :                :         case ECPGt_unsigned_long:
                                541         [ #  # ]:              0 :             if (*(long *) var->ind_value < 0L)
 6839                           542                 :              0 :                 *tobeinserted_p = NULL;
 8451                           543                 :              0 :             break;
                                544                 :              0 :         case ECPGt_long_long:
                                545                 :                :         case ECPGt_unsigned_long_long:
                                546         [ #  # ]:              0 :             if (*(long long int *) var->ind_value < (long long) 0)
 6839                           547                 :              0 :                 *tobeinserted_p = NULL;
 8451                           548                 :              0 :             break;
 8350 meskes@postgresql.or      549                 :CBC        1834 :         case ECPGt_NO_INDICATOR:
 7975                           550         [ +  + ]:           1834 :             if (force_indicator == false)
                                551                 :                :             {
 7982                           552         [ +  + ]:             17 :                 if (ECPGis_noind_null(var->type, var->value))
 6839                           553                 :              9 :                     *tobeinserted_p = NULL;
                                554                 :                :             }
 8350                           555                 :           1834 :             break;
 8451                           556                 :             13 :         default:
                                557                 :             13 :             break;
                                558                 :                :     }
 6839                           559         [ +  + ]:           1852 :     if (*tobeinserted_p != NULL)
                                560                 :                :     {
 7153 bruce@momjian.us          561         [ +  + ]:           1840 :         int         asize = var->arrsize ? var->arrsize : 1;
                                562                 :                : 
 8451 meskes@postgresql.or      563   [ +  +  -  -  :           1840 :         switch (var->type)
                                     +  -  -  -  +  
                                     +  +  +  +  +  
                                     +  +  +  +  +  
                                              -  - ]
                                564                 :                :         {
                                565                 :                :                 int         element;
                                566                 :                : 
                                567                 :              4 :             case ECPGt_short:
 6789                           568         [ -  + ]:              4 :                 if (!(mallocedval = ecpg_alloc(asize * 20, lineno)))
 8451 meskes@postgresql.or      569                 :UBC           0 :                     return false;
                                570                 :                : 
 7200 meskes@postgresql.or      571         [ +  + ]:CBC           4 :                 if (asize > 1)
                                572                 :                :                 {
 4102                           573                 :              2 :                     strcpy(mallocedval, "{");
                                574                 :                : 
 7200                           575         [ +  + ]:             22 :                     for (element = 0; element < asize; element++)
 8451                           576                 :             20 :                         sprintf(mallocedval + strlen(mallocedval), "%hd,", ((short *) var->value)[element]);
                                577                 :                : 
 4102                           578                 :              2 :                     strcpy(mallocedval + strlen(mallocedval) - 1, "}");
                                579                 :                :                 }
                                580                 :                :                 else
 8451                           581                 :              2 :                     sprintf(mallocedval, "%hd", *((short *) var->value));
                                582                 :                : 
                                583                 :              4 :                 *tobeinserted_p = mallocedval;
                                584                 :              4 :                 break;
                                585                 :                : 
                                586                 :           1276 :             case ECPGt_int:
 6789                           587         [ -  + ]:           1276 :                 if (!(mallocedval = ecpg_alloc(asize * 20, lineno)))
 8451 meskes@postgresql.or      588                 :UBC           0 :                     return false;
                                589                 :                : 
 7200 meskes@postgresql.or      590         [ -  + ]:CBC        1276 :                 if (asize > 1)
                                591                 :                :                 {
 6839 meskes@postgresql.or      592                 :UBC           0 :                     strcpy(mallocedval, "{");
                                593                 :                : 
 7200                           594         [ #  # ]:              0 :                     for (element = 0; element < asize; element++)
 8451                           595                 :              0 :                         sprintf(mallocedval + strlen(mallocedval), "%d,", ((int *) var->value)[element]);
                                596                 :                : 
 6839                           597                 :              0 :                     strcpy(mallocedval + strlen(mallocedval) - 1, "}");
                                598                 :                :                 }
                                599                 :                :                 else
 8451 meskes@postgresql.or      600                 :CBC        1276 :                     sprintf(mallocedval, "%d", *((int *) var->value));
                                601                 :                : 
                                602                 :           1276 :                 *tobeinserted_p = mallocedval;
                                603                 :           1276 :                 break;
                                604                 :                : 
 8451 meskes@postgresql.or      605                 :UBC           0 :             case ECPGt_unsigned_short:
 6789                           606         [ #  # ]:              0 :                 if (!(mallocedval = ecpg_alloc(asize * 20, lineno)))
 8451                           607                 :              0 :                     return false;
                                608                 :                : 
 7200                           609         [ #  # ]:              0 :                 if (asize > 1)
                                610                 :                :                 {
 4102                           611                 :              0 :                     strcpy(mallocedval, "{");
                                612                 :                : 
 7200                           613         [ #  # ]:              0 :                     for (element = 0; element < asize; element++)
 8451                           614                 :              0 :                         sprintf(mallocedval + strlen(mallocedval), "%hu,", ((unsigned short *) var->value)[element]);
                                615                 :                : 
 4102                           616                 :              0 :                     strcpy(mallocedval + strlen(mallocedval) - 1, "}");
                                617                 :                :                 }
                                618                 :                :                 else
 8451                           619                 :              0 :                     sprintf(mallocedval, "%hu", *((unsigned short *) var->value));
                                620                 :                : 
                                621                 :              0 :                 *tobeinserted_p = mallocedval;
                                622                 :              0 :                 break;
                                623                 :                : 
                                624                 :              0 :             case ECPGt_unsigned_int:
 6789                           625         [ #  # ]:              0 :                 if (!(mallocedval = ecpg_alloc(asize * 20, lineno)))
 8451                           626                 :              0 :                     return false;
                                627                 :                : 
 7200                           628         [ #  # ]:              0 :                 if (asize > 1)
                                629                 :                :                 {
 4102                           630                 :              0 :                     strcpy(mallocedval, "{");
                                631                 :                : 
 7200                           632         [ #  # ]:              0 :                     for (element = 0; element < asize; element++)
 8451                           633                 :              0 :                         sprintf(mallocedval + strlen(mallocedval), "%u,", ((unsigned int *) var->value)[element]);
                                634                 :                : 
 4102                           635                 :              0 :                     strcpy(mallocedval + strlen(mallocedval) - 1, "}");
                                636                 :                :                 }
                                637                 :                :                 else
 8451                           638                 :              0 :                     sprintf(mallocedval, "%u", *((unsigned int *) var->value));
                                639                 :                : 
                                640                 :              0 :                 *tobeinserted_p = mallocedval;
                                641                 :              0 :                 break;
                                642                 :                : 
 8451 meskes@postgresql.or      643                 :CBC           5 :             case ECPGt_long:
 6789                           644         [ -  + ]:              5 :                 if (!(mallocedval = ecpg_alloc(asize * 20, lineno)))
 8451 meskes@postgresql.or      645                 :UBC           0 :                     return false;
                                646                 :                : 
 7200 meskes@postgresql.or      647         [ -  + ]:CBC           5 :                 if (asize > 1)
                                648                 :                :                 {
 4102 meskes@postgresql.or      649                 :UBC           0 :                     strcpy(mallocedval, "{");
                                650                 :                : 
 7200                           651         [ #  # ]:              0 :                     for (element = 0; element < asize; element++)
 8451                           652                 :              0 :                         sprintf(mallocedval + strlen(mallocedval), "%ld,", ((long *) var->value)[element]);
                                653                 :                : 
 4102                           654                 :              0 :                     strcpy(mallocedval + strlen(mallocedval) - 1, "}");
                                655                 :                :                 }
                                656                 :                :                 else
 8451 meskes@postgresql.or      657                 :CBC           5 :                     sprintf(mallocedval, "%ld", *((long *) var->value));
                                658                 :                : 
                                659                 :              5 :                 *tobeinserted_p = mallocedval;
                                660                 :              5 :                 break;
                                661                 :                : 
 8451 meskes@postgresql.or      662                 :UBC           0 :             case ECPGt_unsigned_long:
 6789                           663         [ #  # ]:              0 :                 if (!(mallocedval = ecpg_alloc(asize * 20, lineno)))
 8451                           664                 :              0 :                     return false;
                                665                 :                : 
 7200                           666         [ #  # ]:              0 :                 if (asize > 1)
                                667                 :                :                 {
 4102                           668                 :              0 :                     strcpy(mallocedval, "{");
                                669                 :                : 
 7200                           670         [ #  # ]:              0 :                     for (element = 0; element < asize; element++)
 8451                           671                 :              0 :                         sprintf(mallocedval + strlen(mallocedval), "%lu,", ((unsigned long *) var->value)[element]);
                                672                 :                : 
 4102                           673                 :              0 :                     strcpy(mallocedval + strlen(mallocedval) - 1, "}");
                                674                 :                :                 }
                                675                 :                :                 else
 8451                           676                 :              0 :                     sprintf(mallocedval, "%lu", *((unsigned long *) var->value));
                                677                 :                : 
                                678                 :              0 :                 *tobeinserted_p = mallocedval;
                                679                 :              0 :                 break;
                                680                 :                : 
                                681                 :              0 :             case ECPGt_long_long:
 6789                           682         [ #  # ]:              0 :                 if (!(mallocedval = ecpg_alloc(asize * 30, lineno)))
 8451                           683                 :              0 :                     return false;
                                684                 :                : 
 7200                           685         [ #  # ]:              0 :                 if (asize > 1)
                                686                 :                :                 {
 4102                           687                 :              0 :                     strcpy(mallocedval, "{");
                                688                 :                : 
 7200                           689         [ #  # ]:              0 :                     for (element = 0; element < asize; element++)
 5487 andrew@dunslane.net       690                 :              0 :                         sprintf(mallocedval + strlen(mallocedval), "%lld,", ((long long int *) var->value)[element]);
                                691                 :                : 
 4102 meskes@postgresql.or      692                 :              0 :                     strcpy(mallocedval + strlen(mallocedval) - 1, "}");
                                693                 :                :                 }
                                694                 :                :                 else
 5487 andrew@dunslane.net       695                 :              0 :                     sprintf(mallocedval, "%lld", *((long long int *) var->value));
                                696                 :                : 
 8451 meskes@postgresql.or      697                 :              0 :                 *tobeinserted_p = mallocedval;
                                698                 :              0 :                 break;
                                699                 :                : 
                                700                 :              0 :             case ECPGt_unsigned_long_long:
 6789                           701         [ #  # ]:              0 :                 if (!(mallocedval = ecpg_alloc(asize * 30, lineno)))
 8451                           702                 :              0 :                     return false;
                                703                 :                : 
 7200                           704         [ #  # ]:              0 :                 if (asize > 1)
                                705                 :                :                 {
 4102                           706                 :              0 :                     strcpy(mallocedval, "{");
                                707                 :                : 
 7200                           708         [ #  # ]:              0 :                     for (element = 0; element < asize; element++)
 5487 andrew@dunslane.net       709                 :              0 :                         sprintf(mallocedval + strlen(mallocedval), "%llu,", ((unsigned long long int *) var->value)[element]);
                                710                 :                : 
 4102 meskes@postgresql.or      711                 :              0 :                     strcpy(mallocedval + strlen(mallocedval) - 1, "}");
                                712                 :                :                 }
                                713                 :                :                 else
 5487 andrew@dunslane.net       714                 :              0 :                     sprintf(mallocedval, "%llu", *((unsigned long long int *) var->value));
                                715                 :                : 
 8451 meskes@postgresql.or      716                 :              0 :                 *tobeinserted_p = mallocedval;
                                717                 :              0 :                 break;
                                718                 :                : 
 8451 meskes@postgresql.or      719                 :CBC           1 :             case ECPGt_float:
 6789                           720         [ -  + ]:              1 :                 if (!(mallocedval = ecpg_alloc(asize * 25, lineno)))
 8451 meskes@postgresql.or      721                 :UBC           0 :                     return false;
                                722                 :                : 
 7200 meskes@postgresql.or      723         [ -  + ]:CBC           1 :                 if (asize > 1)
                                724                 :                :                 {
 4102 meskes@postgresql.or      725                 :UBC           0 :                     strcpy(mallocedval, "{");
                                726                 :                : 
 7200                           727         [ #  # ]:              0 :                     for (element = 0; element < asize; element++)
 5936                           728                 :              0 :                         sprintf_float_value(mallocedval + strlen(mallocedval), ((float *) var->value)[element], ",");
                                729                 :                : 
 4102                           730                 :              0 :                     strcpy(mallocedval + strlen(mallocedval) - 1, "}");
                                731                 :                :                 }
                                732                 :                :                 else
 5936 meskes@postgresql.or      733                 :CBC           1 :                     sprintf_float_value(mallocedval, *((float *) var->value), "");
                                734                 :                : 
 8451                           735                 :              1 :                 *tobeinserted_p = mallocedval;
                                736                 :              1 :                 break;
                                737                 :                : 
                                738                 :              6 :             case ECPGt_double:
 6789                           739         [ -  + ]:              6 :                 if (!(mallocedval = ecpg_alloc(asize * 25, lineno)))
 8451 meskes@postgresql.or      740                 :UBC           0 :                     return false;
                                741                 :                : 
 7200 meskes@postgresql.or      742         [ -  + ]:CBC           6 :                 if (asize > 1)
                                743                 :                :                 {
 4102 meskes@postgresql.or      744                 :UBC           0 :                     strcpy(mallocedval, "{");
                                745                 :                : 
 7200                           746         [ #  # ]:              0 :                     for (element = 0; element < asize; element++)
 5936                           747                 :              0 :                         sprintf_double_value(mallocedval + strlen(mallocedval), ((double *) var->value)[element], ",");
                                748                 :                : 
 4102                           749                 :              0 :                     strcpy(mallocedval + strlen(mallocedval) - 1, "}");
                                750                 :                :                 }
                                751                 :                :                 else
 5936 meskes@postgresql.or      752                 :CBC           6 :                     sprintf_double_value(mallocedval, *((double *) var->value), "");
                                753                 :                : 
 8451                           754                 :              6 :                 *tobeinserted_p = mallocedval;
                                755                 :              6 :                 break;
                                756                 :                : 
                                757                 :              2 :             case ECPGt_bool:
 4102                           758         [ -  + ]:              2 :                 if (!(mallocedval = ecpg_alloc(var->arrsize + sizeof("{}"), lineno)))
 8451 meskes@postgresql.or      759                 :UBC           0 :                     return false;
                                760                 :                : 
 8451 meskes@postgresql.or      761         [ -  + ]:CBC           2 :                 if (var->arrsize > 1)
                                762                 :                :                 {
 4102 meskes@postgresql.or      763                 :UBC           0 :                     strcpy(mallocedval, "{");
                                764                 :                : 
 3883                           765         [ #  # ]:              0 :                     for (element = 0; element < asize; element++)
 3879 peter_e@gmx.net           766         [ #  # ]:              0 :                         sprintf(mallocedval + strlen(mallocedval), "%c,", (((bool *) var->value)[element]) ? 't' : 'f');
                                767                 :                : 
 4102 meskes@postgresql.or      768                 :              0 :                     strcpy(mallocedval + strlen(mallocedval) - 1, "}");
                                769                 :                :                 }
                                770                 :                :                 else
                                771                 :                :                 {
 8451 meskes@postgresql.or      772         [ +  - ]:CBC           2 :                     if (var->offset == sizeof(char))
 6839                           773         [ +  - ]:              2 :                         sprintf(mallocedval, "%c", (*((char *) var->value)) ? 't' : 'f');
 8451 meskes@postgresql.or      774         [ #  # ]:UBC           0 :                     else if (var->offset == sizeof(int))
 6839                           775         [ #  # ]:              0 :                         sprintf(mallocedval, "%c", (*((int *) var->value)) ? 't' : 'f');
                                776                 :                :                     else
 6319 peter_e@gmx.net           777                 :              0 :                         ecpg_raise(lineno, ECPG_CONVERT_BOOL, ECPG_SQLSTATE_DATATYPE_MISMATCH, NULL);
                                778                 :                :                 }
                                779                 :                : 
 8451 meskes@postgresql.or      780                 :CBC           2 :                 *tobeinserted_p = mallocedval;
                                781                 :              2 :                 break;
                                782                 :                : 
                                783                 :            462 :             case ECPGt_char:
                                784                 :                :             case ECPGt_unsigned_char:
                                785                 :                :             case ECPGt_string:
                                786                 :                :                 {
                                787                 :                :                     /* set slen to string length if type is char * */
 6172 bruce@momjian.us          788         [ +  + ]:            462 :                     int         slen = (var->varcharsize == 0) ? strlen((char *) var->value) : (unsigned int) var->varcharsize;
                                789                 :                : 
 6789 meskes@postgresql.or      790         [ -  + ]:            462 :                     if (!(newcopy = ecpg_alloc(slen + 1, lineno)))
 8451 meskes@postgresql.or      791                 :UBC           0 :                         return false;
                                792                 :                : 
 8451 meskes@postgresql.or      793                 :CBC         462 :                     strncpy(newcopy, (char *) var->value, slen);
                                794                 :            462 :                     newcopy[slen] = '\0';
                                795                 :                : 
 7195                           796                 :            462 :                     mallocedval = quote_postgres(newcopy, quote, lineno);
 8451                           797         [ -  + ]:            462 :                     if (!mallocedval)
                                798                 :                :                     {
 4108 heikki.linnakangas@i      799                 :UBC           0 :                         ecpg_free(newcopy);
 8451 meskes@postgresql.or      800                 :              0 :                         return false;
                                801                 :                :                     }
                                802                 :                : 
 8451 meskes@postgresql.or      803                 :CBC         462 :                     *tobeinserted_p = mallocedval;
                                804                 :                :                 }
                                805                 :            462 :                 break;
 8355                           806                 :             37 :             case ECPGt_const:
                                807                 :                :             case ECPGt_char_variable:
                                808                 :                :                 {
 8451                           809                 :             37 :                     int         slen = strlen((char *) var->value);
                                810                 :                : 
 6789                           811         [ -  + ]:             37 :                     if (!(mallocedval = ecpg_alloc(slen + 1, lineno)))
 8451 meskes@postgresql.or      812                 :UBC           0 :                         return false;
                                813                 :                : 
 8451 meskes@postgresql.or      814                 :CBC          37 :                     strncpy(mallocedval, (char *) var->value, slen);
                                815                 :             37 :                     mallocedval[slen] = '\0';
                                816                 :                : 
                                817                 :             37 :                     *tobeinserted_p = mallocedval;
                                818                 :                :                 }
                                819                 :             37 :                 break;
                                820                 :                : 
 2633                           821                 :             13 :             case ECPGt_bytea:
                                822                 :                :                 {
 2108 michael@paquier.xyz       823                 :             13 :                     struct ECPGgeneric_bytea *variable =
                                824                 :                :                         (struct ECPGgeneric_bytea *) (var->value);
                                825                 :                : 
  154 peter@eisentraut.org      826         [ -  + ]:GNC          13 :                     if (!(mallocedval = ecpg_alloc(variable->len, lineno)))
 2633 meskes@postgresql.or      827                 :UBC           0 :                         return false;
                                828                 :                : 
 2633 meskes@postgresql.or      829                 :CBC          13 :                     memcpy(mallocedval, variable->arr, variable->len);
                                830                 :             13 :                     *tobeinserted_p = mallocedval;
                                831                 :                :                 }
                                832                 :             13 :                 break;
                                833                 :                : 
 8451                           834                 :             13 :             case ECPGt_varchar:
                                835                 :                :                 {
                                836                 :             13 :                     struct ECPGgeneric_varchar *variable =
                                837                 :                :                         (struct ECPGgeneric_varchar *) (var->value);
                                838                 :                : 
  154 peter@eisentraut.org      839         [ -  + ]:GNC          13 :                     if (!(newcopy = ecpg_alloc(variable->len + 1, lineno)))
 8451 meskes@postgresql.or      840                 :UBC           0 :                         return false;
                                841                 :                : 
 8451 meskes@postgresql.or      842                 :CBC          13 :                     strncpy(newcopy, variable->arr, variable->len);
                                843                 :             13 :                     newcopy[variable->len] = '\0';
                                844                 :                : 
 7195                           845                 :             13 :                     mallocedval = quote_postgres(newcopy, quote, lineno);
 8451                           846         [ -  + ]:             13 :                     if (!mallocedval)
                                847                 :                :                     {
 4108 heikki.linnakangas@i      848                 :UBC           0 :                         ecpg_free(newcopy);
 8451 meskes@postgresql.or      849                 :              0 :                         return false;
                                850                 :                :                     }
                                851                 :                : 
 8451 meskes@postgresql.or      852                 :CBC          13 :                     *tobeinserted_p = mallocedval;
                                853                 :                :                 }
                                854                 :             13 :                 break;
                                855                 :                : 
 8344                           856                 :              7 :             case ECPGt_decimal:
                                857                 :                :             case ECPGt_numeric:
                                858                 :                :                 {
 8310 bruce@momjian.us          859                 :              7 :                     char       *str = NULL;
                                860                 :                :                     int         slen;
                                861                 :                :                     numeric    *nval;
                                862                 :                : 
 8451 meskes@postgresql.or      863         [ +  + ]:              7 :                     if (var->arrsize > 1)
  286 michael@paquier.xyz       864                 :GNC           3 :                         mallocedval = ecpg_strdup("{", lineno, NULL);
                                865                 :                :                     else
                                866                 :              4 :                         mallocedval = ecpg_strdup("", lineno, NULL);
                                867                 :                : 
 4102 meskes@postgresql.or      868         [ -  + ]:CBC           7 :                     if (!mallocedval)
 4000 bruce@momjian.us          869                 :UBC           0 :                         return false;
                                870                 :                : 
 4102 meskes@postgresql.or      871         [ +  + ]:CBC          41 :                     for (element = 0; element < asize; element++)
                                872                 :                :                     {
                                873                 :                :                         int         result;
                                874                 :                : 
 7244                           875                 :             34 :                         nval = PGTYPESnumeric_new();
 7253                           876         [ -  + ]:             34 :                         if (!nval)
                                877                 :                :                         {
 4102 meskes@postgresql.or      878                 :UBC           0 :                             ecpg_free(mallocedval);
 7253                           879                 :              0 :                             return false;
                                880                 :                :                         }
                                881                 :                : 
 8344 meskes@postgresql.or      882         [ +  + ]:CBC          34 :                         if (var->type == ECPGt_numeric)
 4102                           883                 :             32 :                             result = PGTYPESnumeric_copy(&(((numeric *) (var->value))[element]), nval);
                                884                 :                :                         else
                                885                 :              2 :                             result = PGTYPESnumeric_from_decimal(&(((decimal *) (var->value))[element]), nval);
                                886                 :                : 
 4448 sfrost@snowman.net        887         [ -  + ]:             34 :                         if (result != 0)
                                888                 :                :                         {
 4448 sfrost@snowman.net        889                 :UBC           0 :                             PGTYPESnumeric_free(nval);
 4102 meskes@postgresql.or      890                 :              0 :                             ecpg_free(mallocedval);
 4448 sfrost@snowman.net        891                 :              0 :                             return false;
                                892                 :                :                         }
                                893                 :                : 
 8265 meskes@postgresql.or      894                 :CBC          34 :                         str = PGTYPESnumeric_to_asc(nval, nval->dscale);
 8310 bruce@momjian.us          895                 :             34 :                         slen = strlen(str);
 7253 meskes@postgresql.or      896                 :             34 :                         PGTYPESnumeric_free(nval);
                                897                 :                : 
 4102                           898         [ -  + ]:             34 :                         if (!(newcopy = ecpg_realloc(mallocedval, strlen(mallocedval) + slen + 2, lineno)))
                                899                 :                :                         {
 4102 meskes@postgresql.or      900                 :UBC           0 :                             ecpg_free(mallocedval);
                                901                 :              0 :                             ecpg_free(str);
 8440                           902                 :              0 :                             return false;
                                903                 :                :                         }
 4102 meskes@postgresql.or      904                 :CBC          34 :                         mallocedval = newcopy;
                                905                 :                : 
                                906                 :                :                         /* also copy trailing '\0' */
                                907                 :             34 :                         memcpy(mallocedval + strlen(mallocedval), str, slen + 1);
                                908         [ +  + ]:             34 :                         if (var->arrsize > 1)
                                909                 :             30 :                             strcpy(mallocedval + strlen(mallocedval), ",");
                                910                 :                : 
 6789                           911                 :             34 :                         ecpg_free(str);
                                912                 :                :                     }
                                913                 :                : 
 4102                           914         [ +  + ]:              7 :                     if (var->arrsize > 1)
                                915                 :              3 :                         strcpy(mallocedval + strlen(mallocedval) - 1, "}");
                                916                 :                : 
 8440                           917                 :              7 :                     *tobeinserted_p = mallocedval;
                                918                 :                :                 }
                                919                 :              7 :                 break;
                                920                 :                : 
                                921                 :              3 :             case ECPGt_interval:
                                922                 :                :                 {
 8310 bruce@momjian.us          923                 :              3 :                     char       *str = NULL;
                                924                 :                :                     int         slen;
                                925                 :                : 
 8440 meskes@postgresql.or      926         [ +  - ]:              3 :                     if (var->arrsize > 1)
  286 michael@paquier.xyz       927                 :GNC           3 :                         mallocedval = ecpg_strdup("{", lineno, NULL);
                                928                 :                :                     else
  286 michael@paquier.xyz       929                 :UNC           0 :                         mallocedval = ecpg_strdup("", lineno, NULL);
                                930                 :                : 
 4102 meskes@postgresql.or      931         [ -  + ]:CBC           3 :                     if (!mallocedval)
 4000 bruce@momjian.us          932                 :UBC           0 :                         return false;
                                933                 :                : 
 4102 meskes@postgresql.or      934         [ +  + ]:CBC          33 :                     for (element = 0; element < asize; element++)
                                935                 :                :                     {
                                936                 :             30 :                         str = quote_postgres(PGTYPESinterval_to_asc(&(((interval *) (var->value))[element])), quote, lineno);
 7258                           937         [ -  + ]:             30 :                         if (!str)
                                938                 :                :                         {
 4102 meskes@postgresql.or      939                 :UBC           0 :                             ecpg_free(mallocedval);
 7258                           940                 :              0 :                             return false;
                                941                 :                :                         }
                                942                 :                : 
 8310 bruce@momjian.us          943                 :CBC          30 :                         slen = strlen(str);
                                944                 :                : 
 4102 meskes@postgresql.or      945         [ -  + ]:             30 :                         if (!(newcopy = ecpg_realloc(mallocedval, strlen(mallocedval) + slen + 2, lineno)))
                                946                 :                :                         {
 4102 meskes@postgresql.or      947                 :UBC           0 :                             ecpg_free(mallocedval);
 6789                           948                 :              0 :                             ecpg_free(str);
 8451                           949                 :              0 :                             return false;
                                950                 :                :                         }
 4102 meskes@postgresql.or      951                 :CBC          30 :                         mallocedval = newcopy;
                                952                 :                : 
                                953                 :                :                         /* also copy trailing '\0' */
 4119 tgl@sss.pgh.pa.us         954                 :             30 :                         memcpy(mallocedval + strlen(mallocedval), str, slen + 1);
 4102 meskes@postgresql.or      955         [ +  - ]:             30 :                         if (var->arrsize > 1)
                                956                 :             30 :                             strcpy(mallocedval + strlen(mallocedval), ",");
                                957                 :                : 
 6789                           958                 :             30 :                         ecpg_free(str);
                                959                 :                :                     }
                                960                 :                : 
 4102                           961         [ +  - ]:              3 :                     if (var->arrsize > 1)
                                962                 :              3 :                         strcpy(mallocedval + strlen(mallocedval) - 1, "}");
                                963                 :                : 
 8451                           964                 :              3 :                     *tobeinserted_p = mallocedval;
                                965                 :                :                 }
                                966                 :              3 :                 break;
                                967                 :                : 
 8447                           968                 :              5 :             case ECPGt_date:
                                969                 :                :                 {
 8310 bruce@momjian.us          970                 :              5 :                     char       *str = NULL;
                                971                 :                :                     int         slen;
                                972                 :                : 
 8447 meskes@postgresql.or      973         [ +  + ]:              5 :                     if (var->arrsize > 1)
  286 michael@paquier.xyz       974                 :GNC           3 :                         mallocedval = ecpg_strdup("{", lineno, NULL);
                                975                 :                :                     else
                                976                 :              2 :                         mallocedval = ecpg_strdup("", lineno, NULL);
                                977                 :                : 
 4102 meskes@postgresql.or      978         [ -  + ]:CBC           5 :                     if (!mallocedval)
 4000 bruce@momjian.us          979                 :UBC           0 :                         return false;
                                980                 :                : 
 4102 meskes@postgresql.or      981         [ +  + ]:CBC          37 :                     for (element = 0; element < asize; element++)
                                982                 :                :                     {
                                983                 :             32 :                         str = quote_postgres(PGTYPESdate_to_asc(((date *) (var->value))[element]), quote, lineno);
 7258                           984         [ -  + ]:             32 :                         if (!str)
                                985                 :                :                         {
 4102 meskes@postgresql.or      986                 :UBC           0 :                             ecpg_free(mallocedval);
 7258                           987                 :              0 :                             return false;
                                988                 :                :                         }
                                989                 :                : 
 8310 bruce@momjian.us          990                 :CBC          32 :                         slen = strlen(str);
                                991                 :                : 
 4102 meskes@postgresql.or      992         [ -  + ]:             32 :                         if (!(newcopy = ecpg_realloc(mallocedval, strlen(mallocedval) + slen + 2, lineno)))
                                993                 :                :                         {
 4102 meskes@postgresql.or      994                 :UBC           0 :                             ecpg_free(mallocedval);
 6789                           995                 :              0 :                             ecpg_free(str);
 8447                           996                 :              0 :                             return false;
                                997                 :                :                         }
 4102 meskes@postgresql.or      998                 :CBC          32 :                         mallocedval = newcopy;
                                999                 :                : 
                               1000                 :                :                         /* also copy trailing '\0' */
 4119 tgl@sss.pgh.pa.us        1001                 :             32 :                         memcpy(mallocedval + strlen(mallocedval), str, slen + 1);
 4102 meskes@postgresql.or     1002         [ +  + ]:             32 :                         if (var->arrsize > 1)
                               1003                 :             30 :                             strcpy(mallocedval + strlen(mallocedval), ",");
                               1004                 :                : 
 6789                          1005                 :             32 :                         ecpg_free(str);
                               1006                 :                :                     }
                               1007                 :                : 
 4102                          1008         [ +  + ]:              5 :                     if (var->arrsize > 1)
                               1009                 :              3 :                         strcpy(mallocedval + strlen(mallocedval) - 1, "}");
                               1010                 :                : 
 8447                          1011                 :              5 :                     *tobeinserted_p = mallocedval;
                               1012                 :                :                 }
                               1013                 :              5 :                 break;
                               1014                 :                : 
                               1015                 :              6 :             case ECPGt_timestamp:
                               1016                 :                :                 {
 7221                          1017                 :              6 :                     char       *str = NULL;
                               1018                 :                :                     int         slen;
                               1019                 :                : 
 8447                          1020         [ +  + ]:              6 :                     if (var->arrsize > 1)
  286 michael@paquier.xyz      1021                 :GNC           3 :                         mallocedval = ecpg_strdup("{", lineno, NULL);
                               1022                 :                :                     else
                               1023                 :              3 :                         mallocedval = ecpg_strdup("", lineno, NULL);
                               1024                 :                : 
 4102 meskes@postgresql.or     1025         [ -  + ]:CBC           6 :                     if (!mallocedval)
 4000 bruce@momjian.us         1026                 :UBC           0 :                         return false;
                               1027                 :                : 
 4102 meskes@postgresql.or     1028         [ +  + ]:CBC          39 :                     for (element = 0; element < asize; element++)
                               1029                 :                :                     {
                               1030                 :             33 :                         str = quote_postgres(PGTYPEStimestamp_to_asc(((timestamp *) (var->value))[element]), quote, lineno);
 7258                          1031         [ -  + ]:             33 :                         if (!str)
                               1032                 :                :                         {
 4102 meskes@postgresql.or     1033                 :UBC           0 :                             ecpg_free(mallocedval);
 7258                          1034                 :              0 :                             return false;
                               1035                 :                :                         }
                               1036                 :                : 
 8310 bruce@momjian.us         1037                 :CBC          33 :                         slen = strlen(str);
                               1038                 :                : 
 4102 meskes@postgresql.or     1039         [ -  + ]:             33 :                         if (!(newcopy = ecpg_realloc(mallocedval, strlen(mallocedval) + slen + 2, lineno)))
                               1040                 :                :                         {
 4102 meskes@postgresql.or     1041                 :UBC           0 :                             ecpg_free(mallocedval);
 6789                          1042                 :              0 :                             ecpg_free(str);
 8447                          1043                 :              0 :                             return false;
                               1044                 :                :                         }
 4102 meskes@postgresql.or     1045                 :CBC          33 :                         mallocedval = newcopy;
                               1046                 :                : 
                               1047                 :                :                         /* also copy trailing '\0' */
 4119 tgl@sss.pgh.pa.us        1048                 :             33 :                         memcpy(mallocedval + strlen(mallocedval), str, slen + 1);
 4102 meskes@postgresql.or     1049         [ +  + ]:             33 :                         if (var->arrsize > 1)
                               1050                 :             30 :                             strcpy(mallocedval + strlen(mallocedval), ",");
                               1051                 :                : 
 6789                          1052                 :             33 :                         ecpg_free(str);
                               1053                 :                :                     }
                               1054                 :                : 
 4102                          1055         [ +  + ]:              6 :                     if (var->arrsize > 1)
                               1056                 :              3 :                         strcpy(mallocedval + strlen(mallocedval) - 1, "}");
                               1057                 :                : 
 8447                          1058                 :              6 :                     *tobeinserted_p = mallocedval;
                               1059                 :                :                 }
                               1060                 :              6 :                 break;
                               1061                 :                : 
 7979 meskes@postgresql.or     1062                 :UBC           0 :             case ECPGt_descriptor:
                               1063                 :                :             case ECPGt_sqlda:
                               1064                 :              0 :                 break;
                               1065                 :                : 
 8451                          1066                 :              0 :             default:
                               1067                 :                :                 /* Not implemented yet */
 5350 peter_e@gmx.net          1068                 :              0 :                 ecpg_raise(lineno, ECPG_UNSUPPORTED, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, ecpg_type_name(var->type));
 8451 meskes@postgresql.or     1069                 :              0 :                 return false;
                               1070                 :                :                 break;
                               1071                 :                :         }
                               1072                 :                :     }
 8451 meskes@postgresql.or     1073                 :CBC        1852 :     return true;
                               1074                 :                : }
                               1075                 :                : 
                               1076                 :                : static void
 2633                          1077                 :           1744 : print_param_value(char *value, int len, int is_binary, int lineno, int nth)
                               1078                 :                : {
                               1079                 :                :     char       *value_s;
 2540 tgl@sss.pgh.pa.us        1080                 :           1744 :     bool        malloced = false;
                               1081                 :                : 
 2633 meskes@postgresql.or     1082         [ +  + ]:           1744 :     if (value == NULL)
                               1083                 :             12 :         value_s = "null";
 2540 tgl@sss.pgh.pa.us        1084         [ +  + ]:           1732 :     else if (!is_binary)
 2633 meskes@postgresql.or     1085                 :           1719 :         value_s = value;
                               1086                 :                :     else
                               1087                 :                :     {
 2540 tgl@sss.pgh.pa.us        1088                 :             13 :         value_s = ecpg_alloc(ecpg_hex_enc_len(len) + 1, lineno);
 2625 meskes@postgresql.or     1089         [ +  - ]:             13 :         if (value_s != NULL)
                               1090                 :                :         {
                               1091                 :             13 :             ecpg_hex_encode(value, len, value_s);
                               1092                 :             13 :             value_s[ecpg_hex_enc_len(len)] = '\0';
                               1093                 :             13 :             malloced = true;
                               1094                 :                :         }
                               1095                 :                :         else
 2625 meskes@postgresql.or     1096                 :UBC           0 :             value_s = "no memory for logging of parameter";
                               1097                 :                :     }
                               1098                 :                : 
 2633 meskes@postgresql.or     1099                 :CBC        1744 :     ecpg_log("ecpg_free_params on line %d: parameter %d = %s\n",
                               1100                 :                :              lineno, nth, value_s);
                               1101                 :                : 
                               1102         [ +  + ]:           1744 :     if (malloced)
                               1103                 :             13 :         ecpg_free(value_s);
                               1104                 :           1744 : }
                               1105                 :                : 
                               1106                 :                : void
 3240 tgl@sss.pgh.pa.us        1107                 :           2675 : ecpg_free_params(struct statement *stmt, bool print)
                               1108                 :                : {
                               1109                 :                :     int         n;
                               1110                 :                : 
 4492 alvherre@alvh.no-ip.     1111         [ +  + ]:           4419 :     for (n = 0; n < stmt->nparams; n++)
                               1112                 :                :     {
 6839 meskes@postgresql.or     1113         [ +  - ]:           1744 :         if (print)
 2633                          1114                 :           1744 :             print_param_value(stmt->paramvalues[n], stmt->paramlengths[n],
 2540 tgl@sss.pgh.pa.us        1115                 :           1744 :                               stmt->paramformats[n], stmt->lineno, n + 1);
 4492 alvherre@alvh.no-ip.     1116                 :           1744 :         ecpg_free(stmt->paramvalues[n]);
                               1117                 :                :     }
                               1118                 :           2675 :     ecpg_free(stmt->paramvalues);
 2633 meskes@postgresql.or     1119                 :           2675 :     ecpg_free(stmt->paramlengths);
                               1120                 :           2675 :     ecpg_free(stmt->paramformats);
 4492 alvherre@alvh.no-ip.     1121                 :           2675 :     stmt->paramvalues = NULL;
 2633 meskes@postgresql.or     1122                 :           2675 :     stmt->paramlengths = NULL;
                               1123                 :           2675 :     stmt->paramformats = NULL;
 4492 alvherre@alvh.no-ip.     1124                 :           2675 :     stmt->nparams = 0;
 6839 meskes@postgresql.or     1125                 :           2675 : }
                               1126                 :                : 
                               1127                 :                : static bool
 3240 tgl@sss.pgh.pa.us        1128                 :             97 : insert_tobeinserted(int position, int ph_len, struct statement *stmt, char *tobeinserted)
                               1129                 :                : {
                               1130                 :                :     char       *newcopy;
                               1131                 :                : 
  154 peter@eisentraut.org     1132         [ -  + ]:GNC          97 :     if (!(newcopy = ecpg_alloc(strlen(stmt->command) + strlen(tobeinserted) + 1, stmt->lineno)))
                               1133                 :                :     {
 6685 meskes@postgresql.or     1134                 :UBC           0 :         ecpg_free(tobeinserted);
                               1135                 :              0 :         return false;
                               1136                 :                :     }
                               1137                 :                : 
 6685 meskes@postgresql.or     1138                 :CBC          97 :     strcpy(newcopy, stmt->command);
                               1139                 :             97 :     strcpy(newcopy + position - 1, tobeinserted);
                               1140                 :                : 
                               1141                 :                :     /*
                               1142                 :                :      * The strange thing in the second argument is the rest of the string from
                               1143                 :                :      * the old string
                               1144                 :                :      */
                               1145                 :             97 :     strcat(newcopy,
                               1146                 :             97 :            stmt->command
                               1147                 :                :            + position
                               1148                 :             97 :            + ph_len - 1);
                               1149                 :                : 
                               1150                 :             97 :     ecpg_free(stmt->command);
                               1151                 :             97 :     stmt->command = newcopy;
                               1152                 :                : 
 2625                          1153                 :             97 :     ecpg_free(tobeinserted);
 6685                          1154                 :             97 :     return true;
                               1155                 :                : }
                               1156                 :                : 
                               1157                 :                : static bool
 2633                          1158                 :             15 : store_input_from_desc(struct statement *stmt, struct descriptor_item *desc_item,
                               1159                 :                :                       char **tobeinserted)
                               1160                 :                : {
                               1161                 :                :     struct variable var;
                               1162                 :                : 
                               1163                 :                :     /*
                               1164                 :                :      * In case of binary data, only allocate memory and memcpy because binary
                               1165                 :                :      * data have been already stored into desc_item->data with
                               1166                 :                :      * ecpg_store_input() at ECPGset_desc().
                               1167                 :                :      */
                               1168         [ +  + ]:             15 :     if (desc_item->is_binary)
                               1169                 :                :     {
                               1170         [ -  + ]:              2 :         if (!(*tobeinserted = ecpg_alloc(desc_item->data_len, stmt->lineno)))
 2633 meskes@postgresql.or     1171                 :UBC           0 :             return false;
 2633 meskes@postgresql.or     1172                 :CBC           2 :         memcpy(*tobeinserted, desc_item->data, desc_item->data_len);
                               1173                 :              2 :         return true;
                               1174                 :                :     }
                               1175                 :                : 
                               1176                 :             13 :     var.type = ECPGt_char;
                               1177                 :             13 :     var.varcharsize = strlen(desc_item->data);
                               1178                 :             13 :     var.value = desc_item->data;
                               1179                 :             13 :     var.pointer = &(desc_item->data);
                               1180                 :             13 :     var.arrsize = 1;
                               1181                 :             13 :     var.offset = 0;
                               1182                 :                : 
                               1183         [ +  + ]:             13 :     if (!desc_item->indicator)
                               1184                 :                :     {
                               1185                 :             11 :         var.ind_type = ECPGt_NO_INDICATOR;
                               1186                 :             11 :         var.ind_value = var.ind_pointer = NULL;
                               1187                 :             11 :         var.ind_varcharsize = var.ind_arrsize = var.ind_offset = 0;
                               1188                 :                :     }
                               1189                 :                :     else
                               1190                 :                :     {
                               1191                 :              2 :         var.ind_type = ECPGt_int;
                               1192                 :              2 :         var.ind_value = &(desc_item->indicator);
                               1193                 :              2 :         var.ind_pointer = &(var.ind_value);
                               1194                 :              2 :         var.ind_varcharsize = var.ind_arrsize = 1;
                               1195                 :              2 :         var.ind_offset = 0;
                               1196                 :                :     }
                               1197                 :                : 
                               1198         [ -  + ]:             13 :     if (!ecpg_store_input(stmt->lineno, stmt->force_indicator, &var, tobeinserted, false))
 2633 meskes@postgresql.or     1199                 :UBC           0 :         return false;
                               1200                 :                : 
 2633 meskes@postgresql.or     1201                 :CBC          13 :     return true;
                               1202                 :                : }
                               1203                 :                : 
                               1204                 :                : /*
                               1205                 :                :  * ecpg_build_params
                               1206                 :                :  *      Build statement parameters
                               1207                 :                :  *
                               1208                 :                :  * The input values are taken from user variables, and the results are stored
                               1209                 :                :  * in arrays which can be used by PQexecParams().
                               1210                 :                :  */
                               1211                 :                : bool
 3240 tgl@sss.pgh.pa.us        1212                 :           2675 : ecpg_build_params(struct statement *stmt)
                               1213                 :                : {
                               1214                 :                :     struct variable *var;
 7919 bruce@momjian.us         1215                 :           2675 :     int         desc_counter = 0;
 6746                          1216                 :           2675 :     int         position = 0;
                               1217                 :                :     const char *value;
 3113 meskes@postgresql.or     1218                 :           2675 :     bool        std_strings = false;
                               1219                 :                : 
                               1220                 :                :     /* Get standard_conforming_strings setting. */
                               1221                 :           2675 :     value = PQparameterStatus(stmt->connection->connection, "standard_conforming_strings");
                               1222   [ +  -  +  - ]:           2675 :     if (value && strcmp(value, "on") == 0)
                               1223                 :           2675 :         std_strings = true;
                               1224                 :                : 
                               1225                 :                :     /*
                               1226                 :                :      * If the type is one of the fill in types then we take the argument and
                               1227                 :                :      * enter it to our parameter array at the first position. Then if there
                               1228                 :                :      * are any more fill in types we add more parameters.
                               1229                 :                :      */
 8451                          1230                 :           2675 :     var = stmt->inlist;
                               1231         [ +  + ]:           4516 :     while (var)
                               1232                 :                :     {
                               1233                 :                :         char       *tobeinserted;
 6746 bruce@momjian.us         1234                 :           1841 :         int         counter = 1;
                               1235                 :                :         bool        binary_format;
                               1236                 :                :         int         binary_length;
                               1237                 :                : 
                               1238                 :                : 
 7979 meskes@postgresql.or     1239                 :           1841 :         tobeinserted = NULL;
 2633                          1240                 :           1841 :         binary_length = 0;
                               1241                 :           1841 :         binary_format = false;
                               1242                 :                : 
                               1243                 :                :         /*
                               1244                 :                :          * A descriptor is a special case since it contains many variables but
                               1245                 :                :          * is listed only once.
                               1246                 :                :          */
 7979                          1247         [ +  + ]:           1841 :         if (var->type == ECPGt_descriptor)
                               1248                 :                :         {
                               1249                 :                :             /*
                               1250                 :                :              * We create an additional variable list here, so the same logic
                               1251                 :                :              * applies.
                               1252                 :                :              */
                               1253                 :                :             struct descriptor *desc;
                               1254                 :                :             struct descriptor_item *desc_item;
                               1255                 :                : 
 6789                          1256                 :             15 :             desc = ecpg_find_desc(stmt->lineno, var->pointer);
 7979                          1257         [ -  + ]:             15 :             if (desc == NULL)
 7979 meskes@postgresql.or     1258                 :UBC           0 :                 return false;
                               1259                 :                : 
 7979 meskes@postgresql.or     1260                 :CBC          15 :             desc_counter++;
 6839                          1261         [ +  - ]:             23 :             for (desc_item = desc->items; desc_item; desc_item = desc_item->next)
                               1262                 :                :             {
 2633                          1263         [ +  + ]:             23 :                 if (desc_item->num != desc_counter)
                               1264                 :              8 :                     continue;
                               1265                 :                : 
                               1266         [ -  + ]:             15 :                 if (!store_input_from_desc(stmt, desc_item, &tobeinserted))
 2633 meskes@postgresql.or     1267                 :UBC           0 :                     return false;
                               1268                 :                : 
 2633 meskes@postgresql.or     1269         [ +  + ]:CBC          15 :                 if (desc_item->is_binary)
                               1270                 :                :                 {
                               1271                 :              2 :                     binary_length = desc_item->data_len;
                               1272                 :              2 :                     binary_format = true;
                               1273                 :                :                 }
                               1274                 :             15 :                 break;
                               1275                 :                :             }
 6839                          1276         [ +  + ]:             15 :             if (desc->count == desc_counter)
 7979                          1277                 :              8 :                 desc_counter = 0;
                               1278                 :                :         }
 5964                          1279         [ +  + ]:           1826 :         else if (var->type == ECPGt_sqlda)
                               1280                 :                :         {
                               1281   [ +  +  -  + ]:              4 :             if (INFORMIX_MODE(stmt->compat))
                               1282                 :              2 :             {
 5912 bruce@momjian.us         1283                 :              2 :                 struct sqlda_compat *sqlda = *(struct sqlda_compat **) var->pointer;
                               1284                 :                :                 struct variable desc_inlist;
                               1285                 :                :                 int         i;
                               1286                 :                : 
 5964 meskes@postgresql.or     1287         [ -  + ]:              2 :                 if (sqlda == NULL)
 5964 meskes@postgresql.or     1288                 :UBC           0 :                     return false;
                               1289                 :                : 
 5964 meskes@postgresql.or     1290                 :CBC           2 :                 desc_counter++;
                               1291         [ +  - ]:              2 :                 for (i = 0; i < sqlda->sqld; i++)
                               1292                 :                :                 {
                               1293         [ +  - ]:              2 :                     if (i + 1 == desc_counter)
                               1294                 :                :                     {
                               1295                 :              2 :                         desc_inlist.type = sqlda->sqlvar[i].sqltype;
                               1296                 :              2 :                         desc_inlist.value = sqlda->sqlvar[i].sqldata;
                               1297                 :              2 :                         desc_inlist.pointer = &(sqlda->sqlvar[i].sqldata);
                               1298         [ -  + ]:              2 :                         switch (desc_inlist.type)
                               1299                 :                :                         {
 5964 meskes@postgresql.or     1300                 :UBC           0 :                             case ECPGt_char:
                               1301                 :                :                             case ECPGt_varchar:
                               1302                 :              0 :                                 desc_inlist.varcharsize = strlen(sqlda->sqlvar[i].sqldata);
                               1303                 :              0 :                                 break;
 5964 meskes@postgresql.or     1304                 :CBC           2 :                             default:
                               1305                 :              2 :                                 desc_inlist.varcharsize = 0;
                               1306                 :              2 :                                 break;
                               1307                 :                :                         }
                               1308                 :              2 :                         desc_inlist.arrsize = 1;
                               1309                 :              2 :                         desc_inlist.offset = 0;
                               1310         [ -  + ]:              2 :                         if (sqlda->sqlvar[i].sqlind)
                               1311                 :                :                         {
 5964 meskes@postgresql.or     1312                 :UBC           0 :                             desc_inlist.ind_type = ECPGt_short;
                               1313                 :                :                             /* ECPG expects indicator value < 0 */
                               1314         [ #  # ]:              0 :                             if (*(sqlda->sqlvar[i].sqlind))
                               1315                 :              0 :                                 *(sqlda->sqlvar[i].sqlind) = -1;
                               1316                 :              0 :                             desc_inlist.ind_value = sqlda->sqlvar[i].sqlind;
                               1317                 :              0 :                             desc_inlist.ind_pointer = &(sqlda->sqlvar[i].sqlind);
                               1318                 :              0 :                             desc_inlist.ind_varcharsize = desc_inlist.ind_arrsize = 1;
                               1319                 :              0 :                             desc_inlist.ind_offset = 0;
                               1320                 :                :                         }
                               1321                 :                :                         else
                               1322                 :                :                         {
 5964 meskes@postgresql.or     1323                 :CBC           2 :                             desc_inlist.ind_type = ECPGt_NO_INDICATOR;
                               1324                 :              2 :                             desc_inlist.ind_value = desc_inlist.ind_pointer = NULL;
                               1325                 :              2 :                             desc_inlist.ind_varcharsize = desc_inlist.ind_arrsize = desc_inlist.ind_offset = 0;
                               1326                 :                :                         }
                               1327         [ -  + ]:              2 :                         if (!ecpg_store_input(stmt->lineno, stmt->force_indicator, &desc_inlist, &tobeinserted, false))
 5964 meskes@postgresql.or     1328                 :UBC           0 :                             return false;
                               1329                 :                : 
 5964 meskes@postgresql.or     1330                 :CBC           2 :                         break;
                               1331                 :                :                     }
                               1332                 :                :                 }
                               1333         [ +  - ]:              2 :                 if (sqlda->sqld == desc_counter)
                               1334                 :              2 :                     desc_counter = 0;
                               1335                 :                :             }
                               1336                 :                :             else
                               1337                 :                :             {
 5912 bruce@momjian.us         1338                 :              2 :                 struct sqlda_struct *sqlda = *(struct sqlda_struct **) var->pointer;
                               1339                 :                :                 struct variable desc_inlist;
                               1340                 :                :                 int         i;
                               1341                 :                : 
 5964 meskes@postgresql.or     1342         [ -  + ]:              2 :                 if (sqlda == NULL)
 5964 meskes@postgresql.or     1343                 :UBC           0 :                     return false;
                               1344                 :                : 
 5964 meskes@postgresql.or     1345                 :CBC           2 :                 desc_counter++;
                               1346         [ +  - ]:              2 :                 for (i = 0; i < sqlda->sqln; i++)
                               1347                 :                :                 {
                               1348         [ +  - ]:              2 :                     if (i + 1 == desc_counter)
                               1349                 :                :                     {
                               1350                 :              2 :                         desc_inlist.type = sqlda->sqlvar[i].sqltype;
                               1351                 :              2 :                         desc_inlist.value = sqlda->sqlvar[i].sqldata;
                               1352                 :              2 :                         desc_inlist.pointer = &(sqlda->sqlvar[i].sqldata);
                               1353         [ -  + ]:              2 :                         switch (desc_inlist.type)
                               1354                 :                :                         {
 5964 meskes@postgresql.or     1355                 :UBC           0 :                             case ECPGt_char:
                               1356                 :                :                             case ECPGt_varchar:
                               1357                 :              0 :                                 desc_inlist.varcharsize = strlen(sqlda->sqlvar[i].sqldata);
                               1358                 :              0 :                                 break;
 5964 meskes@postgresql.or     1359                 :CBC           2 :                             default:
                               1360                 :              2 :                                 desc_inlist.varcharsize = 0;
                               1361                 :              2 :                                 break;
                               1362                 :                :                         }
                               1363                 :              2 :                         desc_inlist.arrsize = 1;
                               1364                 :              2 :                         desc_inlist.offset = 0;
                               1365         [ -  + ]:              2 :                         if (sqlda->sqlvar[i].sqlind)
                               1366                 :                :                         {
 5964 meskes@postgresql.or     1367                 :UBC           0 :                             desc_inlist.ind_type = ECPGt_short;
                               1368                 :                :                             /* ECPG expects indicator value < 0 */
                               1369         [ #  # ]:              0 :                             if (*(sqlda->sqlvar[i].sqlind))
                               1370                 :              0 :                                 *(sqlda->sqlvar[i].sqlind) = -1;
                               1371                 :              0 :                             desc_inlist.ind_value = sqlda->sqlvar[i].sqlind;
                               1372                 :              0 :                             desc_inlist.ind_pointer = &(sqlda->sqlvar[i].sqlind);
                               1373                 :              0 :                             desc_inlist.ind_varcharsize = desc_inlist.ind_arrsize = 1;
                               1374                 :              0 :                             desc_inlist.ind_offset = 0;
                               1375                 :                :                         }
                               1376                 :                :                         else
                               1377                 :                :                         {
 5964 meskes@postgresql.or     1378                 :CBC           2 :                             desc_inlist.ind_type = ECPGt_NO_INDICATOR;
                               1379                 :              2 :                             desc_inlist.ind_value = desc_inlist.ind_pointer = NULL;
                               1380                 :              2 :                             desc_inlist.ind_varcharsize = desc_inlist.ind_arrsize = desc_inlist.ind_offset = 0;
                               1381                 :                :                         }
                               1382         [ -  + ]:              2 :                         if (!ecpg_store_input(stmt->lineno, stmt->force_indicator, &desc_inlist, &tobeinserted, false))
 5964 meskes@postgresql.or     1383                 :UBC           0 :                             return false;
                               1384                 :                : 
 5964 meskes@postgresql.or     1385                 :CBC           2 :                         break;
                               1386                 :                :                     }
                               1387                 :                :                 }
                               1388         [ +  - ]:              2 :                 if (sqlda->sqln == desc_counter)
                               1389                 :              2 :                     desc_counter = 0;
                               1390                 :                :             }
                               1391                 :                :         }
                               1392                 :                :         else
                               1393                 :                :         {
 6789                          1394         [ -  + ]:           1822 :             if (!ecpg_store_input(stmt->lineno, stmt->force_indicator, var, &tobeinserted, false))
 7979 meskes@postgresql.or     1395                 :UBC           0 :                 return false;
                               1396                 :                : 
 2633 meskes@postgresql.or     1397         [ +  + ]:CBC        1822 :             if (var->type == ECPGt_bytea)
                               1398                 :                :             {
 2108 michael@paquier.xyz      1399                 :             11 :                 binary_length = ((struct ECPGgeneric_bytea *) (var->value))->len;
 2633 meskes@postgresql.or     1400                 :             11 :                 binary_format = true;
                               1401                 :                :             }
                               1402                 :                :         }
                               1403                 :                : 
                               1404                 :                :         /*
                               1405                 :                :          * now tobeinserted points to an area that contains the next
                               1406                 :                :          * parameter; now find the position in the string where it belongs
                               1407                 :                :          */
 3113                          1408         [ -  + ]:           1841 :         if ((position = next_insert(stmt->command, position, stmt->questionmarks, std_strings) + 1) == 0)
                               1409                 :                :         {
                               1410                 :                :             /*
                               1411                 :                :              * We have an argument but we don't have the matched up
                               1412                 :                :              * placeholder in the string
                               1413                 :                :              */
 6685 meskes@postgresql.or     1414                 :UBC           0 :             ecpg_raise(stmt->lineno, ECPG_TOO_MANY_ARGUMENTS,
                               1415                 :                :                        ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS,
                               1416                 :                :                        NULL);
 4492 alvherre@alvh.no-ip.     1417                 :              0 :             ecpg_free_params(stmt, false);
 2625 meskes@postgresql.or     1418                 :              0 :             ecpg_free(tobeinserted);
 6685                          1419                 :              0 :             return false;
                               1420                 :                :         }
                               1421                 :                : 
                               1422                 :                :         /*
                               1423                 :                :          * if var->type=ECPGt_char_variable we have a dynamic cursor we have
                               1424                 :                :          * to simulate a dynamic cursor because there is no backend
                               1425                 :                :          * functionality for it
                               1426                 :                :          */
 6685 meskes@postgresql.or     1427         [ +  + ]:CBC        1841 :         if (var->type == ECPGt_char_variable)
                               1428                 :                :         {
 6172 bruce@momjian.us         1429         [ -  + ]:             21 :             int         ph_len = (stmt->command[position] == '?') ? strlen("?") : strlen("$1");
                               1430                 :                : 
 6685 meskes@postgresql.or     1431         [ -  + ]:             21 :             if (!insert_tobeinserted(position, ph_len, stmt, tobeinserted))
                               1432                 :                :             {
 4492 alvherre@alvh.no-ip.     1433                 :UBC           0 :                 ecpg_free_params(stmt, false);
 6685 meskes@postgresql.or     1434                 :              0 :                 return false;
                               1435                 :                :             }
 6685 meskes@postgresql.or     1436                 :CBC          21 :             tobeinserted = NULL;
                               1437                 :                :         }
                               1438                 :                : 
                               1439                 :                :         /*
                               1440                 :                :          * if the placeholder is '$0' we have to replace it on the client side
                               1441                 :                :          * this is for places we want to support variables at that are not
                               1442                 :                :          * supported in the backend
                               1443                 :                :          */
 6172 bruce@momjian.us         1444         [ +  + ]:           1820 :         else if (stmt->command[position] == '0')
                               1445                 :                :         {
 2540 meskes@postgresql.or     1446         [ +  + ]:             62 :             if (stmt->statement_type == ECPGst_prepare ||
                               1447         [ +  + ]:             57 :                 stmt->statement_type == ECPGst_exec_with_exprlist)
                               1448                 :                :             {
                               1449                 :                :                 /* Need to double-quote the inserted statement name. */
 2536 tgl@sss.pgh.pa.us        1450                 :             14 :                 char       *str = ecpg_alloc(strlen(tobeinserted) + 2 + 1,
                               1451                 :                :                                              stmt->lineno);
                               1452                 :                : 
                               1453         [ -  + ]:             14 :                 if (!str)
                               1454                 :                :                 {
 2536 tgl@sss.pgh.pa.us        1455                 :UBC           0 :                     ecpg_free(tobeinserted);
                               1456                 :              0 :                     ecpg_free_params(stmt, false);
                               1457                 :              0 :                     return false;
                               1458                 :                :                 }
 2540 meskes@postgresql.or     1459                 :CBC          14 :                 sprintf(str, "\"%s\"", tobeinserted);
                               1460                 :             14 :                 ecpg_free(tobeinserted);
                               1461                 :             14 :                 tobeinserted = str;
                               1462                 :                :             }
                               1463                 :                : 
                               1464         [ -  + ]:             62 :             if (!insert_tobeinserted(position, 2, stmt, tobeinserted))
                               1465                 :                :             {
 2540 meskes@postgresql.or     1466                 :UBC           0 :                 ecpg_free_params(stmt, false);
                               1467                 :              0 :                 return false;
                               1468                 :                :             }
 2540 meskes@postgresql.or     1469                 :CBC          62 :             tobeinserted = NULL;
                               1470                 :                :         }
                               1471         [ +  + ]:           1758 :         else if (stmt->statement_type == ECPGst_exec_with_exprlist)
                               1472                 :                :         {
                               1473         [ -  + ]:             14 :             if (binary_format)
                               1474                 :                :             {
 2536 tgl@sss.pgh.pa.us        1475                 :UBC           0 :                 char       *p = convert_bytea_to_string(tobeinserted,
                               1476                 :                :                                                         binary_length,
                               1477                 :                :                                                         stmt->lineno);
                               1478                 :                : 
                               1479                 :              0 :                 ecpg_free(tobeinserted);
 2540 meskes@postgresql.or     1480         [ #  # ]:              0 :                 if (!p)
                               1481                 :                :                 {
                               1482                 :              0 :                     ecpg_free_params(stmt, false);
                               1483                 :              0 :                     return false;
                               1484                 :                :                 }
                               1485                 :              0 :                 tobeinserted = p;
                               1486                 :                :             }
                               1487                 :                : 
 6685 meskes@postgresql.or     1488         [ -  + ]:CBC          14 :             if (!insert_tobeinserted(position, 2, stmt, tobeinserted))
                               1489                 :                :             {
 4492 alvherre@alvh.no-ip.     1490                 :UBC           0 :                 ecpg_free_params(stmt, false);
 6685 meskes@postgresql.or     1491                 :              0 :                 return false;
                               1492                 :                :             }
 6685 meskes@postgresql.or     1493                 :CBC          14 :             tobeinserted = NULL;
                               1494                 :                :         }
                               1495                 :                :         else
                               1496                 :                :         {
 2298 tgl@sss.pgh.pa.us        1497                 :           1744 :             bool        realloc_failed = false;
                               1498                 :                :             char      **newparamvalues;
                               1499                 :                :             int        *newparamlengths;
                               1500                 :                :             int        *newparamformats;
                               1501                 :                : 
                               1502                 :                :             /* enlarge all the param arrays */
                               1503         [ +  - ]:           1744 :             if ((newparamvalues = (char **) ecpg_realloc(stmt->paramvalues, sizeof(char *) * (stmt->nparams + 1), stmt->lineno)))
                               1504                 :           1744 :                 stmt->paramvalues = newparamvalues;
                               1505                 :                :             else
 2298 tgl@sss.pgh.pa.us        1506                 :UBC           0 :                 realloc_failed = true;
                               1507                 :                : 
 2298 tgl@sss.pgh.pa.us        1508         [ +  - ]:CBC        1744 :             if ((newparamlengths = (int *) ecpg_realloc(stmt->paramlengths, sizeof(int) * (stmt->nparams + 1), stmt->lineno)))
                               1509                 :           1744 :                 stmt->paramlengths = newparamlengths;
                               1510                 :                :             else
 2298 tgl@sss.pgh.pa.us        1511                 :UBC           0 :                 realloc_failed = true;
                               1512                 :                : 
 2298 tgl@sss.pgh.pa.us        1513         [ +  - ]:CBC        1744 :             if ((newparamformats = (int *) ecpg_realloc(stmt->paramformats, sizeof(int) * (stmt->nparams + 1), stmt->lineno)))
                               1514                 :           1744 :                 stmt->paramformats = newparamformats;
                               1515                 :                :             else
 2298 tgl@sss.pgh.pa.us        1516                 :UBC           0 :                 realloc_failed = true;
                               1517                 :                : 
 2298 tgl@sss.pgh.pa.us        1518         [ -  + ]:CBC        1744 :             if (realloc_failed)
                               1519                 :                :             {
 4492 alvherre@alvh.no-ip.     1520                 :UBC           0 :                 ecpg_free_params(stmt, false);
 2625 meskes@postgresql.or     1521                 :              0 :                 ecpg_free(tobeinserted);
 6839                          1522                 :              0 :                 return false;
                               1523                 :                :             }
                               1524                 :                : 
                               1525                 :                :             /* only now can we assign ownership of "tobeinserted" to stmt */
 2298 tgl@sss.pgh.pa.us        1526                 :CBC        1744 :             stmt->paramvalues[stmt->nparams] = tobeinserted;
 2625 meskes@postgresql.or     1527                 :           1744 :             stmt->paramlengths[stmt->nparams] = binary_length;
                               1528                 :           1744 :             stmt->paramformats[stmt->nparams] = (binary_format ? 1 : 0);
 4492 alvherre@alvh.no-ip.     1529                 :           1744 :             stmt->nparams++;
                               1530                 :                : 
                               1531                 :                :             /* let's see if this was an old style placeholder */
 6685 meskes@postgresql.or     1532         [ -  + ]:           1744 :             if (stmt->command[position] == '?')
                               1533                 :                :             {
                               1534                 :                :                 /* yes, replace with new style */
 3240 tgl@sss.pgh.pa.us        1535                 :UBC           0 :                 int         buffersize = sizeof(int) * CHAR_BIT * 10 / 3;   /* a rough guess of the
                               1536                 :                :                                                                              * size we need */
                               1537                 :                : 
  154 peter@eisentraut.org     1538         [ #  # ]:UNC           0 :                 if (!(tobeinserted = ecpg_alloc(buffersize, stmt->lineno)))
                               1539                 :                :                 {
 4492 alvherre@alvh.no-ip.     1540                 :UBC           0 :                     ecpg_free_params(stmt, false);
 6839 meskes@postgresql.or     1541                 :              0 :                     return false;
                               1542                 :                :                 }
                               1543                 :                : 
 6685                          1544                 :              0 :                 snprintf(tobeinserted, buffersize, "$%d", counter++);
                               1545                 :                : 
                               1546         [ #  # ]:              0 :                 if (!insert_tobeinserted(position, 2, stmt, tobeinserted))
                               1547                 :                :                 {
 4492 alvherre@alvh.no-ip.     1548                 :              0 :                     ecpg_free_params(stmt, false);
 6839 meskes@postgresql.or     1549                 :              0 :                     return false;
                               1550                 :                :                 }
 6685                          1551                 :              0 :                 tobeinserted = NULL;
                               1552                 :                :             }
                               1553                 :                :         }
                               1554                 :                : 
 7979 meskes@postgresql.or     1555         [ +  + ]:CBC        1841 :         if (desc_counter == 0)
 7919 bruce@momjian.us         1556                 :           1834 :             var = var->next;
                               1557                 :                :     }
                               1558                 :                : 
                               1559                 :                :     /*
                               1560                 :                :      * Check if there are unmatched things left. PREPARE AS has no parameter.
                               1561                 :                :      * Check other statement.
                               1562                 :                :      */
 2540 meskes@postgresql.or     1563   [ +  +  -  + ]:           5345 :     if (stmt->statement_type != ECPGst_prepare &&
                               1564                 :           2670 :         next_insert(stmt->command, position, stmt->questionmarks, std_strings) >= 0)
                               1565                 :                :     {
 6789 meskes@postgresql.or     1566                 :UBC           0 :         ecpg_raise(stmt->lineno, ECPG_TOO_FEW_ARGUMENTS,
                               1567                 :                :                    ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS, NULL);
 4492 alvherre@alvh.no-ip.     1568                 :              0 :         ecpg_free_params(stmt, false);
 8451 meskes@postgresql.or     1569                 :              0 :         return false;
                               1570                 :                :     }
                               1571                 :                : 
 4492 alvherre@alvh.no-ip.     1572                 :CBC        2675 :     return true;
                               1573                 :                : }
                               1574                 :                : 
                               1575                 :                : /*
                               1576                 :                :  * ecpg_autostart_transaction
                               1577                 :                :  *      If we are in non-autocommit mode, automatically start a transaction.
                               1578                 :                :  */
                               1579                 :                : bool
 3240 tgl@sss.pgh.pa.us        1580                 :           2675 : ecpg_autostart_transaction(struct statement *stmt)
                               1581                 :                : {
 5682 meskes@postgresql.or     1582   [ +  +  +  + ]:           2675 :     if (PQtransactionStatus(stmt->connection->connection) == PQTRANS_IDLE && !stmt->connection->autocommit)
                               1583                 :                :     {
 4492 alvherre@alvh.no-ip.     1584                 :             95 :         stmt->results = PQexec(stmt->connection->connection, "begin transaction");
                               1585         [ -  + ]:             95 :         if (!ecpg_check_PQresult(stmt->results, stmt->lineno, stmt->connection->connection, stmt->compat))
                               1586                 :                :         {
 4492 alvherre@alvh.no-ip.     1587                 :UBC           0 :             ecpg_free_params(stmt, false);
 8451 meskes@postgresql.or     1588                 :              0 :             return false;
                               1589                 :                :         }
 4492 alvherre@alvh.no-ip.     1590                 :CBC          95 :         PQclear(stmt->results);
                               1591                 :             95 :         stmt->results = NULL;
                               1592                 :                :     }
                               1593                 :           2675 :     return true;
                               1594                 :                : }
                               1595                 :                : 
                               1596                 :                : /*
                               1597                 :                :  * ecpg_execute
                               1598                 :                :  *      Execute the SQL statement.
                               1599                 :                :  */
                               1600                 :                : bool
 3240 tgl@sss.pgh.pa.us        1601                 :           2675 : ecpg_execute(struct statement *stmt)
                               1602                 :                : {
 4492 alvherre@alvh.no-ip.     1603                 :           2675 :     ecpg_log("ecpg_execute on line %d: query: %s; with %d parameter(s) on connection %s\n", stmt->lineno, stmt->command, stmt->nparams, stmt->connection->name);
 6839 meskes@postgresql.or     1604         [ +  + ]:           2675 :     if (stmt->statement_type == ECPGst_execute)
                               1605                 :                :     {
 2633                          1606                 :           1668 :         stmt->results = PQexecPrepared(stmt->connection->connection,
                               1607                 :            834 :                                        stmt->name,
                               1608                 :                :                                        stmt->nparams,
                               1609                 :            834 :                                        (const char *const *) stmt->paramvalues,
                               1610                 :            834 :                                        (const int *) stmt->paramlengths,
                               1611                 :            834 :                                        (const int *) stmt->paramformats,
                               1612                 :                :                                        0);
 6563 peter_e@gmx.net          1613                 :            834 :         ecpg_log("ecpg_execute on line %d: using PQexecPrepared for \"%s\"\n", stmt->lineno, stmt->command);
                               1614                 :                :     }
                               1615                 :                :     else
                               1616                 :                :     {
 4492 alvherre@alvh.no-ip.     1617         [ +  + ]:           1841 :         if (stmt->nparams == 0)
                               1618                 :                :         {
                               1619                 :           1382 :             stmt->results = PQexec(stmt->connection->connection, stmt->command);
 6563 peter_e@gmx.net          1620                 :           1382 :             ecpg_log("ecpg_execute on line %d: using PQexec\n", stmt->lineno);
                               1621                 :                :         }
                               1622                 :                :         else
                               1623                 :                :         {
 2633 meskes@postgresql.or     1624                 :            918 :             stmt->results = PQexecParams(stmt->connection->connection,
                               1625                 :            459 :                                          stmt->command, stmt->nparams, NULL,
                               1626                 :            459 :                                          (const char *const *) stmt->paramvalues,
                               1627                 :            459 :                                          (const int *) stmt->paramlengths,
                               1628                 :            459 :                                          (const int *) stmt->paramformats,
                               1629                 :                :                                          0);
                               1630                 :                : 
 6563 peter_e@gmx.net          1631                 :            459 :             ecpg_log("ecpg_execute on line %d: using PQexecParams\n", stmt->lineno);
                               1632                 :                :         }
                               1633                 :                : 
 2540 meskes@postgresql.or     1634         [ +  + ]:           1841 :         if (stmt->statement_type == ECPGst_prepare)
                               1635                 :                :         {
      tgl@sss.pgh.pa.us        1636         [ -  + ]:              5 :             if (!ecpg_register_prepared_stmt(stmt))
                               1637                 :                :             {
 2540 meskes@postgresql.or     1638                 :UBC           0 :                 ecpg_free_params(stmt, true);
                               1639                 :              0 :                 return false;
                               1640                 :                :             }
                               1641                 :                :         }
                               1642                 :                :     }
                               1643                 :                : 
 4492 alvherre@alvh.no-ip.     1644                 :CBC        2675 :     ecpg_free_params(stmt, true);
                               1645                 :                : 
                               1646         [ +  + ]:           2675 :     if (!ecpg_check_PQresult(stmt->results, stmt->lineno, stmt->connection->connection, stmt->compat))
                               1647                 :             13 :         return false;
                               1648                 :                : 
                               1649                 :           2662 :     return true;
                               1650                 :                : }
                               1651                 :                : 
                               1652                 :                : /*-------
                               1653                 :                :  * ecpg_process_output
                               1654                 :                :  *
                               1655                 :                :  *  Process the statement result and store it into application variables.  This
                               1656                 :                :  *  function can be called repeatedly during the same statement in case cursor
                               1657                 :                :  *  readahead is used and the application does FETCH N which overflows the
                               1658                 :                :  *  readahead window.
                               1659                 :                :  *
                               1660                 :                :  * Parameters
                               1661                 :                :  *  stmt    statement structure holding the PGresult and
                               1662                 :                :  *          the list of output variables
                               1663                 :                :  *  clear_result
                               1664                 :                :  *          PQclear() the result upon returning from this function
                               1665                 :                :  *
                               1666                 :                :  * Returns success as boolean. Also an SQL error is raised in case of failure.
                               1667                 :                :  *-------
                               1668                 :                :  */
                               1669                 :                : bool
 3240 tgl@sss.pgh.pa.us        1670                 :           2662 : ecpg_process_output(struct statement *stmt, bool clear_result)
                               1671                 :                : {
                               1672                 :                :     struct variable *var;
 4492 alvherre@alvh.no-ip.     1673                 :           2662 :     bool        status = false;
                               1674                 :                :     char       *cmdstat;
                               1675                 :                :     PGnotify   *notify;
                               1676                 :           2662 :     struct sqlca_t *sqlca = ECPGget_sqlca();
                               1677                 :                :     int         nfields,
                               1678                 :                :                 ntuples,
                               1679                 :                :                 act_field;
                               1680                 :                : 
 3977 meskes@postgresql.or     1681         [ -  + ]:           2662 :     if (sqlca == NULL)
                               1682                 :                :     {
 3977 meskes@postgresql.or     1683                 :UBC           0 :         ecpg_raise(stmt->lineno, ECPG_OUT_OF_MEMORY,
                               1684                 :                :                    ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, NULL);
 3183 peter_e@gmx.net          1685                 :              0 :         return false;
                               1686                 :                :     }
                               1687                 :                : 
 6839 meskes@postgresql.or     1688                 :CBC        2662 :     var = stmt->outlist;
 4492 alvherre@alvh.no-ip.     1689   [ +  +  +  - ]:           2662 :     switch (PQresultStatus(stmt->results))
                               1690                 :                :     {
 6839 meskes@postgresql.or     1691                 :           1054 :         case PGRES_TUPLES_OK:
 4492 alvherre@alvh.no-ip.     1692                 :           1054 :             nfields = PQnfields(stmt->results);
                               1693                 :           1054 :             sqlca->sqlerrd[2] = ntuples = PQntuples(stmt->results);
                               1694                 :                : 
                               1695                 :           1054 :             ecpg_log("ecpg_process_output on line %d: correctly got %d tuples with %d fields\n", stmt->lineno, ntuples, nfields);
 6839 meskes@postgresql.or     1696                 :           1054 :             status = true;
                               1697                 :                : 
                               1698         [ +  + ]:           1054 :             if (ntuples < 1)
                               1699                 :                :             {
                               1700         [ -  + ]:             21 :                 if (ntuples)
 4492 alvherre@alvh.no-ip.     1701                 :UBC           0 :                     ecpg_log("ecpg_process_output on line %d: incorrect number of matches (%d)\n",
                               1702                 :                :                              stmt->lineno, ntuples);
 6789 meskes@postgresql.or     1703                 :CBC          21 :                 ecpg_raise(stmt->lineno, ECPG_NOT_FOUND, ECPG_SQLSTATE_NO_DATA, NULL);
 6839                          1704                 :             21 :                 status = false;
                               1705                 :             21 :                 break;
                               1706                 :                :             }
                               1707                 :                : 
                               1708   [ +  +  +  + ]:           1033 :             if (var != NULL && var->type == ECPGt_descriptor)
                               1709                 :              8 :             {
 6789                          1710                 :              8 :                 struct descriptor *desc = ecpg_find_desc(stmt->lineno, var->pointer);
                               1711                 :                : 
 6790                          1712         [ -  + ]:              8 :                 if (desc == NULL)
 8451 meskes@postgresql.or     1713                 :UBC           0 :                     status = false;
                               1714                 :                :                 else
                               1715                 :                :                 {
 1402 peter@eisentraut.org     1716                 :CBC           8 :                     PQclear(desc->result);
 4492 alvherre@alvh.no-ip.     1717                 :              8 :                     desc->result = stmt->results;
 6790 meskes@postgresql.or     1718                 :              8 :                     clear_result = false;
 4492 alvherre@alvh.no-ip.     1719                 :              8 :                     ecpg_log("ecpg_process_output on line %d: putting result (%d tuples) into descriptor %s\n",
                               1720                 :              8 :                              stmt->lineno, PQntuples(stmt->results), (const char *) var->pointer);
                               1721                 :                :                 }
 6839 meskes@postgresql.or     1722                 :              8 :                 var = var->next;
                               1723                 :                :             }
 5964                          1724   [ +  +  +  + ]:           1025 :             else if (var != NULL && var->type == ECPGt_sqlda)
                               1725                 :                :             {
                               1726   [ +  +  -  + ]:             17 :                 if (INFORMIX_MODE(stmt->compat))
                               1727                 :              8 :                 {
 5912 bruce@momjian.us         1728                 :              8 :                     struct sqlda_compat **_sqlda = (struct sqlda_compat **) var->pointer;
                               1729                 :              8 :                     struct sqlda_compat *sqlda = *_sqlda;
                               1730                 :                :                     struct sqlda_compat *sqlda_new;
                               1731                 :                :                     int         i;
                               1732                 :                : 
                               1733                 :                :                     /*
                               1734                 :                :                      * If we are passed in a previously existing sqlda (chain)
                               1735                 :                :                      * then free it.
                               1736                 :                :                      */
 5964 meskes@postgresql.or     1737         [ +  + ]:             12 :                     while (sqlda)
                               1738                 :                :                     {
                               1739                 :              4 :                         sqlda_new = sqlda->desc_next;
                               1740                 :              4 :                         free(sqlda);
                               1741                 :              4 :                         sqlda = sqlda_new;
                               1742                 :                :                     }
                               1743                 :              8 :                     *_sqlda = sqlda = sqlda_new = NULL;
                               1744         [ +  + ]:             16 :                     for (i = ntuples - 1; i >= 0; i--)
                               1745                 :                :                     {
                               1746                 :                :                         /*
                               1747                 :                :                          * Build a new sqlda structure. Note that only
                               1748                 :                :                          * fetching 1 record is supported
                               1749                 :                :                          */
 4492 alvherre@alvh.no-ip.     1750                 :              8 :                         sqlda_new = ecpg_build_compat_sqlda(stmt->lineno, stmt->results, i, stmt->compat);
                               1751                 :                : 
 5964 meskes@postgresql.or     1752         [ -  + ]:              8 :                         if (!sqlda_new)
                               1753                 :                :                         {
                               1754                 :                :                             /* cleanup all SQLDAs we created up */
 5964 meskes@postgresql.or     1755         [ #  # ]:UBC           0 :                             while (sqlda)
                               1756                 :                :                             {
                               1757                 :              0 :                                 sqlda_new = sqlda->desc_next;
                               1758                 :              0 :                                 free(sqlda);
                               1759                 :              0 :                                 sqlda = sqlda_new;
                               1760                 :                :                             }
                               1761                 :              0 :                             *_sqlda = NULL;
                               1762                 :                : 
 4492 alvherre@alvh.no-ip.     1763                 :              0 :                             ecpg_log("ecpg_process_output on line %d: out of memory allocating a new sqlda\n", stmt->lineno);
 5964 meskes@postgresql.or     1764                 :              0 :                             status = false;
                               1765                 :              0 :                             break;
                               1766                 :                :                         }
                               1767                 :                :                         else
                               1768                 :                :                         {
 4492 alvherre@alvh.no-ip.     1769                 :CBC           8 :                             ecpg_log("ecpg_process_output on line %d: new sqlda was built\n", stmt->lineno);
                               1770                 :                : 
 5964 meskes@postgresql.or     1771                 :              8 :                             *_sqlda = sqlda_new;
                               1772                 :                : 
 4492 alvherre@alvh.no-ip.     1773                 :              8 :                             ecpg_set_compat_sqlda(stmt->lineno, _sqlda, stmt->results, i, stmt->compat);
                               1774                 :              8 :                             ecpg_log("ecpg_process_output on line %d: putting result (1 tuple %d fields) into sqlda descriptor\n",
                               1775                 :              8 :                                      stmt->lineno, PQnfields(stmt->results));
                               1776                 :                : 
 5964 meskes@postgresql.or     1777                 :              8 :                             sqlda_new->desc_next = sqlda;
                               1778                 :              8 :                             sqlda = sqlda_new;
                               1779                 :                :                         }
                               1780                 :                :                     }
                               1781                 :                :                 }
                               1782                 :                :                 else
                               1783                 :                :                 {
 5912 bruce@momjian.us         1784                 :              9 :                     struct sqlda_struct **_sqlda = (struct sqlda_struct **) var->pointer;
                               1785                 :              9 :                     struct sqlda_struct *sqlda = *_sqlda;
                               1786                 :                :                     struct sqlda_struct *sqlda_new;
                               1787                 :                :                     int         i;
                               1788                 :                : 
                               1789                 :                :                     /*
                               1790                 :                :                      * If we are passed in a previously existing sqlda (chain)
                               1791                 :                :                      * then free it.
                               1792                 :                :                      */
 5964 meskes@postgresql.or     1793         [ +  + ]:             13 :                     while (sqlda)
                               1794                 :                :                     {
                               1795                 :              4 :                         sqlda_new = sqlda->desc_next;
                               1796                 :              4 :                         free(sqlda);
                               1797                 :              4 :                         sqlda = sqlda_new;
                               1798                 :                :                     }
                               1799                 :              9 :                     *_sqlda = sqlda = sqlda_new = NULL;
                               1800         [ +  + ]:             22 :                     for (i = ntuples - 1; i >= 0; i--)
                               1801                 :                :                     {
                               1802                 :                :                         /*
                               1803                 :                :                          * Build a new sqlda structure. Note that only
                               1804                 :                :                          * fetching 1 record is supported
                               1805                 :                :                          */
 4492 alvherre@alvh.no-ip.     1806                 :             13 :                         sqlda_new = ecpg_build_native_sqlda(stmt->lineno, stmt->results, i, stmt->compat);
                               1807                 :                : 
 5964 meskes@postgresql.or     1808         [ -  + ]:             13 :                         if (!sqlda_new)
                               1809                 :                :                         {
                               1810                 :                :                             /* cleanup all SQLDAs we created up */
 5964 meskes@postgresql.or     1811         [ #  # ]:UBC           0 :                             while (sqlda)
                               1812                 :                :                             {
                               1813                 :              0 :                                 sqlda_new = sqlda->desc_next;
                               1814                 :              0 :                                 free(sqlda);
                               1815                 :              0 :                                 sqlda = sqlda_new;
                               1816                 :                :                             }
                               1817                 :              0 :                             *_sqlda = NULL;
                               1818                 :                : 
 4492 alvherre@alvh.no-ip.     1819                 :              0 :                             ecpg_log("ecpg_process_output on line %d: out of memory allocating a new sqlda\n", stmt->lineno);
 5964 meskes@postgresql.or     1820                 :              0 :                             status = false;
                               1821                 :              0 :                             break;
                               1822                 :                :                         }
                               1823                 :                :                         else
                               1824                 :                :                         {
 4492 alvherre@alvh.no-ip.     1825                 :CBC          13 :                             ecpg_log("ecpg_process_output on line %d: new sqlda was built\n", stmt->lineno);
                               1826                 :                : 
 5964 meskes@postgresql.or     1827                 :             13 :                             *_sqlda = sqlda_new;
                               1828                 :                : 
 4492 alvherre@alvh.no-ip.     1829                 :             13 :                             ecpg_set_native_sqlda(stmt->lineno, _sqlda, stmt->results, i, stmt->compat);
                               1830                 :             13 :                             ecpg_log("ecpg_process_output on line %d: putting result (1 tuple %d fields) into sqlda descriptor\n",
                               1831                 :             13 :                                      stmt->lineno, PQnfields(stmt->results));
                               1832                 :                : 
 5964 meskes@postgresql.or     1833                 :             13 :                             sqlda_new->desc_next = sqlda;
                               1834                 :             13 :                             sqlda = sqlda_new;
                               1835                 :                :                         }
                               1836                 :                :                     }
                               1837                 :                :                 }
                               1838                 :                : 
                               1839                 :             17 :                 var = var->next;
                               1840                 :                :             }
                               1841                 :                :             else
 6839                          1842   [ +  +  +  - ]:           2243 :                 for (act_field = 0; act_field < nfields && status; act_field++)
                               1843                 :                :                 {
                               1844         [ +  + ]:           1235 :                     if (var != NULL)
                               1845                 :                :                     {
 4492 alvherre@alvh.no-ip.     1846                 :           1233 :                         status = ecpg_store_result(stmt->results, act_field, stmt, var);
 6839 meskes@postgresql.or     1847                 :           1233 :                         var = var->next;
                               1848                 :                :                     }
                               1849   [ -  +  -  - ]:              2 :                     else if (!INFORMIX_MODE(stmt->compat))
                               1850                 :                :                     {
 6789 meskes@postgresql.or     1851                 :UBC           0 :                         ecpg_raise(stmt->lineno, ECPG_TOO_FEW_ARGUMENTS, ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS, NULL);
 3183 peter_e@gmx.net          1852                 :              0 :                         return false;
                               1853                 :                :                     }
                               1854                 :                :                 }
                               1855                 :                : 
 6839 meskes@postgresql.or     1856   [ +  +  -  + ]:CBC        1033 :             if (status && var != NULL)
                               1857                 :                :             {
 6789 meskes@postgresql.or     1858                 :UBC           0 :                 ecpg_raise(stmt->lineno, ECPG_TOO_MANY_ARGUMENTS, ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS, NULL);
 8451                          1859                 :              0 :                 status = false;
                               1860                 :                :             }
                               1861                 :                : 
 6839 meskes@postgresql.or     1862                 :CBC        1033 :             break;
                               1863                 :           1607 :         case PGRES_COMMAND_OK:
                               1864                 :           1607 :             status = true;
 4492 alvherre@alvh.no-ip.     1865                 :           1607 :             cmdstat = PQcmdStatus(stmt->results);
                               1866                 :           1607 :             sqlca->sqlerrd[1] = PQoidValue(stmt->results);
                               1867                 :           1607 :             sqlca->sqlerrd[2] = atol(PQcmdTuples(stmt->results));
                               1868                 :           1607 :             ecpg_log("ecpg_process_output on line %d: OK: %s\n", stmt->lineno, cmdstat);
 6839 meskes@postgresql.or     1869         [ +  - ]:           1607 :             if (stmt->compat != ECPG_COMPAT_INFORMIX_SE &&
                               1870         [ +  + ]:           1607 :                 !sqlca->sqlerrd[2] &&
 5243 peter_e@gmx.net          1871         [ +  + ]:            246 :                 (strncmp(cmdstat, "UPDATE", 6) == 0
                               1872         [ +  + ]:            245 :                  || strncmp(cmdstat, "INSERT", 6) == 0
                               1873         [ +  + ]:            244 :                  || strncmp(cmdstat, "DELETE", 6) == 0))
 6789 meskes@postgresql.or     1874                 :              4 :                 ecpg_raise(stmt->lineno, ECPG_NOT_FOUND, ECPG_SQLSTATE_NO_DATA, NULL);
 6839                          1875                 :           1607 :             break;
                               1876                 :              1 :         case PGRES_COPY_OUT:
                               1877                 :                :             {
                               1878                 :                :                 char       *buffer;
                               1879                 :                :                 int         res;
                               1880                 :                : 
 4492 alvherre@alvh.no-ip.     1881                 :              1 :                 ecpg_log("ecpg_process_output on line %d: COPY OUT data transfer in progress\n", stmt->lineno);
 6839 meskes@postgresql.or     1882                 :              4 :                 while ((res = PQgetCopyData(stmt->connection->connection,
                               1883         [ +  + ]:              4 :                                             &buffer, 0)) > 0)
                               1884                 :                :                 {
                               1885                 :              3 :                     printf("%s", buffer);
                               1886                 :              3 :                     PQfreemem(buffer);
                               1887                 :                :                 }
                               1888         [ +  - ]:              1 :                 if (res == -1)
                               1889                 :                :                 {
                               1890                 :                :                     /* COPY done */
 4492 alvherre@alvh.no-ip.     1891                 :              1 :                     PQclear(stmt->results);
                               1892                 :              1 :                     stmt->results = PQgetResult(stmt->connection->connection);
                               1893         [ +  - ]:              1 :                     if (PQresultStatus(stmt->results) == PGRES_COMMAND_OK)
                               1894                 :              1 :                         ecpg_log("ecpg_process_output on line %d: got PGRES_COMMAND_OK after PGRES_COPY_OUT\n", stmt->lineno);
                               1895                 :                :                     else
 4492 alvherre@alvh.no-ip.     1896                 :UBC           0 :                         ecpg_log("ecpg_process_output on line %d: got error after PGRES_COPY_OUT: %s", stmt->lineno, PQresultErrorMessage(stmt->results));
                               1897                 :                :                 }
 8451 meskes@postgresql.or     1898                 :CBC           1 :                 break;
                               1899                 :                :             }
 6839 meskes@postgresql.or     1900                 :UBC           0 :         default:
                               1901                 :                : 
                               1902                 :                :             /*
                               1903                 :                :              * execution should never reach this code because it is already
                               1904                 :                :              * handled in ecpg_check_PQresult()
                               1905                 :                :              */
 4492 alvherre@alvh.no-ip.     1906                 :              0 :             ecpg_log("ecpg_process_output on line %d: unknown execution status type\n",
                               1907                 :                :                      stmt->lineno);
                               1908                 :              0 :             ecpg_raise_backend(stmt->lineno, stmt->results, stmt->connection->connection, stmt->compat);
 6839 meskes@postgresql.or     1909                 :              0 :             status = false;
                               1910                 :              0 :             break;
                               1911                 :                :     }
                               1912                 :                : 
 6839 meskes@postgresql.or     1913         [ +  + ]:CBC        2662 :     if (clear_result)
                               1914                 :                :     {
 4492 alvherre@alvh.no-ip.     1915                 :           2654 :         PQclear(stmt->results);
                               1916                 :           2654 :         stmt->results = NULL;
                               1917                 :                :     }
                               1918                 :                : 
                               1919                 :                :     /* check for asynchronous returns */
 2755 tgl@sss.pgh.pa.us        1920                 :           2662 :     PQconsumeInput(stmt->connection->connection);
                               1921         [ -  + ]:           2662 :     while ((notify = PQnotifies(stmt->connection->connection)) != NULL)
                               1922                 :                :     {
 4492 alvherre@alvh.no-ip.     1923                 :UBC           0 :         ecpg_log("ecpg_process_output on line %d: asynchronous notification of \"%s\" from backend PID %d received\n",
                               1924                 :                :                  stmt->lineno, notify->relname, notify->be_pid);
 8355 meskes@postgresql.or     1925                 :              0 :         PQfreemem(notify);
 2755 tgl@sss.pgh.pa.us        1926                 :              0 :         PQconsumeInput(stmt->connection->connection);
                               1927                 :                :     }
                               1928                 :                : 
 8451 meskes@postgresql.or     1929                 :CBC        2662 :     return status;
                               1930                 :                : }
                               1931                 :                : 
                               1932                 :                : /*
                               1933                 :                :  * ecpg_do_prologue
                               1934                 :                :  *
                               1935                 :                :  * Initialize various infrastructure elements for executing the statement:
                               1936                 :                :  *
                               1937                 :                :  *  - create the statement structure
                               1938                 :                :  *  - set the C numeric locale for communicating with the backend
                               1939                 :                :  *  - preprocess the variable list of input/output parameters into
                               1940                 :                :  *    linked lists
                               1941                 :                :  */
                               1942                 :                : bool
 4492 alvherre@alvh.no-ip.     1943                 :           2682 : ecpg_do_prologue(int lineno, const int compat, const int force_indicator,
                               1944                 :                :                  const char *connection_name, const bool questionmarks,
                               1945                 :                :                  enum ECPG_statement_type statement_type, const char *query,
                               1946                 :                :                  va_list args, struct statement **stmt_out)
                               1947                 :                : {
 2653 meskes@postgresql.or     1948                 :           2682 :     struct statement *stmt = NULL;
                               1949                 :                :     struct connection *con;
                               1950                 :                :     enum ECPGttype type;
                               1951                 :                :     struct variable **list;
                               1952                 :                :     char       *prepname;
                               1953                 :                :     bool        is_prepared_name_set;
                               1954                 :                : 
 4492 alvherre@alvh.no-ip.     1955                 :           2682 :     *stmt_out = NULL;
                               1956                 :                : 
 6839 meskes@postgresql.or     1957         [ -  + ]:           2682 :     if (!query)
                               1958                 :                :     {
 6789 meskes@postgresql.or     1959                 :UBC           0 :         ecpg_raise(lineno, ECPG_EMPTY, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, NULL);
 4492 alvherre@alvh.no-ip.     1960                 :              0 :         return false;
                               1961                 :                :     }
                               1962                 :                : 
 1403 noah@leadboat.com        1963                 :CBC        2682 :     ecpg_pthreads_init();
                               1964                 :                : 
                               1965                 :           2682 :     con = ecpg_get_connection(connection_name);
                               1966                 :                : 
                               1967         [ +  + ]:           2682 :     if (!ecpg_init(con, connection_name, lineno))
                               1968                 :              7 :         return false;
                               1969                 :                : 
 4492 alvherre@alvh.no-ip.     1970                 :           2675 :     stmt = (struct statement *) ecpg_alloc(sizeof(struct statement), lineno);
                               1971                 :                : 
                               1972         [ -  + ]:           2675 :     if (stmt == NULL)
 4492 alvherre@alvh.no-ip.     1973                 :UBC           0 :         return false;
                               1974                 :                : 
                               1975                 :                :     /*
                               1976                 :                :      * Make sure we do NOT honor the locale for numeric input/output since the
                               1977                 :                :      * database wants the standard decimal point.  If available, use
                               1978                 :                :      * uselocale() for this because it's thread-safe.  Windows doesn't have
                               1979                 :                :      * that, but it does have _configthreadlocale().
                               1980                 :                :      */
                               1981                 :                : #ifdef HAVE_USELOCALE
                               1982                 :                : 
                               1983                 :                :     /*
                               1984                 :                :      * Since ecpg_init() succeeded, we have a connection.  Any successful
                               1985                 :                :      * connection initializes ecpg_clocale.
                               1986                 :                :      */
  403 peter@eisentraut.org     1987         [ -  + ]:CBC        2675 :     Assert(ecpg_clocale);
                               1988                 :           2675 :     stmt->oldlocale = uselocale(ecpg_clocale);
                               1989         [ -  + ]:           2675 :     if (stmt->oldlocale == (locale_t) 0)
                               1990                 :                :     {
  403 peter@eisentraut.org     1991                 :UBC           0 :         ecpg_do_epilogue(stmt);
                               1992                 :              0 :         return false;
                               1993                 :                :     }
                               1994                 :                : #else
                               1995                 :                : #ifdef WIN32
                               1996                 :                :     stmt->oldthreadlocale = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
                               1997                 :                :     if (stmt->oldthreadlocale == -1)
                               1998                 :                :     {
                               1999                 :                :         ecpg_do_epilogue(stmt);
                               2000                 :                :         return false;
                               2001                 :                :     }
                               2002                 :                : #endif
                               2003                 :                :     stmt->oldlocale = ecpg_strdup(setlocale(LC_NUMERIC, NULL), lineno,
                               2004                 :                :                                   NULL);
                               2005                 :                :     if (stmt->oldlocale == NULL)
                               2006                 :                :     {
                               2007                 :                :         ecpg_do_epilogue(stmt);
                               2008                 :                :         return false;
                               2009                 :                :     }
                               2010                 :                :     setlocale(LC_NUMERIC, "C");
                               2011                 :                : #endif
                               2012                 :                : 
                               2013                 :                :     /*
                               2014                 :                :      * If statement type is ECPGst_prepnormal we are supposed to prepare the
                               2015                 :                :      * statement before executing them
                               2016                 :                :      */
 6839 meskes@postgresql.or     2017         [ +  + ]:CBC        2675 :     if (statement_type == ECPGst_prepnormal)
                               2018                 :                :     {
 5359                          2019         [ -  + ]:              8 :         if (!ecpg_auto_prepare(lineno, connection_name, compat, &prepname, query))
                               2020                 :                :         {
 4492 alvherre@alvh.no-ip.     2021                 :UBC           0 :             ecpg_do_epilogue(stmt);
                               2022                 :              0 :             return false;
                               2023                 :                :         }
                               2024                 :                : 
                               2025                 :                :         /*
                               2026                 :                :          * statement is now prepared, so instead of the query we have to
                               2027                 :                :          * execute the name
                               2028                 :                :          */
 6839 meskes@postgresql.or     2029                 :CBC           8 :         stmt->command = prepname;
                               2030                 :              8 :         statement_type = ECPGst_execute;
                               2031                 :                :     }
                               2032                 :                :     else
                               2033                 :                :     {
  286 michael@paquier.xyz      2034                 :GNC        2667 :         stmt->command = ecpg_strdup(query, lineno, NULL);
                               2035         [ -  + ]:           2667 :         if (!stmt->command)
                               2036                 :                :         {
  286 michael@paquier.xyz      2037                 :UNC           0 :             ecpg_do_epilogue(stmt);
                               2038                 :              0 :             return false;
                               2039                 :                :         }
                               2040                 :                :     }
                               2041                 :                : 
 6839 meskes@postgresql.or     2042                 :CBC        2675 :     stmt->name = NULL;
                               2043                 :                : 
                               2044         [ +  + ]:           2675 :     if (statement_type == ECPGst_execute)
                               2045                 :                :     {
                               2046                 :                :         /* if we have an EXECUTE command, only the name is send */
 6194                          2047                 :            834 :         char       *command = ecpg_prepared(stmt->command, con);
                               2048                 :                : 
 6839                          2049         [ +  - ]:            834 :         if (command)
                               2050                 :                :         {
                               2051                 :            834 :             stmt->name = stmt->command;
  286 michael@paquier.xyz      2052                 :GNC         834 :             stmt->command = ecpg_strdup(command, lineno, NULL);
                               2053         [ -  + ]:            834 :             if (!stmt->command)
                               2054                 :                :             {
  286 michael@paquier.xyz      2055                 :UNC           0 :                 ecpg_do_epilogue(stmt);
                               2056                 :              0 :                 return false;
                               2057                 :                :             }
                               2058                 :                :         }
                               2059                 :                :         else
                               2060                 :                :         {
 6789 meskes@postgresql.or     2061                 :UBC           0 :             ecpg_raise(lineno, ECPG_INVALID_STMT, ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME, stmt->command);
 4492 alvherre@alvh.no-ip.     2062                 :              0 :             ecpg_do_epilogue(stmt);
 3183 peter_e@gmx.net          2063                 :              0 :             return false;
                               2064                 :                :         }
                               2065                 :                :     }
                               2066                 :                :     /* name of PREPARE AS will be set in loop of inlist */
                               2067                 :                : 
 6948 meskes@postgresql.or     2068                 :CBC        2675 :     stmt->connection = con;
                               2069                 :           2675 :     stmt->lineno = lineno;
                               2070                 :           2675 :     stmt->compat = compat;
                               2071                 :           2675 :     stmt->force_indicator = force_indicator;
 6839                          2072                 :           2675 :     stmt->questionmarks = questionmarks;
                               2073                 :           2675 :     stmt->statement_type = statement_type;
                               2074                 :                : 
                               2075                 :                :     /*------
                               2076                 :                :      * create a list of variables
                               2077                 :                :      *
                               2078                 :                :      * The variables are listed with input variables preceding output
                               2079                 :                :      * variables.  The end of each group is marked by an end marker.
                               2080                 :                :      * Per variable we list:
                               2081                 :                :      *
                               2082                 :                :      * type - as defined in ecpgtype.h
                               2083                 :                :      * value - where to store the data
                               2084                 :                :      * varcharsize - length of string in case we have a stringvariable, else 0
                               2085                 :                :      * arraysize - 0 for pointer (we don't know the size of the array), 1 for
                               2086                 :                :      * simple variable, size for arrays
                               2087                 :                :      * offset - offset between ith and (i+1)th entry in an array, normally
                               2088                 :                :      * that means sizeof(type)
                               2089                 :                :      * ind_type - type of indicator variable
                               2090                 :                :      * ind_pointer - pointer to indicator variable
                               2091                 :                :      * ind_varcharsize - empty
                               2092                 :                :      * ind_arrsize - arraysize of indicator array
                               2093                 :                :      * ind_offset - indicator offset
                               2094                 :                :      *------
                               2095                 :                :      */
                               2096                 :                : 
 2540                          2097                 :           2675 :     is_prepared_name_set = false;
                               2098                 :                : 
 6948                          2099                 :           2675 :     list = &(stmt->inlist);
                               2100                 :                : 
                               2101                 :           2675 :     type = va_arg(args, enum ECPGttype);
                               2102                 :                : 
                               2103         [ +  + ]:           8507 :     while (type != ECPGt_EORT)
                               2104                 :                :     {
                               2105         [ +  + ]:           5832 :         if (type == ECPGt_EOIT)
                               2106                 :           2675 :             list = &(stmt->outlist);
                               2107                 :                :         else
                               2108                 :                :         {
                               2109                 :                :             struct variable *var,
                               2110                 :                :                        *ptr;
                               2111                 :                : 
 6789                          2112         [ -  + ]:           3157 :             if (!(var = (struct variable *) ecpg_alloc(sizeof(struct variable), lineno)))
                               2113                 :                :             {
 4492 alvherre@alvh.no-ip.     2114                 :UBC           0 :                 ecpg_do_epilogue(stmt);
 6948 meskes@postgresql.or     2115                 :              0 :                 return false;
                               2116                 :                :             }
                               2117                 :                : 
 6948 meskes@postgresql.or     2118                 :CBC        3157 :             var->type = type;
                               2119                 :           3157 :             var->pointer = va_arg(args, char *);
                               2120                 :                : 
                               2121                 :           3157 :             var->varcharsize = va_arg(args, long);
                               2122                 :           3157 :             var->arrsize = va_arg(args, long);
                               2123                 :           3157 :             var->offset = va_arg(args, long);
                               2124                 :                : 
                               2125                 :                :             /*
                               2126                 :                :              * Unknown array size means pointer to an array. Unknown
                               2127                 :                :              * varcharsize usually also means pointer. But if the type is
                               2128                 :                :              * character and the array size is known, it is an array of
                               2129                 :                :              * pointers to char, so use var->pointer as it is.
                               2130                 :                :              */
 4382                          2131         [ +  + ]:           3157 :             if (var->arrsize == 0 ||
      bruce@momjian.us         2132   [ +  +  -  +  :           2323 :                 (var->varcharsize == 0 && ((var->type != ECPGt_char && var->type != ECPGt_unsigned_char) || (var->arrsize <= 1))))
                                        -  -  +  - ]
 6948 meskes@postgresql.or     2133                 :            882 :                 var->value = *((char **) (var->pointer));
                               2134                 :                :             else
                               2135                 :           2275 :                 var->value = var->pointer;
                               2136                 :                : 
                               2137                 :                :             /*
                               2138                 :                :              * negative values are used to indicate an array without given
                               2139                 :                :              * bounds
                               2140                 :                :              */
                               2141                 :                :             /* reset to zero for us */
                               2142         [ +  + ]:           3157 :             if (var->arrsize < 0)
                               2143                 :             14 :                 var->arrsize = 0;
                               2144         [ -  + ]:           3157 :             if (var->varcharsize < 0)
 6948 meskes@postgresql.or     2145                 :UBC           0 :                 var->varcharsize = 0;
                               2146                 :                : 
 6948 meskes@postgresql.or     2147                 :CBC        3157 :             var->next = NULL;
                               2148                 :                : 
                               2149                 :           3157 :             var->ind_type = va_arg(args, enum ECPGttype);
                               2150                 :           3157 :             var->ind_pointer = va_arg(args, char *);
                               2151                 :           3157 :             var->ind_varcharsize = va_arg(args, long);
                               2152                 :           3157 :             var->ind_arrsize = va_arg(args, long);
                               2153                 :           3157 :             var->ind_offset = va_arg(args, long);
                               2154                 :                : 
                               2155         [ +  + ]:           3157 :             if (var->ind_type != ECPGt_NO_INDICATOR
                               2156   [ +  -  -  + ]:            112 :                 && (var->ind_arrsize == 0 || var->ind_varcharsize == 0))
 6948 meskes@postgresql.or     2157                 :UBC           0 :                 var->ind_value = *((char **) (var->ind_pointer));
                               2158                 :                :             else
 6948 meskes@postgresql.or     2159                 :CBC        3157 :                 var->ind_value = var->ind_pointer;
                               2160                 :                : 
                               2161                 :                :             /*
                               2162                 :                :              * negative values are used to indicate an array without given
                               2163                 :                :              * bounds
                               2164                 :                :              */
                               2165                 :                :             /* reset to zero for us */
                               2166         [ +  + ]:           3157 :             if (var->ind_arrsize < 0)
                               2167                 :             14 :                 var->ind_arrsize = 0;
                               2168         [ -  + ]:           3157 :             if (var->ind_varcharsize < 0)
 6948 meskes@postgresql.or     2169                 :UBC           0 :                 var->ind_varcharsize = 0;
                               2170                 :                : 
                               2171                 :                :             /* if variable is NULL, the statement hasn't been prepared */
 6948 meskes@postgresql.or     2172         [ -  + ]:CBC        3157 :             if (var->pointer == NULL)
                               2173                 :                :             {
 6789 meskes@postgresql.or     2174                 :UBC           0 :                 ecpg_raise(lineno, ECPG_INVALID_STMT, ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME, NULL);
                               2175                 :              0 :                 ecpg_free(var);
 4492 alvherre@alvh.no-ip.     2176                 :              0 :                 ecpg_do_epilogue(stmt);
 6948 meskes@postgresql.or     2177                 :              0 :                 return false;
                               2178                 :                :             }
                               2179                 :                : 
 4492 alvherre@alvh.no-ip.     2180   [ +  +  +  + ]:CBC        3477 :             for (ptr = *list; ptr && ptr->next; ptr = ptr->next)
                               2181                 :                :                 ;
                               2182                 :                : 
 6948 meskes@postgresql.or     2183         [ +  + ]:           3157 :             if (ptr == NULL)
                               2184                 :           2414 :                 *list = var;
                               2185                 :                :             else
                               2186                 :            743 :                 ptr->next = var;
                               2187                 :                : 
 2540                          2188   [ +  -  +  + ]:           3157 :             if (!is_prepared_name_set && stmt->statement_type == ECPGst_prepare)
                               2189                 :                :             {
  286 michael@paquier.xyz      2190                 :GNC           5 :                 stmt->name = ecpg_strdup(var->value, lineno, NULL);
                               2191         [ -  + ]:              5 :                 if (!stmt->name)
                               2192                 :                :                 {
  286 michael@paquier.xyz      2193                 :UNC           0 :                     ecpg_do_epilogue(stmt);
                               2194                 :              0 :                     return false;
                               2195                 :                :                 }
 2540 meskes@postgresql.or     2196                 :CBC           5 :                 is_prepared_name_set = true;
                               2197                 :                :             }
                               2198                 :                :         }
                               2199                 :                : 
 6948                          2200                 :           5832 :         type = va_arg(args, enum ECPGttype);
                               2201                 :                :     }
                               2202                 :                : 
                               2203                 :                :     /* are we connected? */
 8451                          2204   [ +  -  -  + ]:           2675 :     if (con == NULL || con->connection == NULL)
                               2205                 :                :     {
 6319 peter_e@gmx.net          2206         [ #  # ]:UBC           0 :         ecpg_raise(lineno, ECPG_NOT_CONN, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, (con) ? con->name : ecpg_gettext("<empty>"));
 4492 alvherre@alvh.no-ip.     2207                 :              0 :         ecpg_do_epilogue(stmt);
 2540 meskes@postgresql.or     2208                 :              0 :         return false;
                               2209                 :                :     }
                               2210                 :                : 
 2540 meskes@postgresql.or     2211   [ +  +  -  + ]:CBC        2675 :     if (!is_prepared_name_set && stmt->statement_type == ECPGst_prepare)
                               2212                 :                :     {
 2540 meskes@postgresql.or     2213         [ #  # ]:UBC           0 :         ecpg_raise(lineno, ECPG_TOO_FEW_ARGUMENTS, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, (con) ? con->name : ecpg_gettext("<empty>"));
                               2214                 :              0 :         ecpg_do_epilogue(stmt);
 8451                          2215                 :              0 :         return false;
                               2216                 :                :     }
                               2217                 :                : 
                               2218                 :                :     /* initialize auto_mem struct */
 6789 meskes@postgresql.or     2219                 :CBC        2675 :     ecpg_clear_auto_mem();
                               2220                 :                : 
 4492 alvherre@alvh.no-ip.     2221                 :           2675 :     *stmt_out = stmt;
                               2222                 :                : 
                               2223                 :           2675 :     return true;
                               2224                 :                : }
                               2225                 :                : 
                               2226                 :                : /*
                               2227                 :                :  * ecpg_do_epilogue
                               2228                 :                :  *    Restore the application locale and free the statement structure.
                               2229                 :                :  */
                               2230                 :                : void
 3240 tgl@sss.pgh.pa.us        2231                 :           2682 : ecpg_do_epilogue(struct statement *stmt)
                               2232                 :                : {
 4492 alvherre@alvh.no-ip.     2233         [ +  + ]:           2682 :     if (stmt == NULL)
                               2234                 :              7 :         return;
                               2235                 :                : 
                               2236                 :                : #ifdef HAVE_USELOCALE
  403 peter@eisentraut.org     2237         [ +  - ]:           2675 :     if (stmt->oldlocale != (locale_t) 0)
                               2238                 :           2675 :         uselocale(stmt->oldlocale);
                               2239                 :                : #else
                               2240                 :                :     if (stmt->oldlocale)
                               2241                 :                :     {
                               2242                 :                :         setlocale(LC_NUMERIC, stmt->oldlocale);
                               2243                 :                : #ifdef WIN32
                               2244                 :                :         _configthreadlocale(stmt->oldthreadlocale);
                               2245                 :                : #endif
                               2246                 :                :     }
                               2247                 :                : #endif
                               2248                 :                : 
 8451 meskes@postgresql.or     2249                 :           2675 :     free_statement(stmt);
                               2250                 :                : }
                               2251                 :                : 
                               2252                 :                : /*
                               2253                 :                :  * Execute SQL statements in the backend.
                               2254                 :                :  * The input/output parameters (variable argument list) are passed
                               2255                 :                :  * in a va_list, so other functions can use this interface.
                               2256                 :                :  */
                               2257                 :                : bool
 4492 alvherre@alvh.no-ip.     2258                 :           2682 : ecpg_do(const int lineno, const int compat, const int force_indicator, const char *connection_name, const bool questionmarks, const int st, const char *query, va_list args)
                               2259                 :                : {
                               2260                 :           2682 :     struct statement *stmt = NULL;
                               2261                 :                : 
                               2262         [ +  + ]:           2682 :     if (!ecpg_do_prologue(lineno, compat, force_indicator, connection_name,
                               2263                 :                :                           questionmarks, (enum ECPG_statement_type) st,
                               2264                 :                :                           query, args, &stmt))
                               2265                 :              7 :         goto fail;
                               2266                 :                : 
                               2267         [ -  + ]:           2675 :     if (!ecpg_build_params(stmt))
 4492 alvherre@alvh.no-ip.     2268                 :UBC           0 :         goto fail;
                               2269                 :                : 
 4492 alvherre@alvh.no-ip.     2270         [ -  + ]:CBC        2675 :     if (!ecpg_autostart_transaction(stmt))
 4492 alvherre@alvh.no-ip.     2271                 :UBC           0 :         goto fail;
                               2272                 :                : 
 4492 alvherre@alvh.no-ip.     2273         [ +  + ]:CBC        2675 :     if (!ecpg_execute(stmt))
                               2274                 :             13 :         goto fail;
                               2275                 :                : 
                               2276         [ +  + ]:           2662 :     if (!ecpg_process_output(stmt, true))
                               2277                 :             28 :         goto fail;
                               2278                 :                : 
                               2279                 :           2634 :     ecpg_do_epilogue(stmt);
                               2280                 :           2634 :     return true;
                               2281                 :                : 
                               2282                 :             48 : fail:
                               2283                 :             48 :     ecpg_do_epilogue(stmt);
                               2284                 :             48 :     return false;
                               2285                 :                : }
                               2286                 :                : 
                               2287                 :                : /*
                               2288                 :                :  * Execute SQL statements in the backend.
                               2289                 :                :  * The input/output parameters are passed as variable-length argument list.
                               2290                 :                :  */
                               2291                 :                : bool
                               2292                 :           2682 : ECPGdo(const int lineno, const int compat, const int force_indicator, const char *connection_name, const bool questionmarks, const int st, const char *query,...)
                               2293                 :                : {
                               2294                 :                :     va_list     args;
                               2295                 :                :     bool        ret;
                               2296                 :                : 
                               2297                 :           2682 :     va_start(args, query);
 2419 tgl@sss.pgh.pa.us        2298                 :           2682 :     ret = ecpg_do(lineno, compat, force_indicator, connection_name,
                               2299                 :                :                   questionmarks, st, query, args);
 4492 alvherre@alvh.no-ip.     2300                 :           2682 :     va_end(args);
                               2301                 :                : 
                               2302                 :           2682 :     return ret;
                               2303                 :                : }
                               2304                 :                : 
                               2305                 :                : /* old descriptor interface */
                               2306                 :                : bool
 8451 meskes@postgresql.or     2307                 :UBC           0 : ECPGdo_descriptor(int line, const char *connection,
                               2308                 :                :                   const char *descriptor, const char *query)
                               2309                 :                : {
 5350 peter_e@gmx.net          2310                 :              0 :     return ECPGdo(line, ECPG_COMPAT_PGSQL, true, connection, '\0', 0, query, ECPGt_EOIT,
                               2311                 :                :                   ECPGt_descriptor, descriptor, 0L, 0L, 0L,
                               2312                 :                :                   ECPGt_NO_INDICATOR, NULL, 0L, 0L, 0L, ECPGt_EORT);
                               2313                 :                : }
        

Generated by: LCOV version 2.5.0-beta