tags:

views:

39

answers:

2

Why do I get two times "ANSI" and not the first time "ANSI" and the second time "AnyData"?

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


my $parser = SQL::Parser->new();


my @dialects = $parser->list( 'dialects' );
say "available dialects : @dialects"; # AnyData CSV ANSI


my $dialect = $parser->dialect;
say "Current dialect: $dialect"; # ANSI


my $dialect_name = 'AnyData';
$parser->dialect( $dialect_name ); # load a dialect configuration file
$dialect = $parser->dialect; # get the name of the current dialect
say "Current dialect: $dialect"; # ANSI
+3  A: 

I get the same result, but it does seem to work if you specify the dialect in the constructor:

my $parser = SQL::Parser->new('AnyData', {RaiseError=>1});
say "Current dialect: " . $parser->dialect; # AnyData
Andomar
+3  A: 

This appears to be a (documentation?) bug in SQL::Parser, AFAICT new() is calling dialect(), which ensures that the dialect is only set once, preventing you from re-setting it later. This change was apparently done in version 1.003

Hasturkun