How to use SPI? - Mailing list pgsql-general

From Yesid Ortiz Medina
Subject How to use SPI?
Date
Msg-id 1079649991.3995.17.camel@localhost.localdomain
Whole thread Raw
List pgsql-general

I need some hints about SPI functions:


This is my C function (pruebasql.c):

#include "executor/spi.h"

int contar_tabla(int a)
{
  char *query;
  char *when;
  int  *level;
  int  ret;
  int  selected = 0;


  strcpy(query,"select count(*) from t_online");
  SPI_connect();
  if ((ret = SPI_exec(query, 0)) < 0)
     elog(ERROR, "funny_dup17 (fired %s) on level %3d: SPI_exec (select
...) returned %d",when, *level, ret);
  if (SPI_processed > 0)
        {
           selected =
DatumGetInt32(DirectFunctionCall1(int4in,CStringGetDatum(SPI_getvalue(
SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1 ))));
        }
  SPI_finish();
  return selected;
}

$ cc -c pruebasql.c -o pruebasql.o

And this the sql

create function cuenta_registros(int) returns int
as '/xx/xx/pruebasql.o' language 'c';

When I execute with psql, it sends this message:

The `phentsize' of '/xx/xx/pruebasql.o'  ELF unexpected size


And I can't to have the new function.

Which is the problem?


--
Yesid E.Ortiz M.
Ing. de Desarrollo
Computec S.A.- Documentos
Tel. (571) 2607111
BOG. COL.

***************************************************************************
Nota: La información transmitida a través de este correo electrónico es
confidencial y está dirigida únicamente a su destinatario.  Su reproducción,
lectura o uso está prohibido a cualquier persona o entidad diferente. Aunque
Computec S.A. ha realizado su mejor esfuerzo para asegurar que el presente
mensaje y sus archivos anexos se encuentran libre de virus y defectos que
puedan llegar a afectar los computadores o sistemas que lo reciban, no se
hace responsable por la eventual transmisión de virus o programas dañinos
por este conducto, y por lo tanto es responsabilidad del destinatario
confirmar la existencia de este tipo de elementos al momento de recibirlo y
abrirlo.  Ni Computec S.A. ni ninguna de sus divisiones o dependencias
aceptan responsabilidad alguna por eventuales daños o alteraciones derivados
de la recepcion o uso del presente mensaje.
************************************************************************
Note: The information transmitted through this E-mail is confidential and is
intended to reach only its addressee.  Reproduction and usage of this
message or its contents, in whole or in part, are strictly forbidden without
the prior written consent of Computec S.A.  Computec S.A. has made its best
efforts to ensure that this message and any attached files are free of any
virus or other potentially harmful content, but makes no representations to
this effect.  Addressee shall assume full responsibility for ensuring that
opening or reading this message and any attachments will not result in harm
to their system.  Neither Computec nor any of its divisions accepts any
responsibility for damages arising from opening or reading this message or
any attachments thereto.
************************************************************************

pgsql-general by date:

Previous
From: CSN
Date:
Subject: phppgadmin: add unique index vs. add unique key
Next
From: Steve Krall
Date:
Subject: pg_dump on older version of postgres eating huge amounts of memory