RE: Can't delete postgresql table record using Perl
От | Aleksey M Boltenkov |
---|---|
Тема | RE: Can't delete postgresql table record using Perl |
Дата | |
Msg-id | 1581957408.149955.25064.35174@mail.rambler.ru обсуждение исходный текст |
Ответ на | Can't delete postgresql table record using Perl (barry kimelman <perlmaster56@gmail.com>) |
Ответы |
Re: Can't delete postgresql table record using Perl
|
Список | pgsql-novice |
You must do $dbh->commit() before $dbh->disconnect or use AutoCommit => 1.
Aleksey M Boltenkov.
17.02.2020, 19:11, barry kimelman <perlmaster56@gmail.com>Hello,my laptop is windows 10 64-bit.my Perl is activestate 5.28.1my postgresql is 12.1everything I do under psql works just fine. Now I have been writing some Perl scripts. The Perl scripts to display data work very well. However the Perl script I wrote to delete a record completes with no error yet when I look at the database table the record is still in there.1 #!C:\Perl64\bin\perl.exe -w
2
3 use strict;
4 use warnings;
5 use DBI;
6 use FindBin;
7 use lib $FindBin::Bin;
8
9 my ( $status , $dbh , $database , $username , $password , $host );
10 my ( $sql , $port , $num_rows );
11
12 $database = 'mydatabase';
13 $username = 'myusername';
14 $password = 'mypassword';
15 $host = "127.0.0.1";
16 $port = 5432;
17
18 $dbh = DBI->connect("dbi:Pg:dbname=$database;host=$host;port=$port",
19 $username,
20 $password,
21 {AutoCommit => 0, RaiseError => 1, PrintError => 0}
22 );
23 unless ( defined $dbh ) {
24 die("Error connecting to '${database}' on '${host}' :\n$DBI::errstr\n ");
25 } # UNLESS
26
27 $sql = "delete from laptop where name = 'Lenovo ThinkPad P71'";
28 print "SQL for delete operation is\n$sql\n";
29 $num_rows = $dbh->do($sql);
30 unless ( defined $num_rows ) {
31 print "error executing : ${sql}\n",$DBI::errstr,"\n";
32 } # UNLESS
33 else {
34 print "${num_rows} rows were successfully deleted\n";
35 } # ELSE
36
37 $dbh->disconnect; # disconnect from databse
38
39 exit 0;Any idea as to why the record is still in the table ?Thanks.--Barrry KimelmanWinnipeg, Manitoba, Canada
В списке pgsql-novice по дате отправления: