RE: Can't delete postgresql table record using Perl

From: "Aleksey M Boltenkov" <holybolt(at)rambler(dot)ru>
To: perlmaster56(at)gmail(dot)com
Cc: pgsql-novice(at)lists(dot)postgresql(dot)org
Subject: RE: Can't delete postgresql table record using Perl
Date: 2020-02-17 16:36:48
Message-ID: 1581957408.149955.25064.35174@mail.rambler.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)gmail(dot)com>Hello,
my laptop is windows 10 64-bit.my Perl is activestate 5.28.1my postgresql is
12.1
everything 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

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message barry kimelman 2020-02-17 16:42:09 Re: Can't delete postgresql table record using Perl
Previous Message David G. Johnston 2020-02-17 16:23:56 Re: Can't delete postgresql table record using Perl