RE: ESQL/C - Receiving and Printing different date
Posted in 2011
Topics: High Availability & Replication, Connectivity: ESQL/C, 4GL & Embedded SQL, Data Types & Schema Design
So, now the question is, how do you print values such as datetime Interval and
money and date strings? I can declare them in an ESQL/C program. Now I need to
print them to a file.
For a datetime interval variable, in the documentation it appears that I can
skip the interval declaration all together and just use a string. The value is
converted automatically. I print a string.
For a date, it appears that I use a date variable and then use
rdatestr(date_vaue, new_string);
If the above two are correct, how do I handle the money. Is it returned with a
"$"? Do I need to convert it to a decimal? Can I just use a decimal to receive
the value from a SELECT?
Thanks.
> To: ids@iiug.org
> From: jonathan.leffler@gmail.com
> Subject: Re: ESQL/C - Multiple cursors open to differen.... [25766]
> Date: Wed, 28 Dec 2011 11:34:43 -0500
>
> On Wed, Dec 28, 2011 at 07:49, LARRY SORENSEN <lsorensen25@msn.com> wrote:
>
> > Question on data types:
> >
> > It appears that the following data type declarations are legal in ESQL/C.
> > Is
> > this correct?
> >
> > money(3,2) some_variable;
> > datetime year to fraction(2) another_variable;
> >
>
> Empirically: YES.
>
> xx.ec:
> $ money(6,2) x;
> $ decimal(14,4) y;>
> xx.c:
> #include <sqlhdr.h>
> #include <sqliapi.h>
> /*
> * $ money(6,2) x;
> */
> #line 1 "xx.ec"
> dec_t x;
> /*
> * $ decimal(14,4) y;
> */
> #line 2 "xx.ec"
> dec_t y;
>
> #line 2 "xx.ec"
>
> Note that there is nothing in those variables that actually limits them to
> being 'money(6,2)' or `decimal(14,4)'; that requires more manipulation of
> the values. And it might be that you'd see those limits imposed in an SQL
> statement.
>
> BUT: your question was 'can you write such declarations' and the answer
> (by demonstration - on MacOS X 10.7.2 with ESQL/C 3.70.FC2) is YES.
>
> PS: Please trim the email trail to that which is relevant. Where there is
> nothing relevant from the trail, think about starting a new thread.
>
> --
> Jonathan Leffler <jonathan.leffler@gmail.com> #include <disclaimer.h>
> Guardian of DBD::Informix - v2011.0612 - http://dbi.perl.org
> "Blessed are we who can laugh at ourselves, for we shall never cease to be
> amused."
>
> --90e6ba6e836c5b41c204b529932a
>
>
>
*******************************************************************************
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
On Wed, Dec 28, 2011 at 09:42, LARRY SORENSEN <lsorensen25@msn.com> wrote:
> So, now the question is, how do you print values such as Datetime,
> Interval,
> money and date strings? I can declare them in an ESQL/C program. Now I
> need to
> print them to a file.
>
> For a datetime interval variable, in the documentation it appears that I
> can
> skip the interval declaration all together and just use a string. The
> value is
> converted automatically. I print a string.
>
There are a collection of functions for converting from the 'raw' database
format to string and vice versa. Many of them start with the letter 'r'
(from the days when Informix was simply a product produced by Relational
Database Systems (RDS) Inc).
rdttofmtasc() - convert datetime (dt) to formatted (fmt) ASCII (asc).
rdtcvfmtasc() - convert (cv) string to datetime using a format string.
rintoasc() - convert interval (in) to ASCII (asc);
rincvasc() - convert string to interval.
There are more date conversion functions to choose from.
Decimals can be handled with:
rdectoasc()
rdeccvasc()
and relatives. More problematic is formatting money.
See:
http://publib.boulder.ibm.com/infocenter/idshelp/v10/index.jsp?topic=/com.ibm.es
qlc.doc/esqlc114.htm
for rfmtdec() and the masks it uses...it is often appropriate for MONEY and
fixed-point decimals generally.
All of these, and many more, functions can be found in the ESQL/C
Programmer's Reference Manual.
One other alternative is to use host variables that are a string type and
make ESQL/C do the conversion for you. However, if you don't like the
format it chooses, for whatever reason, then you're best off going back to
the 'raw' types and formatting them yourself.
> For a date, it appears that I use a date variable and then use
>
> rdatestr(date_vaue, new_string);
>
> If the above two are correct, how do I handle the money. Is it returned
> with a
> "$"? Do I need to convert it to a decimal? Can I just use a decimal to
> receive
> the value from a SELECT?
>
> Thanks.
>
> > To: ids@iiug.org
> > From: jonathan.leffler@gmail.com
> > Subject: Re: ESQL/C - Multiple cursors open to differen.... [25766]
> > Date: Wed, 28 Dec 2011 11:34:43 -0500
> >
> > On Wed, Dec 28, 2011 at 07:49, LARRY SORENSEN <lsorensen25@msn.com>
> wrote:
> >
> > > Question on data types:
> > >
> > > It appears that the following data type declarations are legal in
> ESQL/C.
> > > Is
> > > this correct?
> > >
> > > money(3,2) some_variable;
> > > datetime year to fraction(2) another_variable;
> > >
> >
> > Empirically: YES.
> >
> > xx.ec:
> > $ money(6,2) x;
> > $ decimal(14,4) y;> >
> > xx.c:
> > #include <sqlhdr.h>
> > #include <sqliapi.h>
> > /*
> > * $ money(6,2) x;
> > */
> > #line 1 "xx.ec"
> > dec_t x;
> > /*
> > * $ decimal(14,4) y;
> > */
> > #line 2 "xx.ec"
> > dec_t y;
> >
> > #line 2 "xx.ec"
> >
> > Note that there is nothing in those variables that actually limits them
> to
> > being 'money(6,2)' or `decimal(14,4)'; that requires more manipulation of
> > the values. And it might be that you'd see those limits imposed in an SQL
> > statement.
> >
> > BUT: your question was 'can you write such declarations' and the answer
> > (by demonstration - on MacOS X 10.7.2 with ESQL/C 3.70.FC2) is YES.
>
--
Jonathan Leffler <jonathan.leffler@gmail.com> #include <disclaimer.h>
Guardian of DBD::Informix - v2011.0612 - http://dbi.perl.org
"Blessed are we who can laugh at ourselves, for we shall never cease to be
amused."
--90e6ba6e836c42478804b52f90da