コード例 #1
0
        /// <summary>
        /// Sets <see cref="PDO.PDO_ATTR.ATTR_STRINGIFY_FETCHES"/> attribute value.
        /// </summary>
        /// <param name="pdo">Containing <see cref="PDO"/> object reference.</param>
        /// <param name="stringify">Whether to stringify fetched values.</param>
        /// <returns>Value indicating the attribute was set succesfuly.</returns>
        public virtual bool TrySetStringifyFetches(PDO pdo, bool stringify)
        {
            // NOTE: this method should be removed and stringify handled when actually used in PdoResultResource.GetValues()

            pdo.Stringify = stringify;
            return(true);
        }
コード例 #2
0
ファイル: PDOStatement.cs プロジェクト: toreinar/peachpie
 /// <summary>
 /// Empty ctor.
 /// </summary>
 protected PDOStatement()
 {
     m_pdo     = null;
     m_stmt    = null;
     m_options = PhpArray.Empty;
     m_cmd     = null;
 }
コード例 #3
0
ファイル: PDOStatement.cs プロジェクト: priioom/peachpie
        /// <summary>
        /// Executes a prepared statement
        /// </summary>
        /// <param name="input_parameters">An array of values with as many elements as there are bound parameters in the SQL statement being executed. All values are treated as PDO::PARAM_STR.</param>
        /// <returns>Returns TRUE on success or FALSE on failure</returns>
        public virtual bool execute(PhpArray input_parameters = null)
        {
            if (Result != null)
            {
                // reusing command
                Connection.ClosePendingReader();
            }

            // parameters
            BindParameters(_cmd.Parameters, input_parameters);

            // execute
            Result = Connection.ExecuteCommand(_cmd, convertTypes: true, parameters: null /*already set*/, skipResults: false);

            // handle error:
            if (Connection.LastException == null)
            {
                // TODO: write-back output parameters from _cmd:
            }
            else
            {
                PDO.HandleError(Connection.LastException);
                return(false);
            }

            return(Result != null);
        }
コード例 #4
0
ファイル: PDOStatement.cs プロジェクト: toreinar/peachpie
        /// <summary>
        /// Initializes a new instance of the <see cref="PDOStatement" /> class.
        /// </summary>
        /// <param name="pdo">The pdo.</param>
        /// <param name="statement">The statement.</param>
        /// <param name="driver_options">The driver options.</param>
        internal PDOStatement(PDO pdo, string statement, PhpArray driver_options)
        {
            this.m_pdo     = pdo;
            this.m_stmt    = statement;
            this.m_options = driver_options ?? PhpArray.Empty;

            this.m_cmd = pdo.CreateCommand(this.m_stmt);

            this.SetDefaultAttributes();
        }
コード例 #5
0
 /// <inheritDoc />
 public override string GetLastInsertId(PDO pdo, string name)
 {
     //http://php.net/manual/en/function.db2-last-insert-id.php#98361
     //https://www.ibm.com/support/knowledgecenter/SSEPGG_9.7.0/com.ibm.db2.luw.sql.ref.doc/doc/r0004231.html
     using (var cmd = pdo.CreateCommand("SELECT IDENTITY_VAL_LOCAL() AS LASTID FROM SYSIBM.SYSDUMMY1"))
     {
         object value = cmd.ExecuteScalar();
         return(value?.ToString());
     }
 }
コード例 #6
0
        protected PDOStatement(Context ctx)
        {
            Debug.Assert(ctx != null);

            _ctx      = ctx;
            m_pdo     = null;
            m_stmt    = null;
            m_options = PhpArray.Empty;
            m_cmd     = null;
        }
コード例 #7
0
            public DbCommand CreateCommand(string commandText)
            {
                var dbCommand = Connection.CreateCommand();

                dbCommand.CommandText    = commandText;
                dbCommand.Transaction    = PDO.CurrentTransaction;
                dbCommand.CommandTimeout = (PDO.TryGetAttribute(PDO_ATTR.ATTR_TIMEOUT, out var timeout) ? (int)timeout : 30) * 1000;

                LastCommand = dbCommand;

                return(dbCommand);
            }
コード例 #8
0
ファイル: PDOStatement.cs プロジェクト: Unknown6656/peachpie
        /// <summary>
        /// 2 phase ctor.
        /// Prepares the command.
        /// </summary>
        /// <param name="pdo"></param>
        /// <param name="queryString"></param>
        /// <param name="options">Driver options. Optional.</param>
        internal void Prepare(PdoConnectionResource pdo, string queryString, PhpArray options)
        {
            pdo.ClosePendingReader();

            // initialize properties
            this.Connection  = pdo ?? throw new ArgumentNullException(nameof(pdo));
            this.queryString = queryString;

            //
            var actualQuery = Driver.RewriteCommand(queryString, options, out bound_param_map);

            _cmd = PDO.CreateCommand(actualQuery);

            //_cmd.Prepare(); // <-- compiles the query, needs parameters to be bound
        }
