in reply to Re^3: Appending text to a column in SQL
in thread Appending text to a column in SQL
Are you sure that's right? I thought transactions ensured that multiple changes to the database were either all executed or all aborted, but didn't provide any guarantees that about data that was read. Some quick tests seem to confirm this. For example, if I run multiple copies of this program at the same time, the last one to finish clobbers the values written by any previous runs:
#!/usr/bin/perl use warnings; use strict; use constant DSN => 'DBI:mysql:database=test'; use constant DBUSER => 'user'; use constant DBPASS => 'pass'; use DBI; our $dbh = DBI->connect(DSN, DBUSER, DBPASS, { AutoCommit => 0, RaiseError => 1, } ) or die "Couldn't connect to database: ",$DBI::errstr; # Create the message and get the ID my $sth = $dbh->prepare("SELECT a FROM transtest"); $sth->execute(); my $row = $sth->fetchrow_hashref; warn "$$ a=$row->{a}\n"; sleep(5); $dbh->do("UPDATE transtest SET a = ?",undef,$row->{a}+1); warn "$$ done\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Appending text to a column in SQL
by grep (Monsignor) on Oct 18, 2006 at 03:59 UTC |