5
plan skip_all => 'Not set up for db tests' unless $ENV{DB_TESTING};
7
my $dbh1 = DBI->connect('dbi:Pg:', 'postgres') ;
9
plan skip_all => 'Needs superuser connection for this test script' unless $dbh1;
14
$dbh1->do('CREATE DATABASE pgobject_test_db');
17
my $dbh = DBI->connect('dbi:Pg:dbname=pgobject_test_db', 'postgres');
18
$dbh->{pg_server_prepare} = 0;
22
CREATE FUNCTION public.pg_object_test
23
(in_test1 int, in_test2 text, in_test3 date)
24
RETURNS BOOL LANGUAGE SQL AS $$ SELECT TRUE $$
27
$dbh->do('CREATE DOMAIN public.posint AS int');
29
CREATE FUNCTION public.pg_object_test2
30
(in_test1 posint, in_test2 text, in_test3 date)
31
RETURNS BOOL LANGUAGE SQL AS $$ SELECT TRUE $$
37
# Testing function_info()
38
my $function_info = PGObject->function_info(
40
funcname => 'pg_object_test'
42
my $function_info2 = PGObject->function_info(
44
funcname => 'pg_object_test',
45
funcschema => 'public',
47
my $function_info3 = PGObject->function_info(
49
funcname => 'pg_object_test',
50
funcschema => 'public',
52
argschema => 'pg_catalog',
56
ok(defined $function_info, 'Got function info with default schema');
57
ok(defined $function_info2, 'Got function info with specified schema');
58
ok(defined $function_info3, 'Got function info with specified schema, first arg type');
59
is($function_info->{args}->[0]->{name}, 'in_test1',
60
'default schema, arg1 name');
61
is($function_info->{args}->[1]->{name}, 'in_test2',
62
'default schema, arg2 name');
63
is($function_info->{args}->[2]->{name}, 'in_test3',
64
'default schema, arg3 name');
65
is($function_info2->{args}->[0]->{name}, 'in_test1',
66
'specified schema, arg1 name');
67
is($function_info2->{args}->[1]->{name}, 'in_test2',
68
'specified schema, arg2 name');
69
is($function_info2->{args}->[2]->{name}, 'in_test3',
70
'specified schema, arg1 name');
71
is($function_info3->{args}->[0]->{name}, 'in_test1',
72
'specified schema and arg type, arg1 name');
73
is($function_info3->{args}->[1]->{name}, 'in_test2',
74
'specified schema and arg type, arg2 name');
75
is($function_info3->{args}->[2]->{name}, 'in_test3',
76
'specified schema and arg type, arg1 name');
78
is($function_info->{args}->[0]->{type}, 'integer',
79
'default schema, arg1 type');
80
is($function_info->{args}->[1]->{type}, 'text',
81
'default schema, arg2 type');
82
is($function_info->{args}->[2]->{type}, 'date',
83
'default schema, arg3 type');
84
is($function_info2->{args}->[0]->{type}, 'integer',
85
'specified schema, arg1 type');
86
is($function_info2->{args}->[1]->{type}, 'text',
87
'specified schema, arg2 type');
88
is($function_info2->{args}->[2]->{type}, 'date',
89
'specified schema, arg1 type');
90
is($function_info3->{args}->[0]->{type}, 'integer',
91
'specified schema/arg type, arg1 type');
92
is($function_info3->{args}->[1]->{type}, 'text',
93
'specified schema/arg type, arg2 type');
94
is($function_info3->{args}->[2]->{type}, 'date',
95
'specified schema/arg type, arg1 type');
97
is($function_info->{num_args}, 3, 'Number of args, default schema');
98
is($function_info2->{num_args}, 3, 'Number of args, specified schema');
99
is($function_info->{name}, 'pg_object_test', 'Func. Name, default schema');
100
is($function_info2->{name}, 'pg_object_test', 'Func name, specified schema');
102
# Testing call_procedure()
104
my ($result1) = PGObject->call_procedure(
105
funcname => 'pg_object_test',
106
args => [1, 'test', '2001-01-01'],
109
my ($result2) = PGObject->call_procedure(
110
funcname => 'pg_object_test',
111
funcschema => 'public',
112
args => [1, 'test', '2001-01-01'],
115
my ($result3) = PGObject->call_procedure(
116
funcname => 'pg_object_test',
117
args => [1, 'test', '2001-01-01'],
119
running_funcs => [{agg => 'count(*)', alias => 'lines'}]
121
my ($result4) = PGObject->call_procedure(
123
funcprefix => 'pg_object_',
124
args => [1, 'test', '2001-01-01'],
128
ok(defined $result1, 'Basic call returned results, default schema');
129
ok(defined $result2, 'Basic call returned results, specified schema');
130
ok(defined $result3, 'Call returned results, default schema, windowed aggs');
131
ok(defined $result4, 'Prefixed call returned results, default schema');
132
ok($result1->{pg_object_test}, 'Correct value returned for proc result1');
133
ok($result2->{pg_object_test}, 'Correct value returned for proc result2');
134
ok($result3->{pg_object_test}, 'Correct value returned for proc result3');
135
ok($result4->{pg_object_test}, 'Correct value returned for proc result4');
136
is($result3->{lines}, 1, 'Correct running agg returned for proc result3');
139
$dbh1->do('DROP DATABASE pgobject_test_db');