sql statement parsing

hi guys,
    how can i parse the where clause in an SQL::Statement object instance?
$statement = SQL::Statement->new("select 1,2,3 from table where x=y");
now when i do this:
$where = $stmt->where();
it gives me error:
Can't locate object method "where" via package "SQL::Statement" (perhaps you
for
got to load "SQL::Statement"?) at blah line 34.

any idea?
thanks

--
Hytham Shehab

0
hythamshb
8/10/2002 4:34:33 PM
perl.beginners.cgi 3839 articles. 0 followers. Follow

4 Replies
306 Views

Similar Articles

[PageSpeed] 41

At 07:34 PM 8/10/02 +0300, Hytham Shehab wrote:
>     how can i parse the where clause in an SQL::Statement object instance?
>$statement = SQL::Statement->new("select 1,2,3 from table where x=y");

Hytham,

Although I haven't used SQL::Statement you can certainly do something like:

$condition = $1 if $statement =~ /where (.+)( order by .+){0,1}$/;

I haven't tested this but I expect it to pick up the conditional part of an 
SQL statement which would then be up to you to parse further if needed.

In your example though you have assigned the SQL statement in the code. 
Therefore wouldn't it make more sense if this is really how the code works 
to do something like:

my $cond = 'x=y';
$statement = SQL::Statement->new("select 1,2,3 from table where $cond;");

Then you parse upfront, so to speak. This is how I assemble queries on the 
fly for transactions that need that functionality.

hth,

Marty

--
SIMPL WebSite Creation: http://face2interface.com/Home/Demo.shtml

0
marty
8/10/2002 11:58:44 PM
> Hytham,
>
> Although I haven't used SQL::Statement you can certainly do something
like:
>
> $condition = $1 if $statement =~ /where (.+)( order by .+){0,1}$/;
>
> I haven't tested this but I expect it to pick up the conditional part of
an
> SQL statement which would then be up to you to parse further if needed.
>
> In your example though you have assigned the SQL statement in the code.
> Therefore wouldn't it make more sense if this is really how the code works
> to do something like:
>
> my $cond = 'x=y';
> $statement = SQL::Statement->new("select 1,2,3 from table where $cond;");
>
> Then you parse upfront, so to speak. This is how I assemble queries on the
> fly for transactions that need that functionality.
>
> hth,
>
> Marty
nice way to get the where clause, but i don't want ot get data, nor insert
data, the sole purpose of my script is to type the select statement in more
tree-like structure, so i don't know the values of $cond to evaluate it,
besides, am using SQL::Statement for the pure purpose of parsing, no more,
no less, all what i wounder is, why am getting this error message, and how
to avoid it.
any help or new idea?

--
Hytham Shehab


0
hythamshb
8/11/2002 12:12:25 AM
Posting your whole script, or a larger part might be helpful and get 
more response.  <sidenote>are you using strict and warnings?</sidenote>

My original hunch was that the "where" method was not being exported and 
therefore was not "loaded" by your script, upon a slight more research I 
was *unable* to find the "where" function you are using anywhere except 
in the documentation for SQL::Statement, which makes reference to the 
"where" method existing in the SQL::Statement::OP package which I could 
also not find either in the source for SQL::Statement nor elsewhere on CPAN.

You might want to crack open the source for the module you have 
installed but I wasn't able to locate where this method is defined 
(other than in the docs).  You might also contact the creator of the 
module about this specific problem.

http://danconia.org



Hytham Shehab wrote:
> hi guys,
>     how can i parse the where clause in an SQL::Statement object instance?
> $statement = SQL::Statement->new("select 1,2,3 from table where x=y");
> now when i do this:
> $where = $stmt->where();
> it gives me error:
> Can't locate object method "where" via package "SQL::Statement" (perhaps you
> for
> got to load "SQL::Statement"?) at blah line 34.
> 
> any idea?
> thanks
> 
> --
> Hytham Shehab
> 
> 


0
wiggins
8/11/2002 1:35:36 AM
> Posting your whole script, or a larger part might be helpful and get
> more response.  <sidenote>are you using strict and warnings?</sidenote>
>
> My original hunch was that the "where" method was not being exported and
> therefore was not "loaded" by your script, upon a slight more research I
> was *unable* to find the "where" function you are using anywhere except
> in the documentation for SQL::Statement, which makes reference to the
> "where" method existing in the SQL::Statement::OP package which I could
> also not find either in the source for SQL::Statement nor elsewhere on
CPAN.
>
> You might want to crack open the source for the module you have
> installed but I wasn't able to locate where this method is defined
> (other than in the docs).  You might also contact the creator of the
> module about this specific problem.
>
> http://danconia.org
>
well, i think that u r absolutely right about that it might be *ONLY*
existed in the docs, i may contact the creator for more details regarding
this issue.

btw, am not using warnings nor strict.

thanks.
--
Hytham Shehab

0
hythamshb
8/11/2002 11:10:42 AM
Reply: