Ejemplo n.º 1
0
        internal SqlBuilder GetCountSql <TRecord>(Query <TRecord> aQuery
                                                  , RecordViewTableMap <TRecord> aRecordViewTableMap = null)
            where TRecord : class, IRecord, new()
        {
            //サブクラスでSqlPod.CountSql()にSQLが定義されていなければ、
            //SELECT文にSELECT COUNT(*)を付加する
            if (this.CountSql() == null)
            {
                SqlBuilder selectSql = this.GetSelectSql(aQuery, aRecordViewTableMap);
                selectSql.ClearOrderBy();
                //Return "SELECT COUNT(*) FROM (" + selectSql + ") V1_"
                selectSql.SetCount();
                return(selectSql);
            }

            SqlBuilder sql = this.CountSql();

            //Query.RowRange()で抽出条件が指定されている場合
            if (aQuery.GetRowRange() != null & aRecordViewTableMap != null)
            {
                int begin = aQuery.GetRowRange().Item1;
                int end   = aQuery.GetRowRange().Item2;
                sql.SetRowLimit(begin, end);
            }

            //Pervasiveを除くDBMSではWHERE句などにAS別名は使用できない
            sql.WrapInSelectStar(aRecordViewTableMap.GetAllColumns(sql));

            //最大抽出件数の設定
            //OracleのRowNumによる指定は、SELECT * FROMに指定する
            if (aQuery.GetMaxRows() >= 0)
            {
                sql.SetMaxRows(aQuery.GetMaxRows());
            }

            //AND条件の追加
            if (sql.GetAutoWhere())
            {
                sql.AddAndPredicate(aQuery.GetWhereExp());
            }

            return(sql);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// SELECT文を取得する
        /// </summary>
        /// <param name="aQuery">最大抽出件数,AND条件,OrderBy句,プレースホルダ値をQueryオブジェクトで指定する</param>
        /// <returns></returns>
        /// <remarks>PervasiveはWhere句などにAS別名が使用できるので、
        /// SelectSql()で生成したSQLを抱合するSELECT文は必要ない。(Oracleでは必要)</remarks>
        internal SqlBuilder GetSelectSql <TRecord>(Query <TRecord> aQuery
                                                   , RecordViewTableMap <TRecord> aRecordViewTableMap)
            where TRecord : class, IRecord, new()
        {
            SqlBuilder sql = this.SelectSql();

            // OrderBy句の追加
            // (WrapInSelectStar()でOrderBy句の変換処理を行うのでWrapInSelectStar()の前に処理する)
            sql.AddOrderBy(aQuery.GetOrderByExp());

            // AS別名とテーブル列名が重複する場合にSQL実行エラーになることがあるため
            // 全てのSELECT文についてSELECT * で囲む
            sql.WrapInSelectStar(aRecordViewTableMap.GetAllColumns(sql));

            //最大抽出件数の設定
            //OracleのRowNumによる指定は、SELECT * FROMに指定する
            if (aQuery.GetMaxRows() >= 0)
            {
                sql.SetMaxRows(aQuery.GetMaxRows());
            }

            if (sql.GetAutoWhere())
            {
                //AND条件の追加
                sql.AddAndPredicate(aQuery.GetWhereExp());
            }

            //Query.RowRange()で抽出条件が指定されている場合
            if (aQuery.GetRowRange() != null)
            {
                int begin = aQuery.GetRowRange().Item1;
                int end   = aQuery.GetRowRange().Item2;
                sql.SetRowLimit(begin, end);
            }

            return(sql);
        }