From 1f979955d21690fbdfb5580872c988e0ab0fe41c Mon Sep 17 00:00:00 2001 From: xuefengping02 Date: Sun, 16 Oct 2022 21:53:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=A4=E6=96=AD=E4=B8=B4?= =?UTF-8?q?=E6=97=B6=E8=A1=A8=E6=98=AF=E5=90=A6=E5=AD=98=E5=9C=A8=E7=9A=84?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/DatabaseObjectCommonUtil.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/caf-database-object-common/src/main/java/io/iec/edp/caf/databaseobject/common/DatabaseObjectCommonUtil.java b/caf-database-object-common/src/main/java/io/iec/edp/caf/databaseobject/common/DatabaseObjectCommonUtil.java index 779e60b..7f7a299 100644 --- a/caf-database-object-common/src/main/java/io/iec/edp/caf/databaseobject/common/DatabaseObjectCommonUtil.java +++ b/caf-database-object-common/src/main/java/io/iec/edp/caf/databaseobject/common/DatabaseObjectCommonUtil.java @@ -721,6 +721,54 @@ public class DatabaseObjectCommonUtil { return tables; } + /** + * 判断系统中临时表是否存在 + * + * @param db db + * @return 表名 + */ + public static boolean tempTableIsExist(DBInfo db,String tableName) { + boolean result=false; + String sql = null; + if (db.getDbType() == DbType.Oracle || db.getDbType() == DbType.DM || db.getDbType() == DbType.Oscar) { + sql = "select OBJECT_NAME from ALL_OBJECTS where temporary = 'Y' and OBJECT_NAME = '"+tableName+"'"; + } else if (db.getDbType() == DbType.PgSQL || db.getDbType() == DbType.HighGo) { + sql = "select relname from pg_class where relname='"+tableName+"'"; + } else if (db.getDbType() == DbType.MySQL) { + return false; + } else if (db.getDbType() == DbType.SQLServer) { + sql = "select object_id(N'tempdb.."+tableName+"',N'U')"; + } else if (db.getDbType() == DbType.Kingbase) { + sql = "select 1 from sys_tables where tablename = '"+tableName+"'"; + } else if (db.getDbType() == DbType.DB2) { + return false; + } else { + return false; + } + GspDatabase gspDatabase = GspDbFactory.getDatabase(db); + ResultSet resultSet = null; + try { + resultSet = gspDatabase.executeResultSet(sql); + if (resultSet != null) { + if(resultSet.next()){ + result=true; + } + } + } catch (Exception e) { + throw new RuntimeException("获取数据库表时出错:", e); + } finally { + if (resultSet != null) { + try { + resultSet.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + gspDatabase.close(); + } + return result; + } + /** * 判断表中字段是否存在 * -- Gitee