Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Retrieving multiple records from database

by pernod (Chaplain)
on Oct 16, 2004 at 17:34 UTC ( #399784=note: print w/replies, xml ) Need Help??

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 :)

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://399784]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2019-08-19 23:00 GMT
Find Nodes?
    Voting Booth?
    If you were the first to set foot on the Moon, what would be your epigram?

    Results (141 votes). Check out past polls.