Example #1
0
 /// <summary>
 /// 初始化一个<see cref="WhereClauseTest"/>类型的实例
 /// </summary>
 public WhereClauseTest(ITestOutputHelper output) : base(output)
 {
     _parameterManager = new ParameterManager(new OracleDialect());
     _database         = new TestTableDatabase();
     _builder          = new OracleBuilder(new TestEntityMatedata(), _database, _parameterManager);
     _clause           = new WhereClause(_builder, new OracleDialect(), new EntityResolver(), new EntityAliasRegister(), _parameterManager);
 }
Example #2
0
 /// <summary>
 /// 初始化一个<see cref="FromClause"/>类型的实例
 /// </summary>
 /// <param name="builder">Sql生成器</param>
 /// <param name="dialect">Sql方言</param>
 /// <param name="resolver">实体解析器</param>
 /// <param name="register">实体别名注册器</param>
 /// <param name="tableDatabase">表数据库</param>
 /// <param name="table">表</param>
 public FromClause(ISqlBuilder builder, IDialect dialect, IEntityResolver resolver, IEntityAliasRegister register, ITableDatabase tableDatabase, SqlItem table = null)
 {
     Builder       = builder;
     Dialect       = dialect;
     Resolver      = resolver;
     Register      = register;
     TableDatabase = tableDatabase;
     Table         = table;
 }
Example #3
0
 /// <summary>
 /// 初始化一个<see cref="FromClause"/>类型的实例
 /// </summary>
 /// <param name="builder">Sql生成器</param>
 /// <param name="dialect">Sql方言</param>
 /// <param name="resolver">实体解析器</param>
 /// <param name="register">实体别名注册器</param>
 /// <param name="tableDatabase">表数据库</param>
 /// <param name="table">表</param>
 public SqliteFromClause(ISqlBuilder builder
                         , IDialect dialect
                         , IEntityResolver resolver
                         , IEntityAliasRegister register
                         , ITableDatabase tableDatabase
                         , SqlItem table = null)
     : base(builder, dialect, resolver, register, tableDatabase, table)
 {
 }
 /// <summary>
 /// 初始化一个<see cref="JoinClause"/>类型的实例
 /// </summary>
 /// <param name="sqlBuilder">Sql生成器</param>
 /// <param name="dialect">Sql方言</param>
 /// <param name="resolver">实体解析器</param>
 /// <param name="register">实体别名注册器</param>
 /// <param name="parameterManager">参数管理器</param>
 /// <param name="tableDatabase">表数据库</param>
 public SqliteJoinClause(ISqlBuilder sqlBuilder
                         , IDialect dialect
                         , IEntityResolver resolver
                         , IEntityAliasRegister register
                         , IParameterManager parameterManager
                         , ITableDatabase tableDatabase)
     : base(sqlBuilder, dialect, resolver, register, parameterManager, tableDatabase)
 {
 }
 /// <summary>
 /// 初始化Sql生成器
 /// </summary>
 /// <param name="matedata">实体元数据解析器</param>
 /// <param name="tableDatabase">表数据库</param>
 /// <param name="parameterManager">参数管理器</param>
 protected SqlBuilderBase(IEntityMatedata matedata = null, ITableDatabase tableDatabase = null, IParameterManager parameterManager = null)
 {
     EntityMatedata    = matedata;
     TableDatabase     = tableDatabase;
     _parameterManager = parameterManager;
     EntityResolver    = new EntityResolver(matedata);
     AliasRegister     = new EntityAliasRegister();
     Pager             = new Pager();
     UnionItems        = new List <BuilderItem>();
     CteItems          = new List <BuilderItem>();
 }
Example #6
0
 /// <summary>
 /// 初始化表连接子句
 /// </summary>
 /// <param name="sqlBuilder">Sql生成器</param>
 /// <param name="dialect">方言</param>
 /// <param name="resolver">实体解析器</param>
 /// <param name="register">实体别名注册器</param>
 /// <param name="parameterManager">参数管理器</param>
 /// <param name="tableDatabase">表数据库</param>
 /// <param name="joinItems">连接参数列表</param>
 public JoinClause(ISqlBuilder sqlBuilder, IDialect dialect, IEntityResolver resolver, IEntityAliasRegister register,
                   IParameterManager parameterManager, ITableDatabase tableDatabase, List <JoinItem> joinItems = null)
 {
     _sqlBuilder       = sqlBuilder;
     _dialect          = dialect;
     _resolver         = resolver;
     _register         = register;
     _parameterManager = parameterManager;
     TableDatabase     = tableDatabase;
     _helper           = new Helper(dialect, resolver, register, parameterManager);
     _params           = joinItems ?? new List <JoinItem>();
 }
