r35968 - in /branches/upstream/libjifty-dbi-perl/current: ./ lib/Jifty/ lib/Jifty/DBI/ lib/Jifty/DBI/Handle/ t/

yvesago-guest at users.alioth.debian.org yvesago-guest at users.alioth.debian.org
Wed May 20 07:38:20 UTC 2009


Author: yvesago-guest
Date: Wed May 20 07:38:13 2009
New Revision: 35968

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=35968
Log:
[svn-upgrade] Integrating new upstream version, libjifty-dbi-perl (0.57)

Added:
    branches/upstream/libjifty-dbi-perl/current/.gitignore
    branches/upstream/libjifty-dbi-perl/current/t/03rename_column.t
    branches/upstream/libjifty-dbi-perl/current/t/03rename_table.t
    branches/upstream/libjifty-dbi-perl/current/t/06filter_salthash.t
Modified:
    branches/upstream/libjifty-dbi-perl/current/Changes
    branches/upstream/libjifty-dbi-perl/current/MANIFEST
    branches/upstream/libjifty-dbi-perl/current/SIGNATURE
    branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI.pm
    branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Column.pm
    branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Handle.pm
    branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Handle/SQLite.pm
    branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Handle/mysql.pm
    branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/HasFilters.pm
    branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Record.pm
    branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Schema.pm
    branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/SchemaGenerator.pm
    branches/upstream/libjifty-dbi-perl/current/t/02searches_joins.t
    branches/upstream/libjifty-dbi-perl/current/t/utils.pl

Added: branches/upstream/libjifty-dbi-perl/current/.gitignore
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjifty-dbi-perl/current/.gitignore?rev=35968&op=file
==============================================================================
--- branches/upstream/libjifty-dbi-perl/current/.gitignore (added)
+++ branches/upstream/libjifty-dbi-perl/current/.gitignore Wed May 20 07:38:13 2009
@@ -1,0 +1,10 @@
+MANIFEST
+MANIFEST.bak
+META.yml
+Makefile
+Makefile.old
+SIGNATURE
+blib/
+inc/
+pm_to_blib
+

Modified: branches/upstream/libjifty-dbi-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjifty-dbi-perl/current/Changes?rev=35968&op=diff
==============================================================================
--- branches/upstream/libjifty-dbi-perl/current/Changes (original)
+++ branches/upstream/libjifty-dbi-perl/current/Changes Wed May 20 07:38:13 2009
@@ -1,4 +1,43 @@
 Revision history for Perl extension Jifty::DBI.
+
+0.57 Tue May 19 08:02:03 EDT 2009
+- Major bugfixes:
+    * Use eval {} in Jifty::DBI::Handle's DESTROY block when manipulating DBI
+        Alterations to the DBI object in the DESTROY block must be wrapped in
+        an eval {}, as object destruction order is not guaranteed during
+        global destruction, and this interacts poorly with DBI's tie'd object.
+    * During DESTROY, don't explicitly disconnect a dbh set InactiveDestroy
+        The InactiveDestroy flag on DBI objects prevent them from being
+        implicitly disconnected when they go out of scope -- for example, in
+        the case where a process has forked, and two processes hold the socket
+        open.
+        However, it does not prevent them from being _explicitly_
+        disconnected, as we were doing in Jifty::DBI::Handle's DESTROY method.
+        This caused InactiveDestroy to never kick in, causing either a shared
+        socket, or two closed handles after a fork.  We prevent this by having
+        Jifty::DBI::Handle respect InactiveDestroy in its DESTROY method.
+    * Do not use Scalar::Defer defaults for columns' defaults in the db
+
+- New features:
+    * Add a display_length attribute on columns
+    * add schema manipulation tables: rename_column and rename_table
+    * If a column's default is a record, call its id method
+
+- Fixes:
+    * Improve SQL error message and avoid its duplication
+    * Pull the input_ and output_filters out of the instance hash
+
+- Tests:
+    * Added a unit test for the SaltHash filter
+    * use drop_table_if_exists in tests
+    * add drop_table_if_exists in t/utils.t
+    * unconditionaly drop tables for testing
+    * test rename_table
+    * add tests for rename_column
+    * SaltHash test does not need an is_deeply()
+    * Don't explicitly disconnect the handle, DESTROY handles it better
+    * Test for warnings instead of letting them leak into the test output
+
 
 0.53 Wed Mar 25 15:27:03 EDT 2009
 - Major bugfixes:

Modified: branches/upstream/libjifty-dbi-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjifty-dbi-perl/current/MANIFEST?rev=35968&op=diff
==============================================================================
--- branches/upstream/libjifty-dbi-perl/current/MANIFEST (original)
+++ branches/upstream/libjifty-dbi-perl/current/MANIFEST Wed May 20 07:38:13 2009
@@ -1,3 +1,4 @@
+.gitignore
 Changes
 debian/changelog
 debian/compat
