Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ensembl-gh-mirror
ensembl-hive
Commits
08145c68
Commit
08145c68
authored
May 10, 2017
by
Leo Gordon
Browse files
update() is now smart about updating CURRENT_TIMESTAMP columns
parent
12f759d1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
7 deletions
+18
-7
modules/Bio/EnsEMBL/Hive/DBSQL/BaseAdaptor.pm
modules/Bio/EnsEMBL/Hive/DBSQL/BaseAdaptor.pm
+16
-3
modules/Bio/EnsEMBL/Hive/DBSQL/RoleAdaptor.pm
modules/Bio/EnsEMBL/Hive/DBSQL/RoleAdaptor.pm
+2
-4
No files found.
modules/Bio/EnsEMBL/Hive/DBSQL/BaseAdaptor.pm
View file @
08145c68
...
...
@@ -431,11 +431,24 @@ sub update { # update (some or all) non_primary columns from the primary
throw
("
There are no dependent columns to update, as everything seems to belong to the primary key
");
}
my
$sql
=
"
UPDATE
$table_name
SET
"
.
join
('
,
',
map
{
"
$_
=?
"
}
@$columns_to_update
)
.
"
WHERE
$primary_key_constraint
";
my
@placeholders
=
();
my
@values
=
();
foreach
my
$idx
(
0
..
scalar
(
@$columns_to_update
)
-
1
)
{
my
(
$column_name
,
$value
)
=
(
$columns_to_update
->
[
$idx
],
$values_to_update
->
[
$idx
]);
if
(
$column_name
=~
/^when_/
and
defined
(
$value
)
and
$value
eq
'
CURRENT_TIMESTAMP
')
{
push
@placeholders
,
$column_name
.
'
=CURRENT_TIMESTAMP
';
}
else
{
push
@placeholders
,
$column_name
.
'
=?
';
push
@values
,
$value
;
}
}
my
$sql
=
"
UPDATE
$table_name
SET
"
.
join
('
,
',
@placeholders
)
.
"
WHERE
$primary_key_constraint
";
# warn "SQL: $sql\n";
my
$sth
=
$self
->
prepare
(
$sql
);
# warn "VALUES_TO_UPDATE: ".join(', ', map { "'$_'" } @
$
values
_to_update
)."\n";
$sth
->
execute
(
@
$
values
_to_update
);
# warn "VALUES_TO_UPDATE: ".join(', ', map { "'$_'" } @values)."\n";
$sth
->
execute
(
@values
);
$sth
->
finish
();
}
...
...
modules/Bio/EnsEMBL/Hive/DBSQL/RoleAdaptor.pm
View file @
08145c68
...
...
@@ -57,10 +57,8 @@ sub object_class {
sub
finalize_role
{
my
(
$self
,
$role
,
$release_undone_jobs
)
=
@_
;
my
$role_id
=
$role
->
dbID
;
my
$when_finished
=
$role
->
when_finished
?
"
'
"
.
$role
->
when_finished
.
"
'
"
:
'
CURRENT_TIMESTAMP
';
$self
->
dbc
->
do
(
"
UPDATE role SET when_finished=
$when_finished
WHERE role_id=
$role_id
"
);
$role
->
when_finished
(
'
CURRENT_TIMESTAMP
'
);
$self
->
update_when_finished
(
$role
);
$self
->
db
->
get_AnalysisStatsAdaptor
->
increment_a_counter
(
'
num_running_workers
',
-
1
,
$role
->
analysis_id
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment