[system] / trunk / webwork-modperl / lib / WeBWorK / DB / Driver / SQL.pm Repository:
ViewVC logotype

View of /trunk/webwork-modperl/lib/WeBWorK/DB/Driver/SQL.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 874 - (download) (as text) (annotate)
Tue May 20 23:08:03 2003 UTC (10 years, 1 month ago) by sh002i
File size: 1980 byte(s)
initial work on SQL backend. untested.
-sam

    1 ################################################################################
    2 # WeBWorK mod_perl (c) 2000-2002 WeBWorK Project
    3 # $Id$
    4 ################################################################################
    5 
    6 package WeBWorK::DB::Driver::SQL;
    7 
    8 =head1 NAME
    9 
   10 WeBWorK::DB::Driver::SQL - SQL style interface to SQL databases.
   11 
   12 =cut
   13 
   14 use strict;
   15 use warnings;
   16 use DBI;
   17 
   18 use constant STYLE => "sql";
   19 
   20 ################################################################################
   21 # static functions
   22 ################################################################################
   23 
   24 sub style() {
   25   return STYLE;
   26 }
   27 
   28 ################################################################################
   29 # constructor
   30 ################################################################################
   31 
   32 sub new($$$) {
   33   my ($proto, $source, $params) = @_;
   34   my $class = ref($proto) || $proto;
   35 
   36   $handleRO = DBI->connect($source, $param->{usernameRO}, $param->{passwordRO});
   37   return 0 unless defined $handleRO;
   38 
   39   $handleRW = DBI->connect($source, $param->{usernameRW}, $param->{passwordRW});
   40   return 0 unless defined $handleRW;
   41 
   42   my $self = {
   43     handle   => undef,
   44     handleRO => $handleRO,
   45     handleRW => $handleRW,
   46     source   => $source,
   47     params   => $params,
   48   };
   49   bless $self, $class;
   50   return $self;
   51 }
   52 
   53 ################################################################################
   54 # common methods
   55 ################################################################################
   56 
   57 sub connect($$) {
   58   my ($self, $mode) = @_;
   59 
   60   if ($mode eq "ro") {
   61     $self->{handle} = $self->{handleRO};
   62   } else {
   63     $self->{handle} = $self->{handleRW};
   64   }
   65 
   66   return 1;
   67 }
   68 
   69 sub disconnect($) {
   70   my $self = shift;
   71 
   72   undef $self->{handle};
   73 
   74   return 1;
   75 }
   76 
   77 ################################################################################
   78 # sql-style methods
   79 ################################################################################
   80 
   81 sub handle($) {
   82   my ($self) = @_;
   83   return $self->{handle};
   84 }
   85 
   86 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9