File: lob_read.pl

package info (click to toggle)
libdbd-odbc-perl 1.50-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,392 kB
  • ctags: 496
  • sloc: perl: 8,818; ansic: 6,376; makefile: 33; sql: 8
file content (44 lines) | stat: -rw-r--r-- 1,180 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# $Id$
#
# Example of DBD::ODBC's lob_read
#
#use Log::Log4perl qw(:easy);
#Log::Log4perl->easy_init($DEBUG);
#use DBIx::Log4perl;
use DBI qw(:sql_types);
use strict;
use warnings;

#my $h = DBI->connect("dbi:ODBC:baugi","sa","easysoft",
#                     {PrintError => 1, RaiseError => 1, PrintWarn => 1});
my $h = DBI->connect;
$h->{PrintError} = $h->{RaiseError} = $h->{PrintWarn} = 1;

my $s = $h->prepare(q{select 'frederickfrederick'});
$s->execute;
$s->bind_col(1, undef, {TreatAsLOB=>1});
$s->fetch;

getit($s, SQL_BINARY);

$s = $h->prepare(q{select 'frederickfrederick'});
$s->execute;
$s->bind_col(1, undef, {TreatAsLOB=>1});
$s->fetch;

# NOTE the difference between receiving something as binary and as a char
# ODBC's SQLGetData is defined as putting a terminating NUL chr at the
# end of strings so even though we ask for 8 we get 7 bytes
getit($s, SQL_CHAR);

sub getit{
    my ($s, $type) = @_;
    my $len;
    while($len = $s->odbc_lob_read(1, \my $x, 8, {TYPE => $type})) {
        print "len=$len, x=$x, ", length($x), "\n";
    }
    print "len at end = $len\n";
    my $x;
    $len = $s->odbc_lob_read(1, \$x, 8);
    print  "len after read $len\n";
}