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/interactive/ecpg-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_version_sql);
EXEC SQL BEGIN DECLARE SECTION;
char _select_version_sql[select_version_sql_l+1];
EXEC SQL END DECLARE SECTION;
strncpy(_select_version_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