Thread: define bool in pgtypeslib_extern.h

define bool in pgtypeslib_extern.h

From
Amit Kapila
Date:
Today, I committed a patch (dddf4cdc) to reorder some of the file
header inclusions and buildfarm members prairiedog and locust failed
as a result of that.  The reason turns out to be that we have defined
a bool in pgtypeslib_extern.h and that definition is different from
what we define in c.h.

c.h defines it as:
#ifndef bool
typedef unsigned char bool;
#endif

pgtypeslib_extern.h defines it as:
#ifndef bool
#define bool char
#endif

Prior to dddf4cdc,  pgtypeslib_extern.h was included as a first header
before any usage of bool, but commit moves it after dt.h in file
dt_common.c.  Now, it seems like dt.h was using a version of bool as
defined in c.h and dt_common.c uses as defined by pgtypeslib_extern.h
which leads to some compilation errors as below:

dt_common.c:672: error: conflicting types for 'EncodeDateOnly'
dt.h:321: error: previous declaration of 'EncodeDateOnly' was here
dt_common.c:756: error: conflicting types for 'EncodeDateTime'
dt.h:316: error: previous declaration of 'EncodeDateTime' was here
dt_common.c:1783: error: conflicting types for 'DecodeDateTime'
dt.h:324: error: previous declaration of 'DecodeDateTime' was here
make[4]: *** [dt_common.o] Error 1

As suggested by Andrew Gierth [1], I think we can remove the define in
pgtypeslib_extern.h as it doesn't seem to be exposed.

Thoughts?

Note - For the time being, I have changed the order of file inclusions
(c114229ca2) in dt_common.c as it was before so that the buildfarm
becomes green again.

[1] - https://www.postgresql.org/message-id/87h83xmg4m.fsf%40news-spur.riddles.org.uk

-- 
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com



Re: define bool in pgtypeslib_extern.h

From
Tom Lane
Date:
Amit Kapila <amit.kapila16@gmail.com> writes:
> As suggested by Andrew Gierth [1], I think we can remove the define in
> pgtypeslib_extern.h as it doesn't seem to be exposed.

Yeah, it's not good that that results in a header ordering dependency,
and it doesn't seem like a good idea for pgtypeslib_extern.h to be
messing with the issue at all.

If you like, I can experiment with that locally on prairiedog's host
before we make the buildfarm jump through hoops.

            regards, tom lane



Re: define bool in pgtypeslib_extern.h

From
Tom Lane
Date:
I wrote:
> Amit Kapila <amit.kapila16@gmail.com> writes:
>> As suggested by Andrew Gierth [1], I think we can remove the define in
>> pgtypeslib_extern.h as it doesn't seem to be exposed.

> Yeah, it's not good that that results in a header ordering dependency,
> and it doesn't seem like a good idea for pgtypeslib_extern.h to be
> messing with the issue at all.
> If you like, I can experiment with that locally on prairiedog's host
> before we make the buildfarm jump through hoops.

I checked that that works and fixes the immediate problem, so I pushed
it.  However, we're not out of the woods, because lookee here in
ecpglib.h:

#ifndef __cplusplus
#ifndef bool
#define bool char
#endif                          /* ndef bool */

#ifndef true
#define true    ((bool) 1)
#endif                          /* ndef true */
#ifndef false
#define false   ((bool) 0)
#endif                          /* ndef false */
#endif                          /* not C++ */

#ifndef TRUE
#define TRUE    1
#endif                          /* TRUE */

#ifndef FALSE
#define FALSE   0
#endif                          /* FALSE */

This stuff *is* exposed to client programs, so it's not clear how
painless it'd be to monkey around with it.  And it is used, further
down in the same file, so we can't fix it just by deleting it.
Nor can we import c.h to get the "real" definition from that.

I'm more than slightly surprised that we haven't already seen
problems due to this conflicting with d26a810eb.  I've not bothered
to run to ground exactly why not, though.

Thoughts?

            regards, tom lane



Re: define bool in pgtypeslib_extern.h

From
Tom Lane
Date:
I wrote:
> I checked that that works and fixes the immediate problem, so I pushed
> it.  However, we're not out of the woods, because lookee here in
> ecpglib.h:
> ...

Oh, and for extra fun, take a look in src/backend/utils/probes.d :-(

            regards, tom lane



Re: define bool in pgtypeslib_extern.h

From
Amit Kapila
Date:
On Fri, Oct 25, 2019 at 9:55 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> I wrote:
> > Amit Kapila <amit.kapila16@gmail.com> writes:
> >> As suggested by Andrew Gierth [1], I think we can remove the define in
> >> pgtypeslib_extern.h as it doesn't seem to be exposed.
>
> > Yeah, it's not good that that results in a header ordering dependency,
> > and it doesn't seem like a good idea for pgtypeslib_extern.h to be
> > messing with the issue at all.
> > If you like, I can experiment with that locally on prairiedog's host
> > before we make the buildfarm jump through hoops.
>
> I checked that that works and fixes the immediate problem, so I pushed
> it.
>

Thank you.

>  However, we're not out of the woods, because lookee here in
> ecpglib.h:
>
> #ifndef __cplusplus
> #ifndef bool
> #define bool char
> #endif                          /* ndef bool */
>
> #ifndef true
> #define true    ((bool) 1)
> #endif                          /* ndef true */
> #ifndef false
> #define false   ((bool) 0)
> #endif                          /* ndef false */
> #endif                          /* not C++ */
>
> #ifndef TRUE
> #define TRUE    1
> #endif                          /* TRUE */
>
> #ifndef FALSE
> #define FALSE   0
> #endif                          /* FALSE */
>
> This stuff *is* exposed to client programs, so it's not clear how
> painless it'd be to monkey around with it.  And it is used, further
> down in the same file, so we can't fix it just by deleting it.
> Nor can we import c.h to get the "real" definition from that.
>
> I'm more than slightly surprised that we haven't already seen
> problems due to this conflicting with d26a810eb.
>

I think it is because it never gets any imports from c.h.  It instead
uses postgres_ext.h.  If we want to fix this, the simplest thing that
comes to mind is to change the definition of bool in ecpglib.h and
probes.d to match with c.h.  These files contain exposed interfaces,
so the change can impact clients, but not sure what else we can do
here.  I have also tried to think about moving bool definition to
postgres_ext.h, but I think that won't be straightforward.   OTOH, if
you think that might be worth investigating, I can spend some more
time to see if we can do that way.

-- 
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com



Re: define bool in pgtypeslib_extern.h

From
Tom Lane
Date:
Amit Kapila <amit.kapila16@gmail.com> writes:
> On Fri, Oct 25, 2019 at 9:55 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> However, we're not out of the woods, because lookee here in
>> ecpglib.h:
>> #ifndef bool
>> #define bool char
>> #endif                          /* ndef bool */
>> I'm more than slightly surprised that we haven't already seen
>> problems due to this conflicting with d26a810eb.

> I think it is because it never gets any imports from c.h.

On closer inspection, it seems to be just blind luck.  For example,
if I rearrange the inclusion order in a file using ecpglib.h:

diff --git a/src/interfaces/ecpg/ecpglib/data.c b/src/interfaces/ecpg/ecpglib/data.c
index 7d2a78a..09944ff 100644
--- a/src/interfaces/ecpg/ecpglib/data.c
+++ b/src/interfaces/ecpg/ecpglib/data.c
@@ -6,8 +6,8 @@
 #include <math.h>

 #include "ecpgerrno.h"
-#include "ecpglib.h"
 #include "ecpglib_extern.h"
+#include "ecpglib.h"
 #include "ecpgtype.h"
 #include "pgtypes_date.h"
 #include "pgtypes_interval.h"

then on a PPC Mac I get

data.c:210: error: conflicting types for 'ecpg_get_data'
ecpglib_extern.h:167: error: previous declaration of 'ecpg_get_data' was here

It's exactly the same problem as we saw with pgtypeslib_extern.h:
header ordering changes affect the meaning of uses of bool, and that's
just not acceptable.

In this case it's even worse because we're mucking with type definitions
in a user-visible header.  I'm surprised we've not gotten bug reports
about that.  Maybe all ECPG users include <stdbool.h> before they
include ecpglib.h, but that doesn't exactly make things worry-free either,
because code doing that will think that these functions return _Bool,
when the compiled library possibly thinks differently.  Probably the
only thing saving us is that sizeof(_Bool) is 1 on just about every
platform in common use nowadays.

I'm inclined to think that we need to make ecpglib.h's bool-related
definitions exactly match c.h, which will mean that it has to pull in
<stdbool.h> on most platforms, which will mean adding a control symbol
for that to ecpg_config.h.  I do not think we should export
HAVE_STDBOOL_H and SIZEOF_BOOL there though; probably better to have
configure make the choice and export something named like PG_USE_STDBOOL.

            regards, tom lane



Re: define bool in pgtypeslib_extern.h

From
Andrew Gierth
Date:
>>>>> "Tom" == Tom Lane <tgl@sss.pgh.pa.us> writes:

 Tom> On closer inspection, it seems to be just blind luck. For example,
 Tom> if I rearrange the inclusion order in a file using ecpglib.h:

Ugh.

 Tom> I'm inclined to think that we need to make ecpglib.h's
 Tom> bool-related definitions exactly match c.h,

I'm wondering whether we should actually go the opposite way and say
that c.h's "bool" definition should be backend only, and that in
frontend code we should define a PG_bool type or something of that ilk
for when we want "PG's 1-byte bool" and otherwise let the platform
define "bool" however it wants.

And we certainly shouldn't be defining "bool" in something that's going
to be included in the user's code the way that ecpglib.h is.

-- 
Andrew.



Re: define bool in pgtypeslib_extern.h

From
Tom Lane
Date:
Andrew Gierth <andrew@tao11.riddles.org.uk> writes:
> "Tom" == Tom Lane <tgl@sss.pgh.pa.us> writes:
>  Tom> I'm inclined to think that we need to make ecpglib.h's
>  Tom> bool-related definitions exactly match c.h,

> I'm wondering whether we should actually go the opposite way and say
> that c.h's "bool" definition should be backend only, and that in
> frontend code we should define a PG_bool type or something of that ilk
> for when we want "PG's 1-byte bool" and otherwise let the platform
> define "bool" however it wants.

> And we certainly shouldn't be defining "bool" in something that's going
> to be included in the user's code the way that ecpglib.h is.

The trouble here is the hazard of creating an ABI break, if we modify
ecpglib.h in a way that causes its "bool" references to be interpreted
differently than they were before.  I don't think we want that (although
I suspect we have inadvertently caused ABI breaks already on platforms
where this matters).

In practice, since v11 on every modern platform, the exported ecpglib
functions have supposed that "bool" is _Bool, because they were compiled
in files that included c.h before ecpglib.h.  I assert furthermore that
clients might well have included <stdbool.h> before ecpglib.h and thereby
been fully compatible with that.  If we start having ecpglib.h include
<stdbool.h> itself, we'll just be eliminating a minor header inclusion
order hazard.  It's also rather hard to argue that including <stdbool.h>
automatically is really likely to break anything that was including
ecpglib.h already, since that file was already usurping those symbols.
Except on platforms where sizeof(_Bool) isn't 1, but things are already
pretty darn broken there.

