Header And Logo

PostgreSQL
| The world's most advanced open source database.

Defines | Functions | Variables

sqlda.c File Reference

#include "postgres_fe.h"
#include "pg_type.h"
#include "ecpg-pthread-win32.h"
#include "decimal.h"
#include "ecpgtype.h"
#include "ecpglib.h"
#include "ecpgerrno.h"
#include "extern.h"
#include "sqlca.h"
#include "sqlda-native.h"
#include "sqlda-compat.h"
Include dependency graph for sqlda.c:

Go to the source code of this file.

Defines

#define POSTGRES_ECPG_INTERNAL

Functions

static void ecpg_sqlda_align_add_size (long offset, int alignment, int size, long *current, long *next)
static long sqlda_compat_empty_size (const PGresult *res)
static long sqlda_common_total_size (const PGresult *res, int row, enum COMPAT_MODE compat, long offset)
static long sqlda_compat_total_size (const PGresult *res, int row, enum COMPAT_MODE compat)
static long sqlda_native_empty_size (const PGresult *res)
static long sqlda_native_total_size (const PGresult *res, int row, enum COMPAT_MODE compat)
struct sqlda_compatecpg_build_compat_sqlda (int line, PGresult *res, int row, enum COMPAT_MODE compat)
void ecpg_set_compat_sqlda (int lineno, struct sqlda_compat **_sqlda, const PGresult *res, int row, enum COMPAT_MODE compat)
struct sqlda_structecpg_build_native_sqlda (int line, PGresult *res, int row, enum COMPAT_MODE compat)
void ecpg_set_native_sqlda (int lineno, struct sqlda_struct **_sqlda, const PGresult *res, int row, enum COMPAT_MODE compat)

Variables

static int16 value_is_null = -1
static int16 value_is_not_null = 0

Define Documentation

#define POSTGRES_ECPG_INTERNAL

Definition at line 9 of file sqlda.c.


Function Documentation

struct sqlda_compat* ecpg_build_compat_sqlda ( int  line,
PGresult res,
int  row,
enum COMPAT_MODE  compat 
) [read]

Definition at line 202 of file sqlda.c.

References sqlda_compat::desc_occ, ecpg_alloc(), ecpg_log(), i, PQfname(), PQfsize(), PQftype(), PQnfields(), sqlda_compat::sqld, sqlda_compat_total_size(), sqlda_dynamic_type(), sqlvar_compat::sqlname, sqlvar_compat::sqltype, sqlvar_compat::sqltypelen, sqlda_compat::sqlvar, and sqlvar_compat::sqlxid.

Referenced by ecpg_execute(), and ECPGdescribe().

{
    struct sqlda_compat *sqlda;
    struct sqlvar_compat *sqlvar;
    char       *fname;
    long        size;
    int         sqld;
    int         i;

    size = sqlda_compat_total_size(res, row, compat);
    sqlda = (struct sqlda_compat *) ecpg_alloc(size, line);
    if (!sqlda)
        return NULL;

    memset(sqlda, 0, size);
    sqlvar = (struct sqlvar_compat *) (sqlda + 1);
    sqld = PQnfields(res);
    fname = (char *) (sqlvar + sqld);

    sqlda->sqld = sqld;
    ecpg_log("ecpg_build_compat_sqlda on line %d sqld = %d\n", line, sqld);
    sqlda->desc_occ = size;     /* cheat here, keep the full allocated size */
    sqlda->sqlvar = sqlvar;

    for (i = 0; i < sqlda->sqld; i++)
    {
        sqlda->sqlvar[i].sqltype = sqlda_dynamic_type(PQftype(res, i), compat);
        strcpy(fname, PQfname(res, i));
        sqlda->sqlvar[i].sqlname = fname;
        fname += strlen(sqlda->sqlvar[i].sqlname) + 1;

        /*
         * this is reserved for future use, so we leave it empty for the time
         * being
         */
        /* sqlda->sqlvar[i].sqlformat = (char *) (long) PQfformat(res, i); */
        sqlda->sqlvar[i].sqlxid = PQftype(res, i);
        sqlda->sqlvar[i].sqltypelen = PQfsize(res, i);
    }

    return sqlda;
}

