예제 #1
0
        protected virtual ResultResource ExecuteCommandInternal(string /*!*/ commandText, CommandType commandType, bool convertTypes, IEnumerable <IDataParameter> parameters, bool skipResults)
        {
            ClosePendingReader();

            // IDbCommand
            IDbCommand command = CreateCommand(commandText, commandType);

            if (parameters != null)
            {
                command.Parameters.Clear();
                foreach (IDataParameter parameter in parameters)
                {
                    command.Parameters.Add(parameter);
                }
            }

            // ExecuteReader
            ResultResource result = null;

            try
            {
                var /*!*/ reader = _pendingReader = command.ExecuteReader();

                if (skipResults)
                {
                    // reads all data:
                    do
                    {
                        while (reader.Read())
                        {
                            ;
                        }
                    } while (reader.NextResult());
                }
                else
                {
                    _lastResult = null;

                    // read all data into PhpDbResult:
                    result         = GetResult(this, reader, convertTypes);
                    result.command = command;

                    _lastResult = result;
                }

                _lastException = null;
            }
            catch (Exception e)
            {
                _lastException = e;
                PhpException.Throw(PhpError.Warning, LibResources.command_execution_failed, GetExceptionMessage(e));
            }

            //
            return(result);
        }
예제 #2
0
        protected virtual ResultResource ExecuteCommandProtected(IDbCommand command, bool convertTypes, IList <IDataParameter> parameters, bool skipResults)
        {
            if (parameters != null)
            {
                command.Parameters.Clear();

                for (int iparam = 0; iparam < parameters.Count; iparam++)
                {
                    command.Parameters.Add(parameters[iparam]);
                }
            }

            // ExecuteReader
            ResultResource result = null;

            try
            {
                var /*!*/ reader = _pendingReader = command.ExecuteReader();

                if (skipResults)
                {
                    // reads all data:
                    do
                    {
                        while (reader.Read())
                        {
                            ;
                        }
                    } while (reader.NextResult());
                }
                else
                {
                    _lastResult = null;

                    // read all data into PhpDbResult:
                    result         = GetResult(reader, convertTypes);
                    result.command = command;

                    _lastResult = result;
                }

                _lastException = null;
            }
            catch (Exception e)
            {
                _lastException = e;
                PhpException.Throw(PhpError.Warning, LibResources.command_execution_failed, GetExceptionMessage(e));
            }

            //
            return(result);
        }
예제 #3
0
        /// <summary>
        /// Reexecutes a command associated with a specified result resource to get schema of the command result.
        /// </summary>
        /// <param name="result">The result resource.</param>
        internal void ReexecuteSchemaQuery(ResultResource /*!*/ result)
        {
            if (!Connect() || result.Command == null)
            {
                return;
            }

            ClosePendingReader();

            try
            {
                result.Reader = _pendingReader = result.Command.ExecuteReader(CommandBehavior.KeyInfo | CommandBehavior.SchemaOnly);
            }
            catch (Exception e)
            {
                _lastException = e;
                PhpException.Throw(PhpError.Warning, LibResources.command_execution_failed, GetExceptionMessage(e));
            }
        }
예제 #4
0
        /// <summary>
        /// Reexecutes a command associated with a specified result resource to get schema of the command result.
        /// </summary>
        /// <param name="result">The result resource.</param>
        internal void ReexecuteSchemaQuery(ResultResource /*!*/ result)
        {
            if (!Connect() || result.Command == null)
            {
                return;
            }

            ClosePendingReader();

            try
            {
                result.Reader = _pendingReader = result.Command.ExecuteReader(CommandBehavior.KeyInfo | CommandBehavior.SchemaOnly);
            }
            catch (System.Exception e)
            {
                _lastException = e;
                throw new NotImplementedException(); // ERR
                //PhpException.Throw(PhpError.Warning, LibResources.GetString("command_execution_failed",
                //    GetExceptionMessage(e)));
            }
        }