I think it's possible to construct a counterexample that will fail
for *anything* we can do here.  I'm not inclined to uglify things like
mad to reduce the problem space from 0.1% to 0.01% of use-cases, or
whatever the numbers would be in practice.

            regards, tom lane



Re: define bool in pgtypeslib_extern.h

From
Amit Kapila
Date:
On Sat, Oct 26, 2019 at 10:49 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> I'm inclined to think that we need to make ecpglib.h's bool-related
> definitions exactly match c.h, which will mean that it has to pull in
> <stdbool.h> on most platforms, which will mean adding a control symbol
> for that to ecpg_config.h.  I do not think we should export
> HAVE_STDBOOL_H and SIZEOF_BOOL there though; probably better to have
> configure make the choice and export something named like PG_USE_STDBOOL.
>

This sounds reasonable to me, but we also might want to do something
for probes.d.  To be clear, I am not immediately planning to write a
patch for this.

-- 
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com



Re: define bool in pgtypeslib_extern.h

From
Tom Lane
Date:
Amit Kapila <amit.kapila16@gmail.com> writes:
> On Sat, Oct 26, 2019 at 10:49 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> I'm inclined to think that we need to make ecpglib.h's bool-related
>> definitions exactly match c.h, which will mean that it has to pull in
>> <stdbool.h> on most platforms, which will mean adding a control symbol
>> for that to ecpg_config.h.  I do not think we should export
>> HAVE_STDBOOL_H and SIZEOF_BOOL there though; probably better to have
>> configure make the choice and export something named like PG_USE_STDBOOL.

> This sounds reasonable to me, but we also might want to do something
> for probes.d.  To be clear, I am not immediately planning to write a
> patch for this.

As far as probes.d goes, it seems to work to do

@@ -20,7 +20,7 @@
 #define BlockNumber unsigned int
 #define Oid unsigned int
 #define ForkNumber int
-#define bool char
+#define bool _Bool
 
 provider postgresql {
 
although removing the macro altogether leads to compilation failures.
I surmise that dtrace is trying to compile the generated code without
any #include's, so that only compiler built-in types will do.

(I tried this on macOS, FreeBSD, and NetBSD, to the extent of seeing
whether a build with --enable-dtrace goes through.  I don't know
enough about dtrace to test the results easily, but I suppose that
if it compiles then this is OK.)

This would, of course, not work on any platform where we're not
using <stdbool.h>, but I doubt that the set of platforms where
dtrace works includes any such.

A plausible alternative is to do

-#define bool char
+#define bool unsigned char

which is correct on platforms where we don't use <stdbool.h>,
and is at least no worse than now on those where we do.  In
practice, since we know sizeof(_Bool) == 1 on platforms where
we use it, this is probably just fine for dtrace's purposes.

Anyone have a preference?

            regards, tom lane



Re: define bool in pgtypeslib_extern.h

From
Amit Kapila
Date:
On Mon, Oct 28, 2019 at 11:27 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> Amit Kapila <amit.kapila16@gmail.com> writes:
> > On Sat, Oct 26, 2019 at 10:49 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> >> I'm inclined to think that we need to make ecpglib.h's bool-related
> >> definitions exactly match c.h, which will mean that it has to pull in
> >> <stdbool.h> on most platforms, which will mean adding a control symbol
> >> for that to ecpg_config.h.  I do not think we should export
> >> HAVE_STDBOOL_H and SIZEOF_BOOL there though; probably better to have
> >> configure make the choice and export something named like PG_USE_STDBOOL.
>
> > This sounds reasonable to me, but we also might want to do something
> > for probes.d.  To be clear, I am not immediately planning to write a
> > patch for this.
>
> As far as probes.d goes, it seems to work to do
>
> @@ -20,7 +20,7 @@
>  #define BlockNumber unsigned int
>  #define Oid unsigned int
>  #define ForkNumber int
> -#define bool char
> +#define bool _Bool
>
>  provider postgresql {
>
> although removing the macro altogether leads to compilation failures.
> I surmise that dtrace is trying to compile the generated code without
> any #include's, so that only compiler built-in types will do.
>
> (I tried this on macOS, FreeBSD, and NetBSD, to the extent of seeing
> whether a build with --enable-dtrace goes through.  I don't know
> enough about dtrace to test the results easily, but I suppose that
> if it compiles then this is OK.)
>
> This would, of course, not work on any platform where we're not
> using <stdbool.h>, but I doubt that the set of platforms where
> dtrace works includes any such.
>
> A plausible alternative is to do
>
> -#define bool char
> +#define bool unsigned char
>
> which is correct on platforms where we don't use <stdbool.h>,
> and is at least no worse than now on those where we do.  In
> practice, since we know sizeof(_Bool) == 1 on platforms where
> we use it, this is probably just fine for dtrace's purposes.
>
> Anyone have a preference?
>

+1 for the second alternative as it will make it similar to c.h.


-- 
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com



Re: define bool in pgtypeslib_extern.h

From
Tom Lane
Date:
Amit Kapila <amit.kapila16@gmail.com> writes:
> On Mon, Oct 28, 2019 at 11:27 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> A plausible alternative is to do
>> 
>> -#define bool char
>> +#define bool unsigned char
>> 
>> which is correct on platforms where we don't use <stdbool.h>,
>> and is at least no worse than now on those where we do.  In
>> practice, since we know sizeof(_Bool) == 1 on platforms where
>> we use it, this is probably just fine for dtrace's purposes.

> +1 for the second alternative as it will make it similar to c.h.

Yeah, that's the minimum-risk alternative.  I'll go make it so.

            regards, tom lane



Re: define bool in pgtypeslib_extern.h

From
Tom Lane
Date:
Andrew Gierth <andrew@tao11.riddles.org.uk> writes:
> I'm wondering whether we should actually go the opposite way and say
> that c.h's "bool" definition should be backend only, and that in
> frontend code we should define a PG_bool type or something of that ilk
> for when we want "PG's 1-byte bool" and otherwise let the platform
> define "bool" however it wants.
> And we certainly shouldn't be defining "bool" in something that's going
> to be included in the user's code the way that ecpglib.h is.

I experimented with doing things that way, and ended up with the attached
draft patch.  It basically gets ecpglib.h out of the business of declaring
any bool-related stuff at all, instead insisting that client code include
<stdbool.h> or otherwise declare bool for itself.  The function
declarations that were previously relying on "bool" now use the "pqbool"
typedef that libpq-fe.h was already exporting.  Per discussion, that's
not an ABI break, even on platforms where sizeof(_Bool) > 1, because
the actual underlying library functions are certainly expecting to take
or return a value of size 1.

While this seems like a generally cleaner place to be, I'm a bit concerned
about a number of aspects:

* This will of course be an API break for clients, which might not've
included <stdbool.h> before.

* On platforms where sizeof(_Bool) > 1, it's far from clear to me that
ECPG will interface correctly with client code that is treating bool
as _Bool.  There are some places that seem to be prepared for bool
client variables to be either sizeof(char) or sizeof(int), for example
ecpg_store_input(), but there are a fair number of other places that
seem to assume that sizeof(bool) is relevant, which it won't be.
The ECPG regression tests do pass for me on a PPC Mac, but I wonder
how much that proves.

* The "sql/dyntest.pgc" test declares BOOLVAR as "char" and then does

  exec sql var BOOLVAR is bool;

It's not clear to me what the implications of that statement are
(and our manual is no help), but looking at the generated code,
it seems like this causes ecpg to believe that the size of the
variable is sizeof(bool).  So that looks like buffer overrun
trouble waiting to happen.  I changed the variable declaration to
"bool" in the attached, but I wonder what's supposed to be getting
tested there.

On the whole I'm not finding this an attractive way to proceed
compared to the other approach I sketched.  It will certainly
cause some clients to have compile failures, and I'm at best
queasy about whether it will really work on platforms where
sizeof(_Bool) > 1.  I think we're better off to go with the
other approach of making ecpglib.h export what we think the
correct definition of bool is.  For most people that will
end up being <stdbool.h>, which I think will be unsurprising.

            regards, tom lane

PS: another issue this fixes, which I think we ought to fix and back-patch
regardless of what we decide about bool, is it moves the declaration for
ecpg_gettext() out of ecpglib.h and into the private header
ecpglib_extern.h.  That function isn't meant for client access, the
declaration is wrong where it is because it is not inside extern "C",
and the declaration wouldn't even compile for clients because they
will not know what pg_attribute_format_arg() is.  The only reason we've
not had complaints, I imagine, is that nobody's tried to compile client
code with ENABLE_NLS defined ... but that's already an intrusion on
client namespace.

diff --git a/doc/src/sgml/ecpg.sgml b/doc/src/sgml/ecpg.sgml
index 8fe2a90..7e3f9ff 100644
--- a/doc/src/sgml/ecpg.sgml
+++ b/doc/src/sgml/ecpg.sgml
@@ -944,7 +944,7 @@ do

       <row>
        <entry><type>boolean</type></entry>
-       <entry><type>bool</type><footnote><para>declared in <filename>ecpglib.h</filename> if not
native</para></footnote></entry>
+       <entry><type>bool</type><footnote><para>should be declared by including
<filename><stdbool.h></filename></para></footnote></entry>
       </row>

       <row>
diff --git a/src/interfaces/ecpg/ecpglib/connect.c b/src/interfaces/ecpg/ecpglib/connect.c
index 1cb5211..f816f8b 100644
--- a/src/interfaces/ecpg/ecpglib/connect.c
+++ b/src/interfaces/ecpg/ecpglib/connect.c
@@ -161,7 +161,7 @@ ecpg_finish(struct connection *act)
         ecpg_log("ecpg_finish: called an extra time\n");
 }

-bool
+pqbool
 ECPGsetcommit(int lineno, const char *mode, const char *connection_name)
 {
     struct connection *con = ecpg_get_connection(connection_name);
@@ -198,7 +198,7 @@ ECPGsetcommit(int lineno, const char *mode, const char *connection_name)
     return true;
 }

-bool
+pqbool
 ECPGsetconn(int lineno, const char *connection_name)
 {
     struct connection *con = ecpg_get_connection(connection_name);
@@ -267,7 +267,7 @@ ECPGnoticeReceiver(void *arg, const PGresult *result)
 }

 /* this contains some quick hacks, needs to be cleaned up, but it works */
-bool
+pqbool
 ECPGconnect(int lineno, int c, const char *name, const char *user, const char *passwd, const char *connection_name,
intautocommit) 
 {
     struct sqlca_t *sqlca = ECPGget_sqlca();
@@ -680,7 +680,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
     return true;
 }

-bool
+pqbool
 ECPGdisconnect(int lineno, const char *connection_name)
 {
     struct sqlca_t *sqlca = ECPGget_sqlca();
diff --git a/src/interfaces/ecpg/ecpglib/descriptor.c b/src/interfaces/ecpg/ecpglib/descriptor.c
index ead8778..5ba444b 100644
--- a/src/interfaces/ecpg/ecpglib/descriptor.c
+++ b/src/interfaces/ecpg/ecpglib/descriptor.c
@@ -87,7 +87,7 @@ ecpg_dynamic_type_DDT(Oid type)
     }
 }