コード例 #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PDOStatement" /> class.
        /// </summary>
        /// <param name="ctx">The php context.</param>
        /// <param name="pdo">The PDO statement is created for.</param>
        /// <param name="statement">The statement.</param>
        /// <param name="driver_options">The driver options.</param>
        internal PDOStatement(Context ctx, PDO pdo, string statement, PhpArray driver_options)
        {
            if (pdo.HasExecutedQuery)
            {
                if (!pdo.StoreLastExecutedQuery())
                {
                    pdo.HandleError(new PDOException("Last executed PDOStatement result set could not be saved correctly."));
                }
            }

            this.m_pdo     = pdo;
            this._ctx      = ctx;
            this.m_stmt    = statement;
            this.m_options = driver_options ?? PhpArray.Empty;

            this.m_cmd = pdo.CreateCommand(this.m_stmt);

            PrepareStatement();

            this.SetDefaultAttributes();
        }
コード例 #10
0
ファイル: PDODriver.cs プロジェクト: priioom/peachpie
 /// <summary>
 /// Opens a DataReader.
 /// </summary>
 /// <param name="pdo">The pdo.</param>
 /// <param name="cmd">The command.</param>
 /// <param name="cursor">The cursor configuration.</param>
 /// <returns></returns>
 public virtual DbDataReader OpenReader(PDO pdo, DbCommand cmd, PDO.PDO_CURSOR cursor)
 {
     return(cmd.ExecuteReader());
 }
コード例 #11
0
ファイル: PDODriver.cs プロジェクト: priioom/peachpie
 /// <summary>
 /// Gets the driver specific attribute value
 /// </summary>
 /// <param name="pdo">The pdo.</param>
 /// <param name="attribute">The attribute.</param>
 /// <returns></returns>
 public virtual PhpValue GetAttribute(PDO pdo, PDO.PDO_ATTR attribute)
 {
     return(PhpValue.Null);
 }
コード例 #12
0
ファイル: PDODriver.cs プロジェクト: priioom/peachpie
 /// <summary>
 /// Gets the last insert identifier.
 /// </summary>
 /// <param name="pdo">Reference to corresponding <see cref="PDO"/> instance.</param>
 /// <param name="name">The name.</param>
 /// <returns></returns>
 public abstract string GetLastInsertId(PDO pdo, string name);
コード例 #13
0
ファイル: PDOStatement.cs プロジェクト: Unknown6656/peachpie
 private protected void HandleError(ErrorInfo error)
 {
     _lastError = error;
     PDO.HandleError(error);
 }
コード例 #14
0
 /// <summary>
 /// Tries to set a driver specific attribute value.
 /// </summary>
 /// <param name="pdo">Containing <see cref="PDO"/> object reference.</param>
 /// <param name="attributes">The current attributes collection.</param>
 /// <param name="attribute">The attribute to set.</param>
 /// <param name="value">The value.</param>
 /// <returns>true if value is valid, or false if value can't be set.</returns>
 public virtual bool TrySetAttribute(PDO pdo, Dictionary <PDO.PDO_ATTR, PhpValue> attributes, int attribute, PhpValue value)
 {
     return(false);
 }
コード例 #15
0
 public PdoConnectionResource(PDO pdo, DbConnection connection)
     : base(connection.ConnectionString, nameof(PdoConnectionResource))
 {
     this.PDO        = pdo;
     this.Connection = connection ?? throw new ArgumentNullException(nameof(connection));
 }
コード例 #16
0
ファイル: PDOStatement.cs プロジェクト: priioom/peachpie
        /// <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);
            }
        }
コード例 #17
0
 /// <summary>
 /// Gets the driver specific attribute value
 /// </summary>
 /// <param name="pdo">The pdo.</param>
 /// <param name="attribute">The attribute.</param>
 /// <returns></returns>
 public virtual PhpValue GetAttribute(PDO pdo, int attribute)
 {
     return(PhpValue.Null);
 }
コード例 #18
0
ファイル: PDOStatement.cs プロジェクト: Unknown6656/peachpie
 private protected void ClearError()
 {
     _lastError = default;
     PDO.ClearError();
 }
コード例 #19
0
ファイル: PDODriver.cs プロジェクト: yh200212121212/peachpie
        /// <inheritDoc />
        public virtual PDOStatement PrepareStatement(PDO pdo, string statement, PhpArray driver_options)
        {
            PDOStatement stmt = new PDOStatement(pdo, statement, driver_options);

            return(stmt);
        }