[Dbix-class] Re: "Dry-run" for SQL ?
fREW Schmidt
frioux at gmail.com
Thu Jul 2 21:18:18 GMT 2009
> > I usually do something like this:
> >
> > my $transaction=3Dsub {
> > # 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 =3D 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 =3D $schema->resultset('CD')->search(
{ 'me.year' =3D> 2001, 'artist.name' =3D> 'Caterwauler McCrae' },
{ join =3D> 'artist' });
eval { $rs->count };
is_same_sql_bind(
$sql, \@bind,
"SELECT COUNT( * ) FROM `cd` `me` JOIN `artist` `artist` ON (
`artist`.`artistid` =3D `me`.`artist` ) WHERE ( `artist`.`name` =3D ? AND
`me`.`year` =3D ? )", ["'Caterwauler McCrae'", "'2001'"],
'got correct SQL for count query with quoting'
);
-- =
fREW Schmidt
http://blog.afoolishmanifesto.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20090702/052=
f0574/attachment.htm
More information about the DBIx-Class
mailing list