Client 3—Processing Queries

Now, let's turn our attention to query processing. DBI treats SELECT commands and non-SELECT commands differently. Commands other than SELECT require less-complex processing, so let's look at those first. Listing 14.6 shows the source code for client3a:

Listing 14.6. client3a.pl
 1 #!/usr/bin/perl -W
 2 #
 3 #  Filename: client3a.pl
 4 #
 5
 6 use strict;
 7 use DBI;
 8
 9 my $dbh = DBI->connect( "dbi:Pg:", undef, undef, {PrintError => 0} )
10   or die "Can't connect to PostgreSQL: $DBI::errstr ($DBI::err)\n";
11
12 my $rows = $dbh->do( $ARGV[0] );
13
14 if( !defined( $rows )) {
15     print( $dbh->errstr."(".$dbh->err().")\n" );
16 }
17 else {
18     print( "Ok: $rows rows affected\n" );
19 }
20
21 $dbh->disconnect();

After successfully ...

Get PostgreSQL, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.