| Printed |
Page 61
|
Example 2-2 has a line:
---
$underline = '=' x ($msg_len + 6);
---
This should be
---
my $underline = '=' x ($msg_len + 6);
---
The full example, should be as below:
========== Code should be as below ==============
#!perl -w
use strict;
use DBI;
my $dbh = DBI->connect('dbi:Oracle:orcl','scott','tiger',
{RaiseError =>1, AutoCommit => 0});
my $msg =
$dbh->selectrow_array(
"SELECT SYSDATE || ' Hello Cygwin DBI! :-)' message FROM DUAL"
);
# Let's have some formatting fun! :-)
my $msg_len = length( $msg );
my $underline = '=' x ($msg_len + 6);
print "
", $underline, "
",
"|| ", ' ' x $msg_len, " ||", "
",
"|| ", $msg, " ||", "
",
"|| ", ' ' x $msg_len, " ||", "
",
$underline, "
";
$dbh->disconnect;
========== Code should be as above ==============
|
Anonymous |
|
| Printed |
Page 71
|
Typo in Example 3-2. Code snippet below is missing a dollar symbol. Around
half-way down the page, there is a line which currently says:
---
my oracleTime;
---
It should say:
---
my $oracleTime;
---
Full code should be as below:
========== Code should be as below ==============
#!/usr/bin/perl
# Step 1: Get hold of the main Perl/Tk package, DBI, and set the
# Oracle Environment, plus set the database connection and SQL.
use Tk;
use DBI;
use strict;
my $dbh = DBI->connect( 'dbi:Oracle:orcl', 'scott', 'tiger',
{RaiseError=>1, AutoCommit=>0 } );
my $sql = qq{ SELECT TO_CHAR(SYSDATE, 'HH:MI:SS') FROM DUAL };
my $mw = MainWindow->new(-title=>$0);
# Step 2: Get the latest time from the Oracle database.
my $oracleTime;
getTheOracleTime();
# Step 3: Pack a simple button onto the screen, to ask Oracle for the
# current SYSDATE time. Assign the appropriate callback.
$mw->Button(-text=>"What's the Time, according to Oracle?",
-command=> &getTheOracleTime )->pack(-side=>'top');
# Step 4: Pack a label onto the screen holding the SYSDATE time.
$mw->Label(-textvariable=> $oracleTime, -anchor=>'center'
)->pack(-side=>'bottom');
# Create another button to neatly exit the program.
$mw->Button( -text=>'Exit',
-command=>&doExit )->pack(-side=>'bottom');
# Launch the Perl/Tk looping process, to display the window! :-)
MainLoop();
# Step 5: Create the two required subroutines.
sub getTheOracleTime {
my $sth = $dbh->prepare( $sql );
$sth->execute();
($oracleTime) = $sth->fetchrow_array();
}
sub doExit {
$dbh->disconnect(); # A clean and gracefull disconnection 8-)
exit;
}
========== Code should be as above ==============
|
Anonymous |
|
| Printed |
Page 197
|
In Example 7-3, please change the following two lines (they work
on Solaris, but not Linux):
===
bless $dbh => 'OCIEnvPtr';
OCIHandleAlloc($dbh, my $dschp, OCI_HTYPE_DESCRIBE, 0, 0);
===
to
===
bless $dbh => 'OCIEnvPtr';
OCIHandleAlloc($dbh, my $dschp, OCI_HTYPE_DESCRIBE, 0, 0);
# Alternative to two lines above, if they fail to work on your OS.
#my $env = get_oci_handle($dbh, OCI_HTYPE_ENV);
#OCIHandleAlloc($env, my $dschp, OCI_HTYPE_DESCRIBE, 0, 0);
===
The bottom two lines work on Linux.
The full example is now:
========== Code should be as below ==============
#!/usr/bin/perl -w
use strict;
# Blended DBI and OCI
use DBI qw(neat);
use Oracle::OCI qw(:all);
# Step 1: Get the environment right, and set up your target
# database and user.
$ENV{ORACLE_SID} ||= 'ORCL';
my $dbuser = $ENV{ORACLE_USERID} || 'scott/tiger';
# Steps 2 & 3: We initialize and log onto the database.
my ($user, $pass) = split ///, $dbuser;
my $dbh = DBI->connect("dbi:Oracle:$ENV{ORACLE_SID}", $user, $pass);
# Step 4: Now prepare the description of the target table, this time
# using OCI, after we've established our connection with DBI.
# Notice the frequent use of the Perl DBI $dbh variable.
my $tablename = $ARGV[0];
bless $dbh => 'OCIEnvPtr';
OCIHandleAlloc($dbh, my $dschp, OCI_HTYPE_DESCRIBE, 0, 0);
# Alternative to two lines above, if they fail to work on your OS.
#my $env = get_oci_handle($dbh, OCI_HTYPE_ENV);
#OCIHandleAlloc($env, my $dschp, OCI_HTYPE_DESCRIBE, 0, 0);
bless $dschp => 'OCIDescribePtr';
OCIDescribeAny ($dbh, $dbh, oci_buf_len($tablename), OCI_OTYPE_NAME,
1, OCI_PTYPE_TABLE, $dschp);
# Get the parameter descriptor.
OCIAttrGet ($dschp, OCI_HTYPE_DESCRIBE, my $parmp, 0, OCI_ATTR_PARAM,
$dbh, 'OCIDescribePtr');
# Get the table list, number of columns and description.
OCIAttrGet ($parmp, OCI_DTYPE_PARAM, my $collst, 0,
OCI_ATTR_LIST_COLUMNS, $dbh, 'OCIParamPtr');
OCIAttrGet ($parmp, OCI_DTYPE_PARAM, my $numcols, 0,
OCI_ATTR_NUM_COLS, $dbh, 'OCIParamPtr');
my $errstr;
# Describe the target table.
printf ("
------------------
");
printf ("TABLE : %s
", $tablename);
printf ("------------------
");
my %col_attr = (
OCI_ATTR_NAME => "ColName",
OCI_ATTR_IS_NULL => "NULL?",
);
my $status;
foreach my $colnum (1..$$numcols) {
my $col_parmdp_int = 0;
my $col_parmdp = bless $col_parmdp_int => 'OCIParamPtr';
OCIParamGet($collst, OCI_DTYPE_PARAM, $dbh, $col_parmdp, $colnum);
my $describe_attr = {
OCI_ATTR_NAME => 0,
OCI_ATTR_IS_NULL => 1,
};
printf "
";
foreach my $attr (sort keys %$describe_attr) {
my $type = $describe_attr->{$attr};
no strict 'refs';
$status = OCIAttrGet( $col_parmdp, OCI_DTYPE_PARAM,
oci_buf_len(my $tmp, 90),
&$attr, $dbh, $type);
warn "$attr: ".get_oci_error($dbh, $status, 'OCIAttrGet')
if $status;
warn get_oci_error($dbh, $status) if $status;
printf "%-20s: %s
", $col_attr{$attr}, neat($tmp);
}
}
# Steps 5 & 6: Logout, clean-up and check out.
$dbh->disconnect; # Bye, Bye !!! >=8+)
========== Code should be as above ==============
|
Anonymous |
|