struct sqlda_struct* ecpg_build_native_sqlda ( int  line,
PGresult res,
int  row,
enum COMPAT_MODE  compat 
) [read]

Definition at line 409 of file sqlda.c.

References sqlname::data, ecpg_alloc(), ecpg_log(), i, sqlname::length, PQfname(), PQftype(), PQnfields(), sqlda_struct::sqld, sqlda_dynamic_type(), sqlda_native_total_size(), sqlda_struct::sqldabc, sqlda_struct::sqldaid, sqlda_struct::sqln, sqlvar_struct::sqlname, sqlvar_struct::sqltype, and sqlda_struct::sqlvar.

Referenced by ecpg_execute(), and ECPGdescribe().

{
    struct sqlda_struct *sqlda;
    long        size;
    int         i;

    size = sqlda_native_total_size(res, row, compat);
    sqlda = (struct sqlda_struct *) ecpg_alloc(size, line);
    if (!sqlda)
        return NULL;

    memset(sqlda, 0, size);

    sprintf(sqlda->sqldaid, "SQLDA  ");
    sqlda->sqld = sqlda->sqln = PQnfields(res);
    ecpg_log("ecpg_build_native_sqlda on line %d sqld = %d\n", line, sqlda->sqld);
    sqlda->sqldabc = sizeof(struct sqlda_struct) + (sqlda->sqld - 1) * sizeof(struct sqlvar_struct);

    for (i = 0; i < sqlda->sqld; i++)
    {
        char       *fname;

        sqlda->sqlvar[i].sqltype = sqlda_dynamic_type(PQftype(res, i), compat);
        fname = PQfname(res, i);
        sqlda->sqlvar[i].sqlname.length = strlen(fname);
        strcpy(sqlda->sqlvar[i].sqlname.data, fname);
    }

    return sqlda;
}

void ecpg_set_compat_sqlda ( int  lineno,
struct sqlda_compat **  _sqlda,
const PGresult res,
int  row,
enum COMPAT_MODE  compat 
)

Definition at line 252 of file sqlda.c.

References numeric::buf, numeric::digits, ECPG_ARRAY_NONE, ecpg_get_data(), ecpg_log(), ecpg_sqlda_align_add_size(), ECPGset_noind_null(), ECPGt_bool, ECPGt_char, ECPGt_date, ECPGt_decimal, ECPGt_double, ECPGt_float, ECPGt_int, ECPGt_interval, ECPGt_long, ECPGt_long_long, ECPGt_NO_INDICATOR, ECPGt_numeric, ECPGt_short, ECPGt_string, ECPGt_timestamp, ECPGt_unsigned_char, ECPGt_unsigned_int, ECPGt_unsigned_long, ECPGt_unsigned_long_long, ECPGt_unsigned_short, i, numeric::ndigits, NULL, PGTYPESnumeric_free(), PGTYPESnumeric_from_asc(), PQgetisnull(), PQgetvalue(), sqlda_compat::sqld, sqlda_compat_empty_size(), sqlvar_compat::sqldata, sqlvar_compat::sqlilen, sqlvar_compat::sqlilongdata, sqlvar_compat::sqlind, sqlvar_compat::sqlitype, sqlvar_compat::sqllen, sqlvar_compat::sqltype, sqlda_compat::sqlvar, val, value_is_not_null, and value_is_null.

Referenced by ecpg_execute().

