Basic/Base.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 43 CC 2 SCAR 11.0
CC
2
Cov
0%
last_insert_id
6.0
dbh
2.0
db_vendor
2.0
CRAP 3.0
1 package CGI::Application::Demo::Basic::Base;
2  
3 # Note:
4 # o tab = 4 spaces || die
5 #
6 # Author:
7 # Ron Savage <ron@savage.net.au>
8 # Home page: http://savage.net.au/index.html
9  
10 use base 'Class::DBI'; # Amazing. For MySQL, Oracle, Postgres and SQLite, use Class::DBI.
11 use strict;
12 use warnings;
13  
14 use CGI::Application::Demo::Basic::Util::Config;
15  
16 my($config);
17  
18 our $VERSION = '1.06';
19  
20 # --------------------------------------------------
21  
22 sub dbh
23 {
24 my($self) = @_;
25  
26 return __PACKAGE__ -> db_Main;
27  
28 } # End of dbh.
29  
30 # --------------------------------------------------
31  
32 sub db_vendor
33 {
34 my($self) = @_;
35 my($vendor) = $$config{'dsn'} =~ /^dbi:(\w+):/i;
36  
37 return uc $vendor;
38  
39 } # End of db_vendor.
40  
41 # --------------------------------------------------
42  
43 sub last_insert_id
44 {
45 my($self, $table_name) = @_;
46  
47 my($id);
48  
49 if ($self -> db_vendor =~ /(?:MYSQL|PG)/)
50 {
51 $id = $self -> dbh -> last_insert_id(undef, undef, $table_name, undef);
52 }
53 else # Oracle.
54 {
55 my($sth) = $self -> dbh -> prepare("select ${table_name}_seq.currval from dual");
56  
57 $sth -> execute;
58  
59 $id = $sth -> fetch;
60  
61 $sth -> finish;
62  
63 $id = $$id[0];
64 }
65  
66 return $id;
67  
68 } # End of last_insert_id.
69  
70 # --------------------------------------------------
71 # Scripts using this will be CGI scripts but not command line scripts.
72  
73 $config = CGI::Application::Demo::Basic::Util::Config -> new('five.conf') -> config;
74  
75 __PACKAGE__ -> set_db
76 (
77 'Main',
78 $$config{'dsn'},
79 $$config{'username'},
80 $$config{'password'},
81 {
82 AutoCommit => $$config{AutoCommit},
83 LongReadLen => $$config{LongReadLen},
84 PrintError => $$config{PrintError},
85 RaiseError => $$config{RaiseError},
86 },
87 );
88  
89 # --------------------------------------------------
90  
91 1;