Преглед изворни кода

修改超级表

mqy20260511
lenovo пре 2 недеља
родитељ
комит
2e06aefae5
1 измењених фајлова са 5 додато и 5 уклоњено
  1. 5
    5
      iot-platform/src/main/java/com/iot/platform/service/TdEngineService.java

+ 5
- 5
iot-platform/src/main/java/com/iot/platform/service/TdEngineService.java Прегледај датотеку

196
 
196
 
197
             // 创建超级表:固定 ts + surfacename,无 ext_data 列
197
             // 创建超级表:固定 ts + surfacename,无 ext_data 列
198
             String stableSql = String.format(
198
             String stableSql = String.format(
199
-                    "CREATE STABLE IF NOT EXISTS %s.%s (ts TIMESTAMP, surfacename VARCHAR(64)) TAGS (location BINARY(64))",
199
+                    "CREATE STABLE IF NOT EXISTS %s.%s (ts TIMESTAMP, surfacename VARCHAR(64)) TAGS (location VARCHAR(255))",
200
                     wrapName(dbName),
200
                     wrapName(dbName),
201
                     wrapName(superTableName)
201
                     wrapName(superTableName)
202
             );
202
             );
540
         }
540
         }
541
 
541
 
542
         try (Connection conn = getConnection()) {
542
         try (Connection conn = getConnection()) {
543
-            // 检查超级表是否存在 — 使用 PreparedStatement 防止 SQL 注入
544
-            String checkStableSql = "SELECT * FROM information_schema.ins_tables WHERE table_name = ? AND db_name = ?";
543
+            // 检查超级表是否存在(stable_name 字段标识超级表)
544
+            String checkStableSql = "SELECT * FROM information_schema.ins_tables WHERE stable_name = ? AND db_name = ?";
545
             try (PreparedStatement pStmt = conn.prepareStatement(checkStableSql)) {
545
             try (PreparedStatement pStmt = conn.prepareStatement(checkStableSql)) {
546
                 pStmt.setString(1, superTableName);
546
                 pStmt.setString(1, superTableName);
547
                 pStmt.setString(2, dbName);
547
                 pStmt.setString(2, dbName);
555
                 }
555
                 }
556
             }
556
             }
557
 
557
 
558
-            // 检查子表是否存在 — 使用 PreparedStatement 防止 SQL 注入
558
+            // 检查子表是否存在
559
             String checkTableSql = "SELECT * FROM information_schema.ins_tables " +
559
             String checkTableSql = "SELECT * FROM information_schema.ins_tables " +
560
-                    "WHERE table_name = ? AND db_name = ? AND table_type = 'CHILD_TABLE'";
560
+                    "WHERE table_name = ? AND db_name = ? AND type = 'CHILD_TABLE'";
561
             try (PreparedStatement pStmt = conn.prepareStatement(checkTableSql)) {
561
             try (PreparedStatement pStmt = conn.prepareStatement(checkTableSql)) {
562
                 pStmt.setString(1, table);
562
                 pStmt.setString(1, table);
563
                 pStmt.setString(2, dbName);
563
                 pStmt.setString(2, dbName);

Loading…
Откажи
Сачувај