[Jifty-commit] r6329 - in jifty/trunk: lib/Jifty lib/Jifty/Script
Jifty commits
jifty-commit at lists.jifty.org
Tue Feb 10 18:45:20 EST 2009
Author: alexmv
Date: Tue Feb 10 18:45:19 2009
New Revision: 6329
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Handle.pm
jifty/trunk/lib/Jifty/Script/Schema.pm
Log:
r41980 at kohr-ah: chmrr | 2009-02-10 18:43:04 -0500
* Bail early with exit value, if database drop or create fails
Modified: jifty/trunk/lib/Jifty/Handle.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Handle.pm (original)
+++ jifty/trunk/lib/Jifty/Handle.pm Tue Feb 10 18:45:19 2009
@@ -234,8 +234,9 @@
C<MODE> is either "print" or "execute".
-This method either prints the commands necessary to create the database
-or actually creates it, depending on the value of MODE.
+This method either prints the commands necessary to create the
+database or actually creates it, depending on the value of MODE.
+Returns undef on failure.
=cut
@@ -248,9 +249,11 @@
$query .= " TEMPLATE template0" if $driver =~ /Pg/;
if ( $mode eq 'print' ) {
print "$query;\n";
- } elsif ( $driver !~ /SQLite/ ) {
- $self->simple_query($query);
- }
+ } elsif ( $driver =~ /SQLite/ ) {
+ return 1; # Kinda an optimistic hack
+ } else {
+ return $self->simple_query($query);
+ }
}
=head2 drop_database MODE
@@ -258,7 +261,8 @@
C<MODE> is either "print" or "execute".
This method either prints the commands necessary to drop the database
-or actually drops it, depending on the value of MODE.
+or actually drops it, depending on the value of MODE. Returns undef
+on failure.
=cut
@@ -273,11 +277,11 @@
# Win32 complains when you try to unlink open DB
$self->disconnect if $^O eq 'MSWin32';
- unlink($database);
+ return unlink($database);
} else {
local $SIG{__WARN__}
= sub { warn $_[0] unless $_[0] =~ /exist|couldn't execute/i };
- $self->simple_query("DROP DATABASE $database");
+ return $self->simple_query("DROP DATABASE $database");
}
}
Modified: jifty/trunk/lib/Jifty/Script/Schema.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Script/Schema.pm (original)
+++ jifty/trunk/lib/Jifty/Script/Schema.pm Tue Feb 10 18:45:19 2009
@@ -300,7 +300,7 @@
}
# Commit it all
- Jifty->handle->commit;
+ Jifty->handle->commit or exit 1;
Jifty::Util->require('IPC::PubSub');
IPC::PubSub->new(
@@ -671,7 +671,8 @@
=head2 manage_database_existence
If the user wants the database created, creates the database. If the
-user wants the old database deleted, does that too.
+user wants the old database deleted, does that too. Exits with a
+return value of 1 if the database drop or create fails.
=cut
@@ -684,8 +685,14 @@
$handle->drop_database('print') if ( $self->{'drop_database'} );
$handle->create_database('print') if ( $self->{'create_database'} );
} else {
- $handle->drop_database('execute') if ( $self->{'drop_database'} );
- $handle->create_database('execute') if ( $self->{'create_database'} );
+ if ( $self->{'drop_database'} ) {
+ exit 1 unless $handle->drop_database('execute');
+ }
+
+ if ( $self->{'create_database'} ) {
+ exit 1 unless $handle->create_database('execute');
+ }
+
$handle->disconnect;
$self->_reinit_handle() if ( $self->{'create_database'} );
}
@@ -698,8 +705,7 @@
sub _exec_sql {
my $sql = shift;
- my $ret = Jifty->handle->simple_query($sql);
- $ret or die "error updating a table: " . $ret->error_message;
+ exit 1 unless Jifty->handle->simple_query($sql);
}
1;
More information about the Jifty-commit
mailing list