[OT [OT]] - assering database query results

Ash Berlin ash_cpan at firemirror.com
Thu Sep 17 14:31:56 BST 2009

On Thu, 17 Sep 2009 13:34:56 +0100, Nicholas Clark <nick at ccl4.org> wrote:
> Off topicly off topic, as it's not even about that 4 letter P word.
> So, we have quite a lot of our database queries in config files, with
> placeholders, etc
> Some of them are only supposed to return 1 row.
> However, if our assumptions are wrong, they might return multiple rows.
> This isn't a fatal bug in our code, which is written such that it takes
> the
> first row returned. However, it is a bug in our logic.
> Is there a good way to "assert" that there is only one row? So that in
> development (and QA) environments, it is fatal to breach assumptions.
> But production keeps going.
> Nicholas Clark

The way DBIx::Class does this is by fetching the first two rows. If there
is a second one, its a warning, or an error in your case:

See select_single in DBIx::Class::Storage::DBI


More information about the london.pm mailing list