[Jifty-commit] r2681 - in jifty/trunk: lib/Jifty
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Sun Jan 28 08:35:40 EST 2007
Author: jesse
Date: Sun Jan 28 08:35:39 2007
New Revision: 2681
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Handle.pm
Log:
r21609 at hualien: jesse | 2007-01-28 21:32:21 +0800
* Added "create db" and "drop db" methods to Jifty::Handle
Modified: jifty/trunk/lib/Jifty/Handle.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Handle.pm (original)
+++ jifty/trunk/lib/Jifty/Handle.pm Sun Jan 28 08:35:39 2007
@@ -159,6 +159,55 @@
}
+=head2 create_database MODE
+
+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.
+
+=cut
+
+sub create_database {
+ my $self = shift;
+ my $mode = shift || 'execute';
+ my $database = $self->canonical_database_name;
+ my $driver = Jifty->config->framework('Database')->{'Driver'};
+ my $query = "CREATE DATABASE $database;\n";
+ if ( $mode eq 'print') {
+ print $query;
+ } elsif ( $driver !~ /SQLite/ ) {
+ $self->simple_query($query);
+ }
+}
+
+=head2 drop_database MODE
+
+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.
+
+=cut
+
+sub drop_database {
+ my $self = shift;
+ my $mode = shift || 'execute';
+ my $database = $self->canonical_database_name;
+ my $driver = Jifty->config->framework('Database')->{'Driver'};
+ if ( $mode eq 'print' ) {
+ print "DROP DATABASE $database;\n";
+ } elsif ( $driver =~ /SQLite/ ) {
+
+ # Win32 complains when you try to unlink open DB
+ $self->disconnect if $^O eq 'MSWin32';
+ unlink($database);
+ } else {
+ $self->simple_query("DROP DATABASE $database");
+ }
+}
+
+
=head1 AUTHOR
Various folks at BestPractical Solutions, LLC.
More information about the Jifty-commit
mailing list