Ejemplo n.º 1
0
        /// <summary>
        /// Connect to database using connection request.
        /// </summary>
        /// <param name="databaseRequest">SQL request</param>
        private string Request(DatabaseRequest databaseRequest)
        {
            var connection = new MySqlConnection(connectionRequest);

            connection.Open();
            var result     = string.Empty;
            var parameters = Math.Clamp(databaseRequest.GetTableParamsAmount(), 0, int.MaxValue);

            var cmd = new MySqlCommand(databaseRequest.ToString(), connection);

            using (var reader = cmd.ExecuteReader())
            {
                if (!reader.HasRows)
                {
                    return(result);
                }
                while (reader.Read())
                {
                    for (int i = 0; i < parameters; i++)
                    {
                        try
                        {
                            result += reader[i];
                        }
                        catch (IndexOutOfRangeException)
                        {
                            break;
                        }
                    }
                }
            }
            connection.Close();
            return(result);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Make asynchronous request to the database.
 /// </summary>
 /// <param name="databaseRequest"></param>
 public async Task <string> MakeRequest(DatabaseRequest databaseRequest)
 {
     return(await Task.Factory.StartNew(() => Request(databaseRequest)));
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Add/replace default request.
 /// </summary>
 /// <param name="keyword">Request keyword</param>
 /// <param name="request">Request holder</param>
 internal void AddDefaultRequest(string keyword, DatabaseRequest request)
 {
     defaultRequests[keyword] = request;
 }