Home > Archive > PostgreSQL Bugs > November 2005 > ECPG: "char*" instead of "const char*" in ecpglib.h









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author ECPG: "char*" instead of "const char*" in ecpglib.h
Tomasz Ostrowski

2005-11-09, 9:24 am

Using "char*" as an argument type instead of "const char*" in ecpglib.h
causes that for example the following sample program, basically
copied from docmentation
http://www.postgresql.org/docs/8.1/...pg-dynamic.html ,
does not compile using "gcc-4.0.1":

test.pgc

#include <stdio.h>

int main()
{
EXEC SQL BEGIN DECLARE SECTION;
const char *select_version_sql = "select version()";
char version[1000];
EXEC SQL END DECLARE SECTION;

EXEC SQL CONNECT TO template1 USER postgres;
EXEC SQL PREPARE select_version FROM :select_version_sql;

EXEC SQL EXECUTE select_version INTO :version;
printf("%s\n", version);
return 0;
}

$ ecpg --version
ecpg (PostgreSQL 8.1.0) 4.1.1

$ecpg test.pgc

$gcc test.c -lecpg
test.pgc: In function 'main':
test.pgc:11: warning: passing argument 3 of 'ECPGprepare' discards qualifiers from pointer target type

$g++ test.c -lecpg
test.pgc: In function 'int main()':
test.pgc:11: error: invalid conversion from 'const char*' to 'char*'
test.pgc:11: error: initializing argument 3 of 'bool ECPGprepare(int, char*, char*)'

----------------------------------------------------------

This forces to use terrible workarounds like:

const char *select_version_sql = "select version()";
int select_version_sql_l
= strlen(select_versio
n_sql);
EXEC SQL BEGIN DECLARE SECTION;
char _select_version_sql& #91;select_version_s
ql_l+1];
EXEC SQL END DECLARE SECTION;
strncpy(_select_vers
ion_sql, select_version_sql, select_version_sql_l
+1);

EXEC SQL PREPARE select_version FROM :_select_version_sql
;

----------------------------------------------------------

This bug was present in 8.0.4 and is present in 8.1.0 - I haven't
checked other versions.


Is this just a function declaration bug or do ecpg functions really
change their arguments so they cannot be declared "const" (also a bug)?

Regards
Tometzky
--
....although Eating Honey was a very good thing to do, there was a
moment just before you began to eat it which was better than when you
were...
Winnie the Pooh

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Qingqing Zhou

2005-11-12, 8:23 pm



On Wed, 9 Nov 2005, Tomasz Ostrowski wrote:
>
> Using "char*" as an argument type instead of "const char*" in ecpglib.h
> causes that for example the following sample program, basically
> copied from docmentation
> http://www.postgresql.org/docs/8.1/...pg-dynamic.html ,
> does not compile using "gcc-4.0.1":
>
> $g++ test.c -lecpg
> test.pgc: In function 'int main()':
> test.pgc:11: error: invalid conversion from 'const char*' to 'char*'
> test.pgc:11: error: initializing argument 3 of 'bool ECPGprepare(int, char*, char*)'
>


Agreed. A patch has been submitted to pg-patches.

Regards,
Qingqing
Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com