[siesta-commit] siesta/lib/Siesta/Storage DBI.pm,1.4,1.5

[prev] [thread] [next] [lurker] [Date index for 2002/09/05]

From: muttley
Subject: [siesta-commit] siesta/lib/Siesta/Storage DBI.pm,1.4,1.5
Date: 13:34 on 05 Sep 2002
Update of /cvsroot/siesta/siesta/lib/Siesta/Storage
In directory usw-pr-cvs1:/tmp/cvs-serv12996/lib/Siesta/Storage

Modified Files:
	DBI.pm 
Log Message:
Consilidate the fields of User and List by making them constants
in the respective modules. Add save and delete methods. 


Index: DBI.pm
===================================================================
RCS file: /cvsroot/siesta/siesta/lib/Siesta/Storage/DBI.pm,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- DBI.pm	3 Sep 2002 21:36:10 -0000	1.4
+++ DBI.pm	5 Sep 2002 12:34:21 -0000	1.5
@@ -40,7 +40,9 @@
     my $self = shift;
     my $user = shift;
 
-    my @fields =  qw(id forename surname password bouncing lastbounce created);
+    my @fields =  @Siesta::User::fields;
+
+
     my @results = $self->_get_rows(table   => 'users',
                                    where   => { id => $user },
                                    columns => \@fields);
@@ -49,16 +51,78 @@
 }
 
 
+sub save_user {
+    my $self = shift;
+    my $user = shift;
+
+    return unless defined $user;
+
+    my @fields =  @Siesta::User::fields;
+
+
+    my $sql    = join ( '',
+                        "INSERT INTO users (", join (',', @fields), ") ",
+                        "VALUES (", join( ',', map { $self->dbh->quote($user->$_()) } @fields) ,")"
+                  ) ;
+
+   return $self->dbh->do($sql)
+	or die $self->dbh->errstr;
+
+
+}
+
+
+sub delete_user {
+     my $self = shift;
+     my $user = shift;
+
+     $user = (ref $user)? $user->id : $user;
+
+     return $self->dbh->do(qq{DELETE FROM users
+                             WHERE id = '$user'});	
+}
+
 sub load_list {
     my $self = shift;
     my $id   = shift;
 
-    my @fields =  qw(id post_address return_path owner created );
+    my @fields = @Siesta::List::fields;
     my @results = $self->_get_rows(table   => 'lists',
                                    where   => { id => $id },
                                    columns => \@fields);
     return unless @results == 1;
     return %{ $results[0] };
+}
+
+sub save_list {
+    my $self = shift;
+    my $list = shift;
+
+    return unless defined $list;
+
+
+    my @fields = @Siesta::List::Fields;
+
+    my $sql    =  join ( '',
+                        "INSERT INTO lists (", join (',', @fields), ") ",
+                        "VALUES (", join( ',', map { $self->dbh->quote($list->$_()) } @fields) ,")"
+                  ) ;
+
+   return $self->dbh->do($sql);
+
+
+}
+
+
+sub delete_list {
+     my $self = shift;
+     my $list = shift;
+
+     # make sure we've got the id 
+     $list = (ref $list)? $list->id : $list;
+
+     return $self->dbh->do(qq{DELETE FROM lists
+                             WHERE id = '$list'});
 }
 
 



Generated at 13:57 on 01 Jul 2004 by mariachi 0.52