-bool
+pqbool
 ECPGget_desc_header(int lineno, const char *desc_name, int *count)
 {
     PGresult   *ECPGresult;
@@ -241,7 +241,7 @@ get_char_item(int lineno, void *var, enum ECPGttype vartype, char *value, int va
                     return false; \
                 }

-bool
+pqbool
 ECPGget_desc(int lineno, const char *desc_name, int index,...)
 {
     va_list        args;
@@ -575,7 +575,7 @@ ECPGget_desc(int lineno, const char *desc_name, int index,...)

 #undef RETURN_IF_NO_DATA

-bool
+pqbool
 ECPGset_desc_header(int lineno, const char *desc_name, int count)
 {
     struct descriptor *desc = ecpg_find_desc(lineno, desc_name);
@@ -607,7 +607,7 @@ set_desc_attr(struct descriptor_item *desc_item, struct variable *var,
 }


-bool
+pqbool
 ECPGset_desc(int lineno, const char *desc_name, int index,...)
 {
     va_list        args;
@@ -750,7 +750,7 @@ descriptor_free(struct descriptor *desc)
     ecpg_free(desc);
 }

-bool
+pqbool
 ECPGdeallocate_desc(int line, const char *name)
 {
     struct descriptor *desc;
@@ -797,7 +797,7 @@ descriptor_deallocate_all(struct descriptor *list)
 }
 #endif                            /* ENABLE_THREAD_SAFETY */

-bool
+pqbool
 ECPGallocate_desc(int line, const char *name)
 {
     struct descriptor *new;
@@ -852,10 +852,10 @@ ecpg_find_desc(int line, const char *name)
     return NULL;                /* not found */
 }

-bool
-ECPGdescribe(int line, int compat, bool input, const char *connection_name, const char *stmt_name,...)
+pqbool
+ECPGdescribe(int line, int compat, pqbool input, const char *connection_name, const char *stmt_name,...)
 {
-    bool        ret = false;
+    pqbool        ret = false;
     struct connection *con;
     struct prepared_statement *prep;
     PGresult   *res;
diff --git a/src/interfaces/ecpg/ecpglib/ecpglib_extern.h b/src/interfaces/ecpg/ecpglib/ecpglib_extern.h
index f788bfd..4bf55fe 100644
--- a/src/interfaces/ecpg/ecpglib/ecpglib_extern.h
+++ b/src/interfaces/ecpg/ecpglib/ecpglib_extern.h
@@ -219,6 +219,12 @@ unsigned    ecpg_hex_dec_len(unsigned srclen);
 unsigned    ecpg_hex_enc_len(unsigned srclen);
 unsigned    ecpg_hex_encode(const char *src, unsigned len, char *dst);

+#ifdef ENABLE_NLS
+extern char *ecpg_gettext(const char *msgid) pg_attribute_format_arg(1);
+#else
+#define ecpg_gettext(x) (x)
+#endif
+
 /* SQLSTATE values generated or processed by ecpglib (intentionally
  * not exported -- users should refer to the codes directly) */

diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c
index 23cc869..c8dbdff 100644
--- a/src/interfaces/ecpg/ecpglib/execute.c
+++ b/src/interfaces/ecpg/ecpglib/execute.c
@@ -2274,11 +2274,11 @@ fail:
  * Execute SQL statements in the backend.
  * The input/output parameters are passed as variable-length argument list.
  */
-bool
-ECPGdo(const int lineno, const int compat, const int force_indicator, const char *connection_name, const bool
questionmarks,const int st, const char *query,...) 
+pqbool
+ECPGdo(const int lineno, const int compat, const int force_indicator, const char *connection_name, const pqbool
questionmarks,const int st, const char *query,...) 
 {
     va_list        args;
-    bool        ret;
+    pqbool        ret;

     va_start(args, query);
     ret = ecpg_do(lineno, compat, force_indicator, connection_name,
@@ -2289,7 +2289,7 @@ ECPGdo(const int lineno, const int compat, const int force_indicator, const char
 }

 /* old descriptor interface */
-bool
+pqbool
 ECPGdo_descriptor(int line, const char *connection,
                   const char *descriptor, const char *query)
 {
diff --git a/src/interfaces/ecpg/ecpglib/misc.c b/src/interfaces/ecpg/ecpglib/misc.c
index 647da14..7311c8c 100644
--- a/src/interfaces/ecpg/ecpglib/misc.c
+++ b/src/interfaces/ecpg/ecpglib/misc.c
@@ -162,7 +162,7 @@ ECPGget_sqlca(void)
 #endif
 }

-bool
+pqbool
 ECPGstatus(int lineno, const char *connection_name)
 {
     struct connection *con = ecpg_get_connection(connection_name);
@@ -196,7 +196,7 @@ ECPGtransactionStatus(const char *connection_name)

 }

-bool
+pqbool
 ECPGtrans(int lineno, const char *connection_name, const char *transaction)
 {
     PGresult   *res;
@@ -388,7 +388,7 @@ _check(const unsigned char *ptr, int length)
     return true;
 }

-bool
+pqbool
 ECPGis_noind_null(enum ECPGttype type, const void *ptr)
 {
     switch (type)
diff --git a/src/interfaces/ecpg/ecpglib/prepare.c b/src/interfaces/ecpg/ecpglib/prepare.c
index b9653c0..397e78a 100644
--- a/src/interfaces/ecpg/ecpglib/prepare.c
+++ b/src/interfaces/ecpg/ecpglib/prepare.c
@@ -213,8 +213,8 @@ prepare_common(int lineno, struct connection *con, const char *name, const char

 /* handle the EXEC SQL PREPARE statement */
 /* questionmarks is not needed but remains in there for the time being to not change the API */
-bool
-ECPGprepare(int lineno, const char *connection_name, const bool questionmarks,
+pqbool
+ECPGprepare(int lineno, const char *connection_name, const pqbool questionmarks,
             const char *name, const char *variable)
 {
     struct connection *con;
@@ -311,7 +311,7 @@ deallocate_one(int lineno, enum COMPAT_MODE c, struct connection *con,
 }

 /* handle the EXEC SQL DEALLOCATE PREPARE statement */
-bool
+pqbool
 ECPGdeallocate(int lineno, int c, const char *connection_name, const char *name)
 {
     struct connection *con;
@@ -346,7 +346,7 @@ ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection *con)
     return true;
 }

-bool
+pqbool
 ECPGdeallocate_all(int lineno, int compat, const char *connection_name)
 {
     return ecpg_deallocate_all_conn(lineno, compat,
diff --git a/src/interfaces/ecpg/include/ecpglib.h b/src/interfaces/ecpg/include/ecpglib.h
index a9bc584..b278c3e 100644
--- a/src/interfaces/ecpg/include/ecpglib.h
+++ b/src/interfaces/ecpg/include/ecpglib.h
@@ -1,6 +1,6 @@
 /*
- * this is a small part of c.h since we don't want to leak all postgres
- * definitions into ecpg programs
+ * Client-visible declarations for ecpglib
+ *
  * src/interfaces/ecpg/include/ecpglib.h
  */

@@ -12,49 +12,22 @@
 #include "sqlca.h"
 #include <string.h>

-#ifdef ENABLE_NLS
-extern char *ecpg_gettext(const char *msgid) pg_attribute_format_arg(1);
-#else
-#define ecpg_gettext(x) (x)
-#endif
-
-#ifndef __cplusplus
-#ifndef bool
-#define bool char
-#endif                            /* ndef bool */
-
-#ifndef true
-#define true    ((bool) 1)
-#endif                            /* ndef true */
-#ifndef false
-#define false    ((bool) 0)
-#endif                            /* ndef false */
-#endif                            /* not C++ */
-
-#ifndef TRUE
-#define TRUE    1
-#endif                            /* TRUE */
-
-#ifndef FALSE
-#define FALSE    0
-#endif                            /* FALSE */
-
 #ifdef __cplusplus
 extern "C"
 {
 #endif

 void        ECPGdebug(int, FILE *);
-bool        ECPGstatus(int, const char *);
-bool        ECPGsetcommit(int, const char *, const char *);
-bool        ECPGsetconn(int, const char *);
-bool        ECPGconnect(int, int, const char *, const char *, const char *, const char *, int);
-bool        ECPGdo(const int, const int, const int, const char *, const bool, const int, const char *,...);
-bool        ECPGtrans(int, const char *, const char *);
-bool        ECPGdisconnect(int, const char *);
-bool        ECPGprepare(int, const char *, const bool, const char *, const char *);
-bool        ECPGdeallocate(int, int, const char *, const char *);
-bool        ECPGdeallocate_all(int, int, const char *);
+pqbool        ECPGstatus(int, const char *);
+pqbool        ECPGsetcommit(int, const char *, const char *);
+pqbool        ECPGsetconn(int, const char *);
+pqbool        ECPGconnect(int, int, const char *, const char *, const char *, const char *, int);
+pqbool        ECPGdo(const int, const int, const int, const char *, const pqbool, const int, const char *,...);
+pqbool        ECPGtrans(int, const char *, const char *);
+pqbool        ECPGdisconnect(int, const char *);
+pqbool        ECPGprepare(int, const char *, const pqbool, const char *, const char *);
+pqbool        ECPGdeallocate(int, int, const char *, const char *);
+pqbool        ECPGdeallocate_all(int, int, const char *);
 char       *ECPGprepared_statement(const char *, const char *, int);
 PGconn       *ECPGget_PGconn(const char *);
 PGTransactionStatusType ECPGtransactionStatus(const char *);
@@ -69,17 +42,17 @@ void        sqlprint(void);

 /* dynamic SQL */

-bool        ECPGdo_descriptor(int, const char *, const char *, const char *);
-bool        ECPGdeallocate_desc(int, const char *);
-bool        ECPGallocate_desc(int, const char *);
-bool        ECPGget_desc_header(int, const char *, int *);
-bool        ECPGget_desc(int, const char *, int,...);
-bool        ECPGset_desc_header(int, const char *, int);
-bool        ECPGset_desc(int, const char *, int,...);
+pqbool        ECPGdo_descriptor(int, const char *, const char *, const char *);
+pqbool        ECPGdeallocate_desc(int, const char *);
+pqbool        ECPGallocate_desc(int, const char *);
+pqbool        ECPGget_desc_header(int, const char *, int *);
+pqbool        ECPGget_desc(int, const char *, int,...);
+pqbool        ECPGset_desc_header(int, const char *, int);
+pqbool        ECPGset_desc(int, const char *, int,...);

 void        ECPGset_noind_null(enum ECPGttype, void *);
-bool        ECPGis_noind_null(enum ECPGttype, const void *);
-bool        ECPGdescribe(int, int, bool, const char *, const char *,...);
+pqbool        ECPGis_noind_null(enum ECPGttype, const void *);
+pqbool        ECPGdescribe(int, int, pqbool, const char *, const char *,...);

 void        ECPGset_var(int, void *, int);
 void       *ECPGget_var(int number);
diff --git a/src/interfaces/ecpg/test/compat_informix/rnull.pgc b/src/interfaces/ecpg/test/compat_informix/rnull.pgc
index a6ad35e..5604a91 100644
--- a/src/interfaces/ecpg/test/compat_informix/rnull.pgc
+++ b/src/interfaces/ecpg/test/compat_informix/rnull.pgc
@@ -1,5 +1,6 @@
 #include "sqltypes.h"
 #include <stdlib.h>
+#include <stdbool.h>

 $include ../regression;
 $define NUMBER 12;
diff --git a/src/interfaces/ecpg/test/expected/compat_informix-rnull.c
b/src/interfaces/ecpg/test/expected/compat_informix-rnull.c
index d7ba69c..28d7ba1 100644
--- a/src/interfaces/ecpg/test/expected/compat_informix-rnull.c
+++ b/src/interfaces/ecpg/test/expected/compat_informix-rnull.c
@@ -11,6 +11,7 @@
 #line 1 "rnull.pgc"
 #include "sqltypes.h"
 #include <stdlib.h>
+#include <stdbool.h>


 #line 1 "regression.h"
@@ -20,7 +21,7 @@



-#line 4 "rnull.pgc"
+#line 5 "rnull.pgc"



@@ -33,89 +34,89 @@ test_null(int type, char *ptr)
 int main(void)
 {

-#line 15 "rnull.pgc"
- char c [] = "abc" ;
-
-#line 15 "rnull.pgc"
-
-
 #line 16 "rnull.pgc"
- short s = 17 ;
+ char c [] = "abc" ;

 #line 16 "rnull.pgc"


 #line 17 "rnull.pgc"
- int i = - 74874 ;
+ short s = 17 ;

 #line 17 "rnull.pgc"


 #line 18 "rnull.pgc"
- bool b = 1 ;
+ int i = - 74874 ;

 #line 18 "rnull.pgc"


 #line 19 "rnull.pgc"
- float f = 3.71 ;
+ bool b = 1 ;

 #line 19 "rnull.pgc"


 #line 20 "rnull.pgc"
- long l = 487444 ;
+ float f = 3.71 ;

 #line 20 "rnull.pgc"


 #line 21 "rnull.pgc"
- double dbl = 404.404 ;
+ long l = 487444 ;

 #line 21 "rnull.pgc"


 #line 22 "rnull.pgc"
- decimal dec ;
+ double dbl = 404.404 ;

 #line 22 "rnull.pgc"


 #line 23 "rnull.pgc"
- date dat ;
+ decimal dec ;

 #line 23 "rnull.pgc"


 #line 24 "rnull.pgc"
- timestamp tmp ;
+ date dat ;

 #line 24 "rnull.pgc"

+
+#line 25 "rnull.pgc"
+ timestamp tmp ;
+
+#line 25 "rnull.pgc"
+

     ECPGdebug(1, stderr);
     /* exec sql whenever sqlerror  do sqlprint ( ) ; */
-#line 27 "rnull.pgc"
+#line 28 "rnull.pgc"


     { ECPGconnect(__LINE__, 1, "ecpg1_regression" , NULL, NULL , NULL, 0);
-#line 29 "rnull.pgc"
+#line 30 "rnull.pgc"

 if (sqlca.sqlcode < 0) sqlprint ( );}
-#line 29 "rnull.pgc"
+#line 30 "rnull.pgc"


     { ECPGdo(__LINE__, 1, 0, NULL, 0, ECPGst_normal, "create table test ( id int , c char ( 10 ) , s smallint , i int
,b bool , f float , l bigint , dbl double precision , dec decimal , dat date , tmp timestamptz )", ECPGt_EOIT,
ECPGt_EORT);
-#line 33 "rnull.pgc"
+#line 34 "rnull.pgc"

 if (sqlca.sqlcode < 0) sqlprint ( );}
-#line 33 "rnull.pgc"
+#line 34 "rnull.pgc"

     { ECPGtrans(__LINE__, NULL, "commit");
-#line 34 "rnull.pgc"
+#line 35 "rnull.pgc"

 if (sqlca.sqlcode < 0) sqlprint ( );}
-#line 34 "rnull.pgc"
+#line 35 "rnull.pgc"


     { ECPGdo(__LINE__, 1, 0, NULL, 0, ECPGst_normal, "insert into test ( id , c , s , i , b , f , l , dbl ) values ( 1
,$1  , $2  , $3  , $4  , $5  , $6  , $7  )",  
@@ -133,16 +134,16 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
     ECPGt_double,&(dbl),(long)1,(long)1,sizeof(double),
     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
-#line 38 "rnull.pgc"
+#line 39 "rnull.pgc"

 if (sqlca.sqlcode < 0) sqlprint ( );}
-#line 38 "rnull.pgc"
+#line 39 "rnull.pgc"

     { ECPGtrans(__LINE__, NULL, "commit");
-#line 39 "rnull.pgc"
+#line 40 "rnull.pgc"

 if (sqlca.sqlcode < 0) sqlprint ( );}
-#line 39 "rnull.pgc"
+#line 40 "rnull.pgc"


     rsetnull(CCHARTYPE, (char *) c);
@@ -177,16 +178,16 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
     ECPGt_timestamp,&(tmp),(long)1,(long)1,sizeof(timestamp),
     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
-#line 54 "rnull.pgc"
+#line 55 "rnull.pgc"

 if (sqlca.sqlcode < 0) sqlprint ( );}
-#line 54 "rnull.pgc"
+#line 55 "rnull.pgc"

     { ECPGtrans(__LINE__, NULL, "commit");
-#line 55 "rnull.pgc"
+#line 56 "rnull.pgc"

 if (sqlca.sqlcode < 0) sqlprint ( );}
-#line 55 "rnull.pgc"
+#line 56 "rnull.pgc"


     printf("first select\n");
@@ -212,10 +213,10 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
     ECPGt_timestamp,&(tmp),(long)1,(long)1,sizeof(timestamp),
     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
-#line 61 "rnull.pgc"
+#line 62 "rnull.pgc"

 if (sqlca.sqlcode < 0) sqlprint ( );}
-#line 61 "rnull.pgc"
+#line 62 "rnull.pgc"


     test_null(CCHARTYPE, (char *) c);
@@ -252,10 +253,10 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
     ECPGt_timestamp,&(tmp),(long)1,(long)1,sizeof(timestamp),
     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
-#line 78 "rnull.pgc"
+#line 79 "rnull.pgc"

 if (sqlca.sqlcode < 0) sqlprint ( );}
-#line 78 "rnull.pgc"
+#line 79 "rnull.pgc"


     test_null(CCHARTYPE, (char *) c);
@@ -270,23 +271,23 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
     test_null(CDTIMETYPE, (char *) &tmp);

     { ECPGdo(__LINE__, 1, 0, NULL, 0, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT);
-#line 91 "rnull.pgc"
+#line 92 "rnull.pgc"

 if (sqlca.sqlcode < 0) sqlprint ( );}
-#line 91 "rnull.pgc"
+#line 92 "rnull.pgc"

     { ECPGtrans(__LINE__, NULL, "commit");
-#line 92 "rnull.pgc"
+#line 93 "rnull.pgc"

 if (sqlca.sqlcode < 0) sqlprint ( );}
-#line 92 "rnull.pgc"
+#line 93 "rnull.pgc"


     { ECPGdisconnect(__LINE__, "CURRENT");
-#line 94 "rnull.pgc"
+#line 95 "rnull.pgc"

 if (sqlca.sqlcode < 0) sqlprint ( );}
-#line 94 "rnull.pgc"
+#line 95 "rnull.pgc"


     return 0;
diff --git a/src/interfaces/ecpg/test/expected/compat_informix-rnull.stderr
b/src/interfaces/ecpg/test/expected/compat_informix-rnull.stderr
index dd3d8b7..1c9b461 100644
--- a/src/interfaces/ecpg/test/expected/compat_informix-rnull.stderr
+++ b/src/interfaces/ecpg/test/expected/compat_informix-rnull.stderr
@@ -2,123 +2,123 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGconnect: opening database ecpg1_regression on <DEFAULT> port <DEFAULT>
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 31: query: create table test ( id int , c char ( 10 ) , s smallint , i int , b bool , f
float, l bigint , dbl double precision , dec decimal , dat date , tmp timestamptz ); with 0 parameter(s) on connection
ecpg1_regression
+[NO_PID]: ecpg_execute on line 32: query: create table test ( id int , c char ( 10 ) , s smallint , i int , b bool , f
float, l bigint , dbl double precision , dec decimal , dat date , tmp timestamptz ); with 0 parameter(s) on connection
ecpg1_regression
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 31: using PQexec
+[NO_PID]: ecpg_execute on line 32: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_process_output on line 31: OK: CREATE TABLE
+[NO_PID]: ecpg_process_output on line 32: OK: CREATE TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGtrans on line 34: action "commit"; connection "ecpg1_regression"
+[NO_PID]: ECPGtrans on line 35: action "commit"; connection "ecpg1_regression"
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 36: query: insert into test ( id , c , s , i , b , f , l , dbl ) values ( 1 , $1  , $2
,$3  , $4  , $5  , $6  , $7  ); with 7 parameter(s) on connection ecpg1_regression 
+[NO_PID]: ecpg_execute on line 37: query: insert into test ( id , c , s , i , b , f , l , dbl ) values ( 1 , $1  , $2
,$3  , $4  , $5  , $6  , $7  ); with 7 parameter(s) on connection ecpg1_regression 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 36: using PQexecParams
+[NO_PID]: ecpg_execute on line 37: using PQexecParams
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_free_params on line 36: parameter 1 = abc
+[NO_PID]: ecpg_free_params on line 37: parameter 1 = abc
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_free_params on line 36: parameter 2 = 17
+[NO_PID]: ecpg_free_params on line 37: parameter 2 = 17
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_free_params on line 36: parameter 3 = -74874
+[NO_PID]: ecpg_free_params on line 37: parameter 3 = -74874
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_free_params on line 36: parameter 4 = t
+[NO_PID]: ecpg_free_params on line 37: parameter 4 = t
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_free_params on line 36: parameter 5 = 3.71000003814697
+[NO_PID]: ecpg_free_params on line 37: parameter 5 = 3.71000003814697
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_free_params on line 36: parameter 6 = 487444
+[NO_PID]: ecpg_free_params on line 37: parameter 6 = 487444
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_free_params on line 36: parameter 7 = 404.404
+[NO_PID]: ecpg_free_params on line 37: parameter 7 = 404.404
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_process_output on line 36: OK: INSERT 0 1
+[NO_PID]: ecpg_process_output on line 37: OK: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGtrans on line 39: action "commit"; connection "ecpg1_regression"
+[NO_PID]: ECPGtrans on line 40: action "commit"; connection "ecpg1_regression"
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 52: query: insert into test ( id , c , s , i , b , f , l , dbl , dec , dat , tmp )
values( 2 , $1  , $2  , $3  , $4  , $5  , $6  , $7  , $8  , $9  , $10  ); with 10 parameter(s) on connection
ecpg1_regression
+[NO_PID]: ecpg_execute on line 53: query: insert into test ( id , c , s , i , b , f , l , dbl , dec , dat , tmp )
values( 2 , $1  , $2  , $3  , $4  , $5  , $6  , $7  , $8  , $9  , $10  ); with 10 parameter(s) on connection
ecpg1_regression
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 52: using PQexecParams
+[NO_PID]: ecpg_execute on line 53: using PQexecParams
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_free_params on line 52: parameter 1 = null
+[NO_PID]: ecpg_free_params on line 53: parameter 1 = null
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_free_params on line 52: parameter 2 = null
+[NO_PID]: ecpg_free_params on line 53: parameter 2 = null
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_free_params on line 52: parameter 3 = null
+[NO_PID]: ecpg_free_params on line 53: parameter 3 = null
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_free_params on line 52: parameter 4 = t
+[NO_PID]: ecpg_free_params on line 53: parameter 4 = t
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_free_params on line 52: parameter 5 = null
+[NO_PID]: ecpg_free_params on line 53: parameter 5 = null
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_free_params on line 52: parameter 6 = null
+[NO_PID]: ecpg_free_params on line 53: parameter 6 = null
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_free_params on line 52: parameter 7 = null
+[NO_PID]: ecpg_free_params on line 53: parameter 7 = null
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_free_params on line 52: parameter 8 = null
+[NO_PID]: ecpg_free_params on line 53: parameter 8 = null
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_free_params on line 52: parameter 9 = null
+[NO_PID]: ecpg_free_params on line 53: parameter 9 = null
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_free_params on line 52: parameter 10 = null
+[NO_PID]: ecpg_free_params on line 53: parameter 10 = null
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_process_output on line 52: OK: INSERT 0 1
+[NO_PID]: ecpg_process_output on line 53: OK: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGtrans on line 55: action "commit"; connection "ecpg1_regression"
+[NO_PID]: ECPGtrans on line 56: action "commit"; connection "ecpg1_regression"
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 59: query: select c , s , i , b , f , l , dbl , dec , dat , tmp from test where id = 1;
with0 parameter(s) on connection ecpg1_regression 
+[NO_PID]: ecpg_execute on line 60: query: select c , s , i , b , f , l , dbl , dec , dat , tmp from test where id = 1;
with0 parameter(s) on connection ecpg1_regression 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 59: using PQexec
+[NO_PID]: ecpg_execute on line 60: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_process_output on line 59: correctly got 1 tuples with 10 fields
+[NO_PID]: ecpg_process_output on line 60: correctly got 1 tuples with 10 fields
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 59: RESULT: abc        offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 60: RESULT: abc        offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 59: RESULT: 17 offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 60: RESULT: 17 offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 59: RESULT: -74874 offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 60: RESULT: -74874 offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 59: RESULT: t offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 60: RESULT: t offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 59: RESULT: 3.71000003814697 offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 60: RESULT: 3.71000003814697 offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 59: RESULT: 487444 offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 60: RESULT: 487444 offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 59: RESULT: 404.404 offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 60: RESULT: 404.404 offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 59: RESULT:  offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 60: RESULT:  offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 59: RESULT:  offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 60: RESULT:  offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 59: RESULT:  offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 60: RESULT:  offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 76: query: select c , s , i , b , f , l , dbl , dec , dat , tmp from test where id = 2;
with0 parameter(s) on connection ecpg1_regression 
+[NO_PID]: ecpg_execute on line 77: query: select c , s , i , b , f , l , dbl , dec , dat , tmp from test where id = 2;
with0 parameter(s) on connection ecpg1_regression 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 76: using PQexec
+[NO_PID]: ecpg_execute on line 77: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_process_output on line 76: correctly got 1 tuples with 10 fields
+[NO_PID]: ecpg_process_output on line 77: correctly got 1 tuples with 10 fields
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 76: RESULT:  offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 77: RESULT:  offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 76: RESULT:  offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 77: RESULT:  offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 76: RESULT:  offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 77: RESULT:  offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 76: RESULT: t offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 77: RESULT: t offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 76: RESULT:  offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 77: RESULT:  offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 76: RESULT:  offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 77: RESULT:  offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 76: RESULT:  offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 77: RESULT:  offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 76: RESULT:  offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 77: RESULT:  offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 76: RESULT:  offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 77: RESULT:  offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 76: RESULT:  offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 77: RESULT:  offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 91: query: drop table test; with 0 parameter(s) on connection ecpg1_regression
+[NO_PID]: ecpg_execute on line 92: query: drop table test; with 0 parameter(s) on connection ecpg1_regression
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 91: using PQexec
+[NO_PID]: ecpg_execute on line 92: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_process_output on line 91: OK: DROP TABLE
+[NO_PID]: ecpg_process_output on line 92: OK: DROP TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGtrans on line 92: action "commit"; connection "ecpg1_regression"
+[NO_PID]: ECPGtrans on line 93: action "commit"; connection "ecpg1_regression"
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ecpg_finish: connection ecpg1_regression closed
 [NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test2.c
b/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test2.c
index b3e1e75..506bcab 100644
--- a/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test2.c
+++ b/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test2.c
@@ -10,6 +10,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <stdbool.h>
 #include <limits.h>
 #include <pgtypes_date.h>
 #include <pgtypes_timestamp.h>
@@ -22,7 +23,7 @@



-#line 8 "dt_test2.pgc"
+#line 9 "dt_test2.pgc"


 char *dates[] = { "19990108foobar",
@@ -83,22 +84,22 @@ main(void)



-#line 62 "dt_test2.pgc"
+#line 63 "dt_test2.pgc"
  date date1 ;

-#line 63 "dt_test2.pgc"
+#line 64 "dt_test2.pgc"
  timestamp ts1 , ts2 ;

-#line 64 "dt_test2.pgc"
+#line 65 "dt_test2.pgc"
  char * text ;

-#line 65 "dt_test2.pgc"
+#line 66 "dt_test2.pgc"
  interval * i1 ;

-#line 66 "dt_test2.pgc"
+#line 67 "dt_test2.pgc"
  date * dc ;
 /* exec sql end declare section */
-#line 67 "dt_test2.pgc"
+#line 68 "dt_test2.pgc"


     int i, j;
diff --git a/src/interfaces/ecpg/test/expected/preproc-init.c b/src/interfaces/ecpg/test/expected/preproc-init.c
index b0e0473..84d0066 100644
--- a/src/interfaces/ecpg/test/expected/preproc-init.c
+++ b/src/interfaces/ecpg/test/expected/preproc-init.c
@@ -7,6 +7,8 @@
 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))

 #line 1 "init.pgc"
+#include <stdbool.h>
+

 #line 1 "sqlca.h"
 #ifndef POSTGRES_SQLCA_H
@@ -76,7 +78,7 @@ struct sqlca_t *ECPGget_sqlca(void);

 #endif

-#line 1 "init.pgc"
+#line 3 "init.pgc"


 enum e { ENUM0, ENUM1 };
@@ -149,40 +151,40 @@ int main(void)

           /* = 1L */

-#line 60 "init.pgc"
+#line 62 "init.pgc"
  int a = ( int ) 2 ;

-#line 61 "init.pgc"
+#line 63 "init.pgc"
  int b = 2 + 2 ;

-#line 62 "init.pgc"
+#line 64 "init.pgc"
  int b2 = ( 14 * 7 ) ;

-#line 63 "init.pgc"
+#line 65 "init.pgc"
  int d = x . member ;

-#line 64 "init.pgc"
+#line 66 "init.pgc"
  int g = fb ( 2 ) ;

-#line 65 "init.pgc"
+#line 67 "init.pgc"
  int i = 3 ^ 1 ;

-#line 66 "init.pgc"
+#line 68 "init.pgc"
  int j = 1 ? 1 : 2 ;

-#line 68 "init.pgc"
+#line 70 "init.pgc"
  int e = y -> member ;

-#line 69 "init.pgc"
+#line 71 "init.pgc"
  int c = 10 >> 2 ;

-#line 70 "init.pgc"
+#line 72 "init.pgc"
  bool h = 2 || 1 ;

-#line 71 "init.pgc"
+#line 73 "init.pgc"
  long iay ;
 /* exec sql end declare section */
-#line 72 "init.pgc"
+#line 74 "init.pgc"


     int f=fa();
@@ -191,10 +193,10 @@ int main(void)
     /* exec sql begin declare section */
       /* compile error */

-#line 78 "init.pgc"
+#line 80 "init.pgc"
  int k = N : : i ;
 /* exec sql end declare section */
-#line 79 "init.pgc"
+#line 81 "init.pgc"

 #endif

@@ -204,58 +206,58 @@ int main(void)
     iay = 0;
     printf("%ld\n", iay);
     /* exec sql whenever sqlerror  do fa ( ) ; */
-#line 87 "init.pgc"
-
-    { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select now ( )", ECPGt_EOIT, ECPGt_EORT);
-#line 88 "init.pgc"
-
-if (sqlca.sqlcode < 0) fa ( );}
-#line 88 "init.pgc"
-
-    /* exec sql whenever sqlerror  do fb ( 20 ) ; */
 #line 89 "init.pgc"

     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select now ( )", ECPGt_EOIT, ECPGt_EORT);
 #line 90 "init.pgc"

-if (sqlca.sqlcode < 0) fb ( 20 );}
+if (sqlca.sqlcode < 0) fa ( );}
 #line 90 "init.pgc"

-    /* exec sql whenever sqlerror  do fc ( \"50\" ) ; */
+    /* exec sql whenever sqlerror  do fb ( 20 ) ; */
 #line 91 "init.pgc"

     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select now ( )", ECPGt_EOIT, ECPGt_EORT);
 #line 92 "init.pgc"

-if (sqlca.sqlcode < 0) fc ( "50" );}
+if (sqlca.sqlcode < 0) fb ( 20 );}
 #line 92 "init.pgc"

-    /* exec sql whenever sqlerror  do fd ( \"50\" , 1 ) ; */
+    /* exec sql whenever sqlerror  do fc ( \"50\" ) ; */
 #line 93 "init.pgc"

     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select now ( )", ECPGt_EOIT, ECPGt_EORT);
 #line 94 "init.pgc"

-if (sqlca.sqlcode < 0) fd ( "50" , 1 );}
+if (sqlca.sqlcode < 0) fc ( "50" );}
 #line 94 "init.pgc"

-    /* exec sql whenever sqlerror  do fe ( ENUM0 ) ; */
+    /* exec sql whenever sqlerror  do fd ( \"50\" , 1 ) ; */
 #line 95 "init.pgc"

     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select now ( )", ECPGt_EOIT, ECPGt_EORT);
 #line 96 "init.pgc"

-if (sqlca.sqlcode < 0) fe ( ENUM0 );}
+if (sqlca.sqlcode < 0) fd ( "50" , 1 );}
 #line 96 "init.pgc"

-    /* exec sql whenever sqlerror  do sqlnotice ( NULL , 0 ) ; */
+    /* exec sql whenever sqlerror  do fe ( ENUM0 ) ; */
 #line 97 "init.pgc"

     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select now ( )", ECPGt_EOIT, ECPGt_EORT);
 #line 98 "init.pgc"

-if (sqlca.sqlcode < 0) sqlnotice ( NULL , 0 );}
+if (sqlca.sqlcode < 0) fe ( ENUM0 );}
 #line 98 "init.pgc"

