Thread: Re: :PgSQL: More Queestions
On Wednesday, November 20, 2002, at 06:53 AM, Tim Bunce wrote: >> But if I change it (as I'm seriously considering, in light of >> PostgreSQL 7.3's support for prepared statements), I'll probably do no >> parsing for comments. > > I think that would be a bad move. Yes, your last post makes very clear why. Thanks. > If it's seen the start of a string ("..." or '...') then it just > keeps copying the string till it finds the same type of quote > character to mark the end of the string. The 'fiddly bit in the > middle' is handling backslashes used to escape quote chars in the > middle of the string: "...\"..." and "...\\" (odd vs even number). Seems rather opaque. Maybe I'm just reflecting my C-newbieness, but why wouldn't this work as well? Borrowing a bit from DBD::ODBC here (but allowing for both kinds of escaping of the quote characters): if (*src == '"' || *src == '\'') { if (!in_literal) { literal_ch = *src; in_literal = 1; } else { if (*src == literal_ch && *(src-1) != '//' && *(src-1)!= literal_ch) { in_literal = 0; } } } > ANSI standard doesn't use backslashes, it uses doubling: "...""..." Yeah, as Rudy pointed out, however, PostgreSQL uses backslashes as well as doubling. > Take a look at dbd_preparse in DBD::Oracle. Will do, when I'm more awake again and find the tuits... > There's also a preparse() in DBI.xs which was destined to become a > standard service offered to drivers - but isn't quite ready yet. Hrm, yes, that could be quite handy, since dbd_preparse() seems to be one of the more complex driver functions... Regards, David -- David Wheeler AIM: dwTheory david@wheeler.net ICQ: 15726394 http://david.wheeler.net/ Yahoo!: dew7e Jabber: Theory@jabber.org
On Wed, Nov 20, 2002 at 10:30:00PM -0800, David Wheeler wrote: > On Wednesday, November 20, 2002, at 06:53 AM, Tim Bunce wrote: > > >>But if I change it (as I'm seriously considering, in light of > >>PostgreSQL 7.3's support for prepared statements), I'll probably do no > >>parsing for comments. > > > >I think that would be a bad move. > > Yes, your last post makes very clear why. Thanks. > > >If it's seen the start of a string ("..." or '...') then it just > >keeps copying the string till it finds the same type of quote > >character to mark the end of the string. The 'fiddly bit in the > >middle' is handling backslashes used to escape quote chars in the > >middle of the string: "...\"..." and "...\\" (odd vs even number). > > Seems rather opaque. Maybe I'm just reflecting my C-newbieness, but why > wouldn't this work as well? Borrowing a bit from DBD::ODBC here (but > allowing for both kinds of escaping of the quote characters): > > if (*src == '"' || *src == '\'') { > if (!in_literal) { > literal_ch = *src; > in_literal = 1; No need for in_literal as literal_ch can serve as a flag as well. > } else { > if (*src == literal_ch && *(src-1) != '//' > && *(src-1) != literal_ch) { > in_literal = 0; > } > } > } Can't distinguish between"....\\\\" - final double quote ends the string"...\\\\\" - final double quote is escapedand string continues... If the original code isn't broken it doesn't need fixing, maybe just commenting. Tim.
> > On Wed, Nov 20, 2002 at 10:30:00PM -0800, David Wheeler wrote: > > On Wednesday, November 20, 2002, at 06:53 AM, Tim Bunce wrote: > > > > >>But if I change it (as I'm seriously considering, in light of > > >>PostgreSQL 7.3's support for prepared statements), I'll probably do no > > >>parsing for comments. > > > > > >I think that would be a bad move. > > > > Yes, your last post makes very clear why. Thanks. > > > > >If it's seen the start of a string ("..." or '...') then it just > > >keeps copying the string till it finds the same type of quote > > >character to mark the end of the string. The 'fiddly bit in the > > >middle' is handling backslashes used to escape quote chars in the > > >middle of the string: "...\"..." and "...\\" (odd vs even number). > > > > Seems rather opaque. Maybe I'm just reflecting my C-newbieness, but why > > wouldn't this work as well? Borrowing a bit from DBD::ODBC here (but > > allowing for both kinds of escaping of the quote characters): > > > > if (*src == '"' || *src == '\'') { > > if (!in_literal) { > > literal_ch = *src; > > in_literal = 1; > > No need for in_literal as literal_ch can serve as a flag as well. True...I was hacking that in and overlooked it. > > > } else { > > if (*src == literal_ch && *(src-1) != '//' > > && *(src-1) != literal_ch) { > > in_literal = 0; > > } > > } > > } > > Can't distinguish between > "....\\\\" - final double quote ends the string > "...\\\\\" - final double quote is escaped and string > continues... > > If the original code isn't broken it doesn't need fixing, maybe > just commenting. I'm tempted to leave it, since nobody is complaining, at the moment...but I'll put it on the list. Jeff