コード例 #1
0
 private void AddParams_Having(
     ISqlObjectFactory factory,
     ISqlCommand sqlCommand,
     SqlHavingCollection sqlHavingCollection,
     int?commandCount)
 {
     sqlHavingCollection?
     .Where(o => o.Using)
     .Where(o => o.Value != null)
     .ForEach(sqlHaving =>
     {
         if (sqlHaving.Value.IsCollection())
         {
             (sqlHaving.Value.ToObjectEnumerable())
             .Select((o, i) => new { Value = o, Index = i })
             .ForEach(data =>
                      AddParam(
                          factory,
                          sqlCommand,
                          sqlHaving.TableName + data.Index + "_",
                          data.Value,
                          commandCount));
         }
         else
         {
             AddParam(
                 factory,
                 sqlCommand,
                 sqlHaving.TableName,
                 sqlHaving.Value,
                 commandCount);
         }
     });
 }
コード例 #2
0
ファイル: SqlHaving.cs プロジェクト: kazuca/Implem.Pleasanter
 public SqlHaving(
     string columnBracket,
     string tableName          = null,
     object value              = null,
     string _operator          = "=",
     string multiParamOperator = " and ",
     SqlStatement sub          = null,
     string raw              = null,
     SqlHavingCollection or  = null,
     Sqls.Functions function = Sqls.Functions.None,
     bool subPrefix          = true,
     bool _using             = true)
 {
     ColumnBracket      = columnBracket;
     TableName          = tableName;
     Value              = value;
     Operator           = _operator;
     MultiParamOperator = multiParamOperator;
     Sub       = sub;
     Raw       = raw;
     Or        = or;
     Function  = function;
     SubPrefix = subPrefix;
     Using     = _using;
 }
コード例 #3
0
        private void BuildCommandText(
            ISqlObjectFactory factory,
            SqlContainer sqlContainer,
            ISqlCommand sqlCommand,
            StringBuilder commandText,
            Sqls.TableTypes tableType,
            Sqls.UnionTypes unionType,
            bool orderBy,
            int?commandCount)
        {
            if (!Using)
            {
                return;
            }
            AddUnion(commandText, unionType);
            SqlColumnCollection?.BuildCommandText(
                factory: factory,
                sqlContainer: sqlContainer,
                sqlCommand: sqlCommand,
                commandText: commandText,
                commandCount: commandCount,
                distinct: Distinct,
                top: Top);
            var from = From(tableType, As);

            commandText.Append(from);
            SqlJoinCollection?.BuildCommandText(commandText: commandText);
            SqlWhereCollection?.BuildCommandText(
                factory: factory,
                sqlContainer: sqlContainer,
                sqlCommand: sqlCommand,
                commandText: commandText,
                commandCount: commandCount,
                select: true);
            SqlGroupByCollection?.BuildCommandText(
                commandText: commandText);
            SqlHavingCollection?.BuildCommandText(
                factory: factory,
                sqlContainer: sqlContainer,
                sqlCommand: sqlCommand,
                commandText: commandText,
                commandCount: commandCount);
            if (orderBy)
            {
                SqlOrderByCollection?.BuildCommandText(
                    commandText: commandText,
                    pageSize: PageSize,
                    tableType: TableType,
                    commandCount: commandCount);
            }
            commandText.Append(
                factory.SqlCommandText.CreateLimitClause(limit: Top));
            AddTermination(commandText);
            AddParams_Where(factory, sqlCommand, commandCount);
            AddParams_Having(factory, sqlCommand, commandCount);
            AddParams_Paging(factory, sqlCommand, commandCount);
            AddParams_Param(factory, sqlCommand, commandCount);
        }
コード例 #4
0
 public SqlHavingCollection Add(
     string columnBracket      = null,
     string name               = "",
     object value              = null,
     string _operator          = "=",
     string multiParamOperator = " and ",
     SqlStatement sub          = null,
     string raw             = "",
     SqlHavingCollection or = null,
     bool _using            = true)
 {
     Add(new SqlHaving(
             columnBracket: columnBracket,
             tableName: name,
             value: value,
             _operator: _operator,
             multiParamOperator: multiParamOperator,
             sub: sub,
             raw: raw,
             _using: _using));
     return(this);
 }
コード例 #5
0
        private void BuildCommandText(
            SqlContainer sqlContainer,
            SqlCommand sqlCommand,
            StringBuilder commandText,
            Sqls.TableTypes tableType,
            Sqls.UnionTypes unionType,
            bool orderBy,
            bool countRecord,
            int?commandCount)
        {
            if (!Using)
            {
                return;
            }
            if (!DataTableName.IsNullOrEmpty())
            {
                sqlContainer.DataTableNames.Add(DataTableName);
            }
            AddUnion(commandText, unionType);
            SqlColumnCollection?.BuildCommandText(
                sqlContainer: sqlContainer,
                sqlCommand: sqlCommand,
                commandText: commandText,
                commandCount: commandCount,
                distinct: Distinct,
                top: Top);
            var from = From(tableType, As);

            commandText.Append(from);
            SqlJoinCollection?.BuildCommandText(commandText: commandText);
            SqlWhereCollection?.BuildCommandText(
                sqlContainer: sqlContainer,
                sqlCommand: sqlCommand,
                commandText: commandText,
                commandCount: commandCount,
                select: true);
            SqlGroupByCollection?.BuildCommandText(
                commandText: commandText);
            SqlHavingCollection?.BuildCommandText(
                sqlContainer: sqlContainer,
                sqlCommand: sqlCommand,
                commandText: commandText,
                commandCount: commandCount);
            if (orderBy)
            {
                SqlOrderByCollection?.BuildCommandText(
                    commandText: commandText,
                    pageSize: PageSize,
                    tableType: TableType,
                    commandCount: commandCount);
            }
            AddTermination(commandText);
            if (countRecord)
            {
                sqlContainer.DataTableNames.Add("Count");
                commandText.Append("select count(*) from ( select 1 as [c] ");
                commandText.Append(from);
                SqlJoinCollection?.BuildCommandText(commandText: commandText);
                SqlWhereCollection?.BuildCommandText(
                    sqlContainer: sqlContainer,
                    sqlCommand: sqlCommand,
                    commandText: commandText,
                    commandCount: commandCount,
                    select: true);
                SqlGroupByCollection?.BuildCommandText(
                    commandText: commandText);
                SqlHavingCollection?.BuildCommandText(
                    sqlContainer: sqlContainer,
                    sqlCommand: sqlCommand,
                    commandText: commandText,
                    commandCount: commandCount);
                commandText.Append(") as [table_count]");
                AddTermination(commandText);
            }
            AddParams_Where(sqlCommand, commandCount);
            AddParams_Having(sqlCommand, commandCount);
            AddParams_Paging(sqlCommand, commandCount);
            AddParams_Param(sqlCommand, commandCount);
        }