{
    struct sqlda_compat *sqlda = (*_sqlda);
    int         i;
    long        offset,
                next_offset;

    if (row < 0)
        return;

    /* Offset for the first field value */
    offset = sqlda_compat_empty_size(res);

    /*
     * Set sqlvar[i]->sqldata pointers and convert values to correct format
     */
    for (i = 0; i < sqlda->sqld; i++)
    {
        int         isnull;
        int         datalen;
        bool        set_data = true;

        switch (sqlda->sqlvar[i].sqltype)
        {
            case ECPGt_short:
            case ECPGt_unsigned_short:
                ecpg_sqlda_align_add_size(offset, sizeof(short), sizeof(short), &offset, &next_offset);
                sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
                sqlda->sqlvar[i].sqllen = sizeof(short);
                break;
            case ECPGt_int:
            case ECPGt_unsigned_int:
                ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(int), &offset, &next_offset);
                sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
                sqlda->sqlvar[i].sqllen = sizeof(int);
                break;
            case ECPGt_long:
            case ECPGt_unsigned_long:
                ecpg_sqlda_align_add_size(offset, sizeof(long), sizeof(long), &offset, &next_offset);
                sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
                sqlda->sqlvar[i].sqllen = sizeof(long);
                break;
            case ECPGt_long_long:
            case ECPGt_unsigned_long_long:
                ecpg_sqlda_align_add_size(offset, sizeof(long long), sizeof(long long), &offset, &next_offset);
                sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
                sqlda->sqlvar[i].sqllen = sizeof(long long);
                break;
            case ECPGt_bool:
                ecpg_sqlda_align_add_size(offset, sizeof(bool), sizeof(bool), &offset, &next_offset);
                sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
                sqlda->sqlvar[i].sqllen = sizeof(bool);
                break;
            case ECPGt_float:
                ecpg_sqlda_align_add_size(offset, sizeof(float), sizeof(float), &offset, &next_offset);
                sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
                sqlda->sqlvar[i].sqllen = sizeof(float);
                break;
            case ECPGt_double:
                ecpg_sqlda_align_add_size(offset, sizeof(double), sizeof(double), &offset, &next_offset);
                sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
                sqlda->sqlvar[i].sqllen = sizeof(double);
                break;
            case ECPGt_decimal:
                ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(decimal), &offset, &next_offset);
                sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
                sqlda->sqlvar[i].sqllen = sizeof(decimal);
                break;
            case ECPGt_numeric:
                {
                    numeric    *num;
                    char       *val;

                    set_data = false;

                    ecpg_sqlda_align_add_size(offset, sizeof(NumericDigit *), sizeof(numeric), &offset, &next_offset);
                    sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
                    sqlda->sqlvar[i].sqllen = sizeof(numeric);

                    if (PQgetisnull(res, row, i))
                    {
                        ECPGset_noind_null(ECPGt_numeric, sqlda->sqlvar[i].sqldata);
                        break;
                    }

                    val = PQgetvalue(res, row, i);
                    num = PGTYPESnumeric_from_asc(val, NULL);
                    if (!num)
                    {
                        ECPGset_noind_null(ECPGt_numeric, sqlda->sqlvar[i].sqldata);
                        break;
                    }

                    memcpy(sqlda->sqlvar[i].sqldata, num, sizeof(numeric));

                    if (num->ndigits)
                    {
                        ecpg_sqlda_align_add_size(next_offset, sizeof(int), num->ndigits + 1, &offset, &next_offset);
                        memcpy((char *) sqlda + offset, num->buf, num->ndigits + 1);

                        ((numeric *) sqlda->sqlvar[i].sqldata)->buf = (NumericDigit *) sqlda + offset;
                        ((numeric *) sqlda->sqlvar[i].sqldata)->digits = (NumericDigit *) sqlda + offset + (num->digits - num->buf);
                    }

                    PGTYPESnumeric_free(num);

                    break;
                }
            case ECPGt_date:
                ecpg_sqlda_align_add_size(offset, sizeof(date), sizeof(date), &offset, &next_offset);
                sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
                sqlda->sqlvar[i].sqllen = sizeof(date);
                break;
            case ECPGt_timestamp:
                ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(timestamp), &offset, &next_offset);
                sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
                sqlda->sqlvar[i].sqllen = sizeof(timestamp);
                break;
            case ECPGt_interval:
                ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(interval), &offset, &next_offset);
                sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
                sqlda->sqlvar[i].sqllen = sizeof(interval);
                break;
            case ECPGt_char:
            case ECPGt_unsigned_char:
            case ECPGt_string:
            default:
                datalen = strlen(PQgetvalue(res, row, i)) + 1;
                ecpg_sqlda_align_add_size(offset, sizeof(int), datalen, &offset, &next_offset);
                sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
                sqlda->sqlvar[i].sqllen = datalen;
                if (datalen > 32768)
                    sqlda->sqlvar[i].sqlilongdata = sqlda->sqlvar[i].sqldata;
                break;
        }

        isnull = PQgetisnull(res, row, i);
        ecpg_log("ecpg_set_compat_sqlda on line %d row %d col %d %s\n", lineno, row, i, isnull ? "IS NULL" : "IS NOT NULL");
        sqlda->sqlvar[i].sqlind = isnull ? &value_is_null : &value_is_not_null;
        sqlda->sqlvar[i].sqlitype = ECPGt_short;
        sqlda->sqlvar[i].sqlilen = sizeof(short);
        if (!isnull)
        {
            if (set_data)
                ecpg_get_data(res, row, i, lineno,
                              sqlda->sqlvar[i].sqltype, ECPGt_NO_INDICATOR,
                              sqlda->sqlvar[i].sqldata, NULL, 0, 0, 0,
                              ECPG_ARRAY_NONE, compat, false);
        }
        else
            ECPGset_noind_null(sqlda->sqlvar[i].sqltype, sqlda->sqlvar[i].sqldata);

        offset = next_offset;
    }
}

