Parent Directory
|
Revision Log
HEAD merge: docs
1 ################################################################################ 2 # WeBWorK Online Homework Delivery System 3 # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ 4 # $CVSHeader$ 5 # 6 # This program is free software; you can redistribute it and/or modify it under 7 # the terms of either: (a) the GNU General Public License as published by the 8 # Free Software Foundation; either version 2, or (at your option) any later 9 # version, or (b) the "Artistic License" which comes with this package. 10 # 11 # This program is distributed in the hope that it will be useful, but WITHOUT 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 # FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the 14 # Artistic License for more details. 15 ################################################################################ 16 17 package WeBWorK::DB::Driver::SQL; 18 use base qw(WeBWorK::DB::Driver); 19 20 =head1 NAME 21 22 WeBWorK::DB::Driver::SQL - SQL style interface to SQL databases. 23 24 =cut 25 26 use strict; 27 use warnings; 28 use DBI; 29 30 use constant STYLE => "dbi"; 31 32 =head1 SOURCE FORMAT 33 34 The C<source> entry for tables handled by this driver should consist of a DBI 35 data source. 36 37 =head1 SUPPORTED PARAMS 38 39 This driver pays attention to the following items in the C<params> entry. 40 41 =over 42 43 =item usernameRO, passwordRO 44 45 Username and password for read-only access to SQL database. 46 47 =item usernameRW, passwordRW 48 49 Username and password for read-write access to SQL database. 50 51 =back 52 53 =cut 54 55 ################################################################################ 56 # constructor 57 ################################################################################ 58 59 sub new($$$) { 60 my ($proto, $source, $params) = @_; 61 62 my $handleRO = DBI->connect_cached($source, $params->{usernameRO}, $params->{passwordRO}); 63 return 0 unless defined $handleRO; 64 65 my $handleRW = DBI->connect_cached($source, $params->{usernameRW}, $params->{passwordRW}); 66 return 0 unless defined $handleRW; 67 68 my $self = $proto->SUPER::new($source, $params); 69 70 # add DBI-specific data 71 $self->{handle} = undef; 72 $self->{handleRO} = $handleRO; 73 $self->{handleRW} = $handleRW; 74 75 return $self; 76 } 77 78 ################################################################################ 79 # common methods 80 ################################################################################ 81 82 sub connect($$) { 83 my ($self, $mode) = @_; 84 85 if ($mode eq "ro") { 86 $self->{handle} = $self->{handleRO}; 87 } else { 88 $self->{handle} = $self->{handleRW}; 89 } 90 91 return 1; 92 } 93 94 sub disconnect($) { 95 my $self = shift; 96 97 undef $self->{handle}; 98 99 return 1; 100 } 101 102 ################################################################################ 103 # dbi-style methods 104 ################################################################################ 105 106 sub dbi($) { 107 my ($self) = @_; 108 return $self->{handle}; 109 } 110 111 1;
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |