开发者

How do I get a list with all reserved words in SQL::Parser?

with

#!/usr/bin/perl
use warnings;
use strict;
use 5.010;
use SQL::Parser;                                 

my $parser = SQL::Parser->new( 'ANSI', {RaiseError=>1} );

my $word = 'BETWEEN';

my $success = $parser-&开发者_如何学Pythongt;feature( 'reserved_words', $word );
$success = $success ? '' : 'NOT';
say "$word is $success a reserved word";

I can check if a word is a reserved word.

Is there a function that gives me a list of all reserved words?


SQL::Dialects::ANSI is a simple interface to information about ANSI SQL in INI format. So you get that and parse it... except its not in INI format because it doesn't contain key = value but just key which chokes Config::INI. Alas, this is one of the few INI parsers I could find that will deal with a string.

So you might have to parse it by hand. That's what SQL::Parser does.

Alternatively you can pull the list out of SQL::Parser's guts.

use Data::Dumper;
use SQL::Parser;

my $s = SQL::Parser->new;
print Dumper $s->{opts}{reserved_words};

This is a hack and will eventually fail.

As per my comments above, the list of ANSI SQL reserved words (hey, which version of ANSI SQL?) is not definitive. The database itself may reserve additional words. And different versions may reserve different words. If you can find a way to do whatever it is you're doing that doesn't rely on a list of reserved words, do that.


Michael gave me this page via RT.

How about a method of SQL::Parser which returns all features of a given class (e.g. 'features($)'), analog to feature()? Would that help you? If yes, please open a feature request on CPAN against SQL::Statement.

I wouldn't break working interfaces others rely on without a good reason - missing feature is not a good reason.


If you don't want it programmatically, ignore everything I just said about SQL::Dialects and read the standard. Always check the standard as derivative works may be incomplete, incorrect or working off dialects. Even though there are updated ANSI SQL standards, most databases use some mutation of SQL-92 or elements of SQL:1999. After that they got silly.

I can't find a copy of the SQL:1999 standard, but here's a BNF which looks very thorough.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