/// <inheritDoc /> public 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) { this.m_pdo.ClearError(); if (storedQueryResult != null) { return(FetchFromStored()); } else { if (cursor_orientation != PDO_FETCH_ORI.FETCH_ORI_NEXT) // 0 { throw new NotSupportedException(nameof(cursor_orientation)); } try { // read next row if (!this.m_dr.Read()) { return(PhpValue.False); } if (m_dr_names == null) { // Get the column schema, if possible, // for the associative fetch initializeColumnNames(); } var style = fetch_style != PDO_FETCH.Default ? fetch_style : m_fetchStyle; var flags = style & PDO_FETCH.Flags; switch (style & ~PDO_FETCH.Flags) { case PDO_FETCH.FETCH_ASSOC: return(this.ReadArray(true, false)); case PDO_FETCH.FETCH_NUM: return(this.ReadArray(false, true)); case PDO_FETCH.Default: case PDO_FETCH.FETCH_BOTH: return(this.ReadArray(true, true)); case PDO_FETCH.FETCH_OBJ: return(this.ReadObj()); case PDO_FETCH.FETCH_COLUMN: if (FetchColNo.HasValue) { return(this.ReadColumn(FetchColNo.Value)); } else { m_pdo.HandleError(new PDOException("The column number for FETCH_COLUMN mode is not set.")); return(PhpValue.False); } //case PDO.PDO_FETCH.FETCH_CLASS: // if (FetchClassName != null) // { // var obj = FetchClassName.Creator(_ctx, FetchClassCtorArgs ?? Array.Empty<PhpValue>()); // // TODO: set properties // return PhpValue.FromClass(obj); // } // else // { // m_pdo.HandleError(new PDOException("The className for FETCH_CLASS mode is not set.")); // return PhpValue.False; // } 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 {style}"); } } catch (System.Exception ex) { this.m_pdo.HandleError(ex); return(PhpValue.False); } } }
/// <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) { ClearError(); if (cursor_orientation != PDO_FETCH_ORI.FETCH_ORI_NEXT) // 0 { throw new NotImplementedException(cursor_orientation.ToString()); } if (Result == null) { // statement not executed PhpException.Throw(PhpError.Notice, "no results to fetch"); return(false); } 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) { HandleError(ex); return(PhpValue.False); } }