Re: problem with splitting a string - Mailing list pgsql-hackers

From Werner Echezuria
Subject Re: problem with splitting a string
Date
Msg-id 2485a25e0908050832o42343996jfca47bb6a01e1ed4@mail.gmail.com
Whole thread Raw
In response to Re: problem with splitting a string  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: problem with splitting a string  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hi,<br /><br />Well, I use TextDatumGetCString in the main file, but it remains with the weird characters.<br /><br
/>thisis the main file:<br /><br />#include "postgres.h"<br />#include "fmgr.h"<br />#include "gram.h"<br /> #include
"sqlf.h"<br/>#include "utils/builtins.h"<br /><br />extern Datum sqlf(PG_FUNCTION_ARGS);<br /><br />PG_MODULE_MAGIC;<br
/><br/>PG_FUNCTION_INFO_V1(sqlf);<br /><br />Datum<br />sqlf(PG_FUNCTION_ARGS){<br /><br />    char        *query =
TextDatumGetCString(PG_GETARG_DATUM(0));<br/>     const char    *parse_str;<br />    char         *result;<br /><br
/>   parse_query(query,&parse_str);<br /><br />    result=parse_str;<br /><br />   
PG_RETURN_TEXT_P(cstring_to_text(result));<br/>}<br /><br />About the PS: Ok, I understand that if I want that you
includethis as a contrib module I need to use bison/flex, I never thought about it, but I now have a couple of
questions:<br/> What are the chances to really include it in PostgreSQL as a contrib module?<br />Are there any
requirementI have to follow?<br /><br /><div class="gmail_quote">2009/8/6 Tom Lane <span dir="ltr"><<a
href="mailto:tgl@sss.pgh.pa.us">tgl@sss.pgh.pa.us</a>></span><br/><blockquote class="gmail_quote"
style="border-left:1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">Werner
Echezuria<<a href="mailto:wercool@gmail.com">wercool@gmail.com</a>> writes:<br /> > I'm trying to develop a
contribmodule in order to parse sqlf queries, I'm<br /> > using lemon as a LALR parser generator (because I think
it'seasier than<br /> > bison) and re2c (because I think it's easier than flex) but when I try to<br /> > split
thestring into words postgres add some weird characters (this works<br /> > in pure gcc), I write something like
"CREATEFUZZY PREDICATE joven ON 0..120<br /> > AS (0,0,35,120);", but postgresql adds a character like   at the end
of<br/> > "joven" and the others words.<br /><br /></div>Maybe you are expecting 'text' values to be
null-terminated? They are<br /> not.  You might look into using TextDatumGetCString or related functions<br /> to
convert.<br/><br />                        regards, tom lane<br /><br /> PS: the chances of us accepting a contrib
modulethat requires<br /> significant unusual infrastructure to build seem pretty low from<br /> where I sit.  You're
certainlyfree to do whatever you want for<br /> private work, or even for a pgfoundry project --- but if you do<br />
haveambitions of this eventually becoming contrib, "it's easier"<br /> is not going to be sufficient rationale to not
usebison/flex.<br /></blockquote></div><br /> 

pgsql-hackers by date:

Previous
From: Heikki Linnakangas
Date:
Subject: Re: md.c should not call files "relations"
Next
From: Tom Lane
Date:
Subject: Re: problem with splitting a string