Example #7
0
 /// <summary>
 /// 获取Sql
 /// </summary>
 public virtual string ToSql(IDialect dialect = null, ITableDatabase tableDatabase = null)
 {
     if (string.IsNullOrWhiteSpace(Name))
     {
         return(null);
     }
     if (Raw)
     {
         return(Name);
     }
     return(string.IsNullOrWhiteSpace(Alias) ? GetColumn(dialect, tableDatabase) : GetColumnAlias(dialect, tableDatabase));
 }
Example #8
0
 /// <summary>
 /// 获取Sql
 /// </summary>
 public string ToSql(IDialect dialect = null, ITableDatabase tableDatabase = null)
 {
     if (string.IsNullOrWhiteSpace(Name))
     {
         return(null);
     }
     if (Raw)
     {
         return(Name);
     }
     return(string.IsNullOrWhiteSpace(Alias) ? GetColumn(dialect, tableDatabase) : $"{GetColumn( dialect, tableDatabase )} As {GetSafeName( dialect, Alias )}");
 }
Example #9
0
        /// <summary>
        /// 获取Sql
        /// </summary>
        /// <param name="dialect">Sql方言</param>
        /// <param name="tableDatabase">表数据库</param>
        public virtual string ToSql(IDialect dialect = null, ITableDatabase tableDatabase = null)
        {
            if (string.IsNullOrWhiteSpace(Name))
            {
                return(null);
            }
            if (Raw)
            {
                return(Name);
            }
            var column      = GetColumn(dialect, tableDatabase);
            var columnAlias = GetSafeName(dialect, Alias);

            return(dialect.GetColumn(column, columnAlias));
        }
Example #10
0
        /// <summary>
        /// 获取列
        /// </summary>
        protected string GetColumn(IDialect dialect, ITableDatabase tableDatabase)
        {
            var result   = new StringBuilder();
            var database = DatabaseName;

            if (string.IsNullOrWhiteSpace(DatabaseName) && tableDatabase != null)
            {
                database = tableDatabase.GetDatabase(GetName());
            }
            if (string.IsNullOrWhiteSpace(database) == false)
            {
                result.Append($"{GetSafeName( dialect, database )}.");
            }
            if (string.IsNullOrWhiteSpace(Prefix) == false)
            {
                result.Append($"{GetSafeName( dialect, Prefix )}.");
            }
            result.Append(GetSafeName(dialect, Name));
            return(result.ToString());
        }
Example #11
0
 /// <summary>
 /// 初始化一个<see cref="PgSqlBuilder"/>类型的实例
 /// </summary>
 /// <param name="matedata">实体元数据解析器</param>
 /// <param name="tableDatabase">表数据库</param>
 /// <param name="parameterManager">参数管理器</param>
 public PgSqlBuilder(IEntityMatedata matedata = null, ITableDatabase tableDatabase = null, IParameterManager parameterManager = null) : base(matedata, tableDatabase, parameterManager)
 {
 }
Example #12
0
 /// <summary>
 /// 获取列名和别名
 /// </summary>
 /// <param name="dialect">Sql方言</param>
 /// <param name="tableDatabase">表数据库</param>
 protected override string GetColumnAlias(IDialect dialect, ITableDatabase tableDatabase) => $"{GetColumn(dialect, tableDatabase)} {GetSafeName(dialect, Alias)}";
Example #13
0
 /// <summary>
 /// 初始化一个<see cref="SqlItemTest"/>类型的实例
 /// </summary>
 public SqlItemTest(ITestOutputHelper output) : base(output)
 {
     _database = new TestTableDatabase();
 }
Example #14
0
 /// <summary>
 /// 初始化一个<see cref="FromClauseTest"/>类型的实例
 /// </summary>
 public FromClauseTest(ITestOutputHelper output) : base(output)
 {
     _database = new TestTableDatabase();
     _clause   = new OracleFromClause(null, new OracleDialect(), new EntityResolver(), new EntityAliasRegister(), null);
 }
Example #15
0
 /// <summary>
 /// 获取列名和别名
 /// </summary>
 protected virtual string GetColumnAlias(IDialect dialect, ITableDatabase tableDatabase)
 {
     return($"{GetColumn( dialect, tableDatabase )} As {GetSafeName( dialect, Alias )}");
 }
Example #16
0
        /// <summary>
        /// 获取Join语句
        /// </summary>
        public string ToSql(IDialect dialect = null, ITableDatabase tableDatabase = null)
        {
            var table = Table.ToSql(dialect, tableDatabase);

            return($"{JoinType} {table}{GetOn()}");
        }