[prev] [thread] [next] [lurker] [Date index for 2003/03/16]
Update of /cvsroot/siesta/siesta/lib/Siesta/Storage In directory sc8-pr-cvs1:/tmp/cvs-serv23708/lib/Siesta/Storage Modified Files: DBI.pm Log Message: refactor the prefs system like billyo Index: DBI.pm =================================================================== RCS file: /cvsroot/siesta/siesta/lib/Siesta/Storage/DBI.pm,v retrieving revision 1.39 retrieving revision 1.40 diff -u -d -r1.39 -r1.40 --- DBI.pm 15 Mar 2003 22:11:56 -0000 1.39 +++ DBI.pm 16 Mar 2003 13:10:37 -0000 1.40 @@ -10,12 +10,13 @@ sub new { my $class = shift; - my $dbh = DBI->connect(@_); + my %options = ( RaiseError => 1 ); + my $dbh = DBI->connect(@_, %options); unless ( $dbh && $_[0] =~ /:SQLite:/ ) { # busy wait for SQLite for ( 1 .. 10 ) { sleep 2; - $dbh = DBI->connect(@_) + $dbh = DBI->connect(@_, %options) and last; } } @@ -81,8 +82,7 @@ } warn $sql if $args{debug}; - $dbh->do($sql) - or die $dbh->errstr." ".$sql; + $dbh->do($sql); } sub _delete { @@ -97,8 +97,7 @@ map { "$_ = " . $dbh->quote( $where{$_} ) } keys %where ) if %where; - $dbh->do($sql) - or die $dbh->errstr; + $dbh->do($sql); } sub get_lists { @@ -123,7 +122,7 @@ my $self = shift; my $user_id = shift; - grep { $self->member_of_list( $_->id, $user_id ) } $self->get_lists; + grep { $self->member_of_list( $_->{id}, $user_id ) } $self->get_lists; } sub user_id_from_email { @@ -208,7 +207,9 @@ my $self = shift; my $list = shift; - return $self->_dbh->do(qq{DELETE FROM lists WHERE id = '$list'}); + return $self->_delete( table => 'lists', + where => { id => $list }, + ); } sub member_of_list { @@ -216,15 +217,14 @@ my $list = shift; my $user = shift; - my @results = $self->_get_rows( - table => 'list_users', - where => { - list_id => $list, - user_id => $user - }, - columns => [ 'id' ], - ); - return scalar @results; + scalar $self->_get_rows( + table => 'list_users', + where => { + list_id => $list, + user_id => $user + }, + columns => [ 'id' ], + ); } sub add_member_to_list { @@ -232,10 +232,8 @@ my $list = shift; my $user = shift; - $self->_dbh->do( - qq{INSERT INTO list_users (list_id, user_id) - VALUES ('$list', '$user')} ) - or die $self->_dbh->errstr; + $self->_dbh->do( "INSERT INTO list_users (list_id, user_id) ". + " VALUES ($list, $user)"); return 1; } @@ -244,9 +242,9 @@ my $list = shift; my $user = shift; - return $self->_dbh->do( - qq{DELETE FROM list_users - WHERE list_id = '$list' AND user_id = '$user'} ); + $self->_delete( table => 'list_users', + where => { list_id => $list, + user_id => $user } ); } sub list_name_from_id { @@ -328,12 +326,7 @@ my $list = shift; my @plugins = @_; - # get rid of the exisiting list. - my $sql = sprintf "DELETE from list_plugins where list_id=%s", - $self->_dbh->quote( $list ); - - $self->_dbh->do($sql) - or die $self->_dbh->errstr; + $self->_dbh->do( "DELETE FROM list_plugins WHERE list_id = $list" ); my $a = 1; foreach my $plugin (@plugins) { @@ -342,8 +335,7 @@ VALUES (%d, %s, %s )", $a++, $self->_dbh->quote($plugin), $self->_dbh->quote( $list ); - $self->_dbh->do($isql) - or die $self->_dbh->errstr; + $self->_dbh->do($isql); } return 1; @@ -378,10 +370,6 @@ sub get_preference { my ( $self, $namespace, $user_id, $list_id, $key ) = @_; - - # just to be sure - $user_id ||= ''; - $list_id ||= ''; my $where = { user_id => $user_id,
Generated at 13:57 on 01 Jul 2004 by mariachi 0.52