void ecpg_set_native_sqlda ( int  lineno,
struct sqlda_struct **  _sqlda,
const PGresult res,
int  row,
enum COMPAT_MODE  compat 
)

Definition at line 441 of file sqlda.c.

References numeric::buf, numeric::digits, ECPG_ARRAY_NONE, ecpg_get_data(), ecpg_log(), ecpg_sqlda_align_add_size(), ECPGset_noind_null(), ECPGt_bool, ECPGt_char, ECPGt_date, ECPGt_decimal, ECPGt_double, ECPGt_float, ECPGt_int, ECPGt_interval, ECPGt_long, ECPGt_long_long, ECPGt_NO_INDICATOR, ECPGt_numeric, ECPGt_short, ECPGt_string, ECPGt_timestamp, ECPGt_unsigned_char, ECPGt_unsigned_int, ECPGt_unsigned_long, ECPGt_unsigned_long_long, ECPGt_unsigned_short, i, numeric::ndigits, NULL, PGTYPESnumeric_free(), PGTYPESnumeric_from_asc(), PQgetisnull(), PQgetvalue(), sqlda_struct::sqld, sqlda_native_empty_size(), sqlvar_struct::sqldata, sqlvar_struct::sqlind, sqlvar_struct::sqllen, sqlvar_struct::sqltype, sqlda_struct::sqlvar, val, value_is_not_null, and value_is_null.

Referenced by ecpg_execute().

