Re: SQL:Statement/Parser

Mauricio Begovich <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.dbi.general
Message-ID <CAOXmd2jKHm3n6YfFuRR=HkfMWN7KOW=DFJ-5gAZTjtZ6D1eaqw@mail.gmail.com>
Hi Ron, nice to meet you and thank you so much for your soon answer.

Got it! now I'll never forget it: it's Perl ;)!

Well, I'm working with the SQL::Statement module. The code with I'm dealing
is the following code:
################################################################################

    use SQL::Statement;
    my $sql    = "SELECT a FROM b JOIN c WHERE c=? AND e=7 ORDER BY f
DESC LIMIT 5,2";
    my $parser = SQL::Parser->new();
    $parser->{RaiseError}=1;
    $parser->{PrintError}=0;
    $parser->parse("LOAD 'MyLib::MySyntax' ");
    my $stmt = SQL::Statement->new($sql,$parser);
    printf "Command             %s\n",$stmt->command;
    printf "Num of Placeholders %s\n",scalar $stmt->params;
    printf "Columns             %s\n",join( ',', map {$_->name}
$stmt->column_defs() );
    printf "Tables              %s\n",join( ',', map {$_->name}
$stmt->tables() );
    printf "Where operator      %s\n",join( ',', $stmt->where->op() );
    printf "Limit               %s\n",$stmt->limit();
    printf "Offset              %s\n",$stmt->offset();

    # these will work not before $stmt->execute()
    printf "Order Columns       %s\n",join(',', map {$_->column}
$stmt->order() );

################################################################################


And the problem I have is that I can't access the $stmt->column_defs()
through the
map{$_->name} function.

When I do something like print DUMP $stmt->column_defs();, I can
visualize the content

of the hash that contents information about the columns of the query.

Have you any ideas of what I'm doing wrong?

Thanks in advance!

Mauricio.



2014-09-10 17:19 GMT-05:00 Ron Savage <[email protected]>:

> Hi Mauricio
>
> >Good morning!
>
> >I'm a Mexican PERL fan, and I write first for congratulate you for >this
> great job.
>
> Glad to hear you're using Perl.
>
> And yes, it's Perl, not PERL.
>
> >I've just download the SQL:Statement from CPAN via MCPAN shell since >my
> Ubuntu console, but I have some issues with the map {$_->name}
> >$stmt->column_defs() method for parsing it.
>
> >Indeed {$_->name} returns an error saying that name can't be found on
> >unbless object.
>
> We need to see the code. Post the shortest possible sample code which
> produces this error.
>
> Are you connecting to a real, pre-existing database with pre-existing
> tables?
>
> If so, how /exactly/ are you doing that?
>
> >I will appreciate too much, any information about this error that was
> >taken from CPAN documentation of this module.
>
> --
> Ron Savage - savage.net.au
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.