Ejemplo n.º 1
0
        /// <summary>
        ///  查询返回第一行第一列字段的值
        /// </summary>
        /// <typeparam name="TResult">接受查询结果类型</typeparam>
        /// <param name="field">查询的字段</param>
        /// <returns></returns>
        public TResult ToScalar <TResult>(string field)
        {
            Fields.Clear();
            Fields.Add(field);
            string cmdText = ToString();
            object result  = null;

            if (Master)
            {
                result = PgSqlHelper.ExecuteScalar(CommandType.Text, cmdText, command =>
                {
                    this.Command    = command;
                    this.Connection = command?.Connection;
                }, this.ParamList.ToArray());
            }
            else
            {
                result = PgSqlHelper.ExecuteScalarSlave(CommandType.Text, cmdText, command =>
                {
                    this.Command    = command;
                    this.Connection = command?.Connection;
                }, this.ParamList.ToArray());
            }
            return((TResult)result);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///  查询返回第一行第一列字段的值
        /// </summary>
        /// <typeparam name="TResult">接受查询结果类型</typeparam>
        /// <param name="field">查询的字段</param>
        /// <returns></returns>
        public TResult ToScalar <TResult>(string field)
        {
            Fields.Clear();
            Fields.Add(field);
            string cmdText = ToString();
            object _val    = null;

            if (PgSqlHelper.InstanceSlave != null && !this.Master)
            {
                _val = PgSqlHelper.ExecuteScalarSlave(CommandType.Text, cmdText, this.ParamList.ToArray());
            }
            else
            {
                _val = PgSqlHelper.ExecuteScalar(CommandType.Text, cmdText, this.ParamList.ToArray());
            }

            return((TResult)_val);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///  查询返回第一行第一列字段的值
        /// </summary>
        /// <typeparam name="TResult">接受查询结果类型</typeparam>
        /// <param name="field">查询的字段</param>
        /// <returns></returns>
        public TResult ToScalar <TResult>(string field)
        {
            if (!string.IsNullOrEmpty(GroupByText))
            {
                throw new ArgumentException("聚合查询不允许使用 GROUP BY 条件!");
            }

            Fields.Clear();
            Fields.Add(field);
            string cmdText = ToSQL();
            object result  = null;

            if (Master)
            {
                result = PgSqlHelper.ExecuteScalar(CommandType.Text, cmdText, command =>
                {
                    this.Command    = command;
                    this.Connection = command?.Connection;
                }, this.ParamList.ToArray());
            }
            else
            {
                result = PgSqlHelper.ExecuteScalarSlave(CommandType.Text, cmdText, command =>
                {
                    this.Command    = command;
                    this.Connection = command?.Connection;
                }, this.ParamList.ToArray());
            }
            // Clear();
            if (result == null)
            {
                return(default(TResult));
            }
            else
            {
                return((TResult)result);
            }
        }