in reply to Why does DBI prepare break my loop?
Here, in a nutshell, is what I think you should be doing. Fortunately, it is an easy change:
For example, in relevant parts ... (extemporaneous coding, might have syntax errors ...)
... and ...# LET'S GIVE MEANINGFUL VARIABLE-NAMES TO THE TWO STATEMENT HANDLES .. +. $sth_select = $dbh->prepare("SELECT volumeletter,peernodes from VolDat +a order + by volumeid"); $sth_select->execute(); $sth_update = $dbh->prepare("UPDATE VolData SET volstatus = ? WHERE vo +lumeletter = ?"); # NOTICE THAT THE '?'S ARE NOT ENCLOSED IN QUOTES!
$sth_update->execute( [$vol_current_state, $vol] );
The question-marks in the prepared statement (which are not enclosed in quotes) act as “placeholders” for values which are provided each time the prepared statement is executed.
NOTE: In the case of an SQLite database, you should also enclose the loop in a transaction. When an UPDATE statement is executed outside of a transaction, SQLite will physically verify (re-read ...) the data after it has written, more than doubling the I/O activity and bringing things to a crawl. When a transaction is active, SQLite performs the expected “lazy writes.” This is not-so important for other database engines, but it is crucial for SQLite.
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Why does DBI prepare break my loop?
by roboticus (Chancellor) on Jul 08, 2014 at 01:56 UTC | |
|
Re^2: Why does DBI prepare break my loop?
by Anonymous Monk on Jul 07, 2014 at 22:39 UTC |