+    /* exec sql whenever sqlerror  do sqlnotice ( NULL , 0 ) ; */
+#line 99 "init.pgc"
+
+    { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select now ( )", ECPGt_EOIT, ECPGt_EORT);
+#line 100 "init.pgc"
+
+if (sqlca.sqlcode < 0) sqlnotice ( NULL , 0 );}
+#line 100 "init.pgc"
+
     return 0;
 }
diff --git a/src/interfaces/ecpg/test/expected/preproc-init.stderr
b/src/interfaces/ecpg/test/expected/preproc-init.stderr
index 1b6fa18..c159d45 100644
--- a/src/interfaces/ecpg/test/expected/preproc-init.stderr
+++ b/src/interfaces/ecpg/test/expected/preproc-init.stderr
@@ -1,7 +1,5 @@
 [NO_PID]: ECPGdebug: set to 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: raising sqlcode -220 on line 88: connection "NULL" does not exist on line 88
-[NO_PID]: sqlca: code: -220, state: 08003
 [NO_PID]: raising sqlcode -220 on line 90: connection "NULL" does not exist on line 90
 [NO_PID]: sqlca: code: -220, state: 08003
 [NO_PID]: raising sqlcode -220 on line 92: connection "NULL" does not exist on line 92
@@ -12,3 +10,5 @@
 [NO_PID]: sqlca: code: -220, state: 08003
 [NO_PID]: raising sqlcode -220 on line 98: connection "NULL" does not exist on line 98
 [NO_PID]: sqlca: code: -220, state: 08003
