| 1 | package EntityModel::Query::Update; | ||||||||||
| 2 | { | ||||||||||
| 3 | 33 | $EntityModel::Query::Update::VERSION = '0.102'; | |||||||||
| 4 | } | ||||||||||
| 5 | 33 | ▶ | use EntityModel::Class { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 33 | _isa => [qw{EntityModel::Query}], | |||||||||
| 7 | 'set' => { type => 'array', subclass => 'EntityModel::Query::Field' }, | ||||||||||
| 8 | 33 | }; | |||||||||
| 9 | |||||||||||
| 10 | =head1 NAME | ||||||||||
| 11 | |||||||||||
| 12 | EntityModel::Query::Update - update statement | ||||||||||
| 13 | |||||||||||
| 14 | =head1 VERSION | ||||||||||
| 15 | |||||||||||
| 16 | version 0.102 | ||||||||||
| 17 | |||||||||||
| 18 | =head1 SYNOPSIS | ||||||||||
| 19 | |||||||||||
| 20 | See L<Entitymodel::Query>. | ||||||||||
| 21 | |||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||
| 23 | |||||||||||
| 24 | See L<Entitymodel::Query>. | ||||||||||
| 25 | |||||||||||
| 26 | =cut | ||||||||||
| 27 | |||||||||||
| 28 | =head1 METHODS | ||||||||||
| 29 | |||||||||||
| 30 | =cut | ||||||||||
| 31 | |||||||||||
| 32 | =head2 import | ||||||||||
| 33 | |||||||||||
| 34 | Register the parse handling for our 'insert' attribute. | ||||||||||
| 35 | |||||||||||
| 36 | =cut | ||||||||||
| 37 | |||||||||||
| 38 | 32 | ▶ | sub import { | ||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||
| 39 | 32 | my $class = shift; | |||||||||
| 40 | $class->register( | ||||||||||
| 41 | 1 | ▶ | 'update' => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 42 | 1 | my $self = shift; | |||||||||
| 43 | 1 | $self->upgradeTo('EntityModel::Query::Update'); | |||||||||
| 44 | 1 | $self->parse_base( | |||||||||
| 45 | @_, | ||||||||||
| 46 | method => 'from', | ||||||||||
| 47 | type => 'EntityModel::Query::FromTable' | ||||||||||
| 48 | ); | ||||||||||
| 49 | } | ||||||||||
| 50 | 32 | ); | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | =head2 type | ||||||||||
| 54 | |||||||||||
| 55 | =cut | ||||||||||
| 56 | |||||||||||
| 57 | 1 | ▶ | sub type { 'update'; } | ||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 58 | |||||||||||
| 59 | =head2 parse_fields | ||||||||||
| 60 | |||||||||||
| 61 | Populate the values for the update statement. | ||||||||||
| 62 | |||||||||||
| 63 | =cut | ||||||||||
| 64 | |||||||||||
| 65 | 1 | ▶ | sub parse_fields { | ||||||||
|
Subroutine
parse_fields: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 66 | 1 | my $self = shift; | |||||||||
| 67 | 1 | my $spec = shift; | |||||||||
| 68 | 1 | ▶ | my @entries = ref $spec eq 'HASH' ? %$spec : @$spec; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 1 | ▶ | while(@entries) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 2 | my $k = shift(@entries); | |||||||||
| 71 | 2 | my $v = shift(@entries); | |||||||||
| 72 | 2 | $self->parse_base({ | |||||||||
| 73 | name => $k, | ||||||||||
| 74 | value => $v, | ||||||||||
| 75 | }, | ||||||||||
| 76 | method => 'set', | ||||||||||
| 77 | type => 'EntityModel::Query::UpdateField' | ||||||||||
| 78 | ); | ||||||||||
| 79 | } | ||||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | =head2 keyword_order | ||||||||||
| 83 | |||||||||||
| 84 | =cut | ||||||||||
| 85 | |||||||||||
| 86 | 0 | ▶ | sub keyword_order { qw{type from join fields where order offset limit}; } | ||||||||
|
Subroutine
keyword_order: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 87 | |||||||||||
| 88 | =head2 fromSQL | ||||||||||
| 89 | |||||||||||
| 90 | =cut | ||||||||||
| 91 | |||||||||||
| 92 | 0 | ▶ | sub fromSQL { | ||||||||
|
Subroutine
fromSQL: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 93 | 0 | my $self = shift; | |||||||||
| 94 | 0 | my $from = join(', ', map { $_->asString } $self->from->list); | |||||||||
| 95 | 0 | ▶ | return unless $from; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 96 | 0 | return $from; | |||||||||
| 97 | } | ||||||||||
| 98 | |||||||||||
| 99 | =head2 fieldsSQL | ||||||||||
| 100 | |||||||||||
| 101 | =cut | ||||||||||
| 102 | |||||||||||
| 103 | 0 | ▶ | sub fieldsSQL { | ||||||||
|
Subroutine
fieldsSQL: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 104 | 0 | my $self = shift; | |||||||||
| 105 | my $fields = join(', ', map { | ||||||||||
| 106 | 0 | $_->asString . ' = ' . $_->quotedValue | |||||||||
| 107 | } $self->set->list); | ||||||||||
| 108 | 0 | ▶ | return unless $fields; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 109 | 0 | return 'set ' . $fields; | |||||||||
| 110 | } | ||||||||||
| 111 | |||||||||||
| 112 | 2 | ▶ | sub inlineSQL { | ||||||||
|
Subroutine
inlineSQL: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 113 | 2 | my $self = shift; | |||||||||
| 114 | my $data = [ | ||||||||||
| 115 | 'update ', | ||||||||||
| 116 | 2 | (map { $_->asString } $self->from->list), | |||||||||
| 117 | ' set ', | ||||||||||
| 118 | ]; | ||||||||||
| 119 | 2 | my @field; | |||||||||
| 120 | 2 | foreach ($self->set->list) { | |||||||||
| 121 | 4 | my $v = $_->value; | |||||||||
| 122 | 4 | ▶ | push @field, ', ' if @field; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 123 | 4 | push @field, $_->name; | |||||||||
| 124 | 4 | push @field, ' = '; | |||||||||
| 125 | 4 | push @field, \$v; | |||||||||
| 126 | } | ||||||||||
| 127 | 2 | push @$data, @field; | |||||||||
| 128 | 2 | ▶ | push @$data, ' ', @{$self->whereSQL} if $self->where; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 129 | 2 | return $data; | |||||||||
| 130 | } | ||||||||||
| 131 | |||||||||||
| 132 | 33 | 1; | |||||||||
| 133 | |||||||||||
| 134 | __END__ | ||||||||||