http://qs321.pair.com?node_id=189608


in reply to DBI execute() args in array format (or similar) possible?

Jim--
I'm starting to feel like a broken record, because most of the SoPWs I answer are about DBI, and my advice usually consists of either:

  • read the docs (which I assume you've done :)
  • consider using $dbh->quote() and $dbh->quote_identifier(), which it appears you haven't.
  • The whole reason I discovered these two methods was in trying to prepare dynamic sql statements, much like you're doing here. I would suggest that you try to apply $dbh->quote_identifier() to the names of any tables or columns, and $dbh->quote() to any values you're using. Try to do the join after these methods have been applied, and you might be successful.

    One consideration is that you seem to be using placeholders. While this is encouraged and can greatly speed up your queries, I've found that it's sometimes difficult to generate queries that are dynamic both at the level of the structure of the query (table names and columns) and at the specific values in the query (using ? as a placeholder for values). While the docs say that specifying a value as a parameter to $dbh->execute() will automatically quote it appropriately, I just haven't had much luck with my attempts. If you continue to have problems, consider rewriting the queries to use explicit values instead of placeholders. Not optimal, but if it works it might give you a place to start debugging from (and a functioning application! :)

    No post of mine regarding DBI would be complete without referring to chromatic's DBI is OK, which was my most valuable resource in moving out of the beginner stages of using DBI. He uses clever quoting and map combinations to dynamically generate queries, and also talks about using placeholders. You should definitely check it out if you haven't.

    good luck with your project, feel free to reply with any questions
    --au