コード例 #1
0
ファイル: PDOStatement.cs プロジェクト: toreinar/peachpie
        /// <inheritDoc />
        public PhpValue fetch(int?fetch_style = default(int?), int cursor_orientation = default(int), int cursor_offet = 0)
        {
            this.m_pdo.ClearError();
            try
            {
                PDO.PDO_FETCH style = PDO.PDO_FETCH.FETCH_BOTH;
                if (fetch_style.HasValue && Enum.IsDefined(typeof(PDO.PDO_FETCH), fetch_style.Value))
                {
                    style = (PDO.PDO_FETCH)fetch_style.Value;
                }
                PDO.PDO_FETCH_ORI ori = PDO.PDO_FETCH_ORI.FETCH_ORI_NEXT;
                if (Enum.IsDefined(typeof(PDO.PDO_FETCH_ORI), cursor_orientation))
                {
                    ori = (PDO.PDO_FETCH_ORI)cursor_orientation;
                }

                switch (ori)
                {
                case PDO.PDO_FETCH_ORI.FETCH_ORI_NEXT:
                    break;

                default:
                    throw new NotSupportedException();
                }

                if (!this.m_dr.Read())
                {
                    return(PhpValue.False);
                }

                switch (style)
                {
                case PDO.PDO_FETCH.FETCH_OBJ:
                    return(this.ReadObj());

                case PDO.PDO_FETCH.FETCH_ASSOC:
                    return(PhpValue.Create(this.ReadArray(true, false)));

                case PDO.PDO_FETCH.FETCH_BOTH:
                case PDO.PDO_FETCH.FETCH_USE_DEFAULT:
                    return(PhpValue.Create(this.ReadArray(true, true)));

                case PDO.PDO_FETCH.FETCH_NUM:
                    return(PhpValue.Create(this.ReadArray(false, true)));

                default:
                    throw new NotImplementedException();
                }
            }
            catch (System.Exception ex)
            {
                this.m_pdo.HandleError(ex);
                return(PhpValue.False);
            }
        }
コード例 #2
0
        /// <inheritDoc />
        public PhpValue fetch(PDO.PDO_FETCH fetch_style = PDO.PDO_FETCH.FETCH_USE_DEFAULT, int cursor_orientation = default(int), int cursor_offet = 0)
        {
            this.m_pdo.ClearError();

            if (storedQueryResult != null)
            {
                return(FetchFromStored());
            }
            else
            {
                try
                {
                    PDO.PDO_FETCH style = this.m_fetchStyle;

                    if ((int)fetch_style != -1 && Enum.IsDefined(typeof(PDO.PDO_FETCH), fetch_style))
                    {
                        style = (PDO.PDO_FETCH)fetch_style;
                    }
                    PDO.PDO_FETCH_ORI ori = PDO.PDO_FETCH_ORI.FETCH_ORI_NEXT;
                    if (Enum.IsDefined(typeof(PDO.PDO_FETCH_ORI), cursor_orientation))
                    {
                        ori = (PDO.PDO_FETCH_ORI)cursor_orientation;
                    }

                    switch (ori)
                    {
                    case PDO.PDO_FETCH_ORI.FETCH_ORI_NEXT:
                        break;

                    default:
                        throw new NotSupportedException();
                    }

                    if (!this.m_dr.Read())
                    {
                        return(PhpValue.False);
                    }

                    // Get the column schema, if possible, for the associative fetch
                    if (this.m_dr_names == null)
                    {
                        this.m_dr_names = new string[m_dr.FieldCount];

                        if (this.m_dr.CanGetColumnSchema())
                        {
                            var columnSchema = this.m_dr.GetColumnSchema();

                            for (int i = 0; i < m_dr.FieldCount; i++)
                            {
                                this.m_dr_names[i] = columnSchema[i].ColumnName;
                            }
                        }
                        else
                        {
                            for (int i = 0; i < m_dr.FieldCount; i++)
                            {
                                this.m_dr_names[i] = this.m_dr.GetName(i);
                            }
                        }
                    }

                    switch (style)
                    {
                    case PDO.PDO_FETCH.FETCH_OBJ:
                        return(this.ReadObj());

                    case PDO.PDO_FETCH.FETCH_ASSOC:
                        return(PhpValue.Create(this.ReadArray(true, false)));

                    case PDO.PDO_FETCH.FETCH_BOTH:
                    case PDO.PDO_FETCH.FETCH_USE_DEFAULT:
                        return(PhpValue.Create(this.ReadArray(true, true)));

                    case PDO.PDO_FETCH.FETCH_NUM:
                        return(PhpValue.Create(this.ReadArray(false, true)));

                    case PDO.PDO_FETCH.FETCH_COLUMN:
                        if (FetchColNo != -1)
                        {
                            m_pdo.HandleError(new PDOException("The column number for FETCH_COLUMN mode is not set."));
                            return(PhpValue.False);
                        }

                        return(this.ReadArray(false, true)[FetchColNo].GetValue());

                    case PDO.PDO_FETCH.FETCH_CLASS:
                        if (FetchClassName == null)
                        {
                            m_pdo.HandleError(new PDOException("The className for FETCH_CLASS mode is not set."));
                            return(PhpValue.False);
                        }

                        var obj = _ctx.Create(FetchClassName, FetchClassCtorArgs ?? Array.Empty <PhpValue>());
                        return(PhpValue.FromClass(obj));

                    default:
                        throw new NotImplementedException();
                    }
                }
                catch (System.Exception ex)
                {
                    this.m_pdo.HandleError(ex);
                    return(PhpValue.False);
                }
            }
        }
