예제 #1
0
        /// <summary>
        /// Executes a given SQL-Query that return Rows.
        /// </summary>
        /// <param name="query">Query to execute.</param>
        /// <param name="callerLineNumber"></param>
        /// <param name="callerMethodName"></param>
        public MySqlDataReader Select(string query, [CallerLineNumber] int callerLineNumber = 0, [CallerMemberName] string callerMethodName = "")
        {
            if (!IsConnected())
            {
                Connect();
            }

            MySqlDataReader reader;

            MySqlCommand cmd = _connection.CreateCommand();

            cmd.CommandText = query;

            try
            {
                reader = cmd.ExecuteReader();
                SqlQueryExecuted?.Invoke(this, new SqlQueryEventArgs(query, SqlQueryEventArgs.QueryType.Select));
            }
            catch (MySqlException e)
            {
                throw new SqlQueryFailedException("SQL-Query failed!", query, callerMethodName, callerLineNumber, e);
            }

            return(reader);
        }
        public MySqlDataReader Select(string query)
        {
            if (!IsConnected)
            {
                Connect();
            }

            MySqlDataReader reader;

            MySqlCommand cmd = _connection.CreateCommand();

            cmd.CommandText = query;

            try
            {
                reader = cmd.ExecuteReader();
                SqlQueryExecuted?.Invoke(this, new SqlQueryEventArgs(query, SqlQueryEventArgs.QueryType.Select));
            }
            catch (MySqlException e)
            {
                throw new SqlQueryFailedException("SQL-Query failed!", query, e);
            }

            return(reader);
        }
예제 #3
0
        /// <summary>
        /// Executes a Prepared statement.
        /// </summary>
        /// <returns>Result of the Query.</returns>
        /// <exception cref="SqlQueryFailedException" />
        /// <exception cref="QueryNotPreparedException" />
        public void ExecutePreparedInsertUpdateDelete([CallerLineNumber] int callerLineNumber = 0, [CallerMemberName] string callerMethodName = "")
        {
            if (!IsConnected())
            {
                Connect();
            }

            if (_prepareSqlCommand != null)
            {
                try
                {
                    _prepareSqlCommand.ExecuteNonQuery();
                    SqlQueryExecuted?.Invoke(this, new SqlQueryEventArgs(ReplacePlaceholderInPreparedQuery(), SqlQueryEventArgs.QueryType.PreparedInsertUpdateDelete));

                    _prepareSqlCommand.Parameters.Clear();
                    _bindedParams.Clear();
                }
                catch (MySqlException e)
                {
                    throw new SqlQueryFailedException("SQL-Query failed", ReplacePlaceholderInPreparedQuery(), callerMethodName, callerLineNumber, e);
                }
            }
            else
            {
                throw new QueryNotPreparedException();
            }
        }
        /// <summary>
        /// Executes a Prepared statement.
        /// </summary>
        /// <returns>Result of the Query.</returns>
        /// <exception cref="SqlQueryFailedException" />
        /// <exception cref="QueryNotPreparedException" />
        public MySqlDataReader ExecutePreparedSelect()
        {
            if (_prepareSqlCommand == null)
            {
                throw new QueryNotPreparedException();
            }

            try
            {
                MySqlDataReader reader = _prepareSqlCommand.ExecuteReader();
                SqlQueryExecuted?.Invoke(this, new SqlQueryEventArgs(ReplacePlaceholderInPreparedQuery(), SqlQueryEventArgs.QueryType.PreparedSelect));

                return(reader);
            }
            catch (Exception e)
            {
                throw new SqlQueryFailedException("Query failed!", ReplacePlaceholderInPreparedQuery(), e);
            }
        }
        public void InsertUpdateDelete(string query)
        {
            if (!IsConnected)
            {
                Connect();
            }

            MySqlCommand cmd = _connection.CreateCommand();

            cmd.CommandText = query;


            try
            {
                cmd.ExecuteNonQuery();
                SqlQueryExecuted?.Invoke(this, new SqlQueryEventArgs(query, SqlQueryEventArgs.QueryType.InsertUpdateDelete));
            }
            catch (MySqlException e)
            {
                throw new SqlQueryFailedException("SQL-Query failed!", query, e);
            }
        }
예제 #6
0
        public void InsertUpdateDelete(string query, [CallerLineNumber] int callerLineNumber = 0, [CallerMemberName] string callerMethodName = "")
        {
            if (!IsConnected)
            {
                Connect();
            }

            MySqlCommand cmd = _connection.CreateCommand();

            cmd.CommandText = query;


            try
            {
                cmd.ExecuteNonQuery();
                SqlQueryExecuted?.Invoke(this, new SqlQueryEventArgs(query, SqlQueryEventArgs.QueryType.InsertUpdateDelete));
            }
            catch (MySqlException e)
            {
                throw new SqlQueryFailedException("SQL-Query failed!", query, callerMethodName, callerLineNumber, e);
            }
        }
예제 #7
0
        /// <summary>
        /// Executes a Prepared statement.
        /// </summary>
        /// <returns>Result of the Query.</returns>
        /// <exception cref="SqlQueryFailedException" />
        /// <exception cref="QueryNotPreparedException" />
        public MySqlDataReader ExecutePreparedSelect([CallerLineNumber] int callerLineNumber = 0, [CallerMemberName] string callerMethodName = "")
        {
            if (_prepareSqlCommand == null)
            {
                throw new QueryNotPreparedException();
            }

            try
            {
                MySqlDataReader reader = _prepareSqlCommand.ExecuteReader();
                SqlQueryExecuted?.Invoke(this, new SqlQueryEventArgs(ReplacePlaceholderInPreparedQuery(), SqlQueryEventArgs.QueryType.PreparedSelect));

                _prepareSqlCommand.Parameters.Clear();
                _bindedParams.Clear();

                return(reader);
            }
            catch (Exception e)
            {
                throw new SqlQueryFailedException("Query failed!", ReplacePlaceholderInPreparedQuery(), callerMethodName, callerLineNumber, e);
            }
        }
        /// <summary>
        /// Executes a Prepared statement.
        /// </summary>
        /// <returns>Result of the Query.</returns>
        /// <exception cref="SqlQueryFailedException" />
        /// <exception cref="QueryNotPreparedException" />
        public void ExecutePreparedInsertUpdateDelete()
        {
            if (!IsConnected())
            {
                Connect();
            }

            if (_prepareSqlCommand != null)
            {
                try
                {
                    _prepareSqlCommand.ExecuteNonQuery();
                    SqlQueryExecuted?.Invoke(this, new SqlQueryEventArgs(ReplacePlaceholderInPreparedQuery(), SqlQueryEventArgs.QueryType.PreparedInsertUpdateDelete));
                }
                catch (MySqlException e)
                {
                    throw new SqlQueryFailedException("SQL-Query failed", ReplacePlaceholderInPreparedQuery(), e);
                }
            }
            else
            {
                throw new QueryNotPreparedException();
            }
        }
 internal void InvokeSqlQueryExecuted(string query, SqlQueryEventArgs.QueryType queryType)
 {
     SqlQueryExecuted?.Invoke(this, new SqlQueryEventArgs(query, SqlQueryEventArgs.QueryType.PreparedInsertUpdateDelete));
 }