+[NO_PID]: raising sqlcode -220 on line 100: connection "NULL" does not exist on line 100
+[NO_PID]: sqlca: code: -220, state: 08003
diff --git a/src/interfaces/ecpg/test/expected/sql-dyntest.c b/src/interfaces/ecpg/test/expected/sql-dyntest.c
index 513d44c..20a8db7 100644
--- a/src/interfaces/ecpg/test/expected/sql-dyntest.c
+++ b/src/interfaces/ecpg/test/expected/sql-dyntest.c
@@ -12,6 +12,7 @@

 #include <stdio.h>
 #include <stdlib.h>
+#include <stdbool.h>


 #line 1 "sql3types.h"
@@ -59,7 +60,7 @@ enum

 #endif                            /* !_ECPG_SQL3TYPES_H */

-#line 7 "dyntest.pgc"
+#line 8 "dyntest.pgc"


 #line 1 "sqlca.h"
@@ -130,7 +131,7 @@ struct sqlca_t *ECPGget_sqlca(void);

 #endif

-#line 8 "dyntest.pgc"
+#line 9 "dyntest.pgc"


 #line 1 "regression.h"
@@ -140,7 +141,7 @@ struct sqlca_t *ECPGget_sqlca(void);



-#line 9 "dyntest.pgc"
+#line 10 "dyntest.pgc"


 static void