{
    struct sqlda_struct *sqlda = (*_sqlda);
    int         i;
    long        offset,
                next_offset;

    if (row < 0)
        return;

    /* Offset for the first field value */
    offset = sqlda_native_empty_size(res);

    /*
     * Set sqlvar[i]->sqldata pointers and convert values to correct format
     */
    for (i = 0; i < sqlda->sqld; i++)
    {
        int         isnull;
        int         datalen;
        bool        set_data = true;

        switch (sqlda->sqlvar[i].sqltype)
        {
            case ECPGt_short:
            case ECPGt_unsigned_short:
                ecpg_sqlda_align_add_size(offset, sizeof(short), sizeof(short), &offset, &next_offset);
                sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
                sqlda->sqlvar[i].sqllen = sizeof(short);
                break;
            case ECPGt_int:
            case ECPGt_unsigned_int:
                ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(int), &offset, &next_offset);
                sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
                sqlda->sqlvar[i].sqllen = sizeof(int);
                break;
            case ECPGt_long:
            case ECPGt_unsigned_long:
                ecpg_sqlda_align_add_size(offset, sizeof(long), sizeof(long), &offset, &next_offset);
                sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
                sqlda->sqlvar[i].sqllen = sizeof(long);
                break;
            case ECPGt_long_long:
            case ECPGt_unsigned_long_long:
                ecpg_sqlda_align_add_size(offset, sizeof(long long), sizeof(long long), &offset, &next_offset);
                sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
                sqlda->sqlvar[i].sqllen = sizeof(long long);
                break;
            case ECPGt_bool:
                ecpg_sqlda_align_add_size(offset, sizeof(bool), sizeof(bool), &offset, &next_offset);
                sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
                sqlda->sqlvar[i].sqllen = sizeof(bool);
                break;
            case ECPGt_float:
                ecpg_sqlda_align_add_size(offset, sizeof(float), sizeof(float), &offset, &next_offset);
                sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
                sqlda->sqlvar[i].sqllen = sizeof(float);
                break;
            case ECPGt_double:
                ecpg_sqlda_align_add_size(offset, sizeof(double), sizeof(double), &offset, &next_offset);
                sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
                sqlda->sqlvar[i].sqllen = sizeof(double);
                break;
            case ECPGt_decimal:
                ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(decimal), &offset, &next_offset);
                sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
                sqlda->sqlvar[i].sqllen = sizeof(decimal);
                break;
            case ECPGt_numeric:
                {
                    numeric    *num;
                    char       *val;

                    set_data = false;

                    ecpg_sqlda_align_add_size(offset, sizeof(NumericDigit *), sizeof(numeric), &offset, &next_offset);
                    sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
                    sqlda->sqlvar[i].sqllen = sizeof(numeric);

                    if (PQgetisnull(res, row, i))
                    {
                        ECPGset_noind_null(ECPGt_numeric, sqlda->sqlvar[i].sqldata);
                        break;
                    }

                    val = PQgetvalue(res, row, i);
                    num = PGTYPESnumeric_from_asc(val, NULL);
                    if (!num)
                    {
                        ECPGset_noind_null(ECPGt_numeric, sqlda->sqlvar[i].sqldata);
                        break;
                    }

                    memcpy(sqlda->sqlvar[i].sqldata, num, sizeof(numeric));

                    if (num->ndigits)
                    {
                        ecpg_sqlda_align_add_size(next_offset, sizeof(int), num->ndigits + 1, &offset, &next_offset);
                        memcpy((char *) sqlda + offset, num->buf, num->ndigits + 1);

                        ((numeric *) sqlda->sqlvar[i].sqldata)->buf = (NumericDigit *) sqlda + offset;
                        ((numeric *) sqlda->sqlvar[i].sqldata)->digits = (NumericDigit *) sqlda + offset + (num->digits - num->buf);
                    }

                    PGTYPESnumeric_free(num);

                    break;
                }
            case ECPGt_date:
                ecpg_sqlda_align_add_size(offset, sizeof(date), sizeof(date), &offset, &next_offset);
                sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
                sqlda->sqlvar[i].sqllen = sizeof(date);
                break;
            case ECPGt_timestamp:
                ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(timestamp), &offset, &next_offset);
                sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
                sqlda->sqlvar[i].sqllen = sizeof(timestamp);
                break;
            case ECPGt_interval:
                ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(interval), &offset, &next_offset);
                sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
                sqlda->sqlvar[i].sqllen = sizeof(interval);
                break;
            case ECPGt_char:
            case ECPGt_unsigned_char:
            case ECPGt_string:
            default:
                datalen = strlen(PQgetvalue(res, row, i)) + 1;
                ecpg_sqlda_align_add_size(offset, sizeof(int), datalen, &offset, &next_offset);
                sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
                sqlda->sqlvar[i].sqllen = datalen;
                break;
        }

        isnull = PQgetisnull(res, row, i);
        ecpg_log("ecpg_set_native_sqlda on line %d row %d col %d %s\n", lineno, row, i, isnull ? "IS NULL" : "IS NOT NULL");
        sqlda->sqlvar[i].sqlind = isnull ? &value_is_null : &value_is_not_null;
        if (!isnull)
        {
            if (set_data)
                ecpg_get_data(res, row, i, lineno,
                              sqlda->sqlvar[i].sqltype, ECPGt_NO_INDICATOR,
                              sqlda->sqlvar[i].sqldata, NULL, 0, 0, 0,
                              ECPG_ARRAY_NONE, compat, false);
        }

        offset = next_offset;
    }
}