コード例 #3
0
        /// <inheritDoc />
        public PhpValue fetch(int fetch_style = -1, int cursor_orientation = default(int), int cursor_offet = 0)
        {
            this.m_pdo.ClearError();
            try
            {
                PDO.PDO_FETCH style = this.m_fetchStyle;

                if (fetch_style != -1 && Enum.IsDefined(typeof(PDO.PDO_FETCH), fetch_style))
                {
                    style = (PDO.PDO_FETCH)fetch_style;
                }
                PDO.PDO_FETCH_ORI ori = PDO.PDO_FETCH_ORI.FETCH_ORI_NEXT;
                if (Enum.IsDefined(typeof(PDO.PDO_FETCH_ORI), cursor_orientation))
                {
                    ori = (PDO.PDO_FETCH_ORI)cursor_orientation;
                }

                switch (ori)
                {
                case PDO.PDO_FETCH_ORI.FETCH_ORI_NEXT:
                    break;

                default:
                    throw new NotSupportedException();
                }

                if (!this.m_dr.Read())
                {
                    return(PhpValue.False);
                }

                // Get the column schema, if possible, for the associative fetch
                if (this.m_dr_names == null)
                {
                    this.m_dr_names = new string[m_dr.FieldCount];

                    if (this.m_dr.CanGetColumnSchema())
                    {
                        var columnSchema = this.m_dr.GetColumnSchema();

                        for (int i = 0; i < m_dr.FieldCount; i++)
                        {
                            this.m_dr_names[i] = columnSchema[i].ColumnName;
                        }
                    }
                }

                switch (style)
                {
                case PDO.PDO_FETCH.FETCH_OBJ:
                    return(this.ReadObj());

                case PDO.PDO_FETCH.FETCH_ASSOC:
                    return(PhpValue.Create(this.ReadArray(true, false)));

                case PDO.PDO_FETCH.FETCH_BOTH:
                case PDO.PDO_FETCH.FETCH_USE_DEFAULT:
                    return(PhpValue.Create(this.ReadArray(true, true)));

                case PDO.PDO_FETCH.FETCH_NUM:
                    return(PhpValue.Create(this.ReadArray(false, true)));

                case PDO.PDO_FETCH.FETCH_COLUMN:
                    return(this.ReadArray(false, true)[FetchColNo].GetValue());

                case PDO.PDO_FETCH.FETCH_CLASS:
                default:
                    throw new NotImplementedException();
                }
            }
            catch (System.Exception ex)
            {
                this.m_pdo.HandleError(ex);
                return(PhpValue.False);
            }
        }