Unix Technical Forum

store and evaluate query

This is a discussion on store and evaluate query within the MySQL forums, part of the Database Server Software category; --> Hi, is it possible to store a query in mysql table and evaluate/ execute it from there? I have ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 11:26 AM
sasi
 
Posts: n/a
Default store and evaluate query

Hi,
is it possible to store a query in mysql table and evaluate/
execute it from there?
I have few big queries & i would like to store them in a table and
execute them from there.
how easy it is? i would also need some place hold to pass args.

Thanks,
Sasi

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 11:26 AM
Jerry Stuckle
 
Posts: n/a
Default Re: store and evaluate query

sasi wrote:
> Hi,
> is it possible to store a query in mysql table and evaluate/
> execute it from there?
> I have few big queries & i would like to store them in a table and
> execute them from there.
> how easy it is? i would also need some place hold to pass args.
>
> Thanks,
> Sasi
>


You can store it like any other string then fetch the string and execute
it in your favorite language. Or you could create a view with the query
and just select from the view.

Alternatively you could create a stored procedure and pass parameters to it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 11:26 AM
sasi
 
Posts: n/a
Default Re: store and evaluate query

thanks for the reply.

i am not using DBI. I am using mysql command line to query data.
i have a table with 2 cols. {name, query}

select query from qrytbl where name = "myqry1"

return the query stored in table, but i dont know how to evaluate it.

any help?
thanks,
--Sasi


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 11:26 AM
Rik
 
Posts: n/a
Default Re: store and evaluate query

On Mon, 13 Aug 2007 17:50:57 +0200, sasi <sasidublin@gmail.com> wrote:

> thanks for the reply.
>
> i am not using DBI. I am using mysql command line to query data.
> i have a table with 2 cols. {name, query}
>
> select query from qrytbl where name = "myqry1"
>
> return the query stored in table, but i dont know how to evaluate it.


Copy/paste?

I'd go for the View if possible.
--
Rik Wasmus
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 11:26 AM
Jerry Stuckle
 
Posts: n/a
Default Re: store and evaluate query

sasi wrote:
> thanks for the reply.
>
> i am not using DBI. I am using mysql command line to query data.
> i have a table with 2 cols. {name, query}
>
> select query from qrytbl where name = "myqry1"
>
> return the query stored in table, but i dont know how to evaluate it.
>
> any help?
> thanks,
> --Sasi
>
>


As Rik indicated - copy/paste. The query will just return the data, not
execute it.

View or stored procedure, depending on your needs.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-28-2008, 11:26 AM
sasi
 
Posts: n/a
Default Re: store and evaluate query

i cannot use views as it doesn't provide any placehold to subtitute
args passed from commandline.
copy/paste will work, not a good idea when many people use.

i am looking for some way simillar to,
call query1 <arg1> <arg2>
or
eval query1 <arg1> <arg2>

can i return a query values from procedures?

say for example, if i want to return the output of this query (select
c1,c2 from t1 where c1 = "str1") from a procedure, how to do it?

pseudo code or any idea welcome

thanks
Sasi





Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-28-2008, 11:26 AM
Jerry Stuckle
 
Posts: n/a
Default Re: store and evaluate query

sasi wrote:
> i cannot use views as it doesn't provide any placehold to subtitute
> args passed from commandline.
> copy/paste will work, not a good idea when many people use.
>
> i am looking for some way simillar to,
> call query1 <arg1> <arg2>
> or
> eval query1 <arg1> <arg2>
>
> can i return a query values from procedures?
>
> say for example, if i want to return the output of this query (select
> c1,c2 from t1 where c1 = "str1") from a procedure, how to do it?
>
> pseudo code or any idea welcome
>
> thanks
> Sasi
>
>
>
>
>


No, you can't evaluate a query like you want.

You can, however, pass 'c1' to a SP and have it perform the select for you.

But if you're talking multiple tables joined together (a typical
example), you could still use a view - just join the tables in your view
and pass your WHERE clause to the view.

Maybe if you post a real query you're trying to do it would help.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:03 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com