@@ -160,47 +161,51 @@ main ()



-
+
+




-#line 22 "dyntest.pgc"
- int COUNT ;
-
 #line 23 "dyntest.pgc"
- int INTVAR ;
+ int COUNT ;

 #line 24 "dyntest.pgc"
- int INDEX ;
+ int INTVAR ;

 #line 25 "dyntest.pgc"
- int INDICATOR ;
+ int INDEX ;

 #line 26 "dyntest.pgc"
- int TYPE , LENGTH , OCTET_LENGTH , PRECISION , SCALE , RETURNED_OCTET_LENGTH ;
+ int INDICATOR ;

 #line 27 "dyntest.pgc"
- int DATETIME_INTERVAL_CODE ;
+ int TYPE , LENGTH , OCTET_LENGTH , PRECISION , SCALE , RETURNED_OCTET_LENGTH ;

 #line 28 "dyntest.pgc"
- char NAME [ 120 ] , BOOLVAR ;
+ int DATETIME_INTERVAL_CODE ;

 #line 29 "dyntest.pgc"
- char STRINGVAR [ 1024 ] ;
+ char NAME [ 120 ] ;

 #line 30 "dyntest.pgc"
- double DOUBLEVAR ;
+ bool BOOLVAR ;

 #line 31 "dyntest.pgc"
+ char STRINGVAR [ 1024 ] ;
+
+#line 32 "dyntest.pgc"
+ double DOUBLEVAR ;
+
+#line 33 "dyntest.pgc"
  char * QUERY ;
 /* exec sql end declare section */
-#line 32 "dyntest.pgc"
+#line 34 "dyntest.pgc"

   int done = 0;

   /* exec sql var BOOLVAR is bool */
-#line 35 "dyntest.pgc"
+#line 37 "dyntest.pgc"


   ECPGdebug (1, stderr);
@@ -208,66 +213,66 @@ main ()
   QUERY = "select * from dyntest";

   /* exec sql whenever sqlerror  do error ( ) ; */
-#line 43 "dyntest.pgc"
+#line 45 "dyntest.pgc"


   ECPGallocate_desc(__LINE__, "MYDESC");
-#line 45 "dyntest.pgc"
+#line 47 "dyntest.pgc"

 if (sqlca.sqlcode < 0) error ( );
-#line 45 "dyntest.pgc"
+#line 47 "dyntest.pgc"


   { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
-#line 47 "dyntest.pgc"
+#line 49 "dyntest.pgc"

 if (sqlca.sqlcode < 0) error ( );}
-#line 47 "dyntest.pgc"
+#line 49 "dyntest.pgc"


   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set datestyle to german", ECPGt_EOIT, ECPGt_EORT);
-#line 49 "dyntest.pgc"
+#line 51 "dyntest.pgc"

 if (sqlca.sqlcode < 0) error ( );}
-#line 49 "dyntest.pgc"
+#line 51 "dyntest.pgc"


   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table dyntest ( name char ( 14 ) , d float8 , i int ,
bignumberint8 , b boolean , comment text , day date )", ECPGt_EOIT, ECPGt_EORT); 
-#line 53 "dyntest.pgc"
+#line 55 "dyntest.pgc"

 if (sqlca.sqlcode < 0) error ( );}
-#line 53 "dyntest.pgc"
+#line 55 "dyntest.pgc"

   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into dyntest values ( 'first entry' , 14.7 , 14 ,
123045607890, true , 'The world''s most advanced open source database.' , '1987-07-14' )", ECPGt_EOIT, ECPGt_EORT); 
-#line 54 "dyntest.pgc"
+#line 56 "dyntest.pgc"

 if (sqlca.sqlcode < 0) error ( );}
-#line 54 "dyntest.pgc"
+#line 56 "dyntest.pgc"

   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into dyntest values ( 'second entry' , 1407.87 , 1407 ,
987065403210, false , 'The elephant never forgets.' , '1999-11-5' )", ECPGt_EOIT, ECPGt_EORT); 
-#line 55 "dyntest.pgc"
+#line 57 "dyntest.pgc"

 if (sqlca.sqlcode < 0) error ( );}
-#line 55 "dyntest.pgc"
+#line 57 "dyntest.pgc"


   { ECPGprepare(__LINE__, NULL, 0, "myquery", QUERY);
-#line 57 "dyntest.pgc"
+#line 59 "dyntest.pgc"

 if (sqlca.sqlcode < 0) error ( );}
-#line 57 "dyntest.pgc"
+#line 59 "dyntest.pgc"

   /* declare MYCURS cursor for $1 */
-#line 58 "dyntest.pgc"
+#line 60 "dyntest.pgc"


   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare MYCURS cursor for $1",
     ECPGt_char_variable,(ECPGprepared_statement(NULL, "myquery", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
-#line 60 "dyntest.pgc"
+#line 62 "dyntest.pgc"

 if (sqlca.sqlcode < 0) error ( );}
-#line 60 "dyntest.pgc"
+#line 62 "dyntest.pgc"


   while (1)
@@ -275,10 +280,10 @@ if (sqlca.sqlcode < 0) error ( );}
       { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch in MYCURS", ECPGt_EOIT,
     ECPGt_descriptor, "MYDESC", 1L, 1L, 1L,
     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
-#line 64 "dyntest.pgc"
+#line 66 "dyntest.pgc"

 if (sqlca.sqlcode < 0) error ( );}
-#line 64 "dyntest.pgc"
+#line 66 "dyntest.pgc"


       if (sqlca.sqlcode)
@@ -286,10 +291,10 @@ if (sqlca.sqlcode < 0) error ( );}

       { ECPGget_desc_header(__LINE__, "MYDESC", &(COUNT));

-#line 69 "dyntest.pgc"
+#line 71 "dyntest.pgc"

 if (sqlca.sqlcode < 0) error ( );}
-#line 69 "dyntest.pgc"
+#line 71 "dyntest.pgc"

       if (!done)
     {
@@ -309,10 +314,10 @@ if (sqlca.sqlcode < 0) error ( );}
     ECPGt_int,&(LENGTH),(long)1,(long)1,sizeof(int), ECPGd_type,
     ECPGt_int,&(TYPE),(long)1,(long)1,sizeof(int), ECPGd_EODT);

-#line 86 "dyntest.pgc"
+#line 88 "dyntest.pgc"

 if (sqlca.sqlcode < 0) error ( );}
-#line 86 "dyntest.pgc"
+#line 88 "dyntest.pgc"

       printf ("%2d\t%s (type: %d length: %d precision: %d scale: %d = " , INDEX, NAME, TYPE, LENGTH, PRECISION,
SCALE);
       switch (TYPE)
@@ -345,10 +350,10 @@ if (sqlca.sqlcode < 0) error ( );}
         { ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_di_code,
     ECPGt_int,&(DATETIME_INTERVAL_CODE),(long)1,(long)1,sizeof(int), ECPGd_EODT);

-#line 116 "dyntest.pgc"
+#line 118 "dyntest.pgc"

 if (sqlca.sqlcode < 0) error ( );}
-#line 116 "dyntest.pgc"
+#line 118 "dyntest.pgc"

           switch (DATETIME_INTERVAL_CODE)
         {
@@ -399,10 +404,10 @@ if (sqlca.sqlcode < 0) error ( );}
           { ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_data,
     ECPGt_bool,&(BOOLVAR),(long)1,(long)1,sizeof(bool), ECPGd_EODT);

-#line 163 "dyntest.pgc"
+#line 165 "dyntest.pgc"

 if (sqlca.sqlcode < 0) error ( );}
-#line 163 "dyntest.pgc"
+#line 165 "dyntest.pgc"

         printf ("%s\n", BOOLVAR ? "true" : "false");
         break;
@@ -411,10 +416,10 @@ if (sqlca.sqlcode < 0) error ( );}
           { ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_data,
     ECPGt_int,&(INTVAR),(long)1,(long)1,sizeof(int), ECPGd_EODT);

-#line 168 "dyntest.pgc"
+#line 170 "dyntest.pgc"

 if (sqlca.sqlcode < 0) error ( );}
-#line 168 "dyntest.pgc"
+#line 170 "dyntest.pgc"

         printf ("%d\n", INTVAR);
         break;
@@ -422,10 +427,10 @@ if (sqlca.sqlcode < 0) error ( );}
           { ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_data,
     ECPGt_double,&(DOUBLEVAR),(long)1,(long)1,sizeof(double), ECPGd_EODT);

-#line 172 "dyntest.pgc"
+#line 174 "dyntest.pgc"

 if (sqlca.sqlcode < 0) error ( );}
-#line 172 "dyntest.pgc"
+#line 174 "dyntest.pgc"

         printf ("%.*f\n", PRECISION, DOUBLEVAR);
         break;
