File: 32xmltype.t

package info (click to toggle)
libdbd-oracle-perl 1.83-3
  • links: PTS, VCS
  • area: contrib
  • in suites: sid
  • size: 1,724 kB
  • sloc: ansic: 8,354; perl: 7,868; makefile: 20
file content (88 lines) | stat: -rw-r--r-- 2,034 bytes parent folder | download | duplicates (4)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!perl

use strict;
use warnings;

use lib 't/lib';
use DBDOracleTestLib qw/ oracle_test_dsn table drop_table db_handle force_drop_table /;

use Test::More;
use DBD::Oracle qw(:ora_types);
use DBI;

## ----------------------------------------------------------------------------
## 03xmlype.t
## By John Scoles, The Pythian Group
## ----------------------------------------------------------------------------
##  Just a few checks to see if one can insert small and large xml files
##  Nothing fancy.
## ----------------------------------------------------------------------------

# create a database handle
my $dbh = eval{ db_handle( {
            RaiseError => 1,
            AutoCommit => 1,
            PrintError => 0
        }) };

if ($dbh) {
    plan skip_all => 'XMLTYPE new in Oracle 9'
      if $dbh->func('ora_server_version')->[0] < 9;
    plan tests => 3;
}
else {
    plan skip_all => 'Unable to connect to Oracle';
}

# check that our db handle is good
isa_ok( $dbh, 'DBI::db' );

my $table = table();
eval { force_drop_table($dbh, $table) };

$dbh->do(
    qq{ CREATE TABLE $table ( id INTEGER NOT NULL, XML_DATA XMLTYPE ) }
);

my ( $stmt, $sth );
my $small_xml = '<books>';
my $large_xml = '<books>';
my $i         = 0;

for ( $i = 0 ; $i <= 10 ; $i++ ) {
    $small_xml =
        $small_xml
      . "<book id='"
      . $i
      . "'><title>the book "
      . $i
      . " title</title></book>";
}

$small_xml = $small_xml . '</books>';

for ( $i = 0 ; $i <= 10000 ; $i++ ) {
    $large_xml =
        $large_xml
      . "<book id='"
      . $i
      . "'><title>the book "
      . $i
      . " title</title></book>";
}

$large_xml = $large_xml . '</books>';

$stmt = "INSERT INTO $table  VALUES (1,?)";

$sth = $dbh->prepare($stmt);

$sth->bind_param( 1, $small_xml, { ora_type => ORA_XMLTYPE } );

ok( $sth->execute(), '... execute for small XML return true' );

$sth->bind_param( 1, $large_xml, { ora_type => ORA_XMLTYPE } );

ok( $sth->execute(), '... execute for large XML return true' );

drop_table($dbh);