Пример #1
0
 private protected void ClearError()
 {
     _lastError = default;
     PDO.ClearError();
 }
Пример #2
0
        /// <summary>
        /// Fetches the specified fetch style.
        /// </summary>
        /// <param name="fetch_style">Controls how the next row will be returned to the caller. This value must be one of the PDO::FETCH_* constants.</param>
        /// <param name="cursor_orientation">This value determines which row will be returned to the caller.</param>
        /// <param name="cursor_offet">Relative or absolute position move for the cursor.</param>
        /// <returns>The return value of this function on success depends on the fetch type. In all cases, FALSE is returned on failure.</returns>
        public virtual PhpValue fetch(PDO.PDO_FETCH fetch_style = PDO_FETCH.Default /*0*/, PDO_FETCH_ORI cursor_orientation = PDO_FETCH_ORI.FETCH_ORI_NEXT /*0*/, int cursor_offet = 0)
        {
            PDO.ClearError();

            if (cursor_orientation != PDO_FETCH_ORI.FETCH_ORI_NEXT) // 0
            {
                throw new NotImplementedException(cursor_orientation.ToString());
            }

            if (Result == null)
            {
                throw new InvalidOperationException();
            }

            try
            {
                var how   = fetch_style != PDO_FETCH.Default ? fetch_style : _default_fetch_type;
                var flags = how & PDO_FETCH.Flags;

                switch (how & ~PDO_FETCH.Flags)
                {
                case PDO_FETCH.Default:
                case PDO_FETCH.FETCH_BOTH:
                    return(Result.FetchArray(true, true) ?? PhpValue.False);

                case PDO_FETCH.FETCH_ASSOC:
                    return(Result.FetchAssocArray() ?? PhpValue.False);

                case PDO_FETCH.FETCH_NUM:
                    return(Result.FetchArray(true, false) ?? PhpValue.False);

                case PDO_FETCH.FETCH_OBJ:
                    return(ObjectOrFalse(Result.FetchStdClass()));

                case PDO_FETCH.FETCH_BOUND:
                    return(FetchBound());

                case PDO_FETCH.FETCH_COLUMN:
                    return(fetchColumn(_fetch_column));

                case PDO.PDO_FETCH.FETCH_CLASS:
                    return(ObjectOrFalse(FetchClass(_default_fetch_class, _default_fetch_class_args)));

                case PDO_FETCH.FETCH_NAMED:
                    return(this.ReadNamed());

                //case PDO_FETCH.FETCH_LAZY:
                //    return new PDORow( ... ) reads columns lazily

                //case PDO_FETCH.FETCH_INTO:

                //case PDO_FETCH.FETCH_FUNC:

                //case PDO_FETCH.FETCH_KEY_PAIR:

                default:
                    throw new NotImplementedException($"fetch {how}");
                }
            }
            catch (System.Exception ex)
            {
                PDO.HandleError(ex);
                return(PhpValue.False);
            }
        }