#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
{
/// The generate statement command base.
public abstract class GenerateStatementCommandBase : CommandBase
{
/// The _sql writer.
private ISqlWriter _sqlWriter;
/// Initializes a new instance of the class.
/// The name.
public GenerateStatementCommandBase(string name)
: base(name)
{
}
/// Gets SqlWriter.
protected ISqlWriter SqlWriter
{
get
{
if (_sqlWriter == null)
{
_sqlWriter = Services.Resolve();
}
return _sqlWriter;
}
}
/// The get table or view by name.
/// The model.
/// The table name.
///
protected DbModelTable GetTableOrViewByName(DbModelInstance model, string tableName)
{
DbModelTable tableOrView = model.FindTable(tableName);
if (tableOrView == null)
{
// check the views
tableOrView = model.FindView(tableName);
}
return tableOrView;
}
/// The trim trailing comma.
/// The sql.
/// The trim trailing comma.
protected string TrimTrailingComma(string sql)
{
if (sql != null && sql.TrimEnd().EndsWith(","))
{
string tmp = sql.TrimEnd();
return tmp.Substring(0, tmp.Length - 1);
}
return sql;
}
}
}