return HeapTuple - Mailing list pgsql-hackers

From Werner Echezuria
Subject return HeapTuple
Date
Msg-id 2485a25e0908250647x15ac114egc0c7c0e8a0d491df@mail.gmail.com
Whole thread Raw
List pgsql-hackers
Hi, I wanna return a group of rows, like when you do "SELECT columns FROM table", but I'm getting some troubles, I don't know if I have to use HeapTuple or Datum. I'm using bison to parse sqlf to sql this way:

-- some code
p, li { white-space: pre-wrap; }


%%

query: /* empty string */

| query command

;

command: '\n'

| CreateFuzzyPredStmt

| DropFuzzyPredStmt

| SelectStmt

{

int i;

*((void **)result) = return_query(fuzzy_query[real_length-1]);

for (i=0;i<real_length;i++)

pfree(fuzzy_query[i]);

}

| error '\n' { yyerrok;}

;


-- some code

p, li { white-space: pre-wrap; }

HeapTuple

return_query(char *str){

HeapTuple rettuple;

int ret, proc;

SPI_connect();

ret=SPI_execute(str,true,1);

proc=SPI_processed;

p, li { white-space: pre-wrap; }

if (ret > 0 && SPI_tuptable != NULL){

SPITupleTable *tuptable = SPI_tuptable;

rettuple = tuptable->vals;

}

 

SPI_finish();

return rettuple;

}

This I have the function:

p, li { white-space: pre-wrap; }

#include "postgres.h"

#include "fmgr.h"

#include "gram.h"

#include "utils/builtins.h"


extern Datum sqlf(PG_FUNCTION_ARGS);

PG_MODULE_MAGIC;

PG_FUNCTION_INFO_V1(sqlf);


Datum

sqlf(PG_FUNCTION_ARGS){

char *query = TextDatumGetCString(PG_GETARG_DATUM(0));

void *result;

yy_scan_string(query);

sqlf_yyparse(&result);

PG_RETURN_HEAPTUPLEHEADER(result);

}



regards.

Attachment

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: setting up scan keys
Next
From: Tom Lane
Date:
Subject: Re: DELETE syntax on JOINS