Example #1
0
        /// <summary>
        ///     Performs a query on this database connection with mysql parameterisation.
        /// </summary>
        /// <returns>A DBResults instances that contains the results of this query, or null if the query failed.</returns>
        public DBResults QueryParameterized(string query, object[] parameters, params object[] formatParam)
        {
            query = String.Format(query, formatParam);

            try
            {
                MySqlCommand currentCommand = new MySqlCommand(query, m_connection);

                int index = 1;
                foreach (object param in parameters)
                {
                    currentCommand.Parameters.Add("@parameter_" + index, param);
                    index++;
                }

                MySqlDataReader currentCommandDataReader = currentCommand.ExecuteReader() as MySqlDataReader;
                DBResults results = new DBResults(currentCommand, currentCommandDataReader);
                currentCommandDataReader.Close();

                return results;
            }
            catch (System.Data.Common.DbException ex)
            {
                Logger.Error("Database query failed with error: {0}", LoggerVerboseLevel.Normal, ex.Message);
                return null;
            }
        }
Example #2
0
        /// <summary>
        ///     Performs a query on this database connection.
        /// </summary>
        /// <returns>A DBResults instances that contains the results of this query, or null if the query failed.</returns>
        public DBResults Query(string query, params object[] formatParam)
        {
            query = String.Format(query, formatParam);

            try
            {
                MySqlCommand    currentCommand           = new MySqlCommand(query, m_connection);
                MySqlDataReader currentCommandDataReader = currentCommand.ExecuteReader() as MySqlDataReader;

                DBResults results = new DBResults(currentCommand, currentCommandDataReader);

                currentCommandDataReader.Close();

                return results;
            }
            catch (System.Data.Common.DbException ex)
            {
                Logger.Error("Database query failed with error: {0}", LoggerVerboseLevel.Normal, ex.Message);
                return null;
            }
        }