App-Sqitch
view release on metacpan or search on metacpan
lib/App/Sqitch/Engine/oracle.pm view on Meta::CPAN
}
return;
},
},
});
}
);
# Need to wait until dbh is defined.
with 'App::Sqitch::Role::DBIEngine';
sub _log_tags_param {
[ map { $_->format_name } $_[1]->tags ];
}
sub _log_requires_param {
[ map { $_->as_string } $_[1]->requires ];
}
sub _log_conflicts_param {
[ map { $_->as_string } $_[1]->conflicts ];
}
sub _ts2char_format {
# q{CAST(to_char(%1$s AT TIME ZONE 'UTC', '"year":YYYY:"month":MM:"day":DD') AS VARCHAR2(100 byte)) || CAST(to_char(%1$s AT TIME ZONE 'UTC', ':"hour":HH24:"minute":MI:"second":SS:"time_zone":"UTC"') AS VARCHAR2(168 byte))}
# Good grief, Oracle, WTF? https://github.com/sqitchers/sqitch/issues/316
join ' || ', (
q{to_char(%1$s AT TIME ZONE 'UTC', '"year":YYYY')},
q{to_char(%1$s AT TIME ZONE 'UTC', ':"month":MM')},
q{to_char(%1$s AT TIME ZONE 'UTC', ':"day":DD')},
q{to_char(%1$s AT TIME ZONE 'UTC', ':"hour":HH24')},
q{to_char(%1$s AT TIME ZONE 'UTC', ':"minute":MI')},
q{to_char(%1$s AT TIME ZONE 'UTC', ':"second":SS')},
q{':time_zone:UTC'},
);
}
sub _ts_default { 'current_timestamp' }
sub _can_limit { 0 }
sub _char2ts {
my $dt = $_[1];
join ' ', $dt->ymd('-'), $dt->hms(':'), $dt->time_zone->name;
}
sub _listagg_format {
# https://stackoverflow.com/q/16313631/79202
return q{CAST(COLLECT(CAST(%s AS VARCHAR2(512))) AS sqitch_array)};
}
sub _regex_op { 'REGEXP_LIKE(%s, ?)' }
sub _simple_from { ' FROM dual' }
sub _multi_values {
my ($self, $count, $expr) = @_;
return join "\nUNION ALL ", ("SELECT $expr FROM dual") x $count;
}
sub _dt($) {
require App::Sqitch::DateTime;
return App::Sqitch::DateTime->new(split /:/ => shift);
}
sub _cid {
my ( $self, $ord, $offset, $project ) = @_;
return try {
return $self->dbh->selectcol_arrayref(qq{
SELECT change_id FROM (
SELECT change_id, rownum as rnum FROM (
SELECT change_id
FROM changes
WHERE project = ?
ORDER BY committed_at $ord
)
) WHERE rnum = ?
}, undef, $project || $self->plan->project, ($offset // 0) + 1)->[0];
} catch {
return if $self->_no_table_error;
die $_;
};
}
sub _cid_head {
my ($self, $project, $change) = @_;
return $self->dbh->selectcol_arrayref(qq{
SELECT change_id FROM (
SELECT change_id
FROM changes
WHERE project = ?
AND change = ?
ORDER BY committed_at DESC
) WHERE rownum = 1
}, undef, $project, $change)->[0];
}
sub _select_state {
my ( $self, $project, $with_hash ) = @_;
my $cdtcol = sprintf $self->_ts2char_format, 'c.committed_at';
my $pdtcol = sprintf $self->_ts2char_format, 'c.planned_at';
my $tagcol = sprintf $self->_listagg_format, 't.tag';
my $hshcol = $with_hash ? "c.script_hash\n , " : '';
my $dbh = $self->dbh;
return $dbh->selectrow_hashref(qq{
SELECT * FROM (
SELECT c.change_id
, ${hshcol}c.change
, c.project
, c.note
, c.committer_name
, c.committer_email
, $cdtcol AS committed_at
, c.planner_name
, c.planner_email
, $pdtcol AS planned_at
, $tagcol AS tags
FROM changes c
LEFT JOIN tags t ON c.change_id = t.change_id
WHERE c.project = ?
GROUP BY c.change_id
, ${hshcol}c.change
( run in 1.034 second using v1.01-cache-2.11-cpan-99c4e6809bf )