增加对大写字母的表名的适配

This commit is contained in:
Yu Sun
2022-07-14 00:13:57 +08:00
parent 0258d6bb9d
commit cea11228cd
2 changed files with 14 additions and 15 deletions

View File

@@ -56,8 +56,8 @@ class EDataCapture {
foreach ($this -> data as $code => $value) {
foreach (array_chunk($value, 6710885, true) as $chunk) {
$sql_head = sprintf(
"INSERT INTO hf_mes_scada_data_capture_node_data_%s (code, v_%s, device_code, batch)
VALUES",
'INSERT INTO "hf_mes_scada_data_capture_node_data_%s" (code, v_%s, device_code, batch)
VALUES',
$this -> working_subclass,
$this -> code_type[$code]
);
@@ -101,9 +101,9 @@ class EDataCapture {
});
$sql_cmd = sprintf(
"SELECT id, code, COALESCE(v_string, v_int::text, v_float::text, v_bool::text) AS value, device_code, batch, capture_time
FROM hf_mes_scada_data_capture_node_data_%s
WHERE capture_time >= '%s' AND capture_time <= '%s'",
'SELECT id, code, COALESCE(v_string, v_int::text, v_float::text, v_bool::text) AS value, device_code, batch, capture_time
FROM "hf_mes_scada_data_capture_node_data_%s"
WHERE capture_time >= \'%s\' AND capture_time <= \'%s\'',
$this -> get['working_subclass'],
date("Y-m-d H:i:s", $this -> get['start_time'] / 1000),
date("Y-m-d H:i:s", $this -> get['end_time'] / 1000)
@@ -111,7 +111,7 @@ class EDataCapture {
if (isset($this -> get['code']))
$sql_cmd .= sprintf(" AND code = '%s'", $this -> get['code']);
$res = pg_fetch_all(pg_query($this -> dbconn, $sql_cmd));
if (count($res) > 2e6)

View File

@@ -18,11 +18,10 @@ class ENodeConfigure {
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");
$res[] = pg_query($this -> dbconn, sprintf(
"CREATE TABLE IF NOT EXISTS %s (
'CREATE TABLE IF NOT EXISTS "%s" (
id serial8,
code text references hf_mes_scada_data_capture_node_configure(code),
v_string text,
@@ -32,7 +31,7 @@ class ENodeConfigure {
device_code text,
batch text,
capture_time timestamp NOT NULL DEFAULT NOW()
)", $table_name
)', $table_name
));
$res[] = pg_insert(
$this -> dbconn,
@@ -47,11 +46,11 @@ class ENodeConfigure {
", $table_name
));
if (!in_array($table_name, pg_fetch_all_columns($table_exists, 1))) {
$res[] = pg_query($this -> dbconn, sprintf("SELECT create_hypertable('%s', 'capture_time')", $table_name));
$res[] = pg_query($this -> dbconn, sprintf("SELECT create_hypertable('\"%s\"', 'capture_time')", $table_name));
$res[] = pg_query($this -> dbconn, sprintf(
"CREATE INDEX ON %s (v_string, v_int, v_float, v_bool, capture_time DESC)
'CREATE INDEX ON "%s" (v_string, v_int, v_float, v_bool, capture_time DESC)
WHERE COALESCE(v_string, v_int::text, v_float::text, v_bool::text) IS NOT NULL
", $table_name
', $table_name
));
}
@@ -73,12 +72,12 @@ class ENodeConfigure {
);
$exists = pg_query(sprintf(
"SELECT EXISTS(
SELECT 1 FROM hf_mes_scada_data_capture_node_configure WHERE code='%s'
SELECT 1 FROM hf_mes_scada_data_capture_node_configure WHERE working_subclass = '%s'
)", $this -> post -> working_subclass
));
if (pg_fetch_assoc($exists)['exists'] == 'f') {
$res[] = pg_query(sprintf(
"DROP TABLE hf_mes_scada_data_capture_node_data_%s",
'DROP TABLE "hf_mes_scada_data_capture_node_data_%s"',
$this -> post -> working_subclass
));
}