Header And Logo

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

Defines | Functions | Variables

informix.c File Reference

#include "postgres_fe.h"
#include <math.h>
#include <ctype.h>
#include <limits.h>
#include <ecpgtype.h>
#include <ecpg_informix.h>
#include <pgtypes_error.h>
#include <pgtypes_date.h>
#include <pgtypes_numeric.h>
#include <sqltypes.h>
#include <sqlca.h>
#include <ecpgerrno.h>
Include dependency graph for informix.c:

Go to the source code of this file.

Defines

#define POSTGRES_ECPG_INTERNAL

Functions

static int deccall2 (decimal *arg1, decimal *arg2, int(*ptr)(numeric *, numeric *))
static int deccall3 (decimal *arg1, decimal *arg2, decimal *result, int(*ptr)(numeric *, numeric *, numeric *))
int decadd (decimal *arg1, decimal *arg2, decimal *sum)
int deccmp (decimal *arg1, decimal *arg2)
void deccopy (decimal *src, decimal *target)
static char * ecpg_strndup (const char *str, size_t len)
int deccvasc (char *cp, int len, decimal *np)
int deccvdbl (double dbl, decimal *np)
int deccvint (int in, decimal *np)
int deccvlong (long lng, decimal *np)
int decdiv (decimal *n1, decimal *n2, decimal *result)
int decmul (decimal *n1, decimal *n2, decimal *result)
int decsub (decimal *n1, decimal *n2, decimal *result)
int dectoasc (decimal *np, char *cp, int len, int right)
int dectodbl (decimal *np, double *dblp)
int dectoint (decimal *np, int *ip)
int dectolong (decimal *np, long *lngp)
int rdatestr (date d, char *str)
int rstrdate (char *str, date *d)
void rtoday (date *d)
int rjulmdy (date d, short mdy[3])
int rdefmtdate (date *d, char *fmt, char *str)
int rfmtdate (date d, char *fmt, char *str)
int rmdyjul (short mdy[3], date *d)
int rdayofweek (date d)
void dtcurrent (timestamp *ts)
int dtcvasc (char *str, timestamp *ts)
int dtcvfmtasc (char *inbuf, char *fmtstr, timestamp *dtvalue)
int dtsub (timestamp *ts1, timestamp *ts2, interval *iv)
int dttoasc (timestamp *ts, char *output)
int dttofmtasc (timestamp *ts, char *output, int str_len, char *fmtstr)
int intoasc (interval *i, char *str)
static int initValue (long lng_val)
static int getRightMostDot (char *str)
int rfmtlong (long lng_val, char *fmt, char *outbuf)
void rupshift (char *str)
int byleng (char *str, int len)
void ldchar (char *src, int len, char *dest)
int rgetmsg (int msgnum, char *s, int maxsize)
int rtypalign (int offset, int type)
int rtypmsize (int type, int len)
int rtypwidth (int sqltype, int sqllen)
void ECPG_informix_set_var (int number, void *pointer, int lineno)
void * ECPG_informix_get_var (int number)
void ECPG_informix_reset_sqlca (void)
int rsetnull (int t, char *ptr)
int risnull (int t, char *ptr)

Variables

