提早事务开始的位置

This commit is contained in:
Yu Sun
2022-08-04 15:26:47 +08:00
parent 17c4d7193a
commit 6e86509e27

View File

@@ -9,6 +9,7 @@ class ENodeConfigure {
) {} ) {}
function add_node() { function add_node() {
pg_query($this -> dbconn, "BEGIN");
$exists = pg_query($this -> dbconn, sprintf( $exists = pg_query($this -> dbconn, sprintf(
"SELECT EXISTS( "SELECT EXISTS(
SELECT 1 FROM hf_mes_scada_data_capture_node_configure SELECT 1 FROM hf_mes_scada_data_capture_node_configure
@@ -16,12 +17,13 @@ class ENodeConfigure {
AND working_subclass = '%s' AND working_subclass = '%s'
)", $this -> post -> code, $this -> post -> working_subclass )", $this -> post -> code, $this -> post -> working_subclass
)); ));
if (pg_fetch_assoc($exists)['exists'] == 't') { if (pg_fetch_assoc($exists)['exists'] === 't') {
pg_query($this -> dbconn, "ROLLBACK");
return "REPLICATED"; return "REPLICATED";
} }
$table_name = 'hf_mes_scada_data_capture_node_data_' . $this -> post -> working_subclass; $table_name = 'hf_mes_scada_data_capture_node_data_' . $this -> post -> working_subclass;
pg_query($this -> dbconn, "BEGIN"); // https://www.postgresql.org/docs/current/when-can-parallel-query-be-used.html
$res[] = pg_query($this -> dbconn, sprintf( $res[] = pg_query($this -> dbconn, sprintf(
'CREATE TABLE IF NOT EXISTS "%s" ( 'CREATE TABLE IF NOT EXISTS "%s" (
id serial8, id serial8,