miniSql

创建
zgc123@gmail.com authored at 11/19/2023 1:40:15 AM
6136600
Tree
0 Parent(s)
Summary: 1 changed files with 70 additions and 0 deletions.
Added +70 -0
Added +70 -0
diff --git a/minisqlquery-master/src/MiniSqlQuery/PlugIns/DatabaseInspector/Commands/GenerateStatementCommandBase.cs b/minisqlquery-master/src/MiniSqlQuery/PlugIns/DatabaseInspector/Commands/GenerateStatementCommandBase.cs
new file mode 100644
index 0000000..1464746
--- /dev/null
+++ b/minisqlquery-master/src/MiniSqlQuery/PlugIns/DatabaseInspector/Commands/GenerateStatementCommandBase.cs
@@ -0,0 +1,70 @@
+#region License
+
+// Copyright 2005-2019 Paul Kohler (https://github.com/paulkohler/minisqlquery). All rights reserved.
+// This source code is made available under the terms of the GNU Lesser General Public License v3.0
+// https://github.com/paulkohler/minisqlquery/blob/master/LICENSE
+#endregion
+
+using MiniSqlQuery.Core.Commands;
+using MiniSqlQuery.Core.DbModel;
+
+namespace MiniSqlQuery.PlugIns.DatabaseInspector.Commands
+{
+    /// <summary>The generate statement command base.</summary>
+    public abstract class GenerateStatementCommandBase : CommandBase
+    {
+        /// <summary>The _sql writer.</summary>
+        private ISqlWriter _sqlWriter;
+
+        /// <summary>Initializes a new instance of the <see cref="GenerateStatementCommandBase"/> class.</summary>
+        /// <param name="name">The name.</param>
+        public GenerateStatementCommandBase(string name)
+            : base(name)
+        {
+        }
+
+        /// <summary>Gets SqlWriter.</summary>
+        protected ISqlWriter SqlWriter
+        {
+            get
+            {
+                if (_sqlWriter == null)
+                {
+                    _sqlWriter = Services.Resolve<ISqlWriter>();
+                }
+
+                return _sqlWriter;
+            }
+        }
+
+        /// <summary>The get table or view by name.</summary>
+        /// <param name="model">The model.</param>
+        /// <param name="tableName">The table name.</param>
+        /// <returns></returns>
+        protected DbModelTable GetTableOrViewByName(DbModelInstance model, string tableName)
+        {
+            DbModelTable tableOrView = model.FindTable(tableName);
+            if (tableOrView == null)
+            {
+                // check the views
+                tableOrView = model.FindView(tableName);
+            }
+
+            return tableOrView;
+        }
+
+        /// <summary>The trim trailing comma.</summary>
+        /// <param name="sql">The sql.</param>
+        /// <returns>The trim trailing comma.</returns>
+        protected string TrimTrailingComma(string sql)
+        {
+            if (sql != null && sql.TrimEnd().EndsWith(","))
+            {
+                string tmp = sql.TrimEnd();
+                return tmp.Substring(0, tmp.Length - 1);
+            }
+
+            return sql;
+        }
+    }
+}
\ No newline at end of file