DBIx-Class

 view release on metacpan or  search on metacpan

lib/DBIx/Class/Admin.pm  view on Meta::CPAN

462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
=item Arguments: $rs, $set, $where
 
=back
 
update takes the name of a resultset from the schema_class, a hashref of data to update and
a where hash used to form the search for the rows to update.
 
=cut
 
sub update {
  my ($self, $rs, $set, $where) = @_;
 
  $rs ||= $self->resultset();
  $where ||= $self->where();
  $set ||= $self->set();
  my $resultset = $self->schema->resultset($rs);
  $resultset = $resultset->search( ($where||{}) );
 
  my $count = $resultset->count();
  print "This action will modify $count ".ref($resultset)." records.\n" if (!$self->quiet);

lib/DBIx/Class/CDBICompat/LazyLoading.pm  view on Meta::CPAN

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
sub resultset_instance {
  my $self = shift;
  my $rs = $self->next::method(@_);
  $rs = $rs->search(undef, { columns => [ $self->columns('Essential') ] });
  return $rs;
}
 
 
# Emulate that CDBI throws out all changed columns and reloads them on
# request in case the database modifies the new value (say, via a trigger)
sub update {
    my $self = shift;
 
    my @dirty_columns = keys %{$self->{_dirty_columns}};
 
    my $ret = $self->next::method(@_);
    $self->_clear_column_data(@dirty_columns);
 
    return $ret;
}

lib/DBIx/Class/CDBICompat/Triggers.pm  view on Meta::CPAN

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  my $self = shift;
 
  return $self->create(@_) unless ref $self;
 
  $self->call_trigger('before_create');
  $self->next::method(@_);
  $self->call_trigger('after_create');
  return $self;
}
 
sub update {
  my $self = shift;
  $self->call_trigger('before_update');
  my @to_update = keys %{$self->{_dirty_columns} || {}};
  return -1 unless @to_update;
  $self->next::method(@_);
  $self->call_trigger('after_update');
  return $self;
}
 
sub delete {

lib/DBIx/Class/FilterColumn.pm  view on Meta::CPAN

148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
    $self->make_column_dirty($col);
    delete $self->{_column_data}{$col};
  }
  else {
    $self->set_column($col, $self->_column_to_storage($col, $filtered));
  };
 
  return $self->{_filtered_column}{$col} = $filtered;
}
 
sub update {
  my ($self, $data, @rest) = @_;
 
  my $colinfos = $self->result_source->columns_info;
 
  foreach my $col (keys %{$data||{}}) {
    if ( exists $colinfos->{$col}{_filter_info} ) {
      $self->set_filtered_column($col, delete $data->{$col});
 
      # FIXME update() reaches directly into the object-hash
      # and we may *not* have a filtered value there - thus

lib/DBIx/Class/Ordered.pm  view on Meta::CPAN

535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
=head2 update
 
Overrides the DBIC update() method by checking for a change
to the position and/or group columns.  Movement within a
group or to another group is handled by repositioning
the appropriate siblings.  Position defaults to the end
of a new group if it has been changed to undef.
 
=cut
 
sub update {
  my $self = shift;
 
  # this is set by _ordered_internal_update()
  return $self->next::method(@_) if $self->result_source->schema->{_ORDERED_INTERNAL_UPDATE};
 
  my $upd = shift;
  $self->set_inflated_columns($upd) if $upd;
 
  my $position_column = $self->position_column;
  my @group_columns = $self->_grouping_columns;

lib/DBIx/Class/Relationship/Base.pm  view on Meta::CPAN

781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
=item Return Value: L<$result|DBIx::Class::Manual::ResultClass>
 
=back
 
Update or create a result object of a related class. See
L<DBIx::Class::ResultSet/update_or_create> for details.
 
=cut
 
sub update_or_create_related {
  #my ($self, $rel, @args) = @_;
  shift->related_resultset(shift)->update_or_create(@_);
}
 
=head2 set_from_related
 
=over 4
 
=item Arguments: $rel_name, L<$result|DBIx::Class::Manual::ResultClass>

lib/DBIx/Class/Relationship/Base.pm  view on Meta::CPAN

843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
=back
 
  $book->update_from_related('author', $author_obj);
 
The same as L</"set_from_related">, but the changes are immediately updated
in storage.
 
=cut
 
sub update_from_related {
  my $self = shift;
  $self->set_from_related(@_);
  $self->update;
}
 
=head2 delete_related
 
=over 4
 
=item Arguments: $rel_name, $cond?, L<\%attrs?|DBIx::Class::ResultSet/ATTRIBUTES>

lib/DBIx/Class/Relationship/CascadeActions.pm  view on Meta::CPAN

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
      }
    }
 
    $guard->commit;
    return $ret;
  }
 
  $self->next::method(@rest);
}
 