@@ -69,12 +70,15 @@
 t/02records_object.t
 t/02searches_joins.t
 t/03rebless.t
+t/03rename_column.t
+t/03rename_table.t
 t/04memcached.t
 t/05raw_value.t
 t/06filter.t
 t/06filter_boolean.t
 t/06filter_datetime.t
 t/06filter_duration.t
+t/06filter_salthash.t
 t/06filter_storable.t
 t/06filter_truncate.t
 t/06filter_utf8.t

Modified: branches/upstream/libjifty-dbi-perl/current/SIGNATURE
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjifty-dbi-perl/current/SIGNATURE?rev=35968&op=diff
==============================================================================
--- branches/upstream/libjifty-dbi-perl/current/SIGNATURE (original)
+++ branches/upstream/libjifty-dbi-perl/current/SIGNATURE Wed May 20 07:38:13 2009
@@ -14,8 +14,9 @@
 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
-SHA1 dff41b1fc8b74cb89e2e268e3ccb15132f0b7a65 Changes
-SHA1 6244026b27f75e581c672d49327905888b088629 MANIFEST
+SHA1 f29ac6543498d1b0e81f387b7284a039f83e7d29 .gitignore
+SHA1 85746120ae35bfdb3811297cfc3331a0d1c56343 Changes
+SHA1 006b044e48cc925d04f620f317a907d459b2d128 MANIFEST
 SHA1 d3897bc376b40669acb9171adfd51f321d184fd8 META.yml
 SHA1 48bd6ca8a37ec79b7cae91028d7e9489ad33a03b Makefile.PL
 SHA1 ae8407c841f230c353f683bd5c257815aed9b9f0 README
@@ -40,11 +41,11 @@
 SHA1 7ad1da4fff7a1e7a634c9d734111c8292be08884 inc/Module/Install/Metadata.pm
 SHA1 e9aa83f3e8b16ccfce544a90a57b63b70a497759 inc/Module/Install/Win32.pm
 SHA1 ade2ac0b0246d4d8e28fa46942e53f6925abda46 inc/Module/Install/WriteAll.pm
-SHA1 071207f492e64cafed55c2c65f3d12b43408395b lib/Jifty/DBI.pm
+SHA1 249e7173876dca5ea914281036c853f7c9226991 lib/Jifty/DBI.pm
 SHA1 f181211220602d2883fd8d006fdb3c79ca417b05 lib/Jifty/DBI/Collection.pm
 SHA1 639ef9c81f03fb084b312a5f9a6f6a3ff63b36b7 lib/Jifty/DBI/Collection/Union.pm
 SHA1 bcba77fd2bacf0475aea1de97f57365c8de92ca6 lib/Jifty/DBI/Collection/Unique.pm
-SHA1 fe97ce175ebf6e001773449531b1971d86c3ec5b lib/Jifty/DBI/Column.pm
+SHA1 6d59ec1286f3ed887494753d01ed1f4760fd0a9b lib/Jifty/DBI/Column.pm
 SHA1 c21a985a5b799e50f2624e0fa6daee0895313825 lib/Jifty/DBI/Filter.pm
 SHA1 e030c3ef5c723ba6dce2e3fc23afecf2a6dfe260 lib/Jifty/DBI/Filter/Boolean.pm
 SHA1 d0addaa43cfa8950cb33d42a364a3c3c56a2dd59 lib/Jifty/DBI/Filter/Date.pm
@@ -58,22 +59,22 @@
 SHA1 67ffe7188a1f529d7594f4fa3803bcbe15ba6485 lib/Jifty/DBI/Filter/YAML.pm
 SHA1 9a6fd17e677321904436fefec4d434e17a4685b1 lib/Jifty/DBI/Filter/base64.pm
 SHA1 deb33fa7b35f3542aac3e2d7fb4b5d3070dc3917 lib/Jifty/DBI/Filter/utf8.pm
-SHA1 319dd0ee5a65b40ca41c0223db6c4acd13ab9f6f lib/Jifty/DBI/Handle.pm
+SHA1 ac3555c9ec6bdf462e24d043e34b977625ca6407 lib/Jifty/DBI/Handle.pm
 SHA1 bcc7c456e1c4d0dddd5564f03c8bb03a6c7e261f lib/Jifty/DBI/Handle/Informix.pm
 SHA1 338116a45f8eb6bfca5e76e8d3be78fb61fffe81 lib/Jifty/DBI/Handle/ODBC.pm
 SHA1 960fd0b63f3de11924c5d47a3c0c6d1db105ed5b lib/Jifty/DBI/Handle/Oracle.pm
 SHA1 23eeff073884c8951e004be4308ca946a1d5e205 lib/Jifty/DBI/Handle/Pg.pm
