Anderson escreveu:
> Alguém sabe me dizer o porque deste erro na hora de criar uma função no
> banco de dados usando uma função feita em C.
>
Porque *não* é assim que cria funções em C no PostgreSQL. Vide exemplos em [1].
> Erro:
>
> ERROR: could not load library "/usr/local/pgsql/lib/teste.so":
> /usr/local/pgsql/lib/teste.so: undefined symbol: ECPGdo
> SQL state: 58P01
> Estou utilizando o PostgreSQL 8.2.6 com o Ubuntu 9.04. Já tentei também
> no PostgreSQL 8.3.6, o erro é o mesmo.
>
O ECPG [2] é uma linguagem para utilização de SQL embutido em um programa C.
Abaixo eu ilustro um exemplo bem simples:
eu...@harman ~ $ cat /tmp/t1.pgc
#include <stdio.h>
int main(void)
{
ECPGdebug(1, stderr);
exec sql connect to eu...@localhost:5433;
exec sql create table foo (a int, b int);
exec sql select * from foo;
exec sql drop table foo;
exec sql disconnect;
return 0;
}
eu...@harman ~ $ ./install/bin/ecpg /tmp/t1.pgc
eu...@harman ~ $ gcc -o /tmp/t1 -I./install/include /tmp/t1.c -lecpg
eu...@harman ~ $ /tmp/t1
[8263]: ECPGdebug: set to 1
[8263]: ECPGconnect: opening database euler on localhost port 5433
[8263]: ecpg_execute line 8: QUERY: create table foo ( a int , b int ) with 0
parameter on connection euler
[8263]: ecpg_execute line 8: using PQexec
[8263]: ecpg_execute line 8 Ok: CREATE TABLE
[8263]: ecpg_execute line 9: QUERY: select * from foo with 0 parameter on
connection euler
[8263]: ecpg_execute line 9: using PQexec
[8263]: ecpg_execute line 9: Correctly got 0 tuples with 2 fields
[8263]: raising sqlcode 100 in line 9, 'No data found in line 9.'.
[8263]: ecpg_execute line 10: QUERY: drop table foo with 0 parameter on
connection euler
[8263]: ecpg_execute line 10: using PQexec
[8263]: ecpg_execute line 10 Ok: DROP TABLE
[8263]: ecpg_finish: Connection euler closed.
[1] http://www.postgresql.org/docs/8.3/static/xfunc-c.html
[2] http://www.postgresql.org/docs/8.3/static/ecpg.html
--
Euler Taveira de Oliveira
http://www.timbira.com/
_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral