LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/ecpglib - sqlda.c (source / functions) Coverage Total Hit
Test: Code coverage Lines: 0.0 % 345 0
Test Date: 2026-01-26 10:56:24 Functions: 0.0 % 10 0
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /*
       2              :  * SQLDA support routines
       3              :  *
       4              :  * The allocated memory area pointed by an sqlda pointer
       5              :  * contains both the metadata and the data, so freeing up
       6              :  * is a simple free(sqlda) as expected by the ESQL/C examples.
       7              :  */
       8              : 
       9              : #define POSTGRES_ECPG_INTERNAL
      10              : #include "postgres_fe.h"
      11              : 
      12              : #include "catalog/pg_type_d.h"
      13              : #include "decimal.h"
      14              : #include "ecpg-pthread-win32.h"
      15              : #include "ecpgerrno.h"
      16              : #include "ecpglib.h"
      17              : #include "ecpglib_extern.h"
      18              : #include "ecpgtype.h"
      19              : #include "sqlca.h"
      20              : #include "sqlda-compat.h"
      21              : #include "sqlda-native.h"
      22              : 
      23              : /*
      24              :  * Compute the next variable's offset with
      25              :  * the current variable's size and alignment.
      26              :  *
      27              :  *
      28              :  * Returns:
      29              :  * - the current variable's offset in *current
      30              :  * - the next variable's offset in *next
      31              :  */
      32              : static void
      33            0 : ecpg_sqlda_align_add_size(long offset, int alignment, int size, long *current, long *next)
      34              : {
      35            0 :         if (offset % alignment)
      36            0 :                 offset += alignment - (offset % alignment);
      37            0 :         if (current)
      38            0 :                 *current = offset;
      39            0 :         offset += size;
      40            0 :         if (next)
      41            0 :                 *next = offset;
      42            0 : }
      43              : 
      44              : static long
      45            0 : sqlda_compat_empty_size(const PGresult *res)
      46              : {
      47            0 :         long            offset;
      48            0 :         int                     i;
      49            0 :         int                     sqld = PQnfields(res);
      50              : 
      51              :         /* Initial size to store main structure and field structures */
      52            0 :         offset = sizeof(struct sqlda_compat) + sqld * sizeof(struct sqlvar_compat);
      53              : 
      54              :         /* Add space for field names */
      55            0 :         for (i = 0; i < sqld; i++)
      56            0 :                 offset += strlen(PQfname(res, i)) + 1;
      57              : 
      58              :         /* Add padding to the first field value */
      59            0 :         ecpg_sqlda_align_add_size(offset, sizeof(int), 0, &offset, NULL);
      60              : 
      61            0 :         return offset;
      62            0 : }
      63              : 
      64              : static long
      65            0 : sqlda_common_total_size(const PGresult *res, int row, enum COMPAT_MODE compat, long offset)
      66              : {
      67            0 :         int                     sqld = PQnfields(res);
      68            0 :         int                     i;
      69            0 :         long            next_offset;
      70              : 
      71              :         /* Add space for the field values */
      72            0 :         for (i = 0; i < sqld; i++)
      73              :         {
      74            0 :                 enum ECPGttype type = sqlda_dynamic_type(PQftype(res, i), compat);
      75              : 
      76            0 :                 switch (type)
      77              :                 {
      78              :                         case ECPGt_short:
      79              :                         case ECPGt_unsigned_short:
      80            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(short), sizeof(short), &offset, &next_offset);
      81            0 :                                 break;
      82              :                         case ECPGt_int:
      83              :                         case ECPGt_unsigned_int:
      84            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(int), &offset, &next_offset);
      85            0 :                                 break;
      86              :                         case ECPGt_long:
      87              :                         case ECPGt_unsigned_long:
      88            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(long), sizeof(long), &offset, &next_offset);
      89            0 :                                 break;
      90              :                         case ECPGt_long_long:
      91              :                         case ECPGt_unsigned_long_long:
      92            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(long long), sizeof(long long), &offset, &next_offset);
      93            0 :                                 break;
      94              :                         case ECPGt_bool:
      95            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(bool), sizeof(bool), &offset, &next_offset);
      96            0 :                                 break;
      97              :                         case ECPGt_float:
      98            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(float), sizeof(float), &offset, &next_offset);
      99            0 :                                 break;
     100              :                         case ECPGt_double:
     101            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(double), sizeof(double), &offset, &next_offset);
     102            0 :                                 break;
     103              :                         case ECPGt_decimal:
     104            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(decimal), &offset, &next_offset);
     105            0 :                                 break;
     106              :                         case ECPGt_numeric:
     107              : 
     108              :                                 /*
     109              :                                  * We align the numeric struct to allow it to store a pointer,
     110              :                                  * while the digits array is aligned to int (which seems like
     111              :                                  * overkill, but let's keep compatibility here).
     112              :                                  *
     113              :                                  * Unfortunately we need to deconstruct the value twice to
     114              :                                  * find out the digits array's size and then later fill it.
     115              :                                  */
     116            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(NumericDigit *), sizeof(numeric), &offset, &next_offset);
     117            0 :                                 if (!PQgetisnull(res, row, i))
     118              :                                 {
     119            0 :                                         char       *val = PQgetvalue(res, row, i);
     120            0 :                                         numeric    *num;
     121              : 
     122            0 :                                         num = PGTYPESnumeric_from_asc(val, NULL);
     123            0 :                                         if (!num)
     124            0 :                                                 break;
     125            0 :                                         if (num->buf)
     126            0 :                                                 ecpg_sqlda_align_add_size(next_offset, sizeof(int), num->digits - num->buf + num->ndigits, &offset, &next_offset);
     127            0 :                                         PGTYPESnumeric_free(num);
     128            0 :                                 }
     129            0 :                                 break;
     130              :                         case ECPGt_date:
     131            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(date), sizeof(date), &offset, &next_offset);
     132            0 :                                 break;
     133              :                         case ECPGt_timestamp:
     134            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(timestamp), &offset, &next_offset);
     135            0 :                                 break;
     136              :                         case ECPGt_interval:
     137            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(interval), &offset, &next_offset);
     138            0 :                                 break;
     139              :                         case ECPGt_char:
     140              :                         case ECPGt_unsigned_char:
     141            0 :                         case ECPGt_string:
     142              :                         default:
     143              :                                 {
     144            0 :                                         long            datalen = strlen(PQgetvalue(res, row, i)) + 1;
     145              : 
     146            0 :                                         ecpg_sqlda_align_add_size(offset, sizeof(int), datalen, &offset, &next_offset);
     147              :                                         break;
     148            0 :                                 }
     149              :                 }
     150            0 :                 offset = next_offset;
     151            0 :         }
     152            0 :         return offset;
     153            0 : }
     154              : 
     155              : 
     156              : static long
     157            0 : sqlda_compat_total_size(const PGresult *res, int row, enum COMPAT_MODE compat)
     158              : {
     159            0 :         long            offset;
     160              : 
     161            0 :         offset = sqlda_compat_empty_size(res);
     162              : 
     163            0 :         if (row < 0)
     164            0 :                 return offset;
     165              : 
     166            0 :         offset = sqlda_common_total_size(res, row, compat, offset);
     167            0 :         return offset;
     168            0 : }
     169              : 
     170              : static long
     171            0 : sqlda_native_empty_size(const PGresult *res)
     172              : {
     173            0 :         long            offset;
     174            0 :         int                     sqld = PQnfields(res);
     175              : 
     176              :         /* Initial size to store main structure and field structures */
     177            0 :         offset = sizeof(struct sqlda_struct) + (sqld - 1) * sizeof(struct sqlvar_struct);
     178              : 
     179              :         /* Add padding to the first field value */
     180            0 :         ecpg_sqlda_align_add_size(offset, sizeof(int), 0, &offset, NULL);
     181              : 
     182            0 :         return offset;
     183            0 : }
     184              : 
     185              : static long
     186            0 : sqlda_native_total_size(const PGresult *res, int row, enum COMPAT_MODE compat)
     187              : {
     188            0 :         long            offset;
     189              : 
     190            0 :         offset = sqlda_native_empty_size(res);
     191              : 
     192            0 :         if (row < 0)
     193            0 :                 return offset;
     194              : 
     195            0 :         offset = sqlda_common_total_size(res, row, compat, offset);
     196            0 :         return offset;
     197            0 : }
     198              : 
     199              : /*
     200              :  * Build "struct sqlda_compat" (metadata only) from PGresult
     201              :  * leaving enough space for the field values in
     202              :  * the given row number
     203              :  */
     204              : struct sqlda_compat *
     205            0 : ecpg_build_compat_sqlda(int line, PGresult *res, int row, enum COMPAT_MODE compat)
     206              : {
     207            0 :         struct sqlda_compat *sqlda;
     208            0 :         struct sqlvar_compat *sqlvar;
     209            0 :         char       *fname;
     210            0 :         long            size;
     211            0 :         int                     sqld;
     212            0 :         int                     i;
     213              : 
     214            0 :         size = sqlda_compat_total_size(res, row, compat);
     215            0 :         sqlda = (struct sqlda_compat *) ecpg_alloc(size, line);
     216            0 :         if (!sqlda)
     217            0 :                 return NULL;
     218              : 
     219            0 :         memset(sqlda, 0, size);
     220            0 :         sqlvar = (struct sqlvar_compat *) (sqlda + 1);
     221            0 :         sqld = PQnfields(res);
     222            0 :         fname = (char *) (sqlvar + sqld);
     223              : 
     224            0 :         sqlda->sqld = sqld;
     225            0 :         ecpg_log("ecpg_build_compat_sqlda on line %d sqld = %d\n", line, sqld);
     226            0 :         sqlda->desc_occ = size;              /* cheat here, keep the full allocated size */
     227            0 :         sqlda->sqlvar = sqlvar;
     228              : 
     229            0 :         for (i = 0; i < sqlda->sqld; i++)
     230              :         {
     231            0 :                 sqlda->sqlvar[i].sqltype = sqlda_dynamic_type(PQftype(res, i), compat);
     232            0 :                 strcpy(fname, PQfname(res, i));
     233            0 :                 sqlda->sqlvar[i].sqlname = fname;
     234            0 :                 fname += strlen(sqlda->sqlvar[i].sqlname) + 1;
     235              : 
     236              :                 /*
     237              :                  * this is reserved for future use, so we leave it empty for the time
     238              :                  * being
     239              :                  */
     240              :                 /* sqlda->sqlvar[i].sqlformat = (char *) (long) PQfformat(res, i); */
     241            0 :                 sqlda->sqlvar[i].sqlxid = PQftype(res, i);
     242            0 :                 sqlda->sqlvar[i].sqltypelen = PQfsize(res, i);
     243            0 :         }
     244              : 
     245            0 :         return sqlda;
     246            0 : }
     247              : 
     248              : /*
     249              :  * Sets values from PGresult.
     250              :  */
     251              : static int16 value_is_null = -1;
     252              : static int16 value_is_not_null = 0;
     253              : 
     254              : void
     255            0 : ecpg_set_compat_sqlda(int lineno, struct sqlda_compat **_sqlda, const PGresult *res, int row, enum COMPAT_MODE compat)
     256              : {
     257            0 :         struct sqlda_compat *sqlda = (*_sqlda);
     258            0 :         int                     i;
     259            0 :         long            offset,
     260              :                                 next_offset;
     261              : 
     262            0 :         if (row < 0)
     263            0 :                 return;
     264              : 
     265              :         /* Offset for the first field value */
     266            0 :         offset = sqlda_compat_empty_size(res);
     267              : 
     268              :         /*
     269              :          * Set sqlvar[i]->sqldata pointers and convert values to correct format
     270              :          */
     271            0 :         for (i = 0; i < sqlda->sqld; i++)
     272              :         {
     273            0 :                 int                     isnull;
     274            0 :                 int                     datalen;
     275            0 :                 bool            set_data = true;
     276              : 
     277            0 :                 switch (sqlda->sqlvar[i].sqltype)
     278              :                 {
     279              :                         case ECPGt_short:
     280              :                         case ECPGt_unsigned_short:
     281            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(short), sizeof(short), &offset, &next_offset);
     282            0 :                                 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
     283            0 :                                 sqlda->sqlvar[i].sqllen = sizeof(short);
     284            0 :                                 break;
     285              :                         case ECPGt_int:
     286              :                         case ECPGt_unsigned_int:
     287            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(int), &offset, &next_offset);
     288            0 :                                 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
     289            0 :                                 sqlda->sqlvar[i].sqllen = sizeof(int);
     290            0 :                                 break;
     291              :                         case ECPGt_long:
     292              :                         case ECPGt_unsigned_long:
     293            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(long), sizeof(long), &offset, &next_offset);
     294            0 :                                 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
     295            0 :                                 sqlda->sqlvar[i].sqllen = sizeof(long);
     296            0 :                                 break;
     297              :                         case ECPGt_long_long:
     298              :                         case ECPGt_unsigned_long_long:
     299            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(long long), sizeof(long long), &offset, &next_offset);
     300            0 :                                 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
     301            0 :                                 sqlda->sqlvar[i].sqllen = sizeof(long long);
     302            0 :                                 break;
     303              :                         case ECPGt_bool:
     304            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(bool), sizeof(bool), &offset, &next_offset);
     305            0 :                                 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
     306            0 :                                 sqlda->sqlvar[i].sqllen = sizeof(bool);
     307            0 :                                 break;
     308              :                         case ECPGt_float:
     309            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(float), sizeof(float), &offset, &next_offset);
     310            0 :                                 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
     311            0 :                                 sqlda->sqlvar[i].sqllen = sizeof(float);
     312            0 :                                 break;
     313              :                         case ECPGt_double:
     314            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(double), sizeof(double), &offset, &next_offset);
     315            0 :                                 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
     316            0 :                                 sqlda->sqlvar[i].sqllen = sizeof(double);
     317            0 :                                 break;
     318              :                         case ECPGt_decimal:
     319            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(decimal), &offset, &next_offset);
     320            0 :                                 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
     321            0 :                                 sqlda->sqlvar[i].sqllen = sizeof(decimal);
     322            0 :                                 break;
     323              :                         case ECPGt_numeric:
     324              :                                 {
     325            0 :                                         numeric    *num;
     326            0 :                                         char       *val;
     327              : 
     328            0 :                                         set_data = false;
     329              : 
     330            0 :                                         ecpg_sqlda_align_add_size(offset, sizeof(NumericDigit *), sizeof(numeric), &offset, &next_offset);
     331            0 :                                         sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
     332            0 :                                         sqlda->sqlvar[i].sqllen = sizeof(numeric);
     333              : 
     334            0 :                                         if (PQgetisnull(res, row, i))
     335              :                                         {
     336            0 :                                                 ECPGset_noind_null(ECPGt_numeric, sqlda->sqlvar[i].sqldata);
     337            0 :                                                 break;
     338              :                                         }
     339              : 
     340            0 :                                         val = PQgetvalue(res, row, i);
     341            0 :                                         num = PGTYPESnumeric_from_asc(val, NULL);
     342            0 :                                         if (!num)
     343              :                                         {
     344            0 :                                                 ECPGset_noind_null(ECPGt_numeric, sqlda->sqlvar[i].sqldata);
     345            0 :                                                 break;
     346              :                                         }
     347              : 
     348            0 :                                         memcpy(sqlda->sqlvar[i].sqldata, num, sizeof(numeric));
     349              : 
     350            0 :                                         if (num->buf)
     351              :                                         {
     352            0 :                                                 ecpg_sqlda_align_add_size(next_offset, sizeof(int), num->digits - num->buf + num->ndigits, &offset, &next_offset);
     353            0 :                                                 memcpy((char *) sqlda + offset, num->buf, num->digits - num->buf + num->ndigits);
     354              : 
     355            0 :                                                 ((numeric *) sqlda->sqlvar[i].sqldata)->buf = (NumericDigit *) sqlda + offset;
     356            0 :                                                 ((numeric *) sqlda->sqlvar[i].sqldata)->digits = (NumericDigit *) sqlda + offset + (num->digits - num->buf);
     357            0 :                                         }
     358              : 
     359            0 :                                         PGTYPESnumeric_free(num);
     360              : 
     361            0 :                                         break;
     362            0 :                                 }
     363              :                         case ECPGt_date:
     364            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(date), sizeof(date), &offset, &next_offset);
     365            0 :                                 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
     366            0 :                                 sqlda->sqlvar[i].sqllen = sizeof(date);
     367            0 :                                 break;
     368              :                         case ECPGt_timestamp:
     369            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(timestamp), &offset, &next_offset);
     370            0 :                                 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
     371            0 :                                 sqlda->sqlvar[i].sqllen = sizeof(timestamp);
     372            0 :                                 break;
     373              :                         case ECPGt_interval:
     374            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(interval), &offset, &next_offset);
     375            0 :                                 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
     376            0 :                                 sqlda->sqlvar[i].sqllen = sizeof(interval);
     377            0 :                                 break;
     378              :                         case ECPGt_char:
     379              :                         case ECPGt_unsigned_char:
     380            0 :                         case ECPGt_string:
     381              :                         default:
     382            0 :                                 datalen = strlen(PQgetvalue(res, row, i)) + 1;
     383            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(int), datalen, &offset, &next_offset);
     384            0 :                                 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
     385            0 :                                 sqlda->sqlvar[i].sqllen = datalen;
     386            0 :                                 if (datalen > 32768)
     387            0 :                                         sqlda->sqlvar[i].sqlilongdata = sqlda->sqlvar[i].sqldata;
     388            0 :                                 break;
     389              :                 }
     390              : 
     391            0 :                 isnull = PQgetisnull(res, row, i);
     392            0 :                 ecpg_log("ecpg_set_compat_sqlda on line %d row %d col %d %s\n", lineno, row, i, isnull ? "IS NULL" : "IS NOT NULL");
     393            0 :                 sqlda->sqlvar[i].sqlind = isnull ? &value_is_null : &value_is_not_null;
     394            0 :                 sqlda->sqlvar[i].sqlitype = ECPGt_short;
     395            0 :                 sqlda->sqlvar[i].sqlilen = sizeof(short);
     396            0 :                 if (!isnull)
     397              :                 {
     398            0 :                         if (set_data)
     399            0 :                                 ecpg_get_data(res, row, i, lineno,
     400            0 :                                                           sqlda->sqlvar[i].sqltype, ECPGt_NO_INDICATOR,
     401            0 :                                                           sqlda->sqlvar[i].sqldata, NULL, 0, 0, 0,
     402            0 :                                                           ECPG_ARRAY_NONE, compat, false);
     403            0 :                 }
     404              :                 else
     405            0 :                         ECPGset_noind_null(sqlda->sqlvar[i].sqltype, sqlda->sqlvar[i].sqldata);
     406              : 
     407            0 :                 offset = next_offset;
     408            0 :         }
     409            0 : }
     410              : 
     411              : struct sqlda_struct *
     412            0 : ecpg_build_native_sqlda(int line, PGresult *res, int row, enum COMPAT_MODE compat)
     413              : {
     414            0 :         struct sqlda_struct *sqlda;
     415            0 :         long            size;
     416            0 :         int                     i;
     417              : 
     418            0 :         size = sqlda_native_total_size(res, row, compat);
     419            0 :         sqlda = (struct sqlda_struct *) ecpg_alloc(size, line);
     420            0 :         if (!sqlda)
     421            0 :                 return NULL;
     422              : 
     423            0 :         memset(sqlda, 0, size);
     424              : 
     425            0 :         sprintf(sqlda->sqldaid, "SQLDA  ");
     426            0 :         sqlda->sqld = sqlda->sqln = PQnfields(res);
     427            0 :         ecpg_log("ecpg_build_native_sqlda on line %d sqld = %d\n", line, sqlda->sqld);
     428            0 :         sqlda->sqldabc = sizeof(struct sqlda_struct) + (sqlda->sqld - 1) * sizeof(struct sqlvar_struct);
     429              : 
     430            0 :         for (i = 0; i < sqlda->sqld; i++)
     431              :         {
     432            0 :                 char       *fname;
     433              : 
     434            0 :                 sqlda->sqlvar[i].sqltype = sqlda_dynamic_type(PQftype(res, i), compat);
     435            0 :                 fname = PQfname(res, i);
     436            0 :                 sqlda->sqlvar[i].sqlname.length = strlen(fname);
     437            0 :                 strcpy(sqlda->sqlvar[i].sqlname.data, fname);
     438            0 :         }
     439              : 
     440            0 :         return sqlda;
     441            0 : }
     442              : 
     443              : void
     444            0 : ecpg_set_native_sqlda(int lineno, struct sqlda_struct **_sqlda, const PGresult *res, int row, enum COMPAT_MODE compat)
     445              : {
     446            0 :         struct sqlda_struct *sqlda = (*_sqlda);
     447            0 :         int                     i;
     448            0 :         long            offset,
     449              :                                 next_offset;
     450              : 
     451            0 :         if (row < 0)
     452            0 :                 return;
     453              : 
     454              :         /* Offset for the first field value */
     455            0 :         offset = sqlda_native_empty_size(res);
     456              : 
     457              :         /*
     458              :          * Set sqlvar[i]->sqldata pointers and convert values to correct format
     459              :          */
     460            0 :         for (i = 0; i < sqlda->sqld; i++)
     461              :         {
     462            0 :                 int                     isnull;
     463            0 :                 int                     datalen;
     464            0 :                 bool            set_data = true;
     465              : 
     466            0 :                 switch (sqlda->sqlvar[i].sqltype)
     467              :                 {
     468              :                         case ECPGt_short:
     469              :                         case ECPGt_unsigned_short:
     470            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(short), sizeof(short), &offset, &next_offset);
     471            0 :                                 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
     472            0 :                                 sqlda->sqlvar[i].sqllen = sizeof(short);
     473            0 :                                 break;
     474              :                         case ECPGt_int:
     475              :                         case ECPGt_unsigned_int:
     476            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(int), &offset, &next_offset);
     477            0 :                                 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
     478            0 :                                 sqlda->sqlvar[i].sqllen = sizeof(int);
     479            0 :                                 break;
     480              :                         case ECPGt_long:
     481              :                         case ECPGt_unsigned_long:
     482            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(long), sizeof(long), &offset, &next_offset);
     483            0 :                                 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
     484            0 :                                 sqlda->sqlvar[i].sqllen = sizeof(long);
     485            0 :                                 break;
     486              :                         case ECPGt_long_long:
     487              :                         case ECPGt_unsigned_long_long:
     488            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(long long), sizeof(long long), &offset, &next_offset);
     489            0 :                                 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
     490            0 :                                 sqlda->sqlvar[i].sqllen = sizeof(long long);
     491            0 :                                 break;
     492              :                         case ECPGt_bool:
     493            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(bool), sizeof(bool), &offset, &next_offset);
     494            0 :                                 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
     495            0 :                                 sqlda->sqlvar[i].sqllen = sizeof(bool);
     496            0 :                                 break;
     497              :                         case ECPGt_float:
     498            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(float), sizeof(float), &offset, &next_offset);
     499            0 :                                 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
     500            0 :                                 sqlda->sqlvar[i].sqllen = sizeof(float);
     501            0 :                                 break;
     502              :                         case ECPGt_double:
     503            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(double), sizeof(double), &offset, &next_offset);
     504            0 :                                 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
     505            0 :                                 sqlda->sqlvar[i].sqllen = sizeof(double);
     506            0 :                                 break;
     507              :                         case ECPGt_decimal:
     508            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(decimal), &offset, &next_offset);
     509            0 :                                 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
     510            0 :                                 sqlda->sqlvar[i].sqllen = sizeof(decimal);
     511            0 :                                 break;
     512              :                         case ECPGt_numeric:
     513              :                                 {
     514            0 :                                         numeric    *num;
     515            0 :                                         char       *val;
     516              : 
     517            0 :                                         set_data = false;
     518              : 
     519            0 :                                         ecpg_sqlda_align_add_size(offset, sizeof(NumericDigit *), sizeof(numeric), &offset, &next_offset);
     520            0 :                                         sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
     521            0 :                                         sqlda->sqlvar[i].sqllen = sizeof(numeric);
     522              : 
     523            0 :                                         if (PQgetisnull(res, row, i))
     524              :                                         {
     525            0 :                                                 ECPGset_noind_null(ECPGt_numeric, sqlda->sqlvar[i].sqldata);
     526            0 :                                                 break;
     527              :                                         }
     528              : 
     529            0 :                                         val = PQgetvalue(res, row, i);
     530            0 :                                         num = PGTYPESnumeric_from_asc(val, NULL);
     531            0 :                                         if (!num)
     532              :                                         {
     533            0 :                                                 ECPGset_noind_null(ECPGt_numeric, sqlda->sqlvar[i].sqldata);
     534            0 :                                                 break;
     535              :                                         }
     536              : 
     537            0 :                                         memcpy(sqlda->sqlvar[i].sqldata, num, sizeof(numeric));
     538              : 
     539            0 :                                         if (num->buf)
     540              :                                         {
     541            0 :                                                 ecpg_sqlda_align_add_size(next_offset, sizeof(int), num->digits - num->buf + num->ndigits, &offset, &next_offset);
     542            0 :                                                 memcpy((char *) sqlda + offset, num->buf, num->digits - num->buf + num->ndigits);
     543              : 
     544            0 :                                                 ((numeric *) sqlda->sqlvar[i].sqldata)->buf = (NumericDigit *) sqlda + offset;
     545            0 :                                                 ((numeric *) sqlda->sqlvar[i].sqldata)->digits = (NumericDigit *) sqlda + offset + (num->digits - num->buf);
     546            0 :                                         }
     547              : 
     548            0 :                                         PGTYPESnumeric_free(num);
     549              : 
     550            0 :                                         break;
     551            0 :                                 }
     552              :                         case ECPGt_date:
     553            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(date), sizeof(date), &offset, &next_offset);
     554            0 :                                 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
     555            0 :                                 sqlda->sqlvar[i].sqllen = sizeof(date);
     556            0 :                                 break;
     557              :                         case ECPGt_timestamp:
     558            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(timestamp), &offset, &next_offset);
     559            0 :                                 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
     560            0 :                                 sqlda->sqlvar[i].sqllen = sizeof(timestamp);
     561            0 :                                 break;
     562              :                         case ECPGt_interval:
     563            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(interval), &offset, &next_offset);
     564            0 :                                 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
     565            0 :                                 sqlda->sqlvar[i].sqllen = sizeof(interval);
     566            0 :                                 break;
     567              :                         case ECPGt_char:
     568              :                         case ECPGt_unsigned_char:
     569            0 :                         case ECPGt_string:
     570              :                         default:
     571            0 :                                 datalen = strlen(PQgetvalue(res, row, i)) + 1;
     572            0 :                                 ecpg_sqlda_align_add_size(offset, sizeof(int), datalen, &offset, &next_offset);
     573            0 :                                 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
     574            0 :                                 sqlda->sqlvar[i].sqllen = datalen;
     575            0 :                                 break;
     576              :                 }
     577              : 
     578            0 :                 isnull = PQgetisnull(res, row, i);
     579            0 :                 ecpg_log("ecpg_set_native_sqlda on line %d row %d col %d %s\n", lineno, row, i, isnull ? "IS NULL" : "IS NOT NULL");
     580            0 :                 sqlda->sqlvar[i].sqlind = isnull ? &value_is_null : &value_is_not_null;
     581            0 :                 if (!isnull)
     582              :                 {
     583            0 :                         if (set_data)
     584            0 :                                 ecpg_get_data(res, row, i, lineno,
     585            0 :                                                           sqlda->sqlvar[i].sqltype, ECPGt_NO_INDICATOR,
     586            0 :                                                           sqlda->sqlvar[i].sqldata, NULL, 0, 0, 0,
     587            0 :                                                           ECPG_ARRAY_NONE, compat, false);
     588            0 :                 }
     589              : 
     590            0 :                 offset = next_offset;
     591            0 :         }
     592            0 : }
        

Generated by: LCOV version 2.3.2-1