1/* src/interfaces/ecpg/compatlib/informix.c */
3 #define POSTGRES_ECPG_INTERNAL
19/* this is also defined in ecpglib/misc.c, by defining it twice we don't have to export the symbol */
24 'S',
'Q',
'L',
'C',
'A',
' ',
' ',
' '
35 'N',
'O',
'T',
' ',
'S',
'E',
'T',
' '
41 0, 0, 0, 0, 0, 0, 0, 0
44 '0',
'0',
'0',
'0',
'0'
94 * we must NOT set the result to NULL here because it may be the same
95 * variable as one of the arguments
132 i = (*ptr) (
a1,
a2, nres);
134 if (
i == 0)
/* No error */
137 /* set the result to null in case it errors out later */
149/* we start with the numeric functions */
175 memcpy(target, src,
sizeof(
decimal));
181 size_t real_len = strlen(
str);
182 int use_len = (int) ((real_len >
len) ?
len : real_len);
184 char *
new =
malloc(use_len + 1);
188 memcpy(
new,
str, use_len);
410 * TODO: have to take care of len here and create exponential notation if
413 if ((
int) (strlen(
str) + 1) >
len)
506/* Now the date functions */
515 /* move to user allocated buffer */
524* the input for this function is mmddyyyy and any non-numeric
525* character can be used as a separator
546 mdy[0] = (short) mdy_int[0];
547 mdy[1] = (short) mdy_int[1];
548 mdy[2] = (short) mdy_int[2];
555 /* TODO: take care of DBCENTURY environment variable */
556 /* PGSQL functions allow all centuries */
609/* And the datetime stuff */
622 char **endptr = &
str;
628 /* TODO: rewrite to Informix error codes */
632 /* extra characters exist at the end */
635 /* TODO: other Informix error codes missing */
637 /* everything went fine */
709 /* set some obvious things */
710 value.val = lng_val >= 0 ? lng_val : lng_val * (-1);
711 value.sign = lng_val >= 0 ?
'+' :
'-';
712 value.maxdigits = log10(2) * (8 *
sizeof(long) - 1);
714 /* determine the number of digits */
722 while ((l - 1) <
value.val && l <= LONG_MAX / 10);
724 if (l <= LONG_MAX / 10)
734 /* convert the long to string */
738 for (
i =
value.digits,
j = 0;
i > 0;
i--,
j++)
740 value.val_string[
j] = dig / l +
'0';
748/* return the position of the right-most dot in some string */
757 for (
i =
len - 1;
i >= 0;
i--)
766/* And finally some misc functions */
768 rfmtlong(
long lng_val,
const char *fmt,
char *outbuf)
770 size_t fmt_len = strlen(fmt);
773 j,
/* position in temp */
787 temp = (
char *)
malloc(fmt_len + 1);
794 /* put all info about the long in a struct */
802 /* '<' is the only format, where we have to align left */
803 if (strchr(fmt, (
int)
'<'))
806 /* '(' requires ')' */
807 if (strchr(fmt, (
int)
'(') && strchr(fmt, (
int)
')'))
811 * get position of the right-most dot in the format-string and fill the
812 * temp-string with '0's up to there.
816 /* start to parse the format-string */
818 k =
value.digits - 1;
/* position in the value_string */
819 for (
i = fmt_len - 1,
j = 0;
i >= 0;
i--,
j++)
821 /* qualify, where we are in the value_string */
829 /* can't use strncat(,,0) here, Solaris would freak out */
838 /* if we're right side of the right-most dot, print '0' */
839 if (dotpos >= 0 && dotpos <=
i)
844 tmp[0] =
value.sign ==
'-' ?
')' :
' ';
853 /* the ',' needs special attention, if it is in the blank area */
854 if (blank && fmt[
i] ==
',')
858 /* waiting for the sign */
861 /* analyse this format-char */
872 tmp[0] =
value.val_string[k];
878 tmp[0] =
value.val_string[k];
884 tmp[0] =
value.val_string[k];
887 if (
sign &&
value.sign ==
'-' && !signdone)
895 tmp[0] =
value.val_string[k];
898 if (
sign && !signdone)
906 tmp[0] =
value.val_string[k];
909 if (
sign && brackets_ok &&
value.sign ==
'-')
914 tmp[0] =
value.val_string[k];
917 if (brackets_ok &&
value.sign ==
'-')
923 if (blank && !entitydone)
931 tmp[0] =
value.val_string[k];
934 tmp[0] =
value.val_string[k];
944 temp[fmt_len] =
'0円';
946 /* reverse the temp-string and put it into the outbuf */
947 temp_len = strlen(temp);
949 for (
i = temp_len - 1;
i >= 0;
i--)
954 outbuf[temp_len] =
'0円';
966 for (; *
str !=
'0円';
str++)
967 if (islower((
unsigned char) *
str))
968 *
str = toupper((
unsigned char) *
str);
983 memmove(
dest, src, dlen);
990 (void) msgnum;
/* keep the compiler quiet */
991 (void) s;
/* keep the compiler quiet */
992 (void) maxsize;
/* keep the compiler quiet */
999 (void) offset;
/* keep the compiler quiet */
1000 (void)
type;
/* keep the compiler quiet */
1007 (void)
type;
/* keep the compiler quiet */
1008 (void)
len;
/* keep the compiler quiet */
1015 (void) sqltype;
/* keep the compiler quiet */
1016 (void) sqllen;
/* keep the compiler quiet */
static const FormData_pg_attribute a1
static const FormData_pg_attribute a2
void ECPGset_var(int number, void *pointer, int lineno)
struct sqlca_t * ECPGget_sqlca(void)
void ECPGset_noind_null(enum ECPGttype type, void *ptr)
bool ECPGis_noind_null(enum ECPGttype type, const void *ptr)
void * ECPGget_var(int number)
int PGTYPESdate_dayofweek(date dDate)
char * PGTYPESdate_to_asc(date dDate)
void PGTYPESdate_today(date *d)
int PGTYPESdate_fmt_asc(date dDate, const char *fmtstring, char *outbuf)
int PGTYPESdate_defmt_asc(date *d, const char *fmt, const char *str)
void PGTYPESdate_julmdy(date jd, int *mdy)
void PGTYPESdate_mdyjul(int *mdy, date *jdate)
#define PGTYPES_DATE_ERR_ENOTDMY
#define PGTYPES_NUM_BAD_NUMERIC
#define PGTYPES_DATE_BAD_DAY
#define PGTYPES_NUM_OVERFLOW
#define PGTYPES_DATE_ERR_ENOSHORTDATE
#define PGTYPES_NUM_UNDERFLOW
#define PGTYPES_NUM_DIVIDE_ZERO
#define PGTYPES_DATE_ERR_EARGS
#define PGTYPES_DATE_BAD_MONTH
char * PGTYPESinterval_to_asc(interval *span)
int PGTYPESnumeric_from_double(double d, numeric *dst)
int PGTYPESnumeric_from_decimal(decimal *src, numeric *dst)
numeric * PGTYPESnumeric_new(void)
int PGTYPESnumeric_to_decimal(numeric *src, decimal *dst)
char * PGTYPESnumeric_to_asc(numeric *num, int dscale)
int PGTYPESnumeric_mul(numeric *var1, numeric *var2, numeric *result)
int PGTYPESnumeric_to_long(numeric *nv, long *lp)
int PGTYPESnumeric_to_double(numeric *nv, double *dp)
int PGTYPESnumeric_from_long(signed long int long_val, numeric *var)
int PGTYPESnumeric_to_int(numeric *nv, int *ip)
int PGTYPESnumeric_from_int(signed int int_val, numeric *var)
int PGTYPESnumeric_sub(numeric *var1, numeric *var2, numeric *result)
void PGTYPESnumeric_free(numeric *var)
int PGTYPESnumeric_cmp(numeric *var1, numeric *var2)
int PGTYPESnumeric_div(numeric *var1, numeric *var2, numeric *result)
int PGTYPESnumeric_add(numeric *var1, numeric *var2, numeric *result)
numeric * PGTYPESnumeric_from_asc(char *str, char **endptr)
timestamp PGTYPEStimestamp_from_asc(char *str, char **endptr)
int PGTYPEStimestamp_sub(timestamp *ts1, timestamp *ts2, interval *iv)
char * PGTYPEStimestamp_to_asc(timestamp tstamp)
void PGTYPEStimestamp_current(timestamp *ts)
int PGTYPEStimestamp_fmt_asc(timestamp *ts, char *output, int str_len, const char *fmtstr)
int PGTYPEStimestamp_defmt_asc(const char *str, const char *fmt, timestamp *d)
static void fmtchar(int value, int leftjust, int minlen, PrintfTarget *target)
static void fmtstr(const char *value, int leftjust, int minlen, int maxwidth, int pointflag, PrintfTarget *target)