-SHA1 d8b18e59ccc89ae80f4fdb4d0db70b85c3a76cd0 lib/Jifty/DBI/Handle/SQLite.pm
+SHA1 1e850abb12a1d970eae373f452219c123be350e6 lib/Jifty/DBI/Handle/SQLite.pm
 SHA1 bba2314c20fcc3ef71cc69090f1cd6bd515cd9b4 lib/Jifty/DBI/Handle/Sybase.pm
-SHA1 643cae4f858c4e7273e5c03f13b3cb910b0840bb lib/Jifty/DBI/Handle/mysql.pm
+SHA1 cf80896a175702a157770f64ae469430678c3357 lib/Jifty/DBI/Handle/mysql.pm
 SHA1 f2cc4fcce79c9a88a023d4e6bd96c2089eef1ced lib/Jifty/DBI/Handle/mysqlPP.pm
-SHA1 f2e9353e3f71443763509d52d9333a135b2cc56b lib/Jifty/DBI/HasFilters.pm
-SHA1 d3cf1144c66a81f78144f45e10588451c34d11f6 lib/Jifty/DBI/Record.pm
+SHA1 45d653e3a223599b50850010826bd835b80368d7 lib/Jifty/DBI/HasFilters.pm
+SHA1 fc176a04f20301b698a390a014eda349d139d94f lib/Jifty/DBI/Record.pm
 SHA1 3853ce268985b129f2175251fb369d9689837f39 lib/Jifty/DBI/Record/Cachable.pm
 SHA1 1aac77960c508d3b2e5188e15825ad5b04391d76 lib/Jifty/DBI/Record/Memcached.pm
 SHA1 53834b3315a509ba33a8647681f472d3ae7b0557 lib/Jifty/DBI/Record/Plugin.pm
-SHA1 57bc9b11c97dc13f538f7b210dc060b38fba2c2f lib/Jifty/DBI/Schema.pm
-SHA1 8e7badfee526f44d09ba09641cf485ed601bd76a lib/Jifty/DBI/SchemaGenerator.pm
+SHA1 501fe382b24b663c328fbb9c1cbf019c78e7bb53 lib/Jifty/DBI/Schema.pm
+SHA1 a4d1a953ea4a29fe169b1c4c043ffff15b24c077 lib/Jifty/DBI/SchemaGenerator.pm
 SHA1 32834b7c4cf5a8d131382fccc8db341be8768291 t/00.load.t
 SHA1 9aa7fed2b2409faa4c71d2a45db210721f47403e t/01-version_checks.t
 SHA1 13c9fe3eeec0d000a7c86ea2474e30186cbc37e2 t/01basics.t
@@ -82,14 +83,17 @@
 SHA1 df97ee4e5bcb4ef0663dcc1a8db86dc66e8d9206 t/02-column_constraints.t
 SHA1 1c2bd056c575bc74caf2e59bdda8d8eb2731a3e7 t/02records_cachable.t
 SHA1 33642a61fd4b5a88436a82c6dd0fef359ba74a2b t/02records_object.t
-SHA1 a5b0e1f214e029ee41e822a19cf07a3250264d3f t/02searches_joins.t
+SHA1 ac42d8f2eea9f4856bee130b3ca557ef13940ad4 t/02searches_joins.t
 SHA1 f1f330dd8b4144e3437aba1455053903306bd0bc t/03rebless.t
+SHA1 4a4ed7341a37aa1ba4ecc03ad73e120a4052eac9 t/03rename_column.t
+SHA1 cb788b5336ae7c6f1fbf7795e38e2c4441f5c216 t/03rename_table.t
 SHA1 62c42d8458d73898f47f1b72d757239747321ef5 t/04memcached.t
 SHA1 4d2b42f80c2adaab70aa236a720cf57fa4b65677 t/05raw_value.t
 SHA1 f0371e275879019e2abe732bbb5626d0d05049a0 t/06filter.t
 SHA1 646947b41cfcddf80b627505940244aed2c6c5ea t/06filter_boolean.t
 SHA1 8d464426f2c5b0ab5ecc5a0a0331e5f77669c2dc t/06filter_datetime.t
 SHA1 172f655a7fdb4771e6e8b3aee45e93b1264a5567 t/06filter_duration.t
+SHA1 94ed632ca88c6094236eec59cffdb1f3fd39f551 t/06filter_salthash.t
 SHA1 1c0727c29fb58462710e4578a237d557b8453a07 t/06filter_storable.t
 SHA1 f0f6ce9d48f419de6ac6154684f9065f32e30ddd t/06filter_truncate.t
 SHA1 2e9777a47e3a920d063bfbf9d56375c67c5b89c5 t/06filter_utf8.t
