Skip to content

Commit

Permalink
README.longs.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
yanick committed Nov 10, 2011
1 parent 4b5a586 commit cd45d9f
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 81 deletions.
81 changes: 0 additions & 81 deletions README.longs.txt

This file was deleted.

73 changes: 73 additions & 0 deletions lib/DBD/Oracle/Troubleshooting.pm
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,79 @@ SQL scripts to get at V$ info.
my $dbh = DBI->connect("dbi:Oracle:$dbname", $dbuser, $dbpass)
|| die "Unable to connect to $dbname: $DBI::errstr\n";
=head1 LONGS
Some examples related to the use of LONG types.
For complete working code, take a look at the t/long.t file.
You must fetch the row before you can fetch the longs associated with
that row. In other words, use the following algorithm...
1) login
2) prepare( select ... )
3) execute
4) while rows to fetch do
5) fetch row
6) repeat
7) fetch chunk of long
8) until have all of it
9) done
If your select selects more than one row the need for step 4 may
become a bit clearer... the blob_read always applies to the row
that was last fetched.
=head2 Example for reading LONG fields via blob_read
$dbh->{RaiseError} = 1;
$dbh->{LongTruncOk} = 1; # truncation on initial fetch is ok
$sth = $dbh->prepare("SELECT key, long_field FROM table_name");
$sth->execute;
while ( ($key) = $sth->fetchrow_array) {
my $offset = 0;
my $lump = 4096; # use benchmarks to get best value for you
my @frags;
while (1) {
my $frag = $sth->blob_read(1, $offset, $lump);
last unless defined $frag;
my $len = length $frag;
last unless $len;
push @frags, $frag;
$offset += $len;
}
my $blob = join "", @frags;
print "$key: $blob\n";
}
=head2 Example for inserting LONGS
# Assuming the existence of @row and an associative array (%clauses) containing the
# column names and placeholders, and an array @types containing column types ...
$ih = $db->prepare("INSERT INTO $table ($clauses{names})
VALUES ($clauses{places})")
|| die "prepare insert into $table: " . $db->errstr;
$attrib{'ora_type'} = $longrawtype; # $longrawtype == 24
##-- bind the parameter for each of the columns
for ($i = 0; $i < @types; $i++) {
##-- long raw values must have their type attribute explicitly specified
if ($types[$i] == $longrawtype) {
$ih->bind_param($i+1, $row[$i], \%attrib)
|| die "binding placeholder for LONG RAW " . $db->errstr;
}
##-- other values work OK with the default attributes
else {
$ih->bind_param($i+1, $row[$i])
|| die "binding placeholder" . $db->errstr;
}
}
$ih->execute || die "execute INSERT into $table: " . $db->errstr;
=head1 LINUX
=head2 Installing with Instantclient .rpm files.
Expand Down

0 comments on commit cd45d9f

Please sign in to comment.