blib/lib/LibWeb/Database/Mysql.pm untested

filter: Statementstmt 0.0% 0 / 28 Branchbran n/a Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 42 CC 1 SCAR 6.9
CC
1
Cov
0%
new
2.0
DESTROY
2.0
get_count
2.0
CRAP 2.0
1 #=============================================================================
2 # LibWeb::Database::Mysql -- Mysql database driver for libweb applications.
3  
4 package LibWeb::Database::Mysql;
5  
6 # Copyright (C) 2000 Colin Kong
7 #
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License
10 # as published by the Free Software Foundation; either version 2
11 # of the License, or (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #=============================================================================
22  
23 # $Id: Mysql.pm,v 1.4 2000/07/18 06:33:30 ckyc Exp $
24  
25 # Implementing common, database-specific subroutines.
26 # This module is for interacting with a MySQL server and therefore
27 # uses MySQL specific syntax and built-in functions.
28  
29 #-############################
30 # Use standard library.
31 use strict;
32 use vars qw(@ISA $VERSION);
33  
34 #-############################
35 # Use custom library.
36 require LibWeb::Database;
37  
38 #-############################
39 # Version.
40 $VERSION = '0.02';
41  
42 #-############################
43 # Inheritance.
44 @ISA = qw(LibWeb::Database);
45  
46 #-############################
47 # Methods.
48 sub new {
49 #
50 # Params: $class [, $rc_file]
51 #
52 # - $class is the class/package name of this package, be it a string
53 # or a reference.
54 # - $rc_file is the absolute path to the rc file for LibWeb.
55 #
56 # Usage: my $object = new LibWeb::Database::Mysql([$rc_file]);
57 #
58 my ($class, $Class, $self);
59 $class = shift;
60 $Class = ref($class) || $class;
61  
62 # Inherit instance variables from the base class.
63 $self = $Class->SUPER::new(shift);
64 bless($self, $Class);
65  
66 # Any necessary initialization.
67 #$self->_init();
68  
69 # Returns a reference to this object.
70 return $self;
71 }
72  
73 sub DESTROY {
74 # Destructor: performs cleanup when this object is not being referenced
75 # any more. For example, disconnect a database connection, filehandle...etc.
76 my $self = shift;
77 $self->done();
78 }
79  
80 sub get_count {
81 #
82 # Params: ( -table =>, -where => ).
83 #
84 # Pre:
85 # -table is a scalar indicating the table's name.
86 # -where is a scalar for the `where' phrase of the SQL query.
87 #
88 # Post:
89 # -return the number of counts satisfying the criteria specified in
90 # the -where parameter.
91 #
92 my ($self, $table, $where, $count);
93 $self = shift;
94 ($table, $where) = $self->rearrange( ['TABLE', 'WHERE'], @_ );
95 $count =
96 $self->do( -sql => "select COUNT(*) " . "from $table " . "where $where" );
97 $self->finish();
98  
99 return $count;
100 }
101  
102 1;
103 __DATA__