Assuming I'm doing something like the following:
my $rows = $dbh->do("UPDATE MYTABLE SET amount=1200 WHERE id =123");
$rowsreturns 1, even if the number is already 1200. Thus, this is considered an updated string.My question is: is there a way to check if the update really changed the values ββin the row besides executing the request before updating?
$rows
Change the SQL query to:
UPDATE MYTABLE SET amount=1200 WHERE id = 123 AND amount <> 1200
The table will be identical, but returns the number of rows that actually changed.
Twinkles , prepare, execute .
Twinkles
prepare
execute
my $update_if_changed = $dbh->prepare('UPDATE mytable SET amount = ? WHERE id = ? AND amount != ?')
$update_if_changed->execute($amount, $id, $amount)
By default, DBD :: mysql returns the number of rows matched in UPDATE, not the number of physically modified rows. You can change this behavior by disabling mysql_client_found_rowsin your call to connect:
UPDATE
mysql_client_found_rows
connect
my $dsn = "DBI:mysql:;mysql_client_found_rows=0"; my $dbh = DBI->connect($dsn, $user, $password);
Source: https://habr.com/ru/post/1531163/More articles:Check if the destination directory exists, then continue if you do not create it later and continue after that VBA - vbanice factor - pythonUnlink function that causes an error for subsequent functions `?` And `plot` - rwarning MSB3305: Processing COM link "NETCONLib" from the path "C: \ Windows \ system32 \ hnetcfg.dll" - c ++Graphviz: how to make a timeline / rank in one line - layoutStyling buttons without shortcut - javascriptSerial delimiters are ignored by the BOOST / tokenizer - c ++The fastest way to load 10Gb RDF into a virtuoso tripestor? - semantic-webLINQ Select entries X Minutes - c #django model integer field with floating point form input - pythonAll Articles