/// <summary>
        /// Queries server for a value of a global variable.
        /// </summary>
        /// <param name="name">Global variable name.</param>
        /// <returns>Global variable value (converted).</returns>
        internal object QueryGlobalVariable(string name)
        {
            // TODO: better query:

            PhpDbResult result = ExecuteQuery("SHOW GLOBAL VARIABLES LIKE '" + name + "'", true);

            // default value
            if (result.FieldCount != 2 || result.RowCount != 1)
            {
                return(null);
            }

            return(result.GetFieldValue(0, 1));
        }
Beispiel #2
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(PhpDbResult /*!*/ 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.GetString("command_execution_failed",
                                                                            GetExceptionMessage(e)));
            }
        }
Beispiel #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(PhpDbResult/*!*/ 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.GetString("command_execution_failed",
					GetExceptionMessage(e)));
			}
		}
Beispiel #4
0
        protected virtual PhpDbResult ExecuteCommandInternal(string/*!*/ commandText, CommandType commandType, bool convertTypes, IEnumerable<IDataParameter> parameters, bool skipResults)
		{
			ClosePendingReader();

            // IDbCommand
			IDbCommand command = CreateCommand();

			command.Connection = connection;
			command.CommandText = commandText;
			command.CommandType = commandType;

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

            // ExecuteReader
            PhpDbResult result = null;

			try
			{
                var/*!*/reader = this.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.GetString("command_execution_failed",
					GetExceptionMessage(e)));
			}

            //
            return result;
		}
Beispiel #5
0
		/// <summary>
		/// Executes a command on the connection.
		/// </summary>
		/// <param name="commandText">Command text.</param>
		/// <param name="convertTypes">Whether to convert data types to PHP ones.</param>
		/// <param name="commandType">Command type.</param>
		/// <param name="parameters">Parameters.</param>
		/// <param name="skipResults">Whether to load results.</param>
		/// <returns>PhpDbResult class representing the data read from database.</returns>
		/// <exception cref="ArgumentNullException"><paramref name="commandText"/> is a <B>null</B> reference.</exception>
		/// <exception cref="PhpException">Command execution failed (Warning).</exception>
		public PhpDbResult ExecuteCommand(string/*!*/ commandText, CommandType commandType, bool convertTypes,
		  IEnumerable<IDataParameter> parameters, bool skipResults)
		{
			if (commandText == null)
				throw new ArgumentNullException("commandText");

			if (!Connect()) return null;

			ClosePendingReader();

			IDbCommand command = CreateCommand();

			command.Connection = connection;
			command.CommandText = commandText;
			command.CommandType = commandType;

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

			try
			{
				if (skipResults)
				{
					pendingReader = command.ExecuteReader();

					// reads all data:
					do { while (pendingReader.Read()); } while (pendingReader.NextResult());

					lastException = null;
					return null;
				}
				else
				{
					lastResult = null;

					pendingReader = command.ExecuteReader();
					PhpDbResult result = GetResult(this, pendingReader, convertTypes);
					result.command = command;

					lastException = null;
					lastResult = result;
					return result;
				}
			}
			catch (Exception e)
			{
				lastException = e;
				PhpException.Throw(PhpError.Warning, LibResources.GetString("command_execution_failed",
					GetExceptionMessage(e)));
				return null;
			}
		}
Beispiel #6
0
 internal SQLiteResult(PhpDbResult res)
     : base("sqlite result")
 {
     this.m_res = (PhpSQLiteDbResult)res;
 }
Beispiel #7
0
        protected virtual PhpDbResult ExecuteCommandInternal(string /*!*/ commandText, CommandType commandType, bool convertTypes, IEnumerable <IDataParameter> parameters, bool skipResults)
        {
            ClosePendingReader();

            // IDbCommand
            IDbCommand command = CreateCommand();

            command.Connection  = connection;
            command.CommandText = commandText;
            command.CommandType = commandType;

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

            // ExecuteReader
            PhpDbResult result = null;

            try
            {
                var /*!*/ reader = this.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.GetString("command_execution_failed",
                                                                            GetExceptionMessage(e)));
            }

            //
            return(result);
        }
Beispiel #8
0
        /// <summary>
        /// Executes a command on the connection.
        /// </summary>
        /// <param name="commandText">Command text.</param>
        /// <param name="convertTypes">Whether to convert data types to PHP ones.</param>
        /// <param name="commandType">Command type.</param>
        /// <param name="parameters">Parameters.</param>
        /// <param name="skipResults">Whether to load results.</param>
        /// <returns>PhpDbResult class representing the data read from database.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="commandText"/> is a <B>null</B> reference.</exception>
        /// <exception cref="PhpException">Command execution failed (Warning).</exception>
        public PhpDbResult ExecuteCommand(string /*!*/ commandText, CommandType commandType, bool convertTypes,
                                          IEnumerable <IDataParameter> parameters, bool skipResults)
        {
            if (commandText == null)
            {
                throw new ArgumentNullException("commandText");
            }

            if (!Connect())
            {
                return(null);
            }

            ClosePendingReader();

            IDbCommand command = CreateCommand();

            command.Connection  = connection;
            command.CommandText = commandText;
            command.CommandType = commandType;

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

            try
            {
                if (skipResults)
                {
                    pendingReader = command.ExecuteReader();

                    // reads all data:
                    do
                    {
                        while (pendingReader.Read())
                        {
                            ;
                        }
                    } while (pendingReader.NextResult());

                    lastException = null;
                    return(null);
                }
                else
                {
                    lastResult = null;

                    pendingReader = command.ExecuteReader();
                    PhpDbResult result = GetResult(this, pendingReader, convertTypes);
                    result.command = command;

                    lastException = null;
                    lastResult    = result;
                    return(result);
                }
            }
            catch (Exception e)
            {
                lastException = e;
                PhpException.Throw(PhpError.Warning, LibResources.GetString("command_execution_failed",
                                                                            GetExceptionMessage(e)));
                return(null);
            }
        }
Beispiel #9
0
 internal SQLiteResult(PhpDbResult res)
     : base("sqlite result")
 {
     this.m_res = (PhpSQLiteDbResult)res;
 }