增加对大写字母的表名的适配
This commit is contained in:
@@ -56,8 +56,8 @@ class EDataCapture {
|
|||||||
foreach ($this -> data as $code => $value) {
|
foreach ($this -> data as $code => $value) {
|
||||||
foreach (array_chunk($value, 6710885, true) as $chunk) {
|
foreach (array_chunk($value, 6710885, true) as $chunk) {
|
||||||
$sql_head = sprintf(
|
$sql_head = sprintf(
|
||||||
"INSERT INTO hf_mes_scada_data_capture_node_data_%s (code, v_%s, device_code, batch)
|
'INSERT INTO "hf_mes_scada_data_capture_node_data_%s" (code, v_%s, device_code, batch)
|
||||||
VALUES",
|
VALUES',
|
||||||
$this -> working_subclass,
|
$this -> working_subclass,
|
||||||
$this -> code_type[$code]
|
$this -> code_type[$code]
|
||||||
);
|
);
|
||||||
@@ -101,9 +101,9 @@ class EDataCapture {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$sql_cmd = sprintf(
|
$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
|
'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
|
FROM "hf_mes_scada_data_capture_node_data_%s"
|
||||||
WHERE capture_time >= '%s' AND capture_time <= '%s'",
|
WHERE capture_time >= \'%s\' AND capture_time <= \'%s\'',
|
||||||
$this -> get['working_subclass'],
|
$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['start_time'] / 1000),
|
||||||
date("Y-m-d H:i:s", $this -> get['end_time'] / 1000)
|
date("Y-m-d H:i:s", $this -> get['end_time'] / 1000)
|
||||||
|
|||||||
@@ -18,11 +18,10 @@ class ENodeConfigure {
|
|||||||
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");
|
pg_query($this -> dbconn, "BEGIN");
|
||||||
$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,
|
||||||
code text references hf_mes_scada_data_capture_node_configure(code),
|
code text references hf_mes_scada_data_capture_node_configure(code),
|
||||||
v_string text,
|
v_string text,
|
||||||
@@ -32,7 +31,7 @@ class ENodeConfigure {
|
|||||||
device_code text,
|
device_code text,
|
||||||
batch text,
|
batch text,
|
||||||
capture_time timestamp NOT NULL DEFAULT NOW()
|
capture_time timestamp NOT NULL DEFAULT NOW()
|
||||||
)", $table_name
|
)', $table_name
|
||||||
));
|
));
|
||||||
$res[] = pg_insert(
|
$res[] = pg_insert(
|
||||||
$this -> dbconn,
|
$this -> dbconn,
|
||||||
@@ -47,11 +46,11 @@ class ENodeConfigure {
|
|||||||
", $table_name
|
", $table_name
|
||||||
));
|
));
|
||||||
if (!in_array($table_name, pg_fetch_all_columns($table_exists, 1))) {
|
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(
|
$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
|
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(
|
$exists = pg_query(sprintf(
|
||||||
"SELECT EXISTS(
|
"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
|
)", $this -> post -> working_subclass
|
||||||
));
|
));
|
||||||
if (pg_fetch_assoc($exists)['exists'] == 'f') {
|
if (pg_fetch_assoc($exists)['exists'] == 'f') {
|
||||||
$res[] = pg_query(sprintf(
|
$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
|
$this -> post -> working_subclass
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user