in reply to Retrieving multiple records from database

I usually do:

my $stmt = "SELECT somedata FROM table WHERE id IN( " . join( ", ", @i +ds_to_match . " )";

Although this assumes that all the id's are properly validated. I don't really like this solution myself as it does not use placeholders. Care should therefore be taken to avoid SQL-injection attacks.

I look forward to seeing better solutions to this problem. Just my two cents anyway :)

pernod
--
Mischief. Mayhem. Soap.

Replies are listed 'Best First'.
Re^2: Retrieving multiple records from database
by pg (Canon) on Oct 16, 2004 at 18:21 UTC

    This is the way to go, however there is a small problem.

    Most databases have a limitation on the length of a SQL query string. By doing a join, without checking length, your code is exposed to this kind of problem.

    An enhanced approach is to join, but multiple joins if needed, and each join only produce string that is shorter than a predetermined length.