@@ -110,11 +114,11 @@
 SHA1 59c44900b1cb957d262f96363ceff21b46e0d598 t/pod-coverage.t
 SHA1 e9c6a5881fc60173fbc8d479c1afd2ce3b43bef1 t/pod.t
 SHA1 62742c946808f35bcc8b2777e975c1ce068a0a71 t/testmodels.pl
-SHA1 2cf6ba23eb00dfed6f10533830da066c774c030c t/utils.pl
+SHA1 b11b0df92ffef5a617cf77b74c8b963be577e3c0 t/utils.pl
 -----BEGIN PGP SIGNATURE-----
-Version: GnuPG v2.0.9 (GNU/Linux)
+Version: GnuPG v1.4.7 (Darwin)
 
-iEYEARECAAYFAknKhi8ACgkQMflWJZZAbqA9NgCgpEvp0YR8wmewsAjdivLnuTBC
-7+oAnAlaNaoZzLoGESkZy5LGG4ZLeZJE
-=XNEb
+iD8DBQFKEqZ7sxfQtHhyRPoRAojSAJsFA4i59HHzcODcLP1I8DldBgijBQCdGsQ1
+zTjK+DO/zkobfCE4js2KjII=
+=cRri
 -----END PGP SIGNATURE-----

Modified: branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI.pm?rev=35968&op=diff
==============================================================================
--- branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI.pm (original)
+++ branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI.pm Wed May 20 07:38:13 2009
@@ -2,7 +2,7 @@
 use warnings;
 use strict;
 
-$Jifty::DBI::VERSION = '0.53';
+$Jifty::DBI::VERSION = '0.57';
 
 =head1 NAME
 

Modified: branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Column.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Column.pm?rev=35968&op=diff
==============================================================================
--- branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Column.pm (original)
+++ branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Column.pm Wed May 20 07:38:13 2009
@@ -37,6 +37,7 @@
 my @handy_attrs = qw/
     container
     label hints render_as
+    display_length
     documentation
     valid_values
     available_values
@@ -141,6 +142,8 @@
 
 =item     label hints render_as
 
+=item     display_length
+
 =item     valid_values
 
 =item     available_values

Modified: branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Handle.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Handle.pm?rev=35968&op=diff
==============================================================================
--- branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Handle.pm (original)
+++ branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Handle.pm Wed May 20 07:38:13 2009
@@ -238,6 +238,21 @@
     return $self->dbh->{PrintError};
 }
 
+=head2 log MESSAGE
+
+Takes a single argument, a message to log.
+
+Currently prints that message to STDERR
+
+=cut
+
+sub log {
+    my $self = shift;
+    my $msg  = shift;
+    warn $msg . "\n";
+
+}
+
 =head2 log_sql_statements BOOL
 
 Takes a boolean argument. If the boolean is true, it will log all SQL
@@ -510,17 +525,16 @@
 
     my $sth = $self->dbh->prepare($query_string);
     unless ($sth) {
+        my $message = "$self couldn't prepare the query '$query_string': "
+                    . $self->dbh->errstr;
         if ($DEBUG) {
-            die "$self couldn't prepare the query '$query_string'"
-                . $self->dbh->errstr . "\n";
+            die "$message\n";
         } else {
-            warn "$self couldn't prepare the query '$query_string'"
-                . $self->dbh->errstr . "\n";
+            warn "$message\n";
             my $ret = Class::ReturnValue->new();
             $ret->as_error(
                 errno   => '-1',
-                message => "Couldn't prepare the query '$query_string'."
-                    . $self->dbh->errstr,
+                message => $message,
                 do_backtrace => undef
             );
             return ( $ret->return_value );
@@ -1250,21 +1264,6 @@
 
 }
 
-=head2 log MESSAGE
-
-Takes a single argument, a message to log.
-
-Currently prints that message to STDERR
-
-=cut
-
-sub log {
-    my $self = shift;
-    my $msg  = shift;
-    warn $msg . "\n";
-
-}
-
 =head2 canonical_true
 
 This returns the canonical true value for this database. For example, in SQLite
@@ -1287,6 +1286,39 @@
 
 sub canonical_false { 0 }
 
+=head2 Schema manipulation methods
+
+=head3 rename_column
+
+Rename a column in a table. Takes 'table', 'column' and new name in 'to'.
+
+=cut
+
+sub rename_column {
+    my $self = shift;
+    my %args = (table => undef, column => undef, to => undef, @_);
+# Oracle: since Oracle 9i R2
+# Pg: 7.4 can this and may be earlier
+    return $self->simple_query(
+        "ALTER TABLE $args{'table'} RENAME COLUMN $args{'column'} TO $args{'to'}"
+    );
+}
+
+
+=head3 rename_table
+
+Renames a table in the DB. Takes 'table' and new name of it in 'to'.
+
+=cut
+
+sub rename_table {
+    my $self = shift;
+    my %args = (table => undef, to => undef, @_);
+# mysql has RENAME TABLE, but alter can rename temporary
+# Oracle, Pg, SQLite are ok with this
+    return $self->simple_query("ALTER TABLE $args{'table'} RENAME TO $args{'to'}");
+}
+
 =head2 DESTROY
 
 When we get rid of the L<Jifty::DBI::Handle>, we need to disconnect
@@ -1296,7 +1328,17 @@
 
 sub DESTROY {
     my $self = shift;
-    $self->disconnect;
+
+    # eval in DESTROY can cause $@ issues elsewhere
+    local $@;
+
+    $self->disconnect
+        unless $self->dbh
+            and $self->dbh
+                # We use an eval {} because DESTROY order during
+                # global destruction is not guaranteed -- the dbh may
+                # no longer be tied, which throws an error.
+            and eval { $self->dbh->{InactiveDestroy} };
     delete $DBIHandle{$self};
 }
 

Modified: branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Handle/SQLite.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Handle/SQLite.pm?rev=35968&op=diff
==============================================================================
--- branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Handle/SQLite.pm (original)
+++ branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Handle/SQLite.pm Wed May 20 07:38:13 2009
@@ -98,6 +98,70 @@
     return("$column COLLATE NOCASE", $operator, $value);
 }
 
+=head2 rename_column ( table => $table, column => $old_column, to => $new_column )
+
+rename column
+
+=cut
+
+sub rename_column {
+    my $self = shift;
+    my %args = (
+        table  => undef,
+        column => undef,
+        to     => undef,
+        @_
+    );
+
+    my $table   = $args{'table'};
+
+    # Convert columns
+    my ($schema) = $self->fetch_result(
+        "SELECT sql FROM sqlite_master WHERE tbl_name = ? AND type = ?",
+        $table, 'table',
+    );
+    $schema =~ s/(.*create\s+table\s+)\S+(.*?\(\s*)//i
+        or die "Cannot find 'CREATE TABLE' statement in schema for '$table': $schema";
+
+    my $new_table    = join( '_', $table, 'new', $$ );
+    my $new_create_clause = "$1$new_table$2";
+
+    my @column_info = ( split /,/, $schema );
+    my @column_names = map { /^\s*(\S+)/ ? $1 : () } @column_info;
+
+    s/^(\s*)\b\Q$args{column}\E\b/$1$args{to}/i for @column_info;
+
+    my $new_schema = $new_create_clause . join( ',', @column_info );
+    my $copy_columns = join(
+        ', ',
+        map {
+            ( lc($_) eq lc( $args{column} ) )
+              ? "$_ AS $args{to}"
+              : $_
+          } @column_names
+    );
+
+    # Convert indices
+    my $indice_sth = $self->simple_query(
+        "SELECT sql FROM sqlite_master WHERE tbl_name = ? AND type = ?",
+        $table, 'index'
+    );
+    my @indice_sql;
+    while ( my ($index) = $indice_sth->fetchrow_array ) {
+        $index =~ s/^(.*\(.*)\b\Q$args{column}\E\b/$1$args{to}/i;
+        push @indice_sql, $index;
+    }
+    $indice_sth->finish;
+
+    # Run the conversion SQLs
+    $self->begin_transaction;
+    $self->simple_query($new_schema);
+    $self->simple_query("INSERT INTO $new_table SELECT $copy_columns FROM $table");
+    $self->simple_query("DROP TABLE $table");
+    $self->simple_query("ALTER TABLE $new_table RENAME TO $table");
+    $self->simple_query($_) for @indice_sql;
+    $self->commit;
+}
 
 1;
 

Modified: branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Handle/mysql.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Handle/mysql.pm?rev=35968&op=diff
==============================================================================
--- branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Handle/mysql.pm (original)
+++ branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Handle/mysql.pm Wed May 20 07:38:13 2009
@@ -81,6 +81,39 @@
     return;
 }
 
+=head2 rename_column ( table => $table, column => $old_column, to => $new_column )
+
+rename column, die if fails
+
+=cut
+
+sub rename_column {
+    my $self = shift;
+    my %args = (
+        table  => undef,
+        column => undef,
+        to     => undef,
+        @_
+    );
+
+    my ($table, $column, $to) = @args{'table', 'column', 'to'};
+
+    # XXX, FIXME, TODO: this is stupid parser of CREATE TABLE, this should be something based on
+    # column_info, schema tables and show fields. The closest thing is RT 3.8/etc/upgrade/upgrade-mysql-schema.pl
+
+    my $create_table = ($self->simple_query("SHOW CREATE TABLE $table")->fetchrow_array)[1];
+    $create_table =~ /create\s+table\s+\S+\s*\((.*)\)/ims
+        or die "Cannot find 'CREATE TABLE' statement in schema for '$table': $create_table";
+    $create_table = $1;
+
+    my ($column_info) = ($create_table =~ /`$column`(.*?)(?:,|$)/i)
+        or die "Cannot find column '$column' in $create_table";
+    my $sth = $self->simple_query("ALTER TABLE $table CHANGE $column $to $column_info");
+    die "Cannot rename column '$column' in table '$table' to '$to': ". $self->dbh->errstr
+        unless $sth;
+    return $sth;
+}
+
 1;
 
 __END__

Modified: branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/HasFilters.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/HasFilters.pm?rev=35968&op=diff
==============================================================================
--- branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/HasFilters.pm (original)
+++ branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/HasFilters.pm Wed May 20 07:38:13 2009
@@ -43,11 +43,11 @@
     my $self = shift;
     if (@_) {    # setting
         my @values = map { UNIVERSAL::isa( $_, 'ARRAY' ) ? @$_ : $_ } @_;
-        $self->_input_filters_accessor( \@values );
+        $self->{input_filters} = \@values;
         return @values;
     }
 
-    return @{ $self->_input_filters_accessor || [] };
+    return @{ $self->{input_filters} || [] };
 }
 
 =head2 output_filters
