Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

array parameter

 
   Database Help (Home) -> mySQL RSS
Next:  PERFORM statement  
Author Message
user

External


Since: Feb 18, 2005
Posts: 8



(Msg. 1) Posted: Sat Feb 19, 2005 6:57 pm
Post subject: array parameter
Archived from groups: mailing>database>mysql (more info?)

since mysql's stored procedure does not accept an array as a parameter,
is it a good practice to input a string delimited parameter eg.

call stored_procedure(param1, param2, 'value1:value2:value3');

 >> Stay informed about: array parameter 
Back to top
Login to vote
Bill Karwin1

External


Since: Jun 17, 2004
Posts: 42



(Msg. 2) Posted: Sat Feb 19, 2005 6:57 pm
Post subject: Re: array parameter [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

- wrote:
 > since mysql's stored procedure does not accept an array as a parameter,
 > is it a good practice to input a string delimited parameter eg.
 >
 > call stored_procedure(param1, param2, 'value1:value2:value3');

That question is impossible to answer for the general case. Good
practice depends on what your procedure needs to do with that list of
values.

What are you storing in the elements of the array?
What are you going to do with the values?
Do you need a way to separate the list into the individual elements
within the procedure?
What alternatives have you considered? E.g., inserting value1, value2,
value3 into a temp table so you can access them from within the stored proc.

Regards,
Bill K.

 >> Stay informed about: array parameter 
Back to top
Login to vote
user

External


Since: Feb 18, 2005
Posts: 8



(Msg. 3) Posted: Sun Feb 20, 2005 12:16 am
Post subject: Re: array parameter [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Bill Karwin wrote:
 >
 > What are you storing in the elements of the array?
 > What are you going to do with the values?
 > Do you need a way to separate the list into the individual elements
 > within the procedure?
 > What alternatives have you considered? E.g., inserting value1, value2,
 > value3 into a temp table so you can access them from within the stored
 > proc.

in this case, i am passing the values to the procedure to indicate which
results to select that has the string in the column.

e.g. ':apple:papaya:watermelon:... so on and so forth.

i haven't considered inserting the values into a temp table. it looks
easier though but if i were to do that, it looks kind of
'unconsolidated' (can't think of a proper term to describe it)
but if this is the preferred way, i won't hesitate to use it.
 >> Stay informed about: array parameter 
Back to top
Login to vote
user

External


Since: Feb 18, 2005
Posts: 8



(Msg. 4) Posted: Mon Feb 21, 2005 1:40 am
Post subject: Re: array parameter [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

hi bill, is it a common practice to store variables into a table and
have 'get', 'set' methods?

create table config_table (
  column1 ...
  column2...
);

create procedure get_column1()
  ...
  ...

create procedure set_column1(..)
  ...
  ...


imo, a table is meant to store records with more than one row rather
than a maximum of one.

but there seems to be no other alternative that i know of to store
variables. so i reckon this is the only way to go?
 >> Stay informed about: array parameter 
Back to top
Login to vote
Bill Karwin1

External


Since: Jun 17, 2004
Posts: 42



(Msg. 5) Posted: Mon Feb 21, 2005 3:20 pm
Post subject: Re: array parameter [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

- wrote:
 > hi bill, is it a common practice to store variables into a table and
 > have 'get', 'set' methods?

I think it's more common practice to define getters and setters in a
host language, e.g. Java.

SQL was never designed or intended as a complete programming language
environment.

Regards,
Bill K.
 >> Stay informed about: array parameter 
Back to top
Login to vote
Bill Karwin1

External


Since: Jun 17, 2004
Posts: 42



(Msg. 6) Posted: Mon Feb 21, 2005 3:23 pm
Post subject: Re: array parameter [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

- wrote:
 > e.g. ':apple:papaya:watermelon:... so on and so forth.

So somehow you need to convert that string into:
IN ('apple', 'papaya', 'watermelon')
or some such. But unfortunately, as we have discussed recently on this
forum, MySQL does not support dynamic queries within stored procedures.
That is, there is no equivalent of EXECUTE IMMEDIATE.

 > i haven't considered inserting the values into a temp table. it looks
 > easier though but if i were to do that, it looks kind of
 > 'unconsolidated' (can't think of a proper term to describe it)
 > but if this is the preferred way, i won't hesitate to use it.

I think the more common solution is to run dynamic queries from a host
language (Java, PHP, Perl, etc.), where you can build a query
dynamically and then execute that string as a SQL statement.

Regards,
Bill K.
 >> Stay informed about: array parameter 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Best way to issue hundreds of inserts/updates??? - Using mysql 4.0.23- What is the best way to execute several (hundreds of) inserts and updates? Rather than issuing tons of individual inserts and updates, can I send the strings to a text file and then have mysql do them all?? IE : query.txt insert..

MySQL freezes, brings XP machine to a grinding halt - I've been using MySQL for a while for fairly light database development on my XP machine. Currently, I am just starting a new project and have experienced some big problems with MySQL today both on my office machine and at home where running a particular...

login as user 'root' but do not have root privlages and my.. - Hi gang: I'm experiencing a problem with MySQL -- I updated MySQL from version 4.1.0 to 4.1.10 and now when I login as root it doesn't show all the databases I should have access to, nor it doesn't recognize me being logged in as root (via..

FLUSH TABLES hangs if table is locked - Using FLUSH TABLES via the C query API mysql_query() hangs if the table is locked already. That is to say, nothing prevents me from running a LOCK TABLES twice; it won't tell me "it's already locked, don't try to run a FLUSH". Anyone know ...

Tool to convert DDL in graphical diagram? - Does anyone know of a tool that will create a graphical diagram from a DDL (SQL create script)? Preferable a free open-source tool. Thanks, A
   Database Help (Home) -> mySQL All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]