Skip to content

Commit

Permalink
Add some more SPI boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
leto committed Jan 8, 2010
1 parent 6a5a19c commit ae90d19
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/handler/plparrot.c
Expand Up @@ -25,19 +25,30 @@ int execq(text *sql, int cnt);
int
execq(text *sql, int cnt)
{
//char *command;
char *command;
int proc;
int ret;

if (SPI_connect() != SPI_OK_CONNECT)
ereport(ERROR, (errcode(ERRCODE_CONNECTION_EXCEPTION), errmsg("Couldn't connect to SPI")));

/* Convert given text object to a C string */
command = DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(sql)));

ret = SPI_exec(command, cnt);

proc = SPI_processed;

/* do stuff */

SPI_finish();
//pfree(command);
pfree(command);

return (proc);
}


Datum plparrot_call_handler(PG_FUNCTION_ARGS);
void plparrot_elog(int level, char *message);

Expand Down

0 comments on commit ae90d19

Please sign in to comment.