static void ecpg_sqlda_align_add_size ( long  offset,
int  alignment,
int  size,
long *  current,
long *  next 
) [static]

Definition at line 33 of file sqlda.c.

Referenced by ecpg_set_compat_sqlda(), ecpg_set_native_sqlda(), sqlda_common_total_size(), sqlda_compat_empty_size(), and sqlda_native_empty_size().

{
    if (offset % alignment)
        offset += alignment - (offset % alignment);
    if (current)
        *current = offset;
    offset += size;
    if (next)
        *next = offset;
}

static long sqlda_common_total_size ( const PGresult res,
int  row,
enum COMPAT_MODE  compat,
long  offset 
) [static]

Definition at line 65 of file sqlda.c.

References ecpg_sqlda_align_add_size(), ECPGt_bool, ECPGt_char, ECPGt_date, ECPGt_decimal, ECPGt_double, ECPGt_float, ECPGt_int, ECPGt_interval, ECPGt_long, ECPGt_long_long, ECPGt_numeric, ECPGt_short, ECPGt_string, ECPGt_timestamp, ECPGt_unsigned_char, ECPGt_unsigned_int, ECPGt_unsigned_long, ECPGt_unsigned_long_long, ECPGt_unsigned_short, i, numeric::ndigits, NULL, PGTYPESnumeric_free(), PGTYPESnumeric_from_asc(), PQftype(), PQgetisnull(), PQgetvalue(), PQnfields(), sqlda_dynamic_type(), and val.

Referenced by sqlda_compat_total_size(), and sqlda_native_total_size().

{
    int         sqld = PQnfields(res);
    int         i;
    long        next_offset;

    /* Add space for the field values */
    for (i = 0; i < sqld; i++)
    {
        enum ECPGttype type = sqlda_dynamic_type(PQftype(res, i), compat);

        switch (type)
        {
            case ECPGt_short:
            case ECPGt_unsigned_short:
                ecpg_sqlda_align_add_size(offset, sizeof(short), sizeof(short), &offset, &next_offset);
                break;
            case ECPGt_int:
            case ECPGt_unsigned_int:
                ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(int), &offset, &next_offset);
                break;
            case ECPGt_long:
            case ECPGt_unsigned_long:
                ecpg_sqlda_align_add_size(offset, sizeof(long), sizeof(long), &offset, &next_offset);
                break;
            case ECPGt_long_long:
            case ECPGt_unsigned_long_long:
                ecpg_sqlda_align_add_size(offset, sizeof(long long), sizeof(long long), &offset, &next_offset);
                break;
            case ECPGt_bool:
                ecpg_sqlda_align_add_size(offset, sizeof(bool), sizeof(bool), &offset, &next_offset);
                break;
            case ECPGt_float:
                ecpg_sqlda_align_add_size(offset, sizeof(float), sizeof(float), &offset, &next_offset);
                break;
            case ECPGt_double:
                ecpg_sqlda_align_add_size(offset, sizeof(double), sizeof(double), &offset, &next_offset);
                break;
            case ECPGt_decimal:
                ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(decimal), &offset, &next_offset);
                break;
            case ECPGt_numeric:

                /*
                 * Let's align both the numeric struct and the digits array to
                 * int Unfortunately we need to do double work here to compute
                 * the size of the space needed for the numeric structure.
                 */
                ecpg_sqlda_align_add_size(offset, sizeof(NumericDigit *), sizeof(numeric), &offset, &next_offset);
                if (!PQgetisnull(res, row, i))
                {
                    char       *val = PQgetvalue(res, row, i);
                    numeric    *num;

                    num = PGTYPESnumeric_from_asc(val, NULL);
                    if (!num)
                        break;
                    if (num->ndigits)
                        ecpg_sqlda_align_add_size(next_offset, sizeof(int), num->ndigits + 1, &offset, &next_offset);
                    PGTYPESnumeric_free(num);
                }
                break;
            case ECPGt_date:
                ecpg_sqlda_align_add_size(offset, sizeof(date), sizeof(date), &offset, &next_offset);
                break;
            case ECPGt_timestamp:
                ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(timestamp), &offset, &next_offset);
                break;
            case ECPGt_interval:
                ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(interval), &offset, &next_offset);
                break;
            case ECPGt_char:
            case ECPGt_unsigned_char:
            case ECPGt_string:
            default:
                {
                    long        datalen = strlen(PQgetvalue(res, row, i)) + 1;

                    ecpg_sqlda_align_add_size(offset, sizeof(int), datalen, &offset, &next_offset);
                    break;
                }
        }
        offset = next_offset;
    }
    return offset;
}