static struct sqlca_t sqlca_init
struct {
   long   val
   int   maxdigits
   int   digits
   int   remaining
   char   sign
   char *   val_string
value

Define Documentation

#define POSTGRES_ECPG_INTERNAL

Definition at line 3 of file informix.c.


Function Documentation

int byleng ( char *  str,
int  len 
)

Definition at line 968 of file informix.c.

Referenced by ldchar(), and main().

{
    for (len--; str[len] && str[len] == ' '; len--);
    return (len + 1);
}

int decadd ( decimal arg1,
decimal arg2,
decimal sum 
)

Definition at line 151 of file informix.c.

References deccall3(), PGTYPES_NUM_OVERFLOW, PGTYPES_NUM_UNDERFLOW, and PGTYPESnumeric_add().

Referenced by main().

{
    errno = 0;
    deccall3(arg1, arg2, sum, PGTYPESnumeric_add);

    if (errno == PGTYPES_NUM_OVERFLOW)
        return ECPG_INFORMIX_NUM_OVERFLOW;
    else if (errno == PGTYPES_NUM_UNDERFLOW)
        return ECPG_INFORMIX_NUM_UNDERFLOW;
    else if (errno != 0)
        return -1;
    else
        return 0;
}

static int deccall2 ( decimal arg1,
decimal arg2,
int(*)(numeric *, numeric *)  ptr 
) [static]

Definition at line 48 of file informix.c.

References a1, a2, i, NULL, PGTYPESnumeric_free(), PGTYPESnumeric_from_decimal(), and PGTYPESnumeric_new().

Referenced by deccmp().

{
    numeric    *a1,
               *a2;
    int         i;

    if ((a1 = PGTYPESnumeric_new()) == NULL)
        return ECPG_INFORMIX_OUT_OF_MEMORY;

    if ((a2 = PGTYPESnumeric_new()) == NULL)
    {
        PGTYPESnumeric_free(a1);
        return ECPG_INFORMIX_OUT_OF_MEMORY;
    }

    if (PGTYPESnumeric_from_decimal(arg1, a1) != 0)
    {
        PGTYPESnumeric_free(a1);
        PGTYPESnumeric_free(a2);
        return ECPG_INFORMIX_OUT_OF_MEMORY;
    }

    if (PGTYPESnumeric_from_decimal(arg2, a2) != 0)
    {
        PGTYPESnumeric_free(a1);
        PGTYPESnumeric_free(a2);
        return ECPG_INFORMIX_OUT_OF_MEMORY;
    }

    i = (*ptr) (a1, a2);

    PGTYPESnumeric_free(a1);
    PGTYPESnumeric_free(a2);

    return (i);
}

static int deccall3 ( decimal arg1,
decimal arg2,
decimal result,
int(*)(numeric *, numeric *, numeric *)  ptr 
) [static]

Definition at line 86 of file informix.c.

References a1, a2, CDECIMALTYPE, i, NULL, PGTYPESnumeric_free(), PGTYPESnumeric_from_decimal(), PGTYPESnumeric_new(), PGTYPESnumeric_to_decimal(), risnull(), and rsetnull().

Referenced by decadd(), decdiv(), decmul(), and decsub().

{
    numeric    *a1,
               *a2,
               *nres;
    int         i;

    /*
     * we must NOT set the result to NULL here because it may be the same
     * variable as one of the arguments
     */
    if (risnull(CDECIMALTYPE, (char *) arg1) || risnull(CDECIMALTYPE, (char *) arg2))
        return 0;

    if ((a1 = PGTYPESnumeric_new()) == NULL)
        return ECPG_INFORMIX_OUT_OF_MEMORY;

    if ((a2 = PGTYPESnumeric_new()) == NULL)
    {
        PGTYPESnumeric_free(a1);
        return ECPG_INFORMIX_OUT_OF_MEMORY;
    }

    if ((nres = PGTYPESnumeric_new()) == NULL)
    {
        PGTYPESnumeric_free(a1);
        PGTYPESnumeric_free(a2);
        return ECPG_INFORMIX_OUT_OF_MEMORY;
    }

    if (PGTYPESnumeric_from_decimal(arg1, a1) != 0)
    {
        PGTYPESnumeric_free(a1);
        PGTYPESnumeric_free(a2);
        PGTYPESnumeric_free(nres);
        return ECPG_INFORMIX_OUT_OF_MEMORY;
    }

    if (PGTYPESnumeric_from_decimal(arg2, a2) != 0)
    {
        PGTYPESnumeric_free(a1);
        PGTYPESnumeric_free(a2);
        PGTYPESnumeric_free(nres);
        return ECPG_INFORMIX_OUT_OF_MEMORY;
    }

    i = (*ptr) (a1, a2, nres);

    if (i == 0)                 /* No error */
    {

        /* set the result to null in case it errors out later */
        rsetnull(CDECIMALTYPE, (char *) result);
        PGTYPESnumeric_to_decimal(nres, result);
    }

    PGTYPESnumeric_free(nres);
    PGTYPESnumeric_free(a1);
    PGTYPESnumeric_free(a2);

    return (i);
}

int deccmp ( decimal arg1,
decimal arg2 
)

Definition at line 167 of file informix.c.

References deccall2(), and PGTYPESnumeric_cmp().

Referenced by main().

{
    return (deccall2(arg1, arg2, PGTYPESnumeric_cmp));
}

void deccopy ( decimal src,
decimal target 
)

Definition at line 173 of file informix.c.

{
    memcpy(target, src, sizeof(decimal));
}

int deccvasc ( char *  cp,
int  len,
decimal np 
)

Definition at line 198 of file informix.c.

References CDECIMALTYPE, CSTRINGTYPE, ecpg_strndup(), free, i, NULL, PGTYPES_NUM_BAD_NUMERIC, PGTYPES_NUM_OVERFLOW, PGTYPESnumeric_free(), PGTYPESnumeric_from_asc(), PGTYPESnumeric_to_decimal(), risnull(), and rsetnull().

Referenced by main().

{
    char       *str;
    int         ret = 0;
    numeric    *result;

    rsetnull(CDECIMALTYPE, (char *) np);
    if (risnull(CSTRINGTYPE, cp))
        return 0;

    str = ecpg_strndup(cp, len);/* decimal_in always converts the complete
                                 * string */
    if (!str)
        ret = ECPG_INFORMIX_NUM_UNDERFLOW;
    else
    {
        errno = 0;
        result = PGTYPESnumeric_from_asc(str, NULL);
        if (!result)
        {
            switch (errno)
            {
                case PGTYPES_NUM_OVERFLOW:
                    ret = ECPG_INFORMIX_NUM_OVERFLOW;
                    break;
                case PGTYPES_NUM_BAD_NUMERIC:
                    ret = ECPG_INFORMIX_BAD_NUMERIC;
                    break;
                default:
                    ret = ECPG_INFORMIX_BAD_EXPONENT;
                    break;
            }
        }
        else
        {
            int         i = PGTYPESnumeric_to_decimal(result, np);

            PGTYPESnumeric_free(result);
            if (i != 0)
                ret = ECPG_INFORMIX_NUM_OVERFLOW;
        }
    }

    free(str);
    return ret;
}

int deccvdbl ( double  dbl,
decimal np 
)

Definition at line 246 of file informix.c.

References CDECIMALTYPE, CDOUBLETYPE, NULL, PGTYPESnumeric_free(), PGTYPESnumeric_from_double(), PGTYPESnumeric_new(), PGTYPESnumeric_to_decimal(), risnull(), and rsetnull().

{
    numeric    *nres;
    int         result = 1;

    rsetnull(CDECIMALTYPE, (char *) np);
    if (risnull(CDOUBLETYPE, (char *) &dbl))
        return 0;

    nres = PGTYPESnumeric_new();
    if (nres == NULL)
        return ECPG_INFORMIX_OUT_OF_MEMORY;

    result = PGTYPESnumeric_from_double(dbl, nres);
    if (result == 0)
        result = PGTYPESnumeric_to_decimal(nres, np);

    PGTYPESnumeric_free(nres);
    return (result);
}

int deccvint ( int  in,
decimal np 
)

Definition at line 268 of file informix.c.

References CDECIMALTYPE, CINTTYPE, NULL, PGTYPESnumeric_free(), PGTYPESnumeric_from_int(), PGTYPESnumeric_new(), PGTYPESnumeric_to_decimal(), risnull(), and rsetnull().

Referenced by main().

{
    numeric    *nres;
    int         result = 1;

    rsetnull(CDECIMALTYPE, (char *) np);
    if (risnull(CINTTYPE, (char *) &in))
        return 0;

    nres = PGTYPESnumeric_new();
    if (nres == NULL)
        return ECPG_INFORMIX_OUT_OF_MEMORY;

    result = PGTYPESnumeric_from_int(in, nres);
    if (result == 0)
        result = PGTYPESnumeric_to_decimal(nres, np);

    PGTYPESnumeric_free(nres);
    return (result);
}

int deccvlong ( long  lng,
decimal np 
)

Definition at line 290 of file informix.c.

References CDECIMALTYPE, CLONGTYPE, NULL, PGTYPESnumeric_free(), PGTYPESnumeric_from_long(), PGTYPESnumeric_new(), PGTYPESnumeric_to_decimal(), risnull(), and rsetnull().

Referenced by main().

{
    numeric    *nres;
    int         result = 1;

    rsetnull(CDECIMALTYPE, (char *) np);
    if (risnull(CLONGTYPE, (char *) &lng))
        return 0;

    nres = PGTYPESnumeric_new();
    if (nres == NULL)
        return ECPG_INFORMIX_OUT_OF_MEMORY;

    result = PGTYPESnumeric_from_long(lng, nres);
    if (result == 0)
        result = PGTYPESnumeric_to_decimal(nres, np);

    PGTYPESnumeric_free(nres);
    return (result);
}

int decdiv ( decimal n1,
decimal n2,
decimal result 
)

Definition at line 312 of file informix.c.

References deccall3(), i, PGTYPES_NUM_DIVIDE_ZERO, PGTYPES_NUM_OVERFLOW, and PGTYPESnumeric_div().

Referenced by main().

{

    int         i;

    errno = 0;
    i = deccall3(n1, n2, result, PGTYPESnumeric_div);

    if (i != 0)
        switch (errno)
        {
            case PGTYPES_NUM_DIVIDE_ZERO:
                return ECPG_INFORMIX_DIVIDE_ZERO;
                break;
            case PGTYPES_NUM_OVERFLOW:
                return ECPG_INFORMIX_NUM_OVERFLOW;
                break;
            default:
                return ECPG_INFORMIX_NUM_UNDERFLOW;
                break;
        }

    return 0;
}

int decmul ( decimal n1,
decimal n2,
decimal result 
)

Definition at line 338 of file informix.c.

References deccall3(), i, PGTYPES_NUM_OVERFLOW, and PGTYPESnumeric_mul().

Referenced by main().

{
    int         i;

    errno = 0;
    i = deccall3(n1, n2, result, PGTYPESnumeric_mul);

    if (i != 0)
        switch (errno)
        {
            case PGTYPES_NUM_OVERFLOW:
                return ECPG_INFORMIX_NUM_OVERFLOW;
                break;
            default:
                return ECPG_INFORMIX_NUM_UNDERFLOW;
                break;
        }

    return 0;
}

int decsub ( decimal n1,
decimal n2,
decimal result 
)

Definition at line 360 of file informix.c.

References deccall3(), i, PGTYPES_NUM_OVERFLOW, and PGTYPESnumeric_sub().

Referenced by main().

{
    int         i;

    errno = 0;
    i = deccall3(n1, n2, result, PGTYPESnumeric_sub);

    if (i != 0)
        switch (errno)
        {
            case PGTYPES_NUM_OVERFLOW:
                return ECPG_INFORMIX_NUM_OVERFLOW;
                break;
            default:
                return ECPG_INFORMIX_NUM_UNDERFLOW;
                break;
        }

    return 0;
}

int dectoasc ( decimal np,
char *  cp,
int  len,
int  right 
)

Definition at line 382 of file informix.c.

References CDECIMALTYPE, CSTRINGTYPE, numeric::dscale, free, NULL, PGTYPESnumeric_free(), PGTYPESnumeric_from_decimal(), PGTYPESnumeric_new(), PGTYPESnumeric_to_asc(), risnull(), and rsetnull().

Referenced by dump_sqlda(), and main().

{
    char       *str;
    numeric    *nres;

    rsetnull(CSTRINGTYPE, (char *) cp);
    if (risnull(CDECIMALTYPE, (char *) np))
        return 0;

    nres = PGTYPESnumeric_new();
    if (nres == NULL)
        return ECPG_INFORMIX_OUT_OF_MEMORY;

    if (PGTYPESnumeric_from_decimal(np, nres) != 0)
    {
        PGTYPESnumeric_free(nres);
        return ECPG_INFORMIX_OUT_OF_MEMORY;
    }

    if (right >= 0)
        str = PGTYPESnumeric_to_asc(nres, right);
    else
        str = PGTYPESnumeric_to_asc(nres, nres->dscale);

    PGTYPESnumeric_free(nres);
    if (!str)
        return -1;

    /*
     * TODO: have to take care of len here and create exponential notation if
     * necessary
     */
    if ((int) (strlen(str) + 1) > len)
    {
        if (len > 1)
        {
            cp[0] = '*';
            cp[1] = '\0';
        }
        free(str);
        return -1;
    }
    else
    {
        strcpy(cp, str);
        free(str);
        return 0;
    }
}

int dectodbl ( decimal np,
double *  dblp 
)

Definition at line 433 of file informix.c.

References i, NULL, PGTYPESnumeric_free(), PGTYPESnumeric_from_decimal(), PGTYPESnumeric_new(), and PGTYPESnumeric_to_double().

Referenced by main().

{
    int         i;
    numeric    *nres = PGTYPESnumeric_new();

    if (nres == NULL)
        return ECPG_INFORMIX_OUT_OF_MEMORY;

    if (PGTYPESnumeric_from_decimal(np, nres) != 0)
    {
        PGTYPESnumeric_free(nres);
        return ECPG_INFORMIX_OUT_OF_MEMORY;
    }

    i = PGTYPESnumeric_to_double(nres, dblp);
    PGTYPESnumeric_free(nres);

    return i;
}

int dectoint ( decimal np,
int *  ip 
)

Definition at line 454 of file informix.c.

References NULL, PGTYPES_NUM_OVERFLOW, PGTYPESnumeric_free(), PGTYPESnumeric_from_decimal(), PGTYPESnumeric_new(), and PGTYPESnumeric_to_int().

Referenced by main().

{
    int         ret;
    numeric    *nres = PGTYPESnumeric_new();

    if (nres == NULL)
        return ECPG_INFORMIX_OUT_OF_MEMORY;

    if (PGTYPESnumeric_from_decimal(np, nres) != 0)
    {
        PGTYPESnumeric_free(nres);
        return ECPG_INFORMIX_OUT_OF_MEMORY;
    }

    ret = PGTYPESnumeric_to_int(nres, ip);
    PGTYPESnumeric_free(nres);

    if (ret == PGTYPES_NUM_OVERFLOW)
        ret = ECPG_INFORMIX_NUM_OVERFLOW;

    return ret;
}

int dectolong ( decimal np,
long *  lngp 
)

Definition at line 478 of file informix.c.

References NULL, PGTYPES_NUM_OVERFLOW, PGTYPESnumeric_free(), PGTYPESnumeric_from_decimal(), PGTYPESnumeric_new(), and PGTYPESnumeric_to_long().

Referenced by main().

{
    int         ret;
    numeric    *nres = PGTYPESnumeric_new();

    if (nres == NULL)
        return ECPG_INFORMIX_OUT_OF_MEMORY;

    if (PGTYPESnumeric_from_decimal(np, nres) != 0)
    {
        PGTYPESnumeric_free(nres);
        return ECPG_INFORMIX_OUT_OF_MEMORY;
    }

    ret = PGTYPESnumeric_to_long(nres, lngp);
    PGTYPESnumeric_free(nres);

    if (ret == PGTYPES_NUM_OVERFLOW)
        ret = ECPG_INFORMIX_NUM_OVERFLOW;

    return ret;
}

void dtcurrent ( timestamp ts  ) 

Definition at line 608 of file informix.c.

References PGTYPEStimestamp_current().

int dtcvasc ( char *  str,
timestamp ts 
)

Definition at line 614 of file informix.c.

References i, and PGTYPEStimestamp_from_asc().

{
    timestamp   ts_tmp;
    int         i;
    char      **endptr = &str;

    errno = 0;
    ts_tmp = PGTYPEStimestamp_from_asc(str, endptr);
    i = errno;
    if (i)
        /* TODO: rewrite to Informix error codes */
        return i;
    if (**endptr)
    {
        /* extra characters exist at the end */
        return ECPG_INFORMIX_EXTRA_CHARS;
    }
    /* TODO: other Informix error codes missing */

    /* everything went fine */
    *ts = ts_tmp;

    return 0;
}

int dtcvfmtasc ( char *  inbuf,
char *  fmtstr,
timestamp dtvalue 
)

Definition at line 640 of file informix.c.

References PGTYPEStimestamp_defmt_asc().

{
    return PGTYPEStimestamp_defmt_asc(inbuf, fmtstr, dtvalue);
}

int dtsub ( timestamp ts1,
timestamp ts2,
interval iv 
)

Definition at line 646 of file informix.c.

References PGTYPEStimestamp_sub().

{
    return PGTYPEStimestamp_sub(ts1, ts2, iv);
}

int dttoasc ( timestamp ts,
char *  output 
)

Definition at line 652 of file informix.c.

References free, and PGTYPEStimestamp_to_asc().

{
    char       *asctime = PGTYPEStimestamp_to_asc(*ts);

    strcpy(output, asctime);
    free(asctime);
    return 0;
}

int dttofmtasc ( timestamp ts,
char *  output,
int  str_len,
char *  fmtstr 
)

Definition at line 662 of file informix.c.

References PGTYPEStimestamp_fmt_asc().

{
    return PGTYPEStimestamp_fmt_asc(ts, output, str_len, fmtstr);
}

void* ECPG_informix_get_var ( int  number  ) 

Definition at line 1023 of file informix.c.

References ECPGget_var().

{
    return ECPGget_var(number);
}

void ECPG_informix_reset_sqlca ( void   ) 

Definition at line 1029 of file informix.c.

References ECPGget_sqlca(), and sqlca.

Referenced by main().

{
    struct sqlca_t *sqlca = ECPGget_sqlca();

    memcpy((char *) sqlca, (char *) &sqlca_init, sizeof(struct sqlca_t));
}

void ECPG_informix_set_var ( int  number,
void *  pointer,
int  lineno 
)

Definition at line 1017 of file informix.c.

References ECPGset_var().

{
    ECPGset_var(number, pointer, lineno);
}

static char* ecpg_strndup ( const char *  str,
size_t  len 
) [static]

Definition at line 179 of file informix.c.

References malloc.

Referenced by deccvasc().

{
    size_t      real_len = strlen(str);
    int         use_len = (int) ((real_len > len) ? len : real_len);

    char       *new = malloc(use_len + 1);

    if (new)
    {
        memcpy(new, str, use_len);
        new[use_len] = '\0';
    }
    else
        errno = ENOMEM;

    return new;
}

static int getRightMostDot ( char *  str  )  [static]

Definition at line 747 of file informix.c.

References i.

Referenced by rfmtlong().

{
    size_t      len = strlen(str);
    int         i,
                j;

    j = 0;
    for (i = len - 1; i >= 0; i--)
    {
        if (str[i] == '.')
            return len - j - 1;
        j++;
    }
    return -1;
}

static int initValue ( long  lng_val  )  [static]

initialize the struct, which holds the different forms of the long value

Definition at line 699 of file informix.c.

References i, malloc, NULL, and value.

Referenced by rfmtlong().

{
    int         i,
                j;
    long        l,
                dig;

    /* set some obvious things */
    value.val = lng_val >= 0 ? lng_val : lng_val * (-1);
    value.sign = lng_val >= 0 ? '+' : '-';
    value.maxdigits = log10(2) * (8 * sizeof(long) - 1);

    /* determine the number of digits */
    i = 0;
    l = 1;
    do
    {
        i++;
        l *= 10;
    }
    while ((l - 1) < value.val && l <= LONG_MAX / 10);

    if (l <= LONG_MAX / 10)
    {
        value.digits = i;
        l /= 10;
    }
    else
        value.digits = i + 1;

    value.remaining = value.digits;

    /* convert the long to string */
    if ((value.val_string = (char *) malloc(value.digits + 1)) == NULL)
        return -1;
    dig = value.val;
    for (i = value.digits, j = 0; i > 0; i--, j++)
    {
        value.val_string[j] = dig / l + '0';
        dig = dig % l;
        l /= 10;
    }
    value.val_string[value.digits] = '\0';
    return 0;
}

int intoasc ( interval i,
char *  str 
)

Definition at line 668 of file informix.c.

References PGTYPESinterval_to_asc().

{
    errno = 0;
    str = PGTYPESinterval_to_asc(i);

    if (!str)
        return -errno;

    return 0;
}

void ldchar ( char *  src,
int  len,
char *  dest 
)

Definition at line 975 of file informix.c.

References byleng(), and memmove.

Referenced by main().

{
    int         dlen = byleng(src, len);

    memmove(dest, src, dlen);
    dest[dlen] = '\0';
}

int rdatestr ( date  d,
char *  str 
)

Definition at line 503 of file informix.c.

References free, and PGTYPESdate_to_asc().

Referenced by date_test_defmt(), date_test_strdate(), and main().

{
    char       *tmp = PGTYPESdate_to_asc(d);

    if (!tmp)
        return ECPG_INFORMIX_DATE_CONVERT;

    /* move to user allocated buffer */
    strcpy(str, tmp);
    free(tmp);

    return 0;
}

int rdayofweek ( date  d  ) 

Definition at line 600 of file informix.c.

References PGTYPESdate_dayofweek().

{
    return (PGTYPESdate_dayofweek(d));
}

int rdefmtdate ( date d,
char *  fmt,
char *  str 
)

Definition at line 549 of file informix.c.

References PGTYPES_DATE_BAD_DAY, PGTYPES_DATE_BAD_MONTH, PGTYPES_DATE_ERR_EARGS, PGTYPES_DATE_ERR_ENOSHORTDATE, PGTYPES_DATE_ERR_ENOTDMY, and PGTYPESdate_defmt_asc().

Referenced by date_test_defmt(), and rstrdate().

{
    /* TODO: take care of DBCENTURY environment variable */
    /* PGSQL functions allow all centuries */

    errno = 0;
    if (PGTYPESdate_defmt_asc(d, fmt, str) == 0)
        return 0;

    switch (errno)
    {
        case PGTYPES_DATE_ERR_ENOSHORTDATE:
            return ECPG_INFORMIX_ENOSHORTDATE;
        case PGTYPES_DATE_ERR_EARGS:
        case PGTYPES_DATE_ERR_ENOTDMY:
            return ECPG_INFORMIX_ENOTDMY;
        case PGTYPES_DATE_BAD_DAY:
            return ECPG_INFORMIX_BAD_DAY;
        case PGTYPES_DATE_BAD_MONTH:
            return ECPG_INFORMIX_BAD_MONTH;
        default:
            return ECPG_INFORMIX_BAD_YEAR;
    }
}

int rfmtdate ( date  d,
char *  fmt,
char *  str 
)

Definition at line 575 of file informix.c.

References PGTYPESdate_fmt_asc().

Referenced by date_test_fmt().

{
    errno = 0;
    if (PGTYPESdate_fmt_asc(d, fmt, str) == 0)
        return 0;

    if (errno == ENOMEM)
        return ECPG_INFORMIX_OUT_OF_MEMORY;

    return ECPG_INFORMIX_DATE_CONVERT;
}

int rfmtlong ( long  lng_val,
char *  fmt,
char *  outbuf 
)

Definition at line 765 of file informix.c.

References fmtchar(), free, getRightMostDot(), i, initValue(), malloc, sign, and value.

Referenced by fmtlong().

{
    size_t      fmt_len = strlen(fmt);
    size_t      temp_len;
    int         i,
                j,              /* position in temp */
                k,
                dotpos;
    int         leftalign = 0,
                blank = 0,
                sign = 0,
                entitydone = 0,
                signdone = 0,
                brackets_ok = 0;
    char       *temp;
    char        tmp[2] = " ";
    char        lastfmt = ' ',
                fmtchar = ' ';

    temp = (char *) malloc(fmt_len + 1);
    if (!temp)
    {
        errno = ENOMEM;
        return -1;
    }

    /* put all info about the long in a struct */
    if (initValue(lng_val) == -1)
    {
        free(temp);
        errno = ENOMEM;
        return -1;
    }

    /* '<' is the only format, where we have to align left */
    if (strchr(fmt, (int) '<'))
        leftalign = 1;

    /* '(' requires ')' */
    if (strchr(fmt, (int) '(') && strchr(fmt, (int) ')'))
        brackets_ok = 1;

    /* get position of the right-most dot in the format-string */
    /* and fill the temp-string wit '0's up to there. */
    dotpos = getRightMostDot(fmt);

    /* start to parse the formatstring */
    temp[0] = '\0';
    k = value.digits - 1;       /* position in the value_string */
    for (i = fmt_len - 1, j = 0; i >= 0; i--, j++)
    {
        /* qualify, where we are in the value_string */
        if (k < 0)
        {
            blank = 1;
            if (k == -1)
                sign = 1;
            if (leftalign)
            {
                /* can't use strncat(,,0) here, Solaris would freek out */
                if (sign)
                    if (signdone)
                    {
                        temp[j] = '\0';
                        break;
                    }
            }
        }
        /* if we're right side of the right-most dot, print '0' */
        if (dotpos >= 0 && dotpos <= i)
        {
            if (dotpos < i)
            {
                if (fmt[i] == ')')
                    tmp[0] = value.sign == '-' ? ')' : ' ';
                else
                    tmp[0] = '0';
            }
            else
                tmp[0] = '.';
            strcat(temp, tmp);
            continue;
        }
        /* the ',' needs special attention, if it is in the blank area */
        if (blank && fmt[i] == ',')
            fmtchar = lastfmt;
        else
            fmtchar = fmt[i];
        /* waiting for the sign */
        if (k < 0 && leftalign && sign && !signdone && fmtchar != '+' && fmtchar != '-')
            continue;
        /* analyse this format-char */
        switch (fmtchar)
        {
            case ',':
                tmp[0] = ',';
                k++;
                break;
            case '*':
                if (blank)
                    tmp[0] = '*';
                else
                    tmp[0] = value.val_string[k];
                break;
            case '&':
                if (blank)
                    tmp[0] = '0';
                else
                    tmp[0] = value.val_string[k];
                break;
            case '#':
                if (blank)
                    tmp[0] = ' ';
                else
                    tmp[0] = value.val_string[k];
                break;
            case '-':
                if (sign && value.sign == '-' && !signdone)
                {
                    tmp[0] = '-';
                    signdone = 1;
                }
                else if (blank)
                    tmp[0] = ' ';
                else
                    tmp[0] = value.val_string[k];
                break;
            case '+':
                if (sign && !signdone)
                {
                    tmp[0] = value.sign;
                    signdone = 1;
                }
                else if (blank)
                    tmp[0] = ' ';
                else
                    tmp[0] = value.val_string[k];
                break;
            case '(':
                if (sign && brackets_ok && value.sign == '-')
                    tmp[0] = '(';
                else if (blank)
                    tmp[0] = ' ';
                else
                    tmp[0] = value.val_string[k];
                break;
            case ')':
                if (brackets_ok && value.sign == '-')
                    tmp[0] = ')';
                else
                    tmp[0] = ' ';
                break;
            case '$':
                if (blank && !entitydone)
                {
                    tmp[0] = '$';
                    entitydone = 1;
                }
                else if (blank)
                    tmp[0] = ' ';
                else
                    tmp[0] = value.val_string[k];
                break;
            case '<':
                tmp[0] = value.val_string[k];
                break;
            default:
                tmp[0] = fmt[i];
        }
        strcat(temp, tmp);
        lastfmt = fmt[i];
        k--;
    }
    /* safety-net */
    temp[fmt_len] = '\0';

    /* reverse the temp-string and put it into the outbuf */
    temp_len = strlen(temp);
    outbuf[0] = '\0';
    for (i = temp_len - 1; i >= 0; i--)
    {
        tmp[0] = temp[i];
        strcat(outbuf, tmp);
    }
    outbuf[temp_len] = '\0';

    /* cleaning up */
    free(temp);
    free(value.val_string);

    return 0;
}

int rgetmsg ( int  msgnum,
char *  s,
int  maxsize 
)

Definition at line 984 of file informix.c.

{
    (void) msgnum;              /* keep the compiler quiet */
    (void) s;                   /* keep the compiler quiet */
    (void) maxsize;             /* keep the compiler quiet */
    return 0;
}

int risnull ( int  t,
char *  ptr 
)

Definition at line 1044 of file informix.c.

References ECPGis_noind_null().

Referenced by deccall3(), deccvasc(), deccvdbl(), deccvint(), deccvlong(), dectoasc(), main(), and test_null().

{
    return (ECPGis_noind_null(t, ptr));
}

int rjulmdy ( date  d,
short  mdy[3] 
)

Definition at line 537 of file informix.c.

References PGTYPESdate_julmdy().

{
    int         mdy_int[3];

    PGTYPESdate_julmdy(d, mdy_int);
    mdy[0] = (short) mdy_int[0];
    mdy[1] = (short) mdy_int[1];
    mdy[2] = (short) mdy_int[2];
    return 0;
}

int rmdyjul ( short  mdy[3],
date d 
)

Definition at line 588 of file informix.c.

References PGTYPESdate_mdyjul().

Referenced by main().

{
    int         mdy_int[3];

    mdy_int[0] = mdy[0];
    mdy_int[1] = mdy[1];
    mdy_int[2] = mdy[2];
    PGTYPESdate_mdyjul(mdy_int, d);
    return 0;
}

int rsetnull ( int  t,
char *  ptr 
)

Definition at line 1037 of file informix.c.

References ECPGset_noind_null().

Referenced by deccall3(), deccvasc(), deccvdbl(), deccvint(), deccvlong(), dectoasc(), and main().

{
    ECPGset_noind_null(t, ptr);
    return 0;
}

int rstrdate ( char *  str,
date d 
)

Definition at line 524 of file informix.c.

References rdefmtdate().

Referenced by date_test_strdate().

{
    return rdefmtdate(d, "mm/dd/yyyy", str);
}

void rtoday ( date d  ) 

Definition at line 530 of file informix.c.

References PGTYPESdate_today().

{
    PGTYPESdate_today(d);
    return;
}

int rtypalign ( int  offset,
int  type 
)

Definition at line 993 of file informix.c.

{
    (void) offset;              /* keep the compiler quiet */
    (void) type;                /* keep the compiler quiet */
    return 0;
}

int rtypmsize ( int  type,
int  len 
)

Definition at line 1001 of file informix.c.

{
    (void) type;                /* keep the compiler quiet */
    (void) len;                 /* keep the compiler quiet */
    return 0;
}

int rtypwidth ( int  sqltype,
int  sqllen 
)

Definition at line 1009 of file informix.c.

{
    (void) sqltype;             /* keep the compiler quiet */
    (void) sqllen;              /* keep the compiler quiet */
    return 0;
}

void rupshift ( char *  str  ) 

Definition at line 959 of file informix.c.

Referenced by main().

{
    for (; *str != '\0'; str++)
        if (islower((unsigned char) *str))
            *str = toupper((unsigned char) *str);
    return;
}


Variable Documentation

int digits
int maxdigits

Definition at line 687 of file informix.c.

Referenced by apply_typmod(), mul_var(), and numeric().

int remaining
char sign
struct sqlca_t sqlca_init [static]
Initial value:
{
    {
        'S', 'Q', 'L', 'C', 'A', ' ', ' ', ' '
    },
    sizeof(struct sqlca_t),
    0,
    {
        0,
        {
            0
        }
    },
    {
        'N', 'O', 'T', ' ', 'S', 'E', 'T', ' '
    },
    {
        0, 0, 0, 0, 0, 0
    },
    {
        0, 0, 0, 0, 0, 0, 0, 0
    },
    {
        '0', '0', '0', '0', '0'
    }
}

Definition at line 21 of file informix.c.

long val

Definition at line 686 of file informix.c.

Referenced by _copyAConst(), _copyResTarget(), _copyValue(), _equalResTarget(), _equalValue(), _ltree_compress(), _outResTarget(), _readBitmapset(), _ShowOption(), AlterDomainValidateConstraint(), assignVariables(), AttrDefaultFetch(), autoinc(), bitfromint4(), bitfromint8(), boolop(), bqarr_in(), build_startup_packet(), BuildIndexValueDescription(), byteaout(), calc_distr(), calc_hist(), cash_words(), check_timezone(), checkcondition_arr(), CheckConstraintFetch(), composite_to_json(), conninfo_array_parse(), convert_string_datum(), CopyReadAttributesText(), datum_write(), DecodeDate(), DecodeDateTime(), DecodeInterval(), DecodeISO8601Interval(), DecodeNumber(), DecodePosixTimezone(), DecodeTimeOnly(), DropConfigurationMapping(), dump_sqlda(), each_object_field_end(), ean13_out(), ecpg_set_compat_sqlda(), ecpg_set_native_sqlda(), elem_contained_by_range(), elements_array_element_end(), esc_decode(), ExecBuildSlotValueDescription(), findoprnd(), findTargetlistEntrySQL92(), flatten_set_variable_args(), float4_numeric(), float4_to_char(), float4in(), float8_numeric(), float8_to_char(), float8in(), get_attstatsslot(), get_prompt(), get_sql_insert(), get_sql_update(), get_stack_depth_rlimit(), getbits(), GetDomainConstraints(), getTokenTypes(), getv4(), GetVariableNum(), ghstore_compress(), gin_extract_query_trgm(), gin_extract_tsquery(), gin_extract_value_trgm(), ginint4_queryextract(), gtrgm_compress(), gtsvector_compress(), GUCArrayDelete(), GUCArrayReset(), hash_object_field_end(), hashint8(), heap_compute_data_size(), heap_fill_tuple(), hstore_contains(), hstore_from_text(), inc_counter(), ineq_histogram_selectivity(), inet_aton(), inet_cidr_pton_ipv6(), int2_numeric(), int4_numeric(), int4_to_char(), int8_numeric(), int8_to_char(), int8out(), interval_part(), interval_trunc(), is_superuser(), is_valid(), isbn_cast_from_ean13(), ismn_cast_from_ean13(), isn_out(), issn_cast_from_ean13(), json_agg_transfn(), ltree_compress(), ltxtq_exec(), main(), make_array_ref(), make_const(), make_valid(), makepol(), MergeWithExistingConstraint(), nodeRead(), nodeTokenType(), numeric_exp(), numeric_float8_no_overflow(), numeric_int2(), numeric_to_char(), numeric_to_double_no_overflow(), numericvar_to_double(), numericvar_to_double_no_overflow(), numericvar_to_int4(), numericvar_to_int8(), OldSerXidGetMinConflictCommitSeqNo(), parse_args(), parse_hba_line(), parse_int(), parse_real(), parse_scalar(), parse_snapshot(), parseIntFromText(), ParseISO8601Number(), parseServiceFile(), parseXidFromText(), pg_get_constraintdef_worker(), plperl_build_tuple_result(), plperl_modify_tuple(), PLy_elog(), populate_recordset_object_field_end(), postgres_fdw_validator(), power_var(), pqGetErrorNotice3(), pqRowProcessor(), pqSetenvPoll(), prsd_headline(), putVariable(), range_contains_elem(), recompute_limits(), RelationBuildTriggers(), RelationGetExclusionInfo(), removeHeapElement(), ReportGUCOption(), ri_ReportViolation(), serialize_deflist(), session_username(), SPI_getvalue(), sqlda_common_total_size(), standard_strings(), str2txid(), strtoi(), sv2cstr(), text_format_parse_digits(), time_part(), timestamp_part(), timestamp_trunc(), timestamp_zone(), timestamptz_part(), timestamptz_trunc(), timestamptz_zone(), timetz_part(), timetz_zone(), to_json(), transformExprRecurse(), trgm2int(), ts_match_vq(), tsqueryrecv(), tstoreReceiveSlot_detoast(), tstz_to_ts_gmt(), txid_current(), untransformRelOptions(), upc_cast_from_ean13(), useKeepalives(), validateCheckConstraint(), and worker_spi_main().

char* val_string

Definition at line 691 of file informix.c.

struct { ... } value [static]

Referenced by _crypt_gensalt_extended_rn(), _crypt_gensalt_md5_rn(), array_fill(), array_fill_with_lower_bounds(), array_to_text_internal(), AuxiliaryProcessMain(), bytea_string_agg_transfn(), call_subtype_diff(), cash_in(), cash_out(), cash_words(), check_pghost_envvar(), compute_array_stats(), compute_minimal_stats(), compute_range_stats(), compute_scalar_stats(), compute_tsvector_stats(), concat_internal(), conninfo_uri_parse_params(), convert_prep_stmt_params(), CopyOneRowTo(), DCH_from_char(), debugtup(), DefineSequence(), domain_in(), domain_recv(), dxsyn_lexize(), exec_assign_c_string(), exec_assign_expr(), exec_command(), exec_move_row(), exec_stmt_case(), exec_stmt_exit(), exec_stmt_foreach_a(), exec_stmt_fori(), exec_stmt_if(), exec_stmt_while(), ExecEvalCoalesce(), ExecEvalMinMax(), ExecEvalXml(), ExecWindowAgg(), filter_list_to_array(), float4_to_char(), Float4GetDatum(), float8_to_char(), Float8GetDatum(), GetComment(), hstore_from_record(), hstore_populate_record(), initValue(), int4_to_char(), int8_to_char(), json_populate_record(), main(), numeric_in(), numeric_recv(), numeric_to_char(), numeric_to_number(), optionListToArray(), parse_one_reloption(), parse_psql_options(), pg_column_size(), pg_get_triggerdef_worker(), PGTYPESnumeric_from_asc(), plpgsql_token_is_unreserved_keyword(), PLy_subtransaction_exit(), PLyDict_FromTuple(), PLyGenericObject_ToComposite(), PLyMapping_ToComposite(), PLySequence_ToComposite(), populate_recordset_object_end(), PostmasterMain(), postquel_get_single_result(), pqRowProcessor(), process_postgres_switches(), process_startup_options(), ProcessGUCArray(), prune_element_hashtable(), read_dictionary(), record_out(), rfmtlong(), set_config_by_name(), ShowGUCConfigOption(), StoreQueryTuple(), text_format(), to_hex32(), to_hex64(), toast_delete(), transformRelOptions(), transtime(), txid_snapshot_xip(), txid_visible_in_snapshot(), and xmlelement().