File: 56connattr.t

package info (click to toggle)
libdbd-mysql-perl 4.041-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,068 kB
  • ctags: 409
  • sloc: ansic: 4,511; perl: 817; makefile: 27; sh: 22
file content (64 lines) | stat: -rwxr-xr-x 1,686 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/perl

use strict;
use warnings;

use DBI;
use DBI::Const::GetInfoType;
use Test::More;
use lib 't', '.';
require 'lib.pl';

use vars qw($test_dsn $test_user $test_password $table);

my $dbh;
eval { $dbh= DBI->connect($test_dsn, $test_user, $test_password,
                      { RaiseError => 1,
                        PrintError => 0,
                        AutoCommit => 0,
                        mysql_conn_attrs => { foo => 'bar' },
                        }
                        );
     };
if ($@) {
    plan skip_all => "no database connection";
}

my @pfenabled = $dbh->selectrow_array("show variables like 'performance_schema'");
if (!@pfenabled) {
  plan skip_all => 'performance schema not available';
}
if ($pfenabled[1] ne 'ON') {
  plan skip_all => 'performance schema not enabled';
}

if ($dbh->{mysql_clientversion} < 50606) {
  plan skip_all => 'client version should be 5.6.6 or later';
}

eval {$dbh->do("select * from performance_schema.session_connect_attrs where processlist_id=connection_id()");};
if ($@) {
  $dbh->disconnect();
  plan skip_all => "no permission on performance_schema tables";
}

plan tests => 8;

my $rows = $dbh->selectall_hashref("select * from performance_schema.session_connect_attrs where processlist_id=connection_id()", "ATTR_NAME");

my $pid =$rows->{_pid}->{ATTR_VALUE};
cmp_ok $pid, '==', $$;

my $progname =$rows->{program_name}->{ATTR_VALUE};
cmp_ok $progname, 'eq', $0;

my $foo_attr =$rows->{foo}->{ATTR_VALUE};
cmp_ok $foo_attr, 'eq', 'bar';

for my $key ('_platform','_client_name','_client_version','_os') {
  my $row = $rows->{$key};

  cmp_ok defined $row, '==', 1, "attribute $key";
}

ok $dbh->disconnect;