Class::Phrasebook Class::Phrasebook 4 of 23 : [PREV] [NEXT]

Design Patterns

We can solve these problems by writing:

$statement = $sql->get("FIND_ISBN", { title => "Design Patterns" });
$sth = $dbh->prepare($statement);
  • SQL referenced by a key
  • Statement parameters passed separately

The SQL statements and their corresponding lookup keys are then stored in a separate place that we call a phrasebook. We can use XML to wrap the SQL and the lookup keys:

<phrase name="FIND_ISBN">
select isbn from book where title = '$title'
  • The SQL statement can hold placeholders, so we can use one generic SQL statement that can be used in different places.

Now, our code is more readable and maintainable.

© 2003 Barbie Home