@@ -434,10 +439,10 @@ if (sqlca.sqlcode < 0) error ( );}
     ECPGt_char,(STRINGVAR),(long)1024,(long)1,(1024)*sizeof(char), ECPGd_di_code,
     ECPGt_int,&(DATETIME_INTERVAL_CODE),(long)1,(long)1,sizeof(int), ECPGd_EODT);

-#line 178 "dyntest.pgc"
+#line 180 "dyntest.pgc"

 if (sqlca.sqlcode < 0) error ( );}
-#line 178 "dyntest.pgc"
+#line 180 "dyntest.pgc"

         printf ("%d \"%s\"\n", DATETIME_INTERVAL_CODE, STRINGVAR);
         break;
@@ -446,10 +451,10 @@ if (sqlca.sqlcode < 0) error ( );}
           { ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_data,
     ECPGt_char,(STRINGVAR),(long)1024,(long)1,(1024)*sizeof(char), ECPGd_EODT);

-#line 183 "dyntest.pgc"
+#line 185 "dyntest.pgc"

 if (sqlca.sqlcode < 0) error ( );}
-#line 183 "dyntest.pgc"
+#line 185 "dyntest.pgc"

         printf ("\"%s\"\n", STRINGVAR);
         break;
@@ -457,10 +462,10 @@ if (sqlca.sqlcode < 0) error ( );}
           { ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_data,
     ECPGt_char,(STRINGVAR),(long)1024,(long)1,(1024)*sizeof(char), ECPGd_EODT);

-#line 187 "dyntest.pgc"
+#line 189 "dyntest.pgc"

 if (sqlca.sqlcode < 0) error ( );}
-#line 187 "dyntest.pgc"
+#line 189 "dyntest.pgc"

         printf ("<\"%s\">\n", STRINGVAR);
         break;
@@ -469,17 +474,17 @@ if (sqlca.sqlcode < 0) error ( );}
     }

   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close MYCURS", ECPGt_EOIT, ECPGt_EORT);
-#line 194 "dyntest.pgc"
+#line 196 "dyntest.pgc"

 if (sqlca.sqlcode < 0) error ( );}
-#line 194 "dyntest.pgc"
+#line 196 "dyntest.pgc"


   ECPGdeallocate_desc(__LINE__, "MYDESC");
-#line 196 "dyntest.pgc"
+#line 198 "dyntest.pgc"

 if (sqlca.sqlcode < 0) error ( );
-#line 196 "dyntest.pgc"
+#line 198 "dyntest.pgc"


   return 0;
diff --git a/src/interfaces/ecpg/test/expected/sql-dyntest.stderr
b/src/interfaces/ecpg/test/expected/sql-dyntest.stderr
index f0b21b0..a79fdd8 100644
--- a/src/interfaces/ecpg/test/expected/sql-dyntest.stderr
+++ b/src/interfaces/ecpg/test/expected/sql-dyntest.stderr
@@ -2,45 +2,45 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGconnect: opening database ecpg1_regression on <DEFAULT> port <DEFAULT>
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 49: query: set datestyle to german; with 0 parameter(s) on connection ecpg1_regression
+[NO_PID]: ecpg_execute on line 51: query: set datestyle to german; with 0 parameter(s) on connection ecpg1_regression
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 49: using PQexec
+[NO_PID]: ecpg_execute on line 51: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_process_output on line 49: OK: SET
+[NO_PID]: ecpg_process_output on line 51: OK: SET
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 51: query: create table dyntest ( name char ( 14 ) , d float8 , i int , bignumber int8
,b boolean , comment text , day date ); with 0 parameter(s) on connection ecpg1_regression 
+[NO_PID]: ecpg_execute on line 53: query: create table dyntest ( name char ( 14 ) , d float8 , i int , bignumber int8
,b boolean , comment text , day date ); with 0 parameter(s) on connection ecpg1_regression 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 51: using PQexec
+[NO_PID]: ecpg_execute on line 53: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_process_output on line 51: OK: CREATE TABLE
+[NO_PID]: ecpg_process_output on line 53: OK: CREATE TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 54: query: insert into dyntest values ( 'first entry' , 14.7 , 14 , 123045607890 , true
,'The world''s most advanced open source database.' , '1987-07-14' ); with 0 parameter(s) on connection
ecpg1_regression
+[NO_PID]: ecpg_execute on line 56: query: insert into dyntest values ( 'first entry' , 14.7 , 14 , 123045607890 , true
,'The world''s most advanced open source database.' , '1987-07-14' ); with 0 parameter(s) on connection
ecpg1_regression
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 54: using PQexec
+[NO_PID]: ecpg_execute on line 56: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_process_output on line 54: OK: INSERT 0 1
+[NO_PID]: ecpg_process_output on line 56: OK: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 55: query: insert into dyntest values ( 'second entry' , 1407.87 , 1407 , 987065403210
,false , 'The elephant never forgets.' , '1999-11-5' ); with 0 parameter(s) on connection ecpg1_regression 
+[NO_PID]: ecpg_execute on line 57: query: insert into dyntest values ( 'second entry' , 1407.87 , 1407 , 987065403210
,false , 'The elephant never forgets.' , '1999-11-5' ); with 0 parameter(s) on connection ecpg1_regression 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 55: using PQexec
+[NO_PID]: ecpg_execute on line 57: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_process_output on line 55: OK: INSERT 0 1
+[NO_PID]: ecpg_process_output on line 57: OK: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: prepare_common on line 57: name myquery; query: "select * from dyntest"
+[NO_PID]: prepare_common on line 59: name myquery; query: "select * from dyntest"
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 60: query: declare MYCURS cursor for select * from dyntest; with 0 parameter(s) on
connectionecpg1_regression 
+[NO_PID]: ecpg_execute on line 62: query: declare MYCURS cursor for select * from dyntest; with 0 parameter(s) on
connectionecpg1_regression 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 60: using PQexec
+[NO_PID]: ecpg_execute on line 62: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_process_output on line 60: OK: DECLARE CURSOR
+[NO_PID]: ecpg_process_output on line 62: OK: DECLARE CURSOR
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 64: query: fetch in MYCURS; with 0 parameter(s) on connection ecpg1_regression
+[NO_PID]: ecpg_execute on line 66: query: fetch in MYCURS; with 0 parameter(s) on connection ecpg1_regression
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 64: using PQexec
+[NO_PID]: ecpg_execute on line 66: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_process_output on line 64: correctly got 1 tuples with 7 fields
+[NO_PID]: ecpg_process_output on line 66: correctly got 1 tuples with 7 fields
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_process_output on line 64: putting result (1 tuples) into descriptor MYDESC
+[NO_PID]: ecpg_process_output on line 66: putting result (1 tuples) into descriptor MYDESC
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_desc_header: found 7 attributes
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -64,7 +64,7 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_desc: reading items for tuple 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 183: RESULT: first entry    offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 185: RESULT: first entry    offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_desc: reading items for tuple 2
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -86,7 +86,7 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_desc: reading items for tuple 2
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 172: RESULT: 14.7 offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 174: RESULT: 14.7 offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_desc: reading items for tuple 3
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -108,7 +108,7 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_desc: reading items for tuple 3
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 168: RESULT: 14 offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 170: RESULT: 14 offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_desc: reading items for tuple 4
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -130,7 +130,7 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_desc: reading items for tuple 4
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 187: RESULT: 123045607890 offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 189: RESULT: 123045607890 offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_desc: reading items for tuple 5
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -152,7 +152,7 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_desc: reading items for tuple 5
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 163: RESULT: t offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 165: RESULT: t offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_desc: reading items for tuple 6
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -174,7 +174,7 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_desc: reading items for tuple 6
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 183: RESULT: The world's most advanced open source database. offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 185: RESULT: The world's most advanced open source database. offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_desc: reading items for tuple 7
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -202,15 +202,15 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_desc: TYPE = 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 176: RESULT: 14.07.1987 offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 178: RESULT: 14.07.1987 offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 64: query: fetch in MYCURS; with 0 parameter(s) on connection ecpg1_regression
+[NO_PID]: ecpg_execute on line 66: query: fetch in MYCURS; with 0 parameter(s) on connection ecpg1_regression
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 64: using PQexec
+[NO_PID]: ecpg_execute on line 66: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_process_output on line 64: correctly got 1 tuples with 7 fields
+[NO_PID]: ecpg_process_output on line 66: correctly got 1 tuples with 7 fields
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_process_output on line 64: putting result (1 tuples) into descriptor MYDESC
+[NO_PID]: ecpg_process_output on line 66: putting result (1 tuples) into descriptor MYDESC
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_desc_header: found 7 attributes
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -234,7 +234,7 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_desc: reading items for tuple 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 183: RESULT: second entry   offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 185: RESULT: second entry   offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_desc: reading items for tuple 2
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -256,7 +256,7 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_desc: reading items for tuple 2
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 172: RESULT: 1407.87 offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 174: RESULT: 1407.87 offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_desc: reading items for tuple 3
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -278,7 +278,7 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_desc: reading items for tuple 3
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 168: RESULT: 1407 offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 170: RESULT: 1407 offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_desc: reading items for tuple 4
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -300,7 +300,7 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_desc: reading items for tuple 4
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 187: RESULT: 987065403210 offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 189: RESULT: 987065403210 offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_desc: reading items for tuple 5
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -322,7 +322,7 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_desc: reading items for tuple 5
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 163: RESULT: f offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 165: RESULT: f offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_desc: reading items for tuple 6
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -344,7 +344,7 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_desc: reading items for tuple 6
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 183: RESULT: The elephant never forgets. offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 185: RESULT: The elephant never forgets. offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_desc: reading items for tuple 7
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -372,19 +372,19 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_desc: TYPE = 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 176: RESULT: 05.11.1999 offset: -1; array: no
+[NO_PID]: ecpg_get_data on line 178: RESULT: 05.11.1999 offset: -1; array: no
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 64: query: fetch in MYCURS; with 0 parameter(s) on connection ecpg1_regression
+[NO_PID]: ecpg_execute on line 66: query: fetch in MYCURS; with 0 parameter(s) on connection ecpg1_regression
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 64: using PQexec
+[NO_PID]: ecpg_execute on line 66: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_process_output on line 64: correctly got 0 tuples with 7 fields
+[NO_PID]: ecpg_process_output on line 66: correctly got 0 tuples with 7 fields
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: raising sqlcode 100 on line 64: no data found on line 64
+[NO_PID]: raising sqlcode 100 on line 66: no data found on line 66
 [NO_PID]: sqlca: code: 100, state: 02000
