diff options
author | Russ Allbery <rra@stanford.edu> | 2007-11-30 02:04:14 +0000 |
---|---|---|
committer | Russ Allbery <rra@stanford.edu> | 2007-11-30 02:04:14 +0000 |
commit | 1e13c0c60c96dd1719e7c4c3931b4196c2b5bc61 (patch) | |
tree | d322cd4ea3257d9c95a2afd06da856de8d8bd87a /perl/Wallet/Object | |
parent | 1cc39c41c7cd2a682d024526f4fe933f7e7722da (diff) |
Initial work on supporting testing with MySQL.
Add a drop() method to Wallet::Schema to destroy the wallet database. Add
a test suite for it. Add a reinitialize() method to Wallet;:Server that
drops the database before creating it.
Modify the wallet object test cases to call reinitialize() to create the
initial database and drop() to clean up the database after the test is
complete.
Fix a bug preventing Wallet::Schema from being initialized multiple times.
We now stash the schema in a class static variable and reuse it for
subsequent initializations, since re-reading DATA doesn't work.
Diffstat (limited to 'perl/Wallet/Object')
-rw-r--r-- | perl/Wallet/Object/Base.pm | 11 | ||||
-rw-r--r-- | perl/Wallet/Object/Keytab.pm | 4 |
2 files changed, 15 insertions, 0 deletions
diff --git a/perl/Wallet/Object/Base.pm b/perl/Wallet/Object/Base.pm index ada211c..1371f7f 100644 --- a/perl/Wallet/Object/Base.pm +++ b/perl/Wallet/Object/Base.pm @@ -41,6 +41,7 @@ sub new { $dbh->{PrintError} = 0; my $sql = 'select ob_name from objects where ob_type = ? and ob_name = ?'; my $data = $dbh->selectrow_array ($sql, undef, $type, $name); + $dbh->commit; die "cannot find ${type}:${name}\n" unless ($data and $data eq $name); my $self = { dbh => $dbh, @@ -240,9 +241,11 @@ sub _get_internal { my $sql = "select $attr from objects where ob_type = ? and ob_name = ?"; $value = $self->{dbh}->selectrow_array ($sql, undef, $type, $name); + $self->{dbh}->commit; }; if ($@) { $self->error ($@); + $self->{dbh}->rollback; return; } return $value; @@ -345,9 +348,11 @@ sub flag_check { my $sql = 'select fl_flag from flags where fl_type = ? and fl_name = ? and fl_flag = ?'; $value = $dbh->selectrow_array ($sql, undef, $type, $name, $flag); + $dbh->commit; }; if ($@) { $self->error ("cannot check flag $flag for ${type}:${name}: $@"); + $dbh->rollback; return; } elsif ($value) { return 1; @@ -401,10 +406,12 @@ sub flag_list { while (defined ($flag = $sth->fetchrow_array)) { push (@flags, $flag); } + $self->{dbh}->commit; }; if ($@) { my $id = $self->{type} . ':' . $self->{name}; $self->error ("cannot retrieve flags for $id: $@"); + $self->{dbh}->rollback; return; } else { return @flags; @@ -490,10 +497,12 @@ sub history { } $output .= "\n by $data[5] from $data[6]\n"; } + $self->{dbh}->commit; }; if ($@) { my $id = $self->{type} . ':' . $self->{name}; $self->error ("cannot read history for $id: $@"); + $self->{dbh}->rollback; return undef; } return $output; @@ -550,9 +559,11 @@ sub show { my $sql = "select $fields from objects where ob_type = ? and ob_name = ?"; @data = $self->{dbh}->selectrow_array ($sql, undef, $type, $name); + $self->{dbh}->commit; }; if ($@) { $self->error ("cannot retrieve data for ${type}:${name}: $@"); + $self->{dbh}->rollback; return undef; } my $output = ''; diff --git a/perl/Wallet/Object/Keytab.pm b/perl/Wallet/Object/Keytab.pm index f91abff..025c9e1 100644 --- a/perl/Wallet/Object/Keytab.pm +++ b/perl/Wallet/Object/Keytab.pm @@ -467,9 +467,11 @@ sub enctypes_list { while (defined ($entry = $sth->fetchrow_arrayref)) { push (@enctypes, @$entry); } + $self->{dbh}->commit; }; if ($@) { $self->error ($@); + $self->{dbh}->rollback; return; } return @enctypes; @@ -562,9 +564,11 @@ sub attr { while (defined ($target = $sth->fetchrow_array)) { push (@targets, $target); } + $self->{dbh}->commit; }; if ($@) { $self->error ($@); + $self->{dbh}->rollback; return; } return @targets; |