static long sqlda_compat_empty_size ( const PGresult res  )  [static]

Definition at line 45 of file sqlda.c.

References ecpg_sqlda_align_add_size(), i, NULL, PQfname(), and PQnfields().

Referenced by ecpg_set_compat_sqlda(), and sqlda_compat_total_size().

{
    long        offset;
    int         i;
    int         sqld = PQnfields(res);

    /* Initial size to store main structure and field structures */
    offset = sizeof(struct sqlda_compat) + sqld * sizeof(struct sqlvar_compat);

    /* Add space for field names */
    for (i = 0; i < sqld; i++)
        offset += strlen(PQfname(res, i)) + 1;

    /* Add padding to the first field value */
    ecpg_sqlda_align_add_size(offset, sizeof(int), 0, &offset, NULL);

    return offset;
}

static long sqlda_compat_total_size ( const PGresult res,
int  row,
enum COMPAT_MODE  compat 
) [static]

Definition at line 154 of file sqlda.c.

References sqlda_common_total_size(), and sqlda_compat_empty_size().

Referenced by ecpg_build_compat_sqlda().

{
    long        offset;

    offset = sqlda_compat_empty_size(res);

    if (row < 0)
        return offset;

    offset = sqlda_common_total_size(res, row, compat, offset);
    return offset;
}

static long sqlda_native_empty_size ( const PGresult res  )  [static]

Definition at line 168 of file sqlda.c.

References ecpg_sqlda_align_add_size(), NULL, and PQnfields().

Referenced by ecpg_set_native_sqlda(), and sqlda_native_total_size().

{
    long        offset;
    int         sqld = PQnfields(res);

    /* Initial size to store main structure and field structures */
    offset = sizeof(struct sqlda_struct) + (sqld - 1) * sizeof(struct sqlvar_struct);

    /* Add padding to the first field value */
    ecpg_sqlda_align_add_size(offset, sizeof(int), 0, &offset, NULL);

    return offset;
}

static long sqlda_native_total_size ( const PGresult res,
int  row,
enum COMPAT_MODE  compat 
) [static]

Definition at line 183 of file sqlda.c.

References sqlda_common_total_size(), and sqlda_native_empty_size().

Referenced by ecpg_build_native_sqlda().

{
    long        offset;

    offset = sqlda_native_empty_size(res);

    if (row < 0)
        return offset;

    offset = sqlda_common_total_size(res, row, compat, offset);
    return offset;
}


Variable Documentation

int16 value_is_not_null = 0 [static]

Definition at line 249 of file sqlda.c.

Referenced by ecpg_set_compat_sqlda(), and ecpg_set_native_sqlda().

int16 value_is_null = -1 [static]

Definition at line 248 of file sqlda.c.

Referenced by ecpg_set_compat_sqlda(), and ecpg_set_native_sqlda().