[Dbix-class] How to

Hardik Joshi hardik at mavenvista.com
Tue Jun 19 09:07:12 GMT 2012


I am posting my code for dbi and dbix here please have a look.

* DBI here AutoCommit =3D 0

my $dbh =3D DBI->connect($dsn, $user, $password,
                      { RaiseError =3D> 1, AutoCommit =3D> 0 });
my $sel_sql =3D qq{select * from test where id =3D 1 for update};
my $rs =3D $dbh->selectrow_array($sel_sql);
sleep(10);
my $ins_sql =3D qq{insert into test(value1, value2) values(10.10,20.1)};
my $sth =3D $dbh->prepare($ins_sql);
$sth->execute();
$dbh->commit();
$dbh->disconnect();


* DBIx here AutoCommit =3D 0

my $schema =3D DB::Model::test->new();
my $rs =3D $schema->resultset('Test');
my $test_res =3D $rs->search( { 'id' =3D> 1 }, { 'for' =3D> 'update' } )->f=
irst();
sleep(10);
$rs->create({value1 =3D> 10.45, value2 =3D> 20.70});
$schema->storage->txn_commit();


here sleep(10) will hold execution for 10 second so meanwhile you can
execute same script from other terminal to generate the scenario.

Thanks,

Hardik Joshi

On Tue, Jun 19, 2012 at 2:08 PM, Dave Howorth <dhoworth at mrc-lmb.cam.ac.uk>w=
rote:

> Hardik Joshi wrote:
> > Thanks Alex,
> >
> > I have tried 'SELECT...FOR UPDATE' with normal DBI module and its worki=
ng
> > well where as via DBIx::Class its not working as per requirement.
>
> I don't understand. The code you said you had tried was doing an INSERT,
> not an UPDATE. So how is SELECT...FOR UPDATE relevant or working in DBI?
>
> > So, I feel I might missing something in DBIx::Class. do you have any id=
ea
> > for that?
>
>
> _______________________________________________
> 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/dbix-class@lists.scsys.co.uk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20120619/b39=
d60ab/attachment.htm


More information about the DBIx-Class mailing list