-[NO_PID]: ecpg_execute on line 194: query: close MYCURS; with 0 parameter(s) on connection ecpg1_regression
+[NO_PID]: ecpg_execute on line 196: query: close MYCURS; with 0 parameter(s) on connection ecpg1_regression
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 194: using PQexec
+[NO_PID]: ecpg_execute on line 196: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_process_output on line 194: OK: CLOSE CURSOR
+[NO_PID]: ecpg_process_output on line 196: OK: CLOSE CURSOR
 [NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/pgtypeslib/dt_test2.pgc b/src/interfaces/ecpg/test/pgtypeslib/dt_test2.pgc
index 62b934b..55870b1 100644
--- a/src/interfaces/ecpg/test/pgtypeslib/dt_test2.pgc
+++ b/src/interfaces/ecpg/test/pgtypeslib/dt_test2.pgc
@@ -1,6 +1,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <stdbool.h>
 #include <limits.h>
 #include <pgtypes_date.h>
 #include <pgtypes_timestamp.h>
diff --git a/src/interfaces/ecpg/test/preproc/init.pgc b/src/interfaces/ecpg/test/preproc/init.pgc
index b1f7199..023aa4b 100644
--- a/src/interfaces/ecpg/test/preproc/init.pgc
+++ b/src/interfaces/ecpg/test/preproc/init.pgc
@@ -1,3 +1,5 @@
+#include <stdbool.h>
+
 exec sql include sqlca;

 enum e { ENUM0, ENUM1 };
diff --git a/src/interfaces/ecpg/test/sql/dyntest.pgc b/src/interfaces/ecpg/test/sql/dyntest.pgc
index 5f02fd5..f2a9cc2 100644
--- a/src/interfaces/ecpg/test/sql/dyntest.pgc
+++ b/src/interfaces/ecpg/test/sql/dyntest.pgc
@@ -3,6 +3,7 @@

 #include <stdio.h>
 #include <stdlib.h>
+#include <stdbool.h>

 exec sql include sql3types;
 exec sql include sqlca;
@@ -25,7 +26,8 @@ main ()
   int INDICATOR;
   int TYPE, LENGTH, OCTET_LENGTH, PRECISION, SCALE, RETURNED_OCTET_LENGTH;
   int DATETIME_INTERVAL_CODE;
-  char NAME[120], BOOLVAR;
+  char NAME[120];
+  bool BOOLVAR;
   char STRINGVAR[1024];
   double DOUBLEVAR;
   char *QUERY;

Re: define bool in pgtypeslib_extern.h

From
Tom Lane
Date:
I wrote:
> I'm inclined to think that we need to make ecpglib.h's bool-related
> definitions exactly match c.h, which will mean that it has to pull in
> <stdbool.h> on most platforms, which will mean adding a control symbol
> for that to ecpg_config.h.  I do not think we should export
> HAVE_STDBOOL_H and SIZEOF_BOOL there though; probably better to have
> configure make the choice and export something named like PG_USE_STDBOOL.

Here's a proposed patch that does it like that.

I'm of two minds about whether to back-patch or not.  This shouldn't
really change anything except on platforms where sizeof(_Bool) isn't
one.  We have some reason to think that nobody is actually using
ecpg on such platforms :-(, because if they were, they'd likely have
complained about breakage.  So maybe we should just put this in HEAD
and be done.

            regards, tom lane

diff --git a/configure b/configure
index 7312bd7..21ee193 100755
--- a/configure
+++ b/configure
@@ -14729,6 +14729,12 @@ _ACEOF



+if test "$ac_cv_header_stdbool_h" = yes -a "$ac_cv_sizeof_bool" = 1; then
+
+$as_echo "#define PG_USE_STDBOOL 1" >>confdefs.h
+
+fi
+

 ##
 ## Functions, global variables
diff --git a/configure.in b/configure.in
index ea83d92..d128e59 100644
--- a/configure.in
+++ b/configure.in
@@ -1590,6 +1590,13 @@ AC_CHECK_SIZEOF([bool], [],
 #include <stdbool.h>
 #endif])

+dnl We use <stdbool.h> if we have it and it declares type bool as having
+dnl size 1.  Otherwise, c.h will fall back to declaring bool as unsigned char.
+if test "$ac_cv_header_stdbool_h" = yes -a "$ac_cv_sizeof_bool" = 1; then
+  AC_DEFINE([PG_USE_STDBOOL], 1,
+            [Define to 1 to use <stdbool.h> to define type bool.])
+fi
+

 ##
 ## Functions, global variables
diff --git a/src/backend/utils/fmgr/dfmgr.c b/src/backend/utils/fmgr/dfmgr.c
index be68478..c8d2cef 100644
--- a/src/backend/utils/fmgr/dfmgr.c
+++ b/src/backend/utils/fmgr/dfmgr.c
@@ -23,7 +23,7 @@
  * On macOS, <dlfcn.h> insists on including <stdbool.h>.  If we're not
  * using stdbool, undef bool to undo the damage.
  */
-#ifndef USE_STDBOOL
+#ifndef PG_USE_STDBOOL
 #ifdef bool
 #undef bool
 #endif
diff --git a/src/include/c.h b/src/include/c.h
index c95acd3..5f800a3 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -288,20 +288,21 @@
  * bool
  *        Boolean value, either true or false.
  *
- * Use stdbool.h if available and its bool has size 1.  That's useful for
+ * We use stdbool.h if available and its bool has size 1.  That's useful for
  * better compiler and debugger output and for compatibility with third-party
  * libraries.  But PostgreSQL currently cannot deal with bool of other sizes;
  * there are static assertions around the code to prevent that.
  *
  * For C++ compilers, we assume the compiler has a compatible built-in
  * definition of bool.
+ *
+ * Note: this stanza also appears in src/interfaces/ecpg/include/ecpglib.h.
  */

 #ifndef __cplusplus

-#if defined(HAVE_STDBOOL_H) && SIZEOF_BOOL == 1
+#ifdef PG_USE_STDBOOL
 #include <stdbool.h>
-#define USE_STDBOOL 1
 #else

 #ifndef bool
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index 2bf5060..249161c 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -823,6 +823,9 @@
 /* Define to best printf format archetype, usually gnu_printf if available. */
 #undef PG_PRINTF_ATTRIBUTE

+/* Define to 1 to use <stdbool.h> to define type bool. */
+#undef PG_USE_STDBOOL
+
 /* PostgreSQL version as a string */
 #undef PG_VERSION

diff --git a/src/include/pg_config.h.win32 b/src/include/pg_config.h.win32
index 6b67fb0..6c98ef4 100644
--- a/src/include/pg_config.h.win32
+++ b/src/include/pg_config.h.win32
@@ -624,6 +624,9 @@
    (--with-krb-srvnam=NAME) */
 #define PG_KRB_SRVNAM "postgres"

+/* Define to 1 to use <stdbool.h> to define type bool. */
+#define PG_USE_STDBOOL 1
+
 /* A string containing the version number, platform, and C compiler */
 #define PG_VERSION_STR "Uninitialized version string (win32)"

diff --git a/src/interfaces/ecpg/include/ecpg_config.h.in b/src/interfaces/ecpg/include/ecpg_config.h.in
index c185561..17e93c4 100644
--- a/src/interfaces/ecpg/include/ecpg_config.h.in
+++ b/src/interfaces/ecpg/include/ecpg_config.h.in
@@ -10,6 +10,9 @@
 /* Define to 1 if `long long int' works and is 64 bits. */
 #undef HAVE_LONG_LONG_INT_64

+/* Define to 1 to use <stdbool.h> to define type bool. */
+#undef PG_USE_STDBOOL
+
 /* Define to 1 to build client libraries as thread-safe code.
  *    (--enable-thread-safety) */
 #undef ENABLE_THREAD_SAFETY
diff --git a/src/interfaces/ecpg/include/ecpglib.h b/src/interfaces/ecpg/include/ecpglib.h
index de9c76a..5cb31e2 100644
--- a/src/interfaces/ecpg/include/ecpglib.h
+++ b/src/interfaces/ecpg/include/ecpglib.h
@@ -1,6 +1,6 @@
 /*
- * this is a small part of c.h since we don't want to leak all postgres
- * definitions into ecpg programs
+ * Client-visible declarations for ecpglib
+ *
  * src/interfaces/ecpg/include/ecpglib.h
  */

@@ -8,30 +8,36 @@
 #define _ECPGLIB_H

 #include "libpq-fe.h"
+#include "ecpg_config.h"
 #include "ecpgtype.h"
 #include "sqlca.h"
 #include <string.h>

+/*
+ * this is a small extract from c.h since we don't want to leak all postgres
+ * definitions into ecpg programs; but we need to know what bool is.
+ */
 #ifndef __cplusplus
+
+#ifdef PG_USE_STDBOOL
+#include <stdbool.h>
+#else
+
 #ifndef bool
-#define bool char
-#endif                            /* ndef bool */
+typedef unsigned char bool;
+#endif

 #ifndef true
 #define true    ((bool) 1)
-#endif                            /* ndef true */
+#endif
+
 #ifndef false
 #define false    ((bool) 0)
-#endif                            /* ndef false */
-#endif                            /* not C++ */
+#endif

-#ifndef TRUE
-#define TRUE    1
-#endif                            /* TRUE */
+#endif
+#endif                            /* not C++ */

-#ifndef FALSE
-#define FALSE    0
-#endif                            /* FALSE */

 #ifdef __cplusplus
 extern "C"
diff --git a/src/pl/plperl/plperl.h b/src/pl/plperl/plperl.h
index 3748158..7ae3c69 100644
--- a/src/pl/plperl/plperl.h
+++ b/src/pl/plperl/plperl.h
@@ -64,7 +64,7 @@
  * warnings.  If PostgreSQL does not but Perl does, we need to undefine bool
  * after we include the Perl headers; see below.
  */
-#ifdef USE_STDBOOL
+#ifdef PG_USE_STDBOOL
 #define HAS_BOOL 1
 #endif

@@ -175,7 +175,7 @@
  * makes bool a macro, but our own replacement is a typedef, so the undef
  * makes ours visible again).
  */
-#ifndef USE_STDBOOL
+#ifndef PG_USE_STDBOOL
 #ifdef bool
 #undef bool
 #endif
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index a695827..7f179f1 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -513,6 +513,7 @@ sub GenerateFiles
         print $o <<EOF;
 #define HAVE_LONG_LONG_INT 1
 #define HAVE_LONG_LONG_INT_64 1
+#define PG_USE_STDBOOL 1
 #define ENABLE_THREAD_SAFETY 1
 EOF
         close($o);

Re: define bool in pgtypeslib_extern.h

From
Amit Kapila
Date:
On Fri, Nov 8, 2019 at 2:17 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> I wrote:
> > I'm inclined to think that we need to make ecpglib.h's bool-related
> > definitions exactly match c.h, which will mean that it has to pull in
> > <stdbool.h> on most platforms, which will mean adding a control symbol
> > for that to ecpg_config.h.  I do not think we should export
> > HAVE_STDBOOL_H and SIZEOF_BOOL there though; probably better to have
> > configure make the choice and export something named like PG_USE_STDBOOL.
>
> Here's a proposed patch that does it like that.
>
> I'm of two minds about whether to back-patch or not.  This shouldn't
> really change anything except on platforms where sizeof(_Bool) isn't
> one.  We have some reason to think that nobody is actually using
> ecpg on such platforms :-(, because if they were, they'd likely have
> complained about breakage.
>

Yeah, this is a valid point, but I think this would have caused
breakage only after d26a810eb which is a recent change.  If that is
right, then I am not sure such an assumption is safe.  Also, we have
already backpatched the probes.d change, so it seems reasonable to
make this change and keep the bool definition consistent in code.
OTOH, I think there is no harm in making this change for HEAD and if
later we face any complaint, we can backpatch it.

-- 
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com