license => 'perl',
module_name => 'DBIx::Class',
requires => {
+ 'Cwd' => 3.19,
'Data::Page' => 2.00,
'Scalar::Util' => 0,
'SQL::Abstract' => 1.20,
'SQL::Abstract::Limit' => 0.101,
+ 'Algorithm::C3' => 0.02,
'Class::C3' => 0.11,
'Storable' => 0,
'Class::Data::Accessor' => 0.01,
Revision history for DBIx::Class
+0.07001
+ - pass $attrs to find from update_or_create so a specific key can be
+ provided
+ - remove anonymous blesses to avoid major speed hit on Fedora Core 5's
+ Perl and possibly others; for more information see:
+ https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=196836
+ - fix a pathological prefetch case
+ - table case fix for Oracle in columns_info_for
+
0.07000 2006-07-23 02:30:00
- supress warnings for possibly non-unique queries, since
_is_unique_query doesn't infer properly in all cases
sub __grouper {
my ($class) = @_;
- return bless({ class => $class}, 'DBIx::Class::CDBICompat::ColumnGroups::GrouperShim');
+ my $grouper = { class => $class };
+ return bless($grouper, 'DBIx::Class::CDBICompat::ColumnGroups::GrouperShim');
}
sub _find_columns {
$self->next::method(@_[1..$#_]);
}
+sub _ident_cond {
+ my ($class) = @_;
+ return join(" AND ", map { "$_ = ?" } $class->primary_columns);
+}
+
sub _flesh {
my ($self, @groups) = @_;
@groups = ('All') unless @groups;
sub setup_schema_instance {
my $class = shift;
- my $schema = bless({}, 'DBIx::Class::Schema');
+ my $schema = {};
+ bless $schema, 'DBIx::Class::Schema';
$class->mk_classdata('schema_instance' => $schema);
}
=item L<DBIx::Class::Manual> - User's Manual overview.
+=item L<DBIx::Class::Manual::FAQ> - Frequently Asked Questions, gathered from IRC and the mailing list.
+
=item L<DBIx::Class::Manual::Intro> - Introduction to setting up and using DBIx::Class.
=item L<DBIx::Class::Manual::Example> - Full example Schema.
=item L<DBIx::Class::PK::Auto> - Magically retrieve auto-incrementing fields.
-=item L<DBIx::Class::Core> - Set of standard components.
+=item L<DBIx::Class::Core> - Set of standard components to load.
=item L<DBIx::Class::Serialize::Storable> - ?
=item L<DBIx::Class::InflateColumn> - Making objects out of your columns.
+=item L<DBIx::Class::InflateColumn::DateTime> - Magically turn your datetime or timestamp columns into DateTime objects.
+
=item L<DBIx::Class::PK> - Dealing with primary keys.
=item L<DBIx::Class::ResultSourceProxy::Table> - Turns the resultsource into a table.
=item L<DBIx::Class::ResultSet> - Selecting and manipulating sets.
+=item L<DBIx::Class::ResultSetColumn> - Perform operations on entire columns of a ResultSet.
+
=item L<DBIx::Class::Row> - Dealing with actual data.
=item L<DBIx::Class::Storage::DBI> - Storage using L<DBI> and L<SQL::Abstract>.
The first argument to C<search> is a hashref of accessor names and
values to filter them by, for example:
- ->search({'created_time' => { '>=', '2006-06-01 00:00:00'} })
+ ->search({'created_time' => { '>=', '2006-06-01 00:00:00' } })
Note that to use a function here you need to make the whole value into
a scalar reference:
- ->search({'created_time' => \'>= yesterday() })
+ ->search({'created_time' => \'>= yesterday()' })
=item .. search in several tables simultaneously?
your search, for example when searching in the Books table for all the
books by the author "Fred Bloggs":
- ->search({'authors.name' => 'Fred Bloggs'}, { join => 'authors'})
+ ->search({'authors.name' => 'Fred Bloggs'}, { join => 'authors' })
The type of join created in your SQL depends on the type of
relationship between the two tables, see L<DBIx::Class::Relationship>
To stop the column name from being quoted, you'll need to supply a
scalar reference:
- ->update({ somecolumn => '\othercolumn'})
+ ->update({ somecolumn => \'othercolumn' })
=back
=cut
-sub _ident_cond {
- my ($class) = @_;
- return join(" AND ", map { "$_ = ?" } $class->primary_columns);
-}
-
sub _ident_values {
my ($self) = @_;
return (map { $self->{_column_data}{$_} } $self->primary_columns);
$attrs->{alias} ||= 'me';
- # XXXX
- # Use a named hash here and bless afterwards to avoid a huge performance hit
- # in perl 5.8.8-5+ FC5 and later, and possibly other distributions.
- #
- # See https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=196836 for more
- # information.
my $self = {
result_source => $source,
result_class => $attrs->{result_class} || $source->result_class,
If no C<key> is specified, it searches on all unique constraints defined on the
source, including the primary key.
+If your table does not have a primary key, you B<must> provide a value for the
+C<key> attribute matching one of the unique constraints on the source.
+
See also L</find_or_create> and L</update_or_create>. For information on how to
declare unique constraints, see
L<DBIx::Class::ResultSource/add_unique_constraint>.
? $self->result_source->unique_constraint_columns($attrs->{key})
: $self->result_source->primary_columns;
$self->throw_exception(
- "Can't find unless a primary key or unique constraint is defined"
+ "Can't find unless a primary key is defined or unique constraint is specified"
) unless @cols;
# Parse out a hashref from input
my $max_length = $rs->get_column('length')->max;
-Returns a ResultSetColumn instance for $column based on $self
+Returns a L<DBIx::Class::ResultSetColumn> instance for a column of the ResultSet.
=cut
my $attrs = (@_ > 1 && ref $_[$#_] eq 'HASH' ? pop(@_) : {});
my $cond = ref $_[0] eq 'HASH' ? shift : {@_};
- my $row = $self->find($cond);
+ my $row = $self->find($cond, $attrs);
if (defined $row) {
$row->update($cond);
return $row;
=head1 DESCRIPTION
-A convenience class used to perform operations on a specific column of a resultset.
+A convenience class used to perform operations on a specific column of
+a resultset.
=cut
my $obj = DBIx::Class::ResultSetColumn->new($rs, $column);
-Creates a new resultset column object from the resultset and column passed as params
+Creates a new resultset column object from the resultset and column
+passed as params. Used internally by L<DBIx::Class::ResultSet/get_column>.
=cut
=back
-Returns the next value of the column in the resultset (C<undef> is there is none).
+Returns the next value of the column in the resultset (or C<undef> if
+there is none).
-Much like $rs->next but just returning the one value
+Much like L<DBIx::Class::ResultSet/next> but just returning the
+one value.
=cut
=back
-Returns all values of the column in the resultset (C<undef> is there are none).
+Returns all values of the column in the resultset (or C<undef> if
+there are none).
-Much like $rs->all but returns values rather than row objects
+Much like L<DBIx::Class::ResultSet/all> but returns values rather
+than row objects.
=cut
=back
-Wrapper for ->func. Returns the lowest value of the column in the resultset (C<undef> is there are none).
+ my $first_year = $year_col->min();
+
+Wrapper for ->func. Returns the lowest value of the column in the
+resultset (or C<undef> if there are none).
=cut
=back
-Wrapper for ->func. Returns the highest value of the column in the resultset (C<undef> is there are none).
+ my $last_year = $year_col->max();
+
+Wrapper for ->func. Returns the highest value of the column in the
+resultset (or C<undef> if there are none).
=cut
=back
-Wrapper for ->func. Returns the sum of all the values in the column of the resultset. Use on varchar-like columns at your own risk.
+ my $total = $prices_col->sum();
+
+Wrapper for ->func. Returns the sum of all the values in the column of
+the resultset. Use on varchar-like columns at your own risk.
=cut
=back
-Runs a query using the function on the column and returns the value. For example
$rs = $schema->resultset("CD")->search({});
$length = $rs->get_column('title')->func('LENGTH');
-Produces the following SQL
- SELECT LENGTH( title ) from cd me
+Runs a query using the function on the column and returns the
+value. Produces the following SQL:
+
+ SELECT LENGTH( title ) FROM cd me
=cut
Luke Saunders <luke.saunders@gmail.com>
+Jess Robinson
+
=head1 LICENSE
You may distribute this code under the same terms as Perl itself.
sub new {
my ($class, $attrs) = @_;
$class = ref $class if ref $class;
- my $new = bless({ %{$attrs || {}}, _resultset => undef }, $class);
+
+ my $new = { %{$attrs || {}}, _resultset => undef };
+ bless $new, $class;
+
$new->{resultset_class} ||= 'DBIx::Class::ResultSet';
$new->{resultset_attributes} = { %{$new->{resultset_attributes} || {}} };
$new->{_ordered_columns} = [ @{$new->{_ordered_columns}||[]}];
sub iterator_class { shift->result_source_instance->resultset_class(@_) }
sub resultset_class { shift->result_source_instance->resultset_class(@_) }
+sub result_class { shift->result_source_instance->result_class(@_) }
sub source_name { shift->result_source_instance->source_name(@_) }
sub resultset_attributes {
*add_column = \&add_columns;
sub has_column {
- my ($self, $column) = @_;
- return $self->result_source_instance->has_column($column);
+ shift->result_source_instance->has_column(@_);
}
sub column_info {
- my ($self, $column) = @_;
- return $self->result_source_instance->column_info($column);
+ shift->result_source_instance->column_info(@_);
}
sub load_column_info_from_storage {
}
sub columns {
- return shift->result_source_instance->columns(@_);
+ shift->result_source_instance->columns(@_);
}
sub remove_columns {
- return shift->result_source_instance->remove_columns(@_);
+ shift->result_source_instance->remove_columns(@_);
}
*remove_column = \&remove_columns;
sub new {
my ($class, $attrs) = @_;
$class = ref $class if ref $class;
- my $new = bless { _column_data => {} }, $class;
+
+ my $new = { _column_data => {} };
+ bless $new, $class;
+
if ($attrs) {
$new->throw_exception("attrs must be a hashref")
unless ref($attrs) eq 'HASH';
$new->store_column($k => $attrs->{$k});
}
}
+
return $new;
}
delete $col_data->{$col}
if $self->result_source->column_info($col)->{is_auto_increment};
}
- my $new = bless { _column_data => $col_data }, ref $self;
+
+ my $new = { _column_data => $col_data };
+ bless $new, ref $self;
+
$new->result_source($self->result_source);
$new->set_columns($changes);
$new->insert;
sub inflate_result {
my ($class, $source, $me, $prefetch) = @_;
#use Data::Dumper; print Dumper(@_);
- my $new = bless({ result_source => $source,
- _column_data => $me,
- _in_storage => 1
- },
- ref $class || $class);
+ my $new = {
+ result_source => $source,
+ _column_data => $me,
+ _in_storage => 1
+ };
+ bless $new, (ref $class || $class);
+
my $schema;
foreach my $pre (keys %{$prefetch||{}}) {
my $pre_val = $prefetch->{$pre};
sub clone {
my ($self) = @_;
- my $clone = bless({ (ref $self ? %$self : ()) }, ref $self || $self);
+ my $clone = { (ref $self ? %$self : ()) };
+ bless $clone, (ref $self || $self);
+
foreach my $moniker ($self->sources) {
my $source = $self->source($moniker);
my $new = $source->new($source);
sub new {
my $class = shift;
- return bless {}, $class;
+ my $self = {};
+ return bless $self, $class;
}
1;
sub new {
my ($self, $schema) = @_;
- my $new = bless({}, ref $self || $self);
-
+ my $new = {};
+ bless $new, (ref $_[0] || $_[0]);
$new->set_schema($schema);
$new->cursor("DBIx::Class::Storage::DBI::Cursor");
$new->transaction_depth(0);
=cut
sub new {
- my $self = bless({}, ref($_[0]) || $_[0]);
+ my $self = {};
+ bless $self, (ref($_[0]) || $_[0]);
return $self;
}
my $schema = DBICTest->init_schema();
-plan tests => 39;
+plan tests => 43;
# Check the defined unique constraints
is_deeply(
is($track->get_column('cd'), 1, 'track cd is correct');
is($track->get_column('position'), 3, 'track position is correct');
+
+# Test a table with a unique constraint but no primary key
+my $row = $schema->resultset('NoPrimaryKey')->update_or_create(
+ {
+ foo => 1,
+ bar => 2,
+ baz => 3,
+ },
+ { key => 'foo_bar' }
+);
+ok(! $row->is_changed, 'update_or_create on table without primary key: row is clean');
+is($row->foo, 1, 'foo is correct');
+is($row->bar, 2, 'bar is correct');
+is($row->baz, 3, 'baz is correct');
'Producer',
'CD_to_Producer',
),
- qw/SelfRefAlias TreeLike TwoKeyTreeLike Event/
+ qw/SelfRefAlias TreeLike TwoKeyTreeLike Event NoPrimaryKey/
);
1;
--- /dev/null
+package # hide from PAUSE
+ DBICTest::Schema::NoPrimaryKey;
+
+use base 'DBIx::Class::Core';
+
+DBICTest::Schema::NoPrimaryKey->table('noprimarykey');
+DBICTest::Schema::NoPrimaryKey->add_columns(
+ 'foo' => { data_type => 'integer' },
+ 'bar' => { data_type => 'integer' },
+ 'baz' => { data_type => 'integer' },
+);
+
+DBICTest::Schema::NoPrimaryKey->add_unique_constraint(foo_bar => [ qw/foo bar/ ]);
+
+1;
);
--
+-- Table: noprimarykey
+--
+CREATE TABLE noprimarykey (
+ foo integer NOT NULL,
+ bar integer NOT NULL,
+ baz integer NOT NULL
+);
+
+--
-- Table: fourkeys
--
CREATE TABLE fourkeys (
CREATE UNIQUE INDEX cd_artist_title_cd on cd (artist, title);
CREATE UNIQUE INDEX track_cd_position_track on track (cd, position);
CREATE UNIQUE INDEX track_cd_title_track on track (cd, title);
+CREATE UNIQUE INDEX foo_bar_noprimarykey on noprimarykey (foo, bar);
CREATE UNIQUE INDEX prod_name_producer on producer (name);
COMMIT;