File: rt13865.t

package info (click to toggle)
libdbd-oracle-perl 1.74-3
  • links: PTS, VCS
  • area: contrib
  • in suites: stretch
  • size: 1,808 kB
  • ctags: 653
  • sloc: ansic: 8,165; perl: 6,942; makefile: 18
file content (88 lines) | stat: -rw-r--r-- 2,284 bytes parent folder | download
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
# $Id$
use strict;

use DBI;
use DBD::Oracle;

use Test::More;

use lib 't';
require 'nchar_test_lib.pl';

my $dbh = db_handle() or plan skip_all => "can't connect to database";

my %priv = map { $_ => 1 } get_privs( $dbh );

unless ( $priv{'CREATE TABLE'} ) {
    plan skip_all => q{requires permissions 'CREATE TABLE'};
}

plan tests => 9;

$dbh->do( 'DROP TABLE RT13865' );

$dbh->do( <<'END_SQL' ) or die $dbh->errstr;
CREATE TABLE RT13865(
    COL_INTEGER INTEGER,
    COL_NUMBER NUMBER,
    COL_NUMBER_37 NUMBER(37),
    COL_DECIMAL NUMBER(9,2),
    COL_FLOAT FLOAT(126),
    COL_VC2   VARCHAR2(67),
    COL_VC2_69CHAR  VARCHAR2(69 CHAR),
    COL_NVC2  NVARCHAR2(69),
    COL_NC    NCHAR(69),
    COL_CHAR  CHAR(67),
    COL_CHAR_69CHAR  CHAR(69 CHAR)
)
END_SQL

my $col_h = $dbh->column_info( undef, undef, 'RT13865', 'COL_INTEGER' );

is $col_h->fetchrow_hashref->{COLUMN_SIZE} => 38,
    "INTEGER is alias for NUMBER(38)";

$col_h = $dbh->column_info( undef, undef, 'RT13865', 'COL_NUMBER_37' );
is $col_h->fetchrow_hashref->{COLUMN_SIZE} => 37,
    "NUMBER(37)";

$col_h = $dbh->column_info( undef, undef, 'RT13865', 'COL_NUMBER' );
cmp_ok $col_h->fetchrow_hashref->{COLUMN_SIZE}, '>', 0,
    "NUMBER";

$col_h = $dbh->column_info( undef, undef, 'RT13865', 'COL_VC2' );
is $col_h->fetchrow_hashref->{COLUMN_SIZE} => 67,
    "VARCHAR(67)";

$col_h = $dbh->column_info( undef, undef, 'RT13865', 'COL_VC2_69CHAR' );
is $col_h->fetchrow_hashref->{COLUMN_SIZE} => 69,
    "VARCHAR(69)";

$col_h = $dbh->column_info( undef, undef, 'RT13865', 'COL_NVC2' );
is $col_h->fetchrow_hashref->{COLUMN_SIZE} => 69,
    "NVARCHAR2(69)";

$col_h = $dbh->column_info( undef, undef, 'RT13865', 'COL_NC' );
is $col_h->fetchrow_hashref->{COLUMN_SIZE} => 69,
    "NCHAR(69)";

$col_h = $dbh->column_info( undef, undef, 'RT13865', 'COL_CHAR' );
is $col_h->fetchrow_hashref->{COLUMN_SIZE} => 67,
    "CHAR(67)";

$col_h = $dbh->column_info( undef, undef, 'RT13865', 'COL_CHAR_69CHAR' );
is $col_h->fetchrow_hashref->{COLUMN_SIZE} => 69,
    "CHAR(69)";

$dbh->do( 'DROP TABLE RT13865' );

# utility functions

sub get_privs  {
    my $dbh = shift;

    my $sth = $dbh->prepare( 'SELECT PRIVILEGE from session_privs' );
    $sth->execute;

    return map { $_->[0] } @{ $sth->fetchall_arrayref };
}