暂时启用AutoCommit
:
sqlite> .header on sqlite> select * from test; field one two
#!/usr/bin/perl use strict; use warnings; use DBI; my $dbh = DBI->connect('dbi:SQLite:test.db', undef, undef, { RaiseError => 1, AutoCommit => 0} ); test_select_with_update($dbh); sub test_select_with_update { my ($dbh) = @_; local $dbh->{AutoCommit} = 1; my $q = $dbh->prepare(q{SELECT field FROM test}); my $u = $dbh->prepare(q{UPDATE test SET field = ? WHERE field = ?}); $q->execute or die; while ( my $r = $q->fetchrow_hashref ) { if ( (my $f = $r->{field}) eq 'one') { $u->execute('1', $f) or die; } } }
代码运行后:
sqlite> .header on sqlite> select * from test; field 1 two