"Johnson, Shaunn" <[EMAIL PROTECTED]> writes:

> --thanks for the reply.
> 
> --i see the same example in the Perldoc for DBI,
> --but what i don't see is if i can substitute:
> 
> 
> >>> $sth->execute('Bill', 32);
> 
> with something like this:
> 
> >>> $sth->execute ('select tableowner from t_table');
> 
> and have the results from that be put in
> place of '?'.

Ah, not directly - you can either do a subselect (which may or may not
be supported by your particular database - I seem to recall reading
that mySQL does not support it.  I use Oracle here at work, and
haven't used mySQL in quite a while), or do it in two steps.

A subselect:

SELECT table_owner,
       table_columns,
       table_def
  FROM master_table
 WHERE table_owner IN(SELECT tableowner FROM t_table)
   AND table_columns <= ?
EOQ

This basically runs the inner 'SELECT' query first, and feeds the
results into the outer query.  Check your database's documentation to
see if subselects are supported.
 
> --but perhaps i am getting too far ahead of myself
> --(more likely than not).  in the above example,
> --you assign 'Bill' and '32' ... but what if 
> --i have a text file created (say the list of
> --users from the original query).  how can i
> --put the list in?  can i say something like
> 
> >>> $sth->execute ($file);

You cannot do that - 

> 
> --maybe read($file)? this is the part that doesn't
> --make sense to me.  how can i pass the list
> --of users inside the sql?  there is a part in 
> --the perldoc DBI that says something like
> 
> open FH, "phone.csv" or die "blah, blah dead:$!";
> while (<FH>) {
> chomp;
> my ($name, phone) = split /,/;
> $sth->execute($name, $phone);
> ;
> close $FH;


Yes, the above should work...You might want to add some error handling
to your parsing - for instance, what if the last line in the file is
blank, or if you have a line like 'Bill Clinton,' ($phone ends up
being undef)

> --i'm going to test this to see if i can
> --use my text file to put data into the
> --query ... 
> 
> --it may just be that i will have to do 
> --this in a two or three step process.

Yes, you will need to do two steps - at least I know of no other way.

Good luck!

-RN

-- 
Robin Norwood
Red Hat, Inc.

"The Sage does nothing, yet nothing remains undone."
-Lao Tzu, Te Tao Ching

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to