Wrapper/MySQL.pm untested

filter: Statementstmt 0.0% 0 / 67 Branchbran 0.0% 0 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 104 CC 14 SCAR 34.5
CC
14
Cov
0%
IsSuperUser
56.0
GetUserNames
30.0
DDMMYYYYToMySQL
20.0
CRAP 31.5
1 package Database::Wrapper::MySQL;
2
3 use strict;
4 use lib qw(../..);
5 use base qw(Database::Wrapper);
6
7 our $VERSION = "1.04";
8 # $Id: MySQL.pm,v 1.3 2005/11/26 00:37:34 incorpoc Exp $
9
10 =pod
11
12 Override the standard 'GetTableNames' as the MySQL driver
13 returns field names wrapped in backticks '`'.
14
15 =cut
16
17 sub GetTableNames($)
18 {
19 my ($self) = (shift);
20 my $raTables = $self->SUPER::GetTableNames();
21
22 # Strip leading and trailing backticks in place
23 grep {s/(^\`|\`$)//go} @$raTables;
24
25 return $raTables;
26 }
27
28 sub GetUserNames
29 {
30 my $rhConnectionData = Database::Wrapper::_GetConnectionData(\@_);
31 return undef
32 if(not defined $rhConnectionData);
33
34 my $sDbiConnectionString = Database::Wrapper::_MakeDsn($rhConnectionData->{ConnectionType}, 'mysql', $rhConnectionData->{Host});
35 if(not defined $sDbiConnectionString)
36 {
37 warn($Database::Wrapper::ConnectionError);
38 return undef;
39 }
40 $rhConnectionData->{DbiConnectionString} = $sDbiConnectionString;
41 my $dbh = Database::Wrapper::_Connect($rhConnectionData);
42 return undef
43 if(not defined $dbh);
44 my $sqry = "SELECT * FROM user;";
45 my $ra = undef;
46 eval
47 {
48 my $sth = $dbh->prepare($sqry);
49 $sth->execute();
50 $ra = $sth->fetchall_arrayref({});
51 };
52 if($@)
53 {
54 warn("GetUserNames(): $@");
55 return undef;
56 }
57 my $raUsers = [map($_->{User}, @$ra)];
58 return $raUsers;
59 }
60
61 sub IsSuperUser
62 {
63 my $rhConnectionData = Database::Wrapper::_GetConnectionData(\@_);
64 return undef
65 if(not defined $rhConnectionData);
66
67 # There should be a user name left in @_
68 my $sUser = shift;
69 my $sDbiConnectionString = Database::Wrapper::_MakeDsn($rhConnectionData->{ConnectionType}, 'mysql', $rhConnectionData->{Host});
70 if(not defined $sDbiConnectionString)
71 {
72 warn($Database::Wrapper::ConnectionError);
73 return undef;
74 }
75 $rhConnectionData->{DbiConnectionString} = $sDbiConnectionString;
76 my $dbh = Database::Wrapper::_Connect($rhConnectionData);
77 return undef
78 if(not defined $dbh);
79 my $sqry = "SELECT * FROM user WHERE User = ?;";
80 my $ra = undef;
81 eval
82 {
83 my $sth = $dbh->prepare($sqry);
84 $sth->execute($sUser);
85 $ra = $sth->fetchall_arrayref({});
86 };
87 if($@)
88 {
89 warn("IsSuperUser(): $@");
90 return undef;
91 }
92
93 return 0
94 if(scalar @$ra == 0);
95 my $rhUser = $ra->[0];
96 return ($rhUser->{Super_priv} eq 'Y') ? 1 : 0;
97 }
98
99 sub DDMMYYYYToMySQL($)
100 {
101 my ($sISODate) = (shift);
102
103 return undef
104 if(not defined $sISODate);
105 return undef
106 if(ref($sISODate) ne "");
107 return undef
108 if($sISODate !~ /(\d{1,2})[\/\:](\d{1,2})[\/\:](\d{4})/o);
109
110 my ($nDay, $nMonth, $nYear) = ($1, $2, $3);
111
112 return sprintf("%04u-%02u-%02u", $nYear, $nMonth, $nDay);
113 }
114
115 1;
116
117 __END__