Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F67487667
sql_state_updater.hh
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Jun 22, 16:59
Size
2 KB
Mime Type
text/x-c
Expires
Mon, Jun 24, 16:59 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
18416494
Attached To
R3127 blackdynamite
sql_state_updater.hh
View Options
#ifndef __AKANTU_SQL_STATE_UPDATER_HH__
#define __AKANTU_SQL_STATE_UPDATER_HH__
/* -------------------------------------------------------------------------- */
#include "pusher.hh"
#include <cmath>
/* -------------------------------------------------------------------------- */
namespace
BlackDynamite
{
class
Pusher
::
SqlStateUpdater
:
public
pqxx
::
transactor
<
transaction
>
{
/* ------------------------------------------------------------------------ */
/* Constructors/Destructors */
/* ------------------------------------------------------------------------ */
public
:
SqlStateUpdater
(
const
std
::
string
&
tablename
,
UInt
run_id
)
:
pqxx
::
transactor
<
transaction
>
(
"Update state of table"
+
tablename
),
tablename
(
tablename
),
run_id
(
run_id
),
state
(
UNDEF
)
{}
/* ------------------------------------------------------------------------ */
/* Accessors */
/* ------------------------------------------------------------------------ */
void
operator
()(
transaction
&
T
);
void
changeState
(
RunState
st
){
state
=
st
;
}
protected
:
std
::
string
makeRequest
(
const
std
::
string
&
field
,
bool
value
);
/* ------------------------------------------------------------------------ */
/* Class Members */
/* ------------------------------------------------------------------------ */
protected
:
std
::
string
tablename
;
UInt
run_id
;
RunState
state
;
};
/* -------------------------------------------------------------------------- */
std
::
string
Pusher
::
SqlStateUpdater
::
makeRequest
(
const
std
::
string
&
field
,
bool
value
){
std
::
stringstream
command
;
command
<<
"UPDATE "
<<
pqxx
::
to_string
(
tablename
)
<<
".runs"
<<
" SET "
<<
pqxx
::
to_string
(
field
)
<<
" = "
<<
pqxx
::
to_string
(
value
)
<<
" WHERE id = "
<<
pqxx
::
to_string
(
run_id
)
<<
";"
;
return
command
.
str
();
}
void
Pusher
::
SqlStateUpdater
::
operator
()(
transaction
&
trans
)
{
std
::
string
command
;
std
::
cout
<<
"state is "
<<
state
<<
" "
<<
this
<<
std
::
endl
;
switch
(
state
){
case
STARTED:
command
=
this
->
makeRequest
(
"has_started"
,
true
);
break
;
case
ENDED:
command
=
this
->
makeRequest
(
"has_finished"
,
true
);
break
;
default
:
FATAL
(
"this should not append"
);
}
std
::
cout
<<
command
<<
std
::
endl
;
// command << "UPDATE " << pqxx::to_string(tablename) << ".runs"
// << " SET has_started = true WHERE id = " << pqxx::to_string(run_id)
// << ";";
try
{
trans
.
exec
(
command
);
}
catch
(
std
::
runtime_error
&
e
)
{
FATAL
(
"Failed to execute query: "
<<
command
<<
std
::
endl
<<
" with message: "
<<
e
.
what
());
}
std
::
cout
<<
"state is "
<<
state
<<
" "
<<
this
<<
std
::
endl
;
}
}
#endif
/* __AKANTU_SQL_STATE_UPDATER_HH__ */
Event Timeline
Log In to Comment