Hello community, here is the log from the commit of package perl-DBIx-Simple for openSUSE:Factory checked in at 2017-12-11 18:56:52 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/perl-DBIx-Simple (Old) and /work/SRC/openSUSE:Factory/.perl-DBIx-Simple.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "perl-DBIx-Simple" Mon Dec 11 18:56:52 2017 rev:6 rq:555677 version:1.37 Changes: -------- --- /work/SRC/openSUSE:Factory/perl-DBIx-Simple/perl-DBIx-Simple.changes 2012-01-09 16:21:48.000000000 +0100 +++ /work/SRC/openSUSE:Factory/.perl-DBIx-Simple.new/perl-DBIx-Simple.changes 2017-12-11 18:56:55.621349806 +0100 @@ -1,0 +2,6 @@ +Sat Dec 9 06:13:35 UTC 2017 - [email protected] + +- updated to 1.37 + see /usr/share/doc/packages/perl-DBIx-Simple/Changes + +------------------------------------------------------------------- Old: ---- DBIx-Simple-1.35.tar.gz New: ---- DBIx-Simple-1.37.tar.gz cpanspec.yml ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ perl-DBIx-Simple.spec ++++++ --- /var/tmp/diff_new_pack.unvpVk/_old 2017-12-11 18:56:57.469261790 +0100 +++ /var/tmp/diff_new_pack.unvpVk/_new 2017-12-11 18:56:57.473261598 +0100 @@ -1,7 +1,7 @@ # # spec file for package perl-DBIx-Simple # -# Copyright (c) 2012 SUSE LINUX Products GmbH, Nuernberg, Germany. +# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -15,22 +15,23 @@ # Please submit bugfixes or comments via http://bugs.opensuse.org/ # + Name: perl-DBIx-Simple -Version: 1.35 +Version: 1.37 Release: 0 -# coolo picked license for the author :) +#Upstream: Pick your favourite OSI approved license :) http://www.opensource.org/licenses/alphabetical %define cpan_name DBIx-Simple Summary: Very complete easy-to-use OO interface to DBI License: MIT Group: Development/Libraries/Perl Url: http://search.cpan.org/dist/DBIx-Simple/ -Source: http://www.cpan.org/authors/id/J/JU/JUERD/%{cpan_name}-%{version}.tar.gz +Source0: https://cpan.metacpan.org/authors/id/J/JU/JUERD/%{cpan_name}-%{version}.tar.gz +Source1: cpanspec.yml BuildArch: noarch BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildRequires: perl BuildRequires: perl-macros BuildRequires: perl(DBI) >= 1.21 -BuildRequires: perl(ExtUtils::MakeMaker) Requires: perl(DBI) >= 1.21 %{perl_requires} @@ -64,9 +65,6 @@ %perl_process_packlist %perl_gen_filelist -%clean -%{__rm} -rf %{buildroot} - %files -f %{name}.files %defattr(-,root,root,755) %doc Changes README ++++++ DBIx-Simple-1.35.tar.gz -> DBIx-Simple-1.37.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/DBIx-Simple-1.35/Changes new/DBIx-Simple-1.37/Changes --- old/DBIx-Simple-1.35/Changes 2011-01-04 23:53:19.000000000 +0100 +++ new/DBIx-Simple-1.37/Changes 2017-12-08 23:49:44.000000000 +0100 @@ -3,15 +3,26 @@ Incompatible changes are marked with "!!". Incompatibility with and changes in "undocumented features" are not always specifically mentioned here. -1.35 Tue Jan 4 23:48 2010 +1.37 2017-12-08 23:49 + - POD syntax fix + +1.36 2017-12-08 21:23 + - $result->object and $result->objects now load any module on demand. + (Suggested by Krasimir Berov.) + - New: $result->group, $result->group_hashes, $result->group_arrays. + (Suggested by Mark Overmeer.) + - Fixed typo in 1.35 release date below. (Reported by Sjors Gielen.) + - Changed changelog date format from insane to ISO 8601-ish. + +1.35 2011-01-04 23:48 !! - RaiseError is now enabled by default, as announced three years ago. Set PERL_DBIX_SIMPLE_NO_RAISEERROR=1 to get the old behavior. -1.34 Mon Dec 12 16:28 2010 - - Added missing documentation. (Reported by Krassimir Berov.) +1.34 2010-12-12 16:28 + - Added missing documentation. (Reported by Krasimir Berov.) - Fixed off-by-20 mistake in unit tests. -1.33 Sat Dec 4 0:30 2010 +1.33 2010-12-04 00:30 - New license: any(OSI). - Documentation overhaul. - New: $result->kv_list, $result->kv_array, $result->kv_flat, @@ -23,34 +34,34 @@ - Please note that very probably RaiseError will be enabled by default in the next version. -1.32 Mon Sep 17 14:58 2007 +1.32 2007-07-17 14:58 - Test updated to conform to fixed bug in Test::More. See http://www.nntp.perl.org/group/perl.qa/2007/09/msg9269.html -1.31 Sun Jul 15 0:29 2007 +1.31 2007-07-15 00:29 - New: $db->iquery. This method loads SQL::Interp on demand. The feature was requested by several people. Thanks go out to David Manura for writing SQL::Interpolate, and to Mark Stosberg for improving it and releasing that as SQL::Interp. -1.30 Sun Apr 8 2:29 2007 +1.30 2007-04-08 02:29 - Fixed bug #18629. Apparently Want does not consider a method call in rvalue context. The premature optimization that used Want has simply been removed. (Reported by Tomi via RT.) - Fixed bug #22829. With connect($dbh) or new($dbh), DBIx::Simple no longer disconnects implicitly. (Reported by BORISZ via RT.) -1.29 Web Apr 4 2:22 2007 +1.29 2007-04-04 02:22 - Fixed documentation typo. -1.28 Wed Apr 4 2:16 2007 +1.28 2007-04-04 02:16 - New: $db->result_class. This allows using a custom subclass. - $result->flat now returns an array reference in scalar context. - Optimized: map (up to 15% faster). - The "map" method now really requires exactly two columns. - Minor documentation improvements. -1.27 Sun Mar 18 21:14 2007 +1.27 2007-0318 21:14 !! - Bugfix: (??) was replaced when quoted !! - Bugfix: \' escaping was assumed, but actually only MySQL uses that - New: support \' escaping only for DBD::mysql @@ -58,15 +69,15 @@ - Removed dependency on Data::Swap !! - Removed compatibility package DBIx::Simple::SQE -1.26 Tue Nov 30 14:25 2004 +1.26 2004-11-30 14:25 - Removed documentation of emulate_subqueries. - Minor documentation fixes. -1.25 Mon Jun 21 9:39 2004 +1.25 2004-06-21 09:39 - New: $result->text. - This new method can use Anno Siegel's Text::Table (loaded on demand). -1.24 Sun Jun 20 21:32 2004 +1.24 2004-06-20 21:32 - New: $result->xto. - New: $result->html. - These new methods use Jeffrey Hayes Anderson's DBIx::XHTML_Table @@ -74,7 +85,7 @@ - New: $result->text. - Documentation =~ s/ESQ/SQE/g. (Reported by Larry Kos) -1.23 Thu Jun 10 0:00 2004 +1.23 2004-06-10 00:00 - New: DBIx::Simple::SQE. - New: $db->abstract. - New: $db->select. @@ -91,17 +102,17 @@ DBIx::Simple::SQE.) !! - Removed: $db->omniholder. (Now a constant: always "(??)".) -1.22 Thu May 6 17:30 2004 +1.22 2004-05-06 17:30 - Changed the declaration of a variable so that it doesn't blow up under 5.8.4's better strict. This should also fix a still undiscovered bug in the deprecated subquery emulation. (Reported and patched by Jos Boumans <irc>) -1.21 Thu Apr 29 14:40 2004 +1.21 2004-04-29 14:40 - Removed two nonsense entries from the changelog. $db->array and $db->hash do NOT reuse. -1.20 Tue Apr 27 11:15 2004 +1.20 2004-04-27 11:15 - Almost a complete rewrite :) - $db->emulate_subqueries is now deprecated. Use a better database engine instead. @@ -133,14 +144,14 @@ order during global destruction better. - Rebuilt distribution with h2xs to get lib/ and t/. -1.11 Tue Mar 26 19:05 2003 +1.11 2003-03-26 19:05 - Documentation updates. !! - list() now returns the *last* element in scalar context (was: first). - hashes() and arrays() now return array references in scalar context. - Migrated two properties to Attribute::Properties. (new dependency) - $VERSION++. -0.10 Thu Jan 9 10:03 2003 +0.10 2003-01-09 10:03 - Documentation rewrite! - New: $db->error(). In an upcoming release, $db->{reason} will be removed. @@ -158,13 +169,13 @@ instead of undef. - PrintError now defaults to 0 -0.09 Sun Dec 8 5:59 2002 +0.09 2002-12-08 05:59 - $dbh->disconnect() only if the object's still there. This works around perl bug #18951. Something is killing objects during (or just before) global destruction. This bug was first found by Gerard Oskamp <[email protected]>. -0.08 Mon Dec 2 21:16 2002 +0.08 2002-12-02 21:16 - Added $result->finish() method - The documentation was wrong: "undef $result" did nothing useful, as DBIx::Simple kept a copy internally, for garbage cleaning purposes. @@ -174,35 +185,35 @@ - When finish() or disconnect() is used, attempts to use the database connection or statement handle now result in a verbose error message. -0.07 Mon Sep 30 7:48 2002 +0.07 2002-09-30 07:48 - Removed TraceLevel thing that caused DBI to output debugging info - Very minor documentation update (removed 2 characters) -0.06 Fri Sep 20 10:55 2002 +0.06 2002-09-20 10:55 - Oops: forgot to update the README file; nothing serious -0.05 Thu Sep 19 14:32 2002 +0.05 2002-09-19 14:32 - Added $db->begin_work - No longer expanding the (??) omniholder inside quoted SQL - Subquery emulation! Have subqueries in MySQL! YAY! (Not enabled by default. Use $db->esq(1) to enable) - This module now requires Perl >= 5.6 -0.04 Tue Sep 17 15:46 2002 +0.04 2002-09-17 15:46 - Documentation updates only -0.03 Thu Jun 13 09:50 2002 +0.03 2002-06-13 09:50 - New: "(??)" and $db->omniholder() (like EZDBI's ??L placeholder) - Documentation updates - Code updates (now uses $_[0] directly for speed in many methods) - $result->list() in scalar context returns first value only -0.02 Sat Mar 30 14:00 2002 +0.02 2002-03-30 14:00 - New: $db->commit() and rollback(). Suggested by tradez (perlmonks.org) - New: $result->map_hashes(), map_arrays(), map(). Suggested by mattr (perlmonks.org) - New: $result->flat(), a plural form of list() -0.01 Thu Mar 28 18:04 2002 +0.01 2002-03-28 18:04 - Initial CPAN release diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/DBIx-Simple-1.35/MANIFEST new/DBIx-Simple-1.37/MANIFEST --- old/DBIx-Simple-1.35/MANIFEST 2007-11-11 01:10:33.000000000 +0100 +++ new/DBIx-Simple-1.37/MANIFEST 2017-12-08 23:51:01.000000000 +0100 @@ -11,3 +11,4 @@ lib/DBIx/Simple/Comparison.pod lib/DBIx/Simple/Result/RowObject.pm META.yml Module meta-data (added by MakeMaker) +META.json Module JSON meta-data (added by MakeMaker) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/DBIx-Simple-1.35/META.json new/DBIx-Simple-1.37/META.json --- old/DBIx-Simple-1.35/META.json 1970-01-01 01:00:00.000000000 +0100 +++ new/DBIx-Simple-1.37/META.json 2017-12-08 23:51:01.000000000 +0100 @@ -0,0 +1,42 @@ +{ + "abstract" : "Very complete easy-to-use OO interface to DBI", + "author" : [ + "Juerd Waalboer <[email protected]>" + ], + "dynamic_config" : 1, + "generated_by" : "ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150010", + "license" : [ + "unknown" + ], + "meta-spec" : { + "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", + "version" : "2" + }, + "name" : "DBIx-Simple", + "no_index" : { + "directory" : [ + "t", + "inc" + ] + }, + "prereqs" : { + "build" : { + "requires" : { + "ExtUtils::MakeMaker" : "0" + } + }, + "configure" : { + "requires" : { + "ExtUtils::MakeMaker" : "0" + } + }, + "runtime" : { + "requires" : { + "DBI" : "1.21" + } + } + }, + "release_status" : "stable", + "version" : "1.37", + "x_serialization_backend" : "JSON::PP version 2.27400_02" +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/DBIx-Simple-1.35/META.yml new/DBIx-Simple-1.37/META.yml --- old/DBIx-Simple-1.35/META.yml 2011-01-04 23:58:25.000000000 +0100 +++ new/DBIx-Simple-1.37/META.yml 2017-12-08 23:51:01.000000000 +0100 @@ -1,22 +1,23 @@ ---- #YAML:1.0 -name: DBIx-Simple -version: 1.35 -abstract: Very complete easy-to-use OO interface to DBI +--- +abstract: 'Very complete easy-to-use OO interface to DBI' author: - - Juerd Waalboer <[email protected]> -license: unknown -distribution_type: module -configure_requires: - ExtUtils::MakeMaker: 0 + - 'Juerd Waalboer <[email protected]>' build_requires: - ExtUtils::MakeMaker: 0 -requires: - DBI: 1.21 -no_index: - directory: - - t - - inc -generated_by: ExtUtils::MakeMaker version 6.55_02 + ExtUtils::MakeMaker: '0' +configure_requires: + ExtUtils::MakeMaker: '0' +dynamic_config: 1 +generated_by: 'ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150010' +license: unknown meta-spec: - url: http://module-build.sourceforge.net/META-spec-v1.4.html - version: 1.4 + url: http://module-build.sourceforge.net/META-spec-v1.4.html + version: '1.4' +name: DBIx-Simple +no_index: + directory: + - t + - inc +requires: + DBI: '1.21' +version: '1.37' +x_serialization_backend: 'CPAN::Meta::YAML version 0.018' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/DBIx-Simple-1.35/lib/DBIx/Simple/Examples.pod new/DBIx-Simple-1.37/lib/DBIx/Simple/Examples.pod --- old/DBIx-Simple-1.35/lib/DBIx/Simple/Examples.pod 2010-12-04 00:27:32.000000000 +0100 +++ new/DBIx-Simple-1.37/lib/DBIx/Simple/Examples.pod 2017-12-08 21:22:54.000000000 +0100 @@ -21,9 +21,9 @@ # Connecting to a MySQL database my $db = DBIx::Simple->connect( - 'DBI:mysql:database=test', # DBI source specification - 'test', 'test', # Username and password - { RaiseError => 1 } # Additional options + 'DBI:mysql:database=test', # DBI source specification + 'test', 'test', # Username and password + { RaiseError => 1 } # Additional options ); # Using an existing database handle @@ -38,16 +38,16 @@ $db->query('DELETE FROM foo WHERE id = ?', $id) or die $db->error; for (1..100) { - $db->query( - 'INSERT INTO randomvalues VALUES (?, ?)', - int rand(10), - int rand(10) - ) or die $db->error; + $db->query( + 'INSERT INTO randomvalues VALUES (?, ?)', + int rand(10), + int rand(10) + ) or die $db->error; } $db->query( - 'INSERT INTO sometable VALUES (??)', - $first, $second, $third, $fourth, $fifth, $sixth + 'INSERT INTO sometable VALUES (??)', + $first, $second, $third, $fourth, $fifth, $sixth ); # (??) is expanded to (?, ?, ?, ?, ?, ?) automatically @@ -57,8 +57,8 @@ my ($three, $four) = $db->query('SELECT 3, 2 + 2')->list; my ($name, $email) = $db->query( - 'SELECT name, email FROM people WHERE email = ? LIMIT 1', - $mail + 'SELECT name, email FROM people WHERE email = ? LIMIT 1', + $mail )->list; Or, more efficiently: @@ -67,8 +67,8 @@ $db->query('SELECT 3, 2 + 2')->into(my ($three, $four)); $db->query( - 'SELECT name, email FROM people WHERE email = ? LIMIT 1', - $mail + 'SELECT name, email FROM people WHERE email = ? LIMIT 1', + $mail )->into(my ($name, $email)); =head2 Fetching all rows in one go @@ -80,13 +80,13 @@ =head3 Rows as array references for my $row ($db->query('SELECT name, email FROM people')->arrays) { - print "Name: $row->[0], Email: $row->[1]\n"; + print "Name: $row->[0], Email: $row->[1]\n"; } =head3 Rows as hash references for my $row ($db->query('SELECT name, email FROM people')->hashes) { - print "Name: $row->{name}, Email: $row->{email}\n"; + print "Name: $row->{name}, Email: $row->{email}\n"; } =head2 Fetching one row at a time @@ -113,58 +113,89 @@ =head3 Rows as lists { - my $result = $db->query('SELECT name, email FROM people'); - while (my @row = $result->list) { - print "Name: $row[0], Email: $row[1]\n"; - } + my $result = $db->query('SELECT name, email FROM people'); + while (my @row = $result->list) { + print "Name: $row[0], Email: $row[1]\n"; + } } =head3 Rows as array references { - my $result = $db->query('SELECT name, email FROM people'); - while (my $row = $result->array) { - print "Name: $row->[0], Email: $row->[1]\n"; - } + my $result = $db->query('SELECT name, email FROM people'); + while (my $row = $result->array) { + print "Name: $row->[0], Email: $row->[1]\n"; + } } =head3 Rows as hash references { - my $result = $db->query('SELECT name, email FROM people'); - while (my $row = $result->hash) { - print "Name: $row->{name}, Email: $row->{email}\n"; - } + my $result = $db->query('SELECT name, email FROM people'); + while (my $row = $result->hash) { + print "Name: $row->{name}, Email: $row->{email}\n"; + } } =head2 Building maps (also fetching all rows in one go) -=head3 A hash of hashes +=head3 map + +=head4 A hash of hashes + + my $customers = + $db + -> query('SELECT id, name, location FROM people') + -> map_hashes('id'); + + # $customers = { $id => { name => $name, location => $location }, ... } + +=head4 A hash of arrays + + my $customers = + $db + -> query('SELECT id, name, location FROM people') + -> map_arrays(0); + + # $customers = { $id => [ $name, $location ], ... } + +=head4 A hash of values (two-column queries) + + my $names = + $db + -> query('SELECT id, name FROM people') + -> map; + + # $names = { $id => $name, ... } + +=head3 group + +=head4 A hash of arrays of hashes my $customers = - $db - -> query('SELECT id, name, location FROM people') - -> map_hashes('id'); + $db + -> query('SELECT id, name, location FROM people') + -> group_hashes('location'); - # $customers = { $id => { name => $name, location => $location } } + # $customers = { $location => [ { id => $id, name => $name }, ... ], ... } -=head3 A hash of arrays +=head4 A hash of arrays of arrays my $customers = - $db - -> query('SELECT id, name, location FROM people') - -> map_arrays(0); + $db + -> query('SELECT id, name, location FROM people') + -> group_arrays(2); - # $customers = { $id => [ $name, $location ] } + # $customers = { $location => [ [ $id, $name ], ... ], ... } -=head3 A hash of values (two-column queries) +=head4 A hash of arrays of values (two-column queries) my $names = - $db - -> query('SELECT id, name FROM people') - -> map; + $db + -> query('SELECT location, name FROM people') + -> group; - # $names = { $id => $name } + # $names = { $location => [ $name, $name, ... ], ... } =head1 EXAMPLES WITH SQL::Interp diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/DBIx-Simple-1.35/lib/DBIx/Simple.pm new/DBIx-Simple-1.37/lib/DBIx/Simple.pm --- old/DBIx-Simple-1.35/lib/DBIx/Simple.pm 2011-01-04 23:53:54.000000000 +0100 +++ new/DBIx-Simple-1.37/lib/DBIx/Simple.pm 2017-12-08 23:49:50.000000000 +0100 @@ -3,7 +3,7 @@ use DBI; use Carp (); -$DBIx::Simple::VERSION = '1.35'; +$DBIx::Simple::VERSION = '1.37'; $Carp::Internal{$_} = 1 for qw(DBIx::Simple DBIx::Simple::Result DBIx::Simple::DeadObject); @@ -397,10 +397,10 @@ $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; my $self = shift; my $class = shift || ':RowObject'; - if ($class =~ /^:/) { - $class = "DBIx::Simple::Result:$class"; - (my $package = "$class.pm") =~ s[::][/]g; - require $package; + $class =~ s/^:/DBIx::Simple::Result::/; + if (not $class->can('new_from_dbix_simple') || $class->can('new')) { + (my $filename = "$class.pm") =~ s[::][/]g; + require $filename; } if ($class->can('new_from_dbix_simple')) { return scalar $class->new_from_dbix_simple($self, @_); @@ -410,7 +410,7 @@ } Carp::croak( qq(Can't locate object method "new_from_dbix_simple" or "new" ) . - qq(via package "$class" (perhaps you forgot to load "$class"?)) + qq(via package "$class".) ); } @@ -454,8 +454,8 @@ $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; my $self = shift; my $class = shift || ':RowObject'; - if ($class =~ /^:/) { - $class = "DBIx::Simple::Result:$class"; + $class =~ s/^:/DBIx::Simple::Result::/; + if (not $class->can('new_from_dbix_simple') || $class->can('new')) { (my $package = "$class.pm") =~ s[::][/]g; require $package; } @@ -473,36 +473,60 @@ ); } -sub map_hashes { +sub _map { + my ($keys, $values) = @_; + my %return; + @return{@$keys} = @$values; + return wantarray ? %return : \%return; +} + +sub _group { + my ($keys, $values) = @_; + my %return; + push @{ $return{shift @$keys} }, shift @$values while @$values; + return wantarray ? %return : \%return; +} + +sub _keys_and_hashes { $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; my ($self, $keyname) = @_; Carp::croak('Key column name not optional') if not defined $keyname; my @rows = $self->hashes; my @keys; push @keys, delete $_->{$keyname} for @rows; - my %return; - @return{@keys} = @rows; - return wantarray ? %return : \%return; + return \@keys, \@rows; } -sub map_arrays { +sub _keys_and_arrays { $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; my ($self, $keyindex) = @_; $keyindex += 0; my @rows = $self->arrays; my @keys; push @keys, splice @$_, $keyindex, 1 for @rows; - my %return; - @return{@keys} = @rows; - return wantarray ? %return : \%return; + return \@keys, \@rows; } +sub group_hashes { return _group shift->_keys_and_hashes(@_) } +sub map_hashes { return _map shift->_keys_and_hashes(@_) } +sub group_arrays { return _group shift->_keys_and_arrays(@_) } +sub map_arrays { return _map shift->_keys_and_arrays(@_) } + sub map { $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; return map @$_, @{ $_[0]->{st}->{sth}->fetchall_arrayref } if wantarray; return { map @$_, @{ $_[0]->{st}->{sth}->fetchall_arrayref } }; } +sub group { + $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; + my %return; + while (my $row = $_[0]->fetch) { + push @{ $return{ $row->[0] } }, $row->[1]; + } + return wantarray ? %return : \%return; +} + sub rows { $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; $_[0]->{st}->{sth}->rows; @@ -628,9 +652,9 @@ $row = $result->kv_array @rows = $result->kv_arrays $obj = $result->object @objs = $result->objects - %map = $result->map_arrays(...) - %map = $result->map_hashes(...) - %map = $result->map + %map = $result->map %grouped = $result->group + %map = $result->map_hashes(...) %grouped = $result->group_hashes(...) + %map = $result->map_arrays(...) %grouped = $result->group_arrays(...) $rows = $result->rows @@ -717,7 +741,7 @@ generated query and bind arguments with C<query>. See SQL::Interp's documentation for usage information. -Requires Mark Storberg's SQL::Interp, which is available from CPAN. SQL::Interp +Requires Mark Stosberg's SQL::Interp, which is available from CPAN. SQL::Interp is a fork from David Manura's SQL::Interpolate. =item C<select>, C<insert>, C<update>, C<delete> @@ -942,23 +966,37 @@ Returns a list of instances of $class. See "Object construction". Possibly affected by C<lc_columns>. -=item C<map_arrays($column_number)> +=item C<map> + +=item C<group> + +Constructs a simple hash, using the two columns as key/value pairs. Should only +be used with queries that return two columns. Returns a list of interleaved +keys and values, or (in scalar context), a reference to a hash. -Constructs a hash of array references keyed by the values in the chosen column, -and returns a list of interleaved keys and values, or (in scalar context), a -reference to a hash. +With unique keys, use C<map>. With non-unique keys, use C<group>, which gives +an array of values per key. =item C<map_hashes($column_name)> -Constructs a hash of hash references keyed by the values in the chosen column, -and returns a list of interleaved keys and values, or (in scalar context), a -reference to a hash. Affected by C<lc_columns>. +=item C<group_arrays($column_number)> -=item C<map> +Constructs a hash keyed by the values in the chosen column, and returns a list +of interleaved keys and values, or (in scalar context), a reference to a hash. +Affected by C<lc_columns>. -Constructs a simple hash, using the two columns as key/value pairs. Should -only be used with queries that return two columns. Returns a list of interleaved -keys and values, or (in scalar context), a reference to a hash. +With unique keys, use C<map_hashes>, which gives a single hash per key. With +non-unique keys, use C<group_hashes>, which gives an array of hashes per key. + +=item C<map_arrays($column_number)> + +=item C<group_arrays($column_number)> + +Constructs a hash keyed by the values in the chosen column, and returns a list +of interleaved keys and values, or (in scalar context), a reference to a hash. + +With unique keys, use C<map_arrays>, which gives a single array per key. With +non-unique keys, use C<group_arrays>, which gives an array of arrays per key. =item C<xto(%attr)> @@ -1019,8 +1057,7 @@ by one of the query methods, two approaches are tried. In either case, pass the name of a class as the first argument. A prefix of a single colon can be used as an alias for C<DBIx::Simple::Result::>, e.g. C<":Example"> is short for -C<"DBIx::Simple::Result::Example">. When this shortcut is used, the -corresponding module is loaded automatically. +C<"DBIx::Simple::Result::Example">. Modules are loaded on demand. The default class when no class is given, is C<:RowObject>. It requires Jos Boumans' Object::Accessor, which is available from CPAN. @@ -1080,7 +1117,6 @@ The mapping methods do not check whether the keys are unique. Rows that are fetched later overwrite earlier ones. - =head1 LICENSE Pick your favourite OSI approved license :) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/DBIx-Simple-1.35/t/sqlite.t new/DBIx-Simple-1.37/t/sqlite.t --- old/DBIx-Simple-1.35/t/sqlite.t 2011-01-04 23:45:50.000000000 +0100 +++ new/DBIx-Simple-1.37/t/sqlite.t 2017-12-08 20:34:23.000000000 +0100 @@ -7,7 +7,7 @@ eval { DBD::SQLite->VERSION >= 1 } or plan skip_all => 'DBD::SQLite >= 1.00 required'; - plan tests => 57; + plan tests => 60; use_ok('DBIx::Simple'); } @@ -15,7 +15,7 @@ # http://use.perl.org/~tomhukins/journal/31457 ++ my $db = DBIx::Simple->connect('dbi:SQLite:dbname=:memory:'); -my $q = 'SELECT * FROM xyzzy ORDER BY foo'; +my $q = 'SELECT FOO, bar, baz FROM xyzzy ORDER BY foo'; ok($db); @@ -119,4 +119,12 @@ is_deeply(scalar $db->query($q)->objects('Mock', 42, 21), [ 1 ]); # wantarray true } +$db->query('INSERT INTO xyzzy (foo, bar, baz) VALUES (??)', 33, 66, 'c'); +$db->query('INSERT INTO xyzzy (foo, bar, baz) VALUES (??)', 44, 77, 'f'); +$db->query('INSERT INTO xyzzy (foo, bar, baz) VALUES (??)', 55, 88, 'h'); + +is_deeply(scalar $db->query($q)->group_arrays(2), { c => [ [ qw(33 66) ], [ qw(a b) ] ], f => [ [ qw(44 77) ], [ qw(d e) ] ], h => [ [ qw(55 88) ], [ qw(g (??)) ] ] }); +is_deeply(scalar $db->query($q)->group_hashes('baz'), { c => [ { qw(foo 33 bar 66) }, { qw(foo a bar b) } ], f => [ { qw(foo 44 bar 77) }, { qw(foo d bar e) } ], h => [ { qw(foo 55 bar 88) }, { qw(foo g bar (??)) } ] }); +is_deeply(scalar $db->query('SELECT baz, foo FROM xyzzy ORDER BY foo')->group, { c => [ qw(33 a) ], f => [ qw(44 d) ], h => [ qw(55 g) ] }); + ok($db->disconnect); ++++++ cpanspec.yml ++++++ --- #description_paragraphs: 3 #description: |- # override description from CPAN #summary: override summary from CPAN #no_testing: broken upstream #sources: # - source1 # - source2 #patches: # foo.patch: -p1 # bar.patch: #preamble: |- # BuildRequires: gcc-c++ #post_prep: |- # hunspell=`pkg-config --libs hunspell | sed -e 's,-l,,; s, *,,g'` # sed -i -e "s,hunspell-X,$hunspell," t/00-prereq.t Makefile.PL #post_build: |- # rm unused.files #post_install: |- # sed on %{name}.files license: MIT #skip_noarch: 1 #custom_build: |- #./Build build flags=%{?_smp_mflags} --myflag #custom_test: |- #startserver && make test #ignore_requires: Bizarre::Module