sub update {
  my ($self, @rest) = @_;
  return $self->next::method(@rest) unless ref $self;
    # Because update cascades on a class *really* don't make sense!
 
  my $source = $self->result_source;
  my %rels = map { $_ => $source->relationship_info($_) } $source->relationships;
  my @cascade = grep { $rels{$_}{attrs}{cascade_update} } keys %rels;
 
  if (@cascade) {
    my $guard = $source->schema->txn_scope_guard;

lib/DBIx/Class/ResultSet.pm  view on Meta::CPAN

2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
Note that L</update> does not process/deflate any of the values passed in.
This is unlike the corresponding L<DBIx::Class::Row/update>. The user must
ensure manually that any value passed to this method will stringify to
something the RDBMS knows how to deal with. A notable example is the
handling of L<DateTime> objects, for more info see:
L<DBIx::Class::Manual::Cookbook/Formatting DateTime objects in queries>.
 
=cut
 
sub update {
  my ($self, $values) = @_;
  $self->throw_exception('Values for update must be a hash')
    unless ref $values eq 'HASH';
 
  return $self->_rs_update_delete ('update', $values);
}
 
=head2 update_all
 
=over 4

lib/DBIx/Class/ResultSet.pm  view on Meta::CPAN

2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
=item Return Value: 1
 
=back
 
Fetches all objects and updates them one at a time via
L<DBIx::Class::Row/update>. Note that C<update_all> will run DBIC defined
triggers, while L</update> will not.
 
=cut
 
sub update_all {
  my ($self, $values) = @_;
  $self->throw_exception('Values for update_all must be a hash')
    unless ref $values eq 'HASH';
 
  my $guard = $self->result_source->schema->txn_scope_guard;
  $_->update({%$values}) for $self->all;  # shallow copy - update will mangle it
  $guard->commit;
  return 1;
}

lib/DBIx/Class/ResultSet.pm  view on Meta::CPAN

3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
See also L</find> and L</find_or_create>. For information on how to declare
unique constraints, see L<DBIx::Class::ResultSource/add_unique_constraint>.
 
If you need to know if an existing row was updated or a new one created use
L</update_or_new> and L<DBIx::Class::Row/in_storage> instead. Don't forget
to call L<DBIx::Class::Row/insert> to save the newly created row to the
database!
 
=cut
 
sub update_or_create {
  my $self = shift;
  my $attrs = (@_ > 1 && ref $_[$#_] eq 'HASH' ? pop(@_) : {});
  my $cond = ref $_[0] eq 'HASH' ? shift : {@_};
 
  my $row = $self->find($cond, $attrs);
  if (defined $row) {
    $row->update($cond);
    return $row;
  }

lib/DBIx/Class/ResultSet.pm  view on Meta::CPAN

3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
B<Note>: Take care when using C<update_or_new> with a table having
columns with default values that you intend to be automatically
supplied by the database (e.g. an auto_increment primary key column).
In normal usage, the value of such columns should NOT be included at
all in the call to C<update_or_new>, even when set to C<undef>.
 
See also L</find>, L</find_or_create> and L</find_or_new>.
 
=cut
 
sub update_or_new {
    my $self  = shift;
    my $attrs = ( @_ > 1 && ref $_[$#_] eq 'HASH' ? pop(@_) : {} );
    my $cond  = ref $_[0] eq 'HASH' ? shift : {@_};
 
    my $row = $self->find( $cond, $attrs );
    if ( defined $row ) {
        $row->update($cond);
        return $row;
    }

lib/DBIx/Class/ResultSetProxy.pm  view on Meta::CPAN

12
13
14
15
16
17
18
19
20
21
22
23
24
sub search           { shift->resultset_instance->search(@_);           }
sub search_literal   { shift->resultset_instance->search_literal(@_);   }
sub search_like      { shift->resultset_instance->search_like(@_);      }
sub count            { shift->resultset_instance->count(@_);            }
sub count_literal    { shift->resultset_instance->count_literal(@_);    }
sub find             { shift->resultset_instance->find(@_);             }
sub create           { shift->resultset_instance->create(@_);           }
sub find_or_create   { shift->resultset_instance->find_or_create(@_);   }
sub find_or_new      { shift->resultset_instance->find_or_new(@_);      }
sub update_or_create { shift->resultset_instance->update_or_create(@_); }
 
1;

lib/DBIx/Class/Row.pm  view on Meta::CPAN

533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
To determine before calling this method, which column values have
changed and will be updated, call L</get_dirty_columns>.
 
To check if any columns will be updated, call L</is_changed>.
 
To force a column to be updated, call L</make_column_dirty> before
this method.
 
=cut
 
sub update {
  my ($self, $upd) = @_;
 
  $self->set_inflated_columns($upd) if $upd;
 
  my %to_update = $self->get_dirty_columns
    or return $self;
 
  $self->throw_exception( "Not in database" ) unless $self->in_storage;
 
  my $rows = $self->result_source->storage->update(

lib/DBIx/Class/Row.pm  view on Meta::CPAN

1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
=head2 insert_or_update
 
  $obj->insert_or_update
 
Alias for L</update_or_insert>
 
=cut
 
sub insert_or_update { shift->update_or_insert(@_) }
 
sub update_or_insert {
  my $self = shift;
  return ($self->in_storage ? $self->update : $self->insert);
}
 
=head2 is_changed
 
  my @changed_col_names = $result->is_changed();
  if ($result->is_changed()) { ... }
 
=over

lib/DBIx/Class/SQLMaker/MySQL.pm  view on Meta::CPAN

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
        $parenthesized = join ' ', '(', $self->$force_double_subq( $parenthesized ), ')';
      }
    }
 
    $new_sql .= $prefix . $parenthesized;
  }
 
  return $new_sql . $sql;
};
 
sub update {
  my $self = shift;
 
  # short-circuit unless understood identifier
  return $self->next::method(@_) unless $self->{_modification_target_referenced_re};
 
  my ($sql, @bind) = $self->next::method(@_);
 
  $sql = $self->$force_double_subq($sql)
    if $sql =~ $self->{_modification_target_referenced_re};

lib/DBIx/Class/Storage.pm  view on Meta::CPAN

579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
=cut
 
sub insert { die "Virtual method!" }
 
=head2 update
 
Handle an update statement.
 
=cut
 
sub update { die "Virtual method!" }
 
=head2 delete
 
Handle a delete statement.
 
=cut
 
sub delete { die "Virtual method!" }
 
=head2 select_single

lib/DBIx/Class/Storage/DBI.pm  view on Meta::CPAN

2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
  }
  catch {
    $err = shift unless defined $err;
  };
 
  $self->throw_exception($err) if defined $err;
 
  return $count;
}
 
sub update {
  #my ($self, $source, @args) = @_;
  shift->_execute('update', @_);
}
 
 
sub delete {
  #my ($self, $source, @args) = @_;
  shift->_execute('delete', @_);
}

lib/DBIx/Class/Storage/DBI/ODBC/ACCESS.pm  view on Meta::CPAN

85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
      last;
    }
  }
 
  local $self->{disable_sth_caching} = 1 if $is_image_insert
    && $self->disable_sth_caching_for_image_insert_or_update;
 
  return $self->next::method(@_);
}
 
sub update {
  my $self = shift;
  my ($source, $fields) = @_;
 
  my $columns_info = $source->columns_info;
 
  my $is_image_insert = 0;
 
  for my $col (keys %$fields) {
    if ($self->_is_binary_lob_type($columns_info->{$col}{data_type})) {
      $is_image_insert = 1;

lib/DBIx/Class/Storage/DBI/Sybase/ASE.pm  view on Meta::CPAN

434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
      ($identity_col => $self->last_insert_id($source, $identity_col)) : ()),
    %$to_insert,
    %$updated_cols,
  };
 
  $self->_insert_blobs ($source, $blob_cols, $final_row) if $blob_cols;
 
  return $updated_cols;
}
 
sub update {
  my $self = shift;
  my ($source, $fields, $where, @rest) = @_;
 
  #
  # When *updating* identities, ASE requires SET IDENTITY_UPDATE called
  #
  if (my $blob_cols = $self->_remove_blob_cols($source, $fields)) {
 
    # If there are any blobs in $where, Sybase will return a descriptive error
    # message.



( run in 1.440 second using v1.01-cache-2.11-cpan-49f99fa48dc )