Translating with DrWatson… this can take a few seconds the first time.
This is a genuine, complex translation. DrWatson protects commands, error codes, and log output while naturally translating the surrounding text. It’s translated once and saved.
lovecreatesbeauty asked whether the ESQL/C datetime type can be used for function parameters and variables that are not host variables. Jonathan Leffler replied with example code using dtime_t, TU_ENCODE for the qualifier and a pointer parameter. He noted conversion functions such as dtcvasc expect the output's qualifier set beforehand, and that intervals work the same way via intrvl_t.
Auto-generated by Claude from the posts below — may be imperfect; read the full thread.
Hello experts,
I declared a function parameter with the ESQL/C datetime type. I didn't
use `EXEC SQL BEGIN DECLARE SECTION` and `EXEC SQL END DECLARE SECTION`
qualifiers, because that declaration is not a host variable
declaration. But there are some errors always.
`IBM Informix ESQL/C Programmer's Manual' says:
datetime.h:
Definitions of the ESQL/C datetime and interval structures, which are
the host variables for DATETIME and INTERVAL columns.
Does it mean that I can't use datetime to declare parameters or
variables which are not host variables. How can I use ESQL/C datatypes
to declare non-host variables / function parameters correctly?
lovecreatesbeauty
lovecreatesbeauty wrote:
> I declared a function parameter with the ESQL/C datetime type. I didn't
> use `EXEC SQL BEGIN DECLARE SECTION` and `EXEC SQL END DECLARE SECTION`
> qualifiers, because that declaration is not a host variable
> declaration. But there are some errors always.
>
> `IBM Informix ESQL/C Programmer's Manual' says:
>
> datetime.h:
> Definitions of the ESQL/C datetime and interval structures, which are
> the host variables for DATETIME and INTERVAL columns.
>
> Does it mean that I can't use datetime to declare parameters or
> variables which are not host variables. How can I use ESQL/C datatypes
> to declare non-host variables / function parameters correctly?
I'm not clear exactly what your problem is, but (uncompiled code):
#include "datetime.h"
/* DATETIME(2005-10-06 23:13:45) YEAR TO SECOND */
static const dtime_t var1 =
{ TU_ENCODE(TU_YEAR, TU_SECOND),
{ 7, +1, 7, { 20, 5, 10, 6, 23, 13, 45 } }
};
void somefunc(dtime_t *dt)
{
dtime_t beauty = *dt;
char buffer[36];
beauty.dt_qual = TU_ENCODE(TU_YEAR, TU_F5);
dttoasc(*beauty, buffer);
printf("DT YR TO F5: %s\\n", buffer);
}
Note that the ESQL/C notation such as:
$ datetime year to second blah;
essentially initializes blah.dt_qual = TU_ENCODE(TU_YEAR, TU_SECOND);
In C99, you can even write that as:
dtime_t blah = { .dt_qual = TU_ENCODE(TU_YEAR, TU_SECOND) };
What's really scary is I can now write initializers like var1
practically in my sleep -- I've been working on some code in this area,
and one part of that involved writing tests, and one part of writing the
tests involved writing out initializers for the expected values of
conversions. Ouch!
Similar rules and observations apply to intervals via intrvl_t.
Note that many of the ESQL/C conversion functions expect the 'output'
parameter to be half-initialized - the qualifier (dt_qual, in_qual)
should be set before calling the function. So, for example, dtcvasc()
expects the output vaslue to be initialized with the desired qualifier.
--
Jonathan Leffler #include <disclaimer.h>
Email: jleffler@earthlink.net, jleffler@us.ibm.com
Guardian of DBD::Informix v2005.02 -- http://dbi.perl.org/
lovecreatesbeauty wrote:
> I declared a function parameter with the ESQL/C datetime type
See my answer in the news group.
--
Jonathan Leffler #include <disclaimer.h>
Email: jleffler@earthlink.net, jleffler@us.ibm.com
Guardian of DBD::Informix v2005.02 -- http://dbi.perl.org/
Jonathan Leffler wrote:
> lovecreatesbeauty wrote:
>> I declared a function parameter with the ESQL/C datetime type
>
> See my answer in the news group.
OK; I goofed. That was meant to be an email response off the group to
lovecreatesbeauty. Apologies.
--
Jonathan Leffler #include <disclaimer.h>
Email: jleffler@earthlink.net, jleffler@us.ibm.com
Guardian of DBD::Informix v2005.02 -- http://dbi.perl.org/
We use strictly necessary cookies to make this site work. With your
consent we’d also use optional cookies for analytics and marketing. You can accept all,
reject all, or choose. Read our Cookie Policy.