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


%%

 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

 HeapTuple

return_query(char *str){

HeapTuple rettuple;

int ret, proc;

 SPI_connect();

ret=SPI_execute(str,true,1);

proc=SPI_processed;


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

SPITupleTable *tuptable = SPI_tuptable;

rettuple = tuptable->vals;

}



SPI_finish();

 return rettuple;

}


This I have the function:

 #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: gram2.y
Description: Binary data

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to