@@ -64,11 +64,11 @@
     my $self = shift;
     if (@_) {    # setting
         my @values = map { UNIVERSAL::isa( $_, 'ARRAY' ) ? @$_ : $_ } @_;
-        $self->_output_filters_accessor( \@values );
+        $self->{output_filters} = \@values;
         return @values;
     }
 
-    my $values = $self->_output_filters_accessor;
+    my $values = $self->{output_filters};
     return @$values if $values && @$values;
 
     return reverse $self->input_filters;

Modified: branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Record.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Record.pm?rev=35968&op=diff
==============================================================================
--- branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Record.pm (original)
+++ branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Record.pm Wed May 20 07:38:13 2009
@@ -9,6 +9,7 @@
 use UNIVERSAL::require  ();
 use Scalar::Util qw(blessed);
 use Class::Trigger;    # exports by default
+use Scalar::Defer 'force';
 
 use base qw/
     Class::Data::Inheritable
@@ -1413,7 +1414,11 @@
             and defined $column->default
             and not ref $column->default )
         {
-            $attribs{ $column->name } = $column->default;
+            my $default = force $column->default;
+            $default = $default->id
+                if UNIVERSAL::isa( $default, 'Jifty::DBI::Record' );
+
+            $attribs{ $column->name } = $default;
 
             $self->_apply_input_filters(
                 column    => $column,

Modified: branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Schema.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Schema.pm?rev=35968&op=diff
==============================================================================
--- branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Schema.pm (original)
+++ branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/Schema.pm Wed May 20 07:38:13 2009
@@ -706,6 +706,12 @@
 might go in this column.  Correct usage is C<hints is 'Used by the
 frobnicator to do strange things'>.
 
+=head2 display_length
+
+The displayed length of form fields. Though you may be able to fit
+500 characters in the field, you would not want to display an HTML
+form with a size 500 input box.
+
 =head2 render_as
 
 Used in user interface generation to know how to render the column.

Modified: branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/SchemaGenerator.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/SchemaGenerator.pm?rev=35968&op=diff
==============================================================================
--- branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/SchemaGenerator.pm (original)
+++ branches/upstream/libjifty-dbi-perl/current/lib/Jifty/DBI/SchemaGenerator.pm Wed May 20 07:38:13 2009
@@ -279,7 +279,9 @@
 
         # Encode default values
         my $default = $column->default;
-        if (defined $default) {
+
+        # Scalar::Defer-powered defaults do not get a default in the database
+        if (ref($default) ne '0' && defined $default) {
             $model->_handle($self->handle);
             $model->_apply_input_filters(
                 column    => $column,

Modified: branches/upstream/libjifty-dbi-perl/current/t/02searches_joins.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjifty-dbi-perl/current/t/02searches_joins.t?rev=35968&op=diff
==============================================================================
--- branches/upstream/libjifty-dbi-perl/current/t/02searches_joins.t (original)
+++ branches/upstream/libjifty-dbi-perl/current/t/02searches_joins.t Wed May 20 07:38:13 2009
@@ -221,7 +221,6 @@
 }
 
     cleanup_schema( 'TestApp', $handle );
-    disconnect_handle($handle);
 }} # SKIP, foreach blocks
 
 1;

Added: branches/upstream/libjifty-dbi-perl/current/t/03rename_column.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjifty-dbi-perl/current/t/03rename_column.t?rev=35968&op=file
==============================================================================
--- branches/upstream/libjifty-dbi-perl/current/t/03rename_column.t (added)
+++ branches/upstream/libjifty-dbi-perl/current/t/03rename_column.t Wed May 20 07:38:13 2009
@@ -1,0 +1,65 @@
+#!/usr/bin/env perl -w
+
+
+use strict;
+use warnings;
+use File::Spec;
+use Test::More;
+use Jifty::DBI::Handle;
+
+BEGIN { require "t/utils.pl" }
+our (@available_drivers);
+
+use constant TESTS_PER_DRIVER => 11;
+
+my $total = scalar(@available_drivers) * TESTS_PER_DRIVER;
+plan tests => $total;
+
+foreach my $d ( @available_drivers ) {
+SKIP: {
+    unless( should_test( $d ) ) {
+        skip "ENV is not defined for driver '$d'", TESTS_PER_DRIVER;
+    }
+
+    my $handle = get_handle($d);
+    connect_handle($handle);
+    isa_ok( $handle->dbh, 'DBI::db' );
+
+    drop_table_if_exists( 'test', $handle );
+
+    my $sth = $handle->simple_query(
+        "CREATE TABLE test (a int, x integer not null default 1)"
+    );
+    ok $sth, 'created a table';
+
+    ok $handle->simple_query("insert into test values(2,2)"), "inserted a record";
+    $sth = $handle->simple_query("select * from test");
+    is $sth->fetchrow_hashref->{'x'}, 2, 'correct value';
+
+    $handle->rename_column( table => 'test', column => 'x', to => 'y' );
+    $sth = $handle->simple_query("select * from test");
+    is $sth->fetchrow_hashref->{'y'}, 2, 'correct value';
+    $sth->finish;
+    undef $sth;
+
+    my @warnings;
+    ok !eval {
+        local $SIG{__WARN__} = sub { push @warnings, @_ };
+        $handle->simple_query("insert into test(x) values(1)");
+    }, "no x anymore";
+    ok((splice @warnings), "we got warnings");
+
+    ok !eval {
+        local $SIG{__WARN__} = sub { push @warnings, @_ };
+        $handle->simple_query("insert into test(y) values(NULL)");
+    }, "NOT NULL is still there";
+    ok((splice @warnings), "we got warnings");
+
+    $handle->simple_query("delete from test");
+    ok $handle->simple_query("insert into test(a) values(1)"), "DEFAULT is still there";
+    is $handle->simple_query("select * from test")->fetchrow_hashref->{'y'},
+        1, 'correct value';
+    undef $handle;
+}} # SKIP, foreach blocks
+
+1;

Added: branches/upstream/libjifty-dbi-perl/current/t/03rename_table.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjifty-dbi-perl/current/t/03rename_table.t?rev=35968&op=file
==============================================================================
--- branches/upstream/libjifty-dbi-perl/current/t/03rename_table.t (added)
+++ branches/upstream/libjifty-dbi-perl/current/t/03rename_table.t Wed May 20 07:38:13 2009
@@ -1,0 +1,53 @@
+#!/usr/bin/env perl -w
+
+
+use strict;
+use warnings;
+use File::Spec;
+use Test::More;
+use Jifty::DBI::Handle;
+
+BEGIN { require "t/utils.pl" }
+our (@available_drivers);
+
+use constant TESTS_PER_DRIVER => 7;
+
+my $total = scalar(@available_drivers) * TESTS_PER_DRIVER;
+plan tests => $total;
+
+foreach my $d ( @available_drivers ) {
+SKIP: {
+    unless( should_test( $d ) ) {
+        skip "ENV is not defined for driver '$d'", TESTS_PER_DRIVER;
+    }
+
+    my $handle = get_handle($d);
+    connect_handle($handle);
+    isa_ok( $handle->dbh, 'DBI::db' );
+
+    my $sth;
+    drop_table_if_exists( 'test', $handle );
+    drop_table_if_exists( 'test1', $handle );
+
+    $sth = $handle->simple_query("CREATE TABLE test (a int)");
+    ok $sth, 'created a table';
+
+    ok $handle->simple_query("insert into test values(1)"), "inserted a record";
+    is $handle->simple_query("select * from test")->fetchrow_hashref->{'a'},
+        1, 'correct value';
+
+    $handle->rename_table( table => 'test', to => 'test1' );
+
+    is $handle->simple_query("select * from test1")->fetchrow_hashref->{'a'},
+        1, 'correct value';
+
+    my @warnings;
+    ok !eval {
+        local $SIG{__WARN__} = sub { push @warnings, @_ };
+        $handle->simple_query("select * from test")
+    }, "no test table anymore";
+    ok(@warnings, "got some warnings");
+
+}} # SKIP, foreach blocks
+
+1;

Added: branches/upstream/libjifty-dbi-perl/current/t/06filter_salthash.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjifty-dbi-perl/current/t/06filter_salthash.t?rev=35968&op=file
==============================================================================
--- branches/upstream/libjifty-dbi-perl/current/t/06filter_salthash.t (added)
+++ branches/upstream/libjifty-dbi-perl/current/t/06filter_salthash.t Wed May 20 07:38:13 2009
@@ -1,0 +1,104 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+use Test::More;
+use Digest::MD5 qw( md5_hex );
+BEGIN { require "t/utils.pl" }
+our (@available_drivers);
+
+use constant TESTS_PER_DRIVER => 10;
+
+my $total = scalar(@available_drivers) * TESTS_PER_DRIVER;
+plan tests => $total;
+
+foreach my $d (@available_drivers) {
+SKIP: {
+    unless (has_schema('TestApp::User', $d)) {
+        skip "No schema for '$d' driver", TESTS_PER_DRIVER;
+    }
+
+    unless (should_test($d)) {
+        skip "ENV is not defined for driver '$d'", TESTS_PER_DRIVER;
+    }
+
+    diag("start testing with '$d' handle") if $ENV{TEST_VERBOSE};
+
+    my $handle = get_handle($d);
+    connect_handle($handle);
+    isa_ok($handle->dbh, 'DBI::db');
+
+    {
+        my $ret = init_schema('TestApp::User', $handle);
+        isa_ok($ret, 'DBI::st', 'init schema');
+    }
+
+   my $rec = TestApp::User->new( handle => $handle );
+   isa_ok($rec, 'Jifty::DBI::Record');
+
+   my ($id) = $rec->create( password => 'very-very-secret' );
+   ok($id, 'created record');
+   ok($rec->load($id), 'loaded record');
+   is($rec->id, $id, 'record id matches');
+   is(ref $rec->password, 'ARRAY', 'password is an ARRAY');
+   is(scalar @{ $rec->password }, 2, 'password array has 2 elements');
+   my ($hash, $salt) = @{ $rec->password };
+   is($hash, md5_hex('very-very-secret', $salt), 'password matches encoding');
+
+   # undef/NULL
+   $rec->set_password;
+   is($rec->password, undef, 'set undef value');
+
+   cleanup_schema('TestApp', $handle);
+   disconnect_handle($handle);
+}
+}
+
+package TestApp::User;
+use base qw/ Jifty::DBI::Record /;
+
+1;
+
+sub schema_sqlite {
+
+<<EOF;
+CREATE table users (
+    id integer primary key,
+    password text
+)
+EOF
+
+}
+
+sub schema_mysql {
+
+<<EOF;
+CREATE TEMPORARY table users (
+    id integer auto_increment primary key,
+    password text
+)
+EOF
+
+}
+
+sub schema_pg {
+
+<<EOF;
+CREATE TEMPORARY table users (
+    id serial primary key,
+    password text
+)
+EOF
+
+}
+
+BEGIN {
+    use Jifty::DBI::Schema;
+
+    use Jifty::DBI::Record schema {
+    column password =>
+        type is 'text',
+        filters are qw/ Jifty::DBI::Filter::SaltHash /;
+    }
+}
+

Modified: branches/upstream/libjifty-dbi-perl/current/t/utils.pl
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjifty-dbi-perl/current/t/utils.pl?rev=35968&op=diff
==============================================================================
--- branches/upstream/libjifty-dbi-perl/current/t/utils.pl (original)
+++ branches/upstream/libjifty-dbi-perl/current/t/utils.pl Wed May 20 07:38:13 2009
@@ -34,7 +34,7 @@
 
 our @available_drivers = grep { eval "require DBD::". $_ } @supported_drivers;
 
-=head1 functionS
+=head1 FUNCTIONS
 
 =head2 get_handle
 
@@ -287,6 +287,24 @@
 }
 
 =head2 init_data
+
+Takes a class to get data from and the handle, calls C<init_data>
+method in the class, result is used to create new records of that
+class. First row is used for columns names.
+
+Example:
+
+    init_data('TestApp::User', $handle);
+
+    ...
+
+    package TestApp::User;
+    sub init_data { return (
+        ['name', 'email'],
+
+        ['ruz', 'ruz at localhost'],
+        ...
+    ) }
 
 =cut
 
@@ -309,4 +327,27 @@
         return $count;
 }
 
+=head2 drop_table_if_exists
+
+Takes a table name and handle. Drops the table in the DB if it exists.
+Returns nothing interesting, shouldn't die.
+
+=cut
+
+sub drop_table_if_exists {
+    my ($table, $handle) = @_;
+    my $d = handle_to_driver( $handle );
+    if ( $d eq 'Pg' ) {
+        my ($exists) = $handle->dbh->selectrow_array(
+            "select 1 from pg_tables where tablename = ?", undef, $table
+        );
+        $handle->simple_query("DROP TABLE $table") if $exists;
+    }
+    else {
+        local $@;
+        eval { $handle->simple_query("DROP TABLE IF EXISTS $table") };
+    }
+    return;
+}
+
 1;




More information about the Pkg-perl-cvs-commits mailing list