From cdebd89918c1a5f589ea637a09b8eaa25c3fe947 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sun, 19 Mar 2023 23:41:45 +0800 Subject: [PATCH] Add db.DbMain.GetProcList --- .../SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs | 4 ++++ Src/Asp.Net/SqlSugar/Interface/IDbMaintenance.cs | 1 + .../Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs | 5 +++++ .../Realization/Oracle/DbMaintenance/OracleDbMaintenance.cs | 5 +++++ .../PostgreSQL/DbMaintenance/PostgreSQLDbMaintenance.cs | 5 +++++ .../SqlServer/DbMaintenance/SqlServerDbMaintenance.cs | 5 +++++ 6 files changed, 25 insertions(+) diff --git a/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs b/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs index 39584741d..ed4336f87 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs @@ -10,6 +10,10 @@ namespace SqlSugar public abstract partial class DbMaintenanceProvider : IDbMaintenance { #region DML + public virtual List GetProcList(string dbName) + { + return new List(); + } public virtual List GetDataBaseList(SqlSugarClient db) { return db.Ado.SqlQuery(this.GetDataBaseSql); diff --git a/Src/Asp.Net/SqlSugar/Interface/IDbMaintenance.cs b/Src/Asp.Net/SqlSugar/Interface/IDbMaintenance.cs index dcde3ef14..ab884e381 100644 --- a/Src/Asp.Net/SqlSugar/Interface/IDbMaintenance.cs +++ b/Src/Asp.Net/SqlSugar/Interface/IDbMaintenance.cs @@ -16,6 +16,7 @@ namespace SqlSugar List GetColumnInfosByTableName(string tableName,bool isCache=true); List GetIsIdentities(string tableName); List GetPrimaries(string tableName); + List GetProcList(string dbName); #endregion #region Check diff --git a/Src/Asp.Net/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs b/Src/Asp.Net/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs index b3b49d471..6c2b9f25e 100644 --- a/Src/Asp.Net/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs +++ b/Src/Asp.Net/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs @@ -282,6 +282,11 @@ namespace SqlSugar #endregion #region Methods + public override List GetProcList(string dbName) + { + var sql = $"SELECT ROUTINE_NAME FROM information_schema.ROUTINES WHERE ROUTINE_TYPE = 'PROCEDURE' AND ROUTINE_SCHEMA = '{dbName}'"; + return this.Context.Ado.SqlQuery(sql); + } public override bool IsAnyTable(string tableName, bool isCache = true) { try diff --git a/Src/Asp.Net/SqlSugar/Realization/Oracle/DbMaintenance/OracleDbMaintenance.cs b/Src/Asp.Net/SqlSugar/Realization/Oracle/DbMaintenance/OracleDbMaintenance.cs index 81f20419e..4dfcb8d6a 100644 --- a/Src/Asp.Net/SqlSugar/Realization/Oracle/DbMaintenance/OracleDbMaintenance.cs +++ b/Src/Asp.Net/SqlSugar/Realization/Oracle/DbMaintenance/OracleDbMaintenance.cs @@ -272,6 +272,11 @@ namespace SqlSugar #endregion #region Methods + public override List GetProcList(string dbName) + { + var sql = $"SELECT OBJECT_NAME FROM ALL_OBJECTS WHERE OBJECT_TYPE = 'PROCEDURE' AND OWNER = '{dbName.ToUpper()}'"; + return this.Context.Ado.SqlQuery(sql); + } public override bool AddColumn(string tableName, DbColumnInfo columnInfo) { if (columnInfo.DataType == "varchar"&& columnInfo.Length ==0) diff --git a/Src/Asp.Net/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLDbMaintenance.cs b/Src/Asp.Net/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLDbMaintenance.cs index 47d02dd1a..de9920539 100644 --- a/Src/Asp.Net/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLDbMaintenance.cs +++ b/Src/Asp.Net/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLDbMaintenance.cs @@ -249,6 +249,11 @@ namespace SqlSugar #endregion #region Methods + public override List GetProcList(string dbName) + { + var sql = $"SELECT proname FROM pg_proc p JOIN pg_namespace n ON p.pronamespace = n.oid WHERE n.nspname = '{dbName}'"; + return this.Context.Ado.SqlQuery(sql); + } public override bool AddDefaultValue(string tableName, string columnName, string defaultValue) { return base.AddDefaultValue(this.SqlBuilder.GetTranslationTableName(tableName), this.SqlBuilder.GetTranslationTableName(columnName), defaultValue); diff --git a/Src/Asp.Net/SqlSugar/Realization/SqlServer/DbMaintenance/SqlServerDbMaintenance.cs b/Src/Asp.Net/SqlSugar/Realization/SqlServer/DbMaintenance/SqlServerDbMaintenance.cs index f9aa18265..a8679df8a 100644 --- a/Src/Asp.Net/SqlSugar/Realization/SqlServer/DbMaintenance/SqlServerDbMaintenance.cs +++ b/Src/Asp.Net/SqlSugar/Realization/SqlServer/DbMaintenance/SqlServerDbMaintenance.cs @@ -321,6 +321,11 @@ namespace SqlSugar #endregion #region Methods + public override List GetProcList(string dbName) + { + var sql = $"SELECT name FROM {dbName}.sys.procedures"; + return this.Context.Ado.SqlQuery(sql); + } public override bool UpdateColumn(string tableName, DbColumnInfo column) { if (column.DataType != null && this.Context.CurrentConnectionConfig?.MoreSettings?.SqlServerCodeFirstNvarchar == true)