> > I usually do something like this:
> >
> >   my $transaction=sub {
> >       # Manipulate database...
> >       die "dry run";
> >   };
> >   $schema->txn_do($transaction);
> >
> > Remembering to put the die in there is of course important :-)
> >
> >
> >   Best regards,
> >
> >     Adam
> >
>

A more automated way to do this would be to do what is done in the DBIC test
suite:

use_ok('DBICTest');
use_ok('DBIC::DebugObj');
my $schema = DBICTest->init_schema();

$schema->storage->sql_maker->quote_char('`');
$schema->storage->sql_maker->name_sep('.');

my ($sql, @bind);
$schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \...@bind));
$schema->storage->debug(1);

my $rs;

$rs = $schema->resultset('CD')->search(
           { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
           { join => 'artist' });
eval { $rs->count };
is_same_sql_bind(
  $sql, \...@bind,
  "SELECT COUNT( * ) FROM `cd` `me`  JOIN `artist` `artist` ON (
`artist`.`artistid` = `me`.`artist` ) WHERE ( `artist`.`name` = ? AND
`me`.`year` = ? )", ["'Caterwauler McCrae'", "'2001'"],
  'got correct SQL for count query with quoting'
);


-- 
fREW Schmidt
http://blog.afoolishmanifesto.com
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]

Reply via email to