Exemple #1
0
        /// <summary>
        /// Runs one prepared query with the given values as parameters and returns an IndexRowset representing the result
        /// </summary>
        /// <param name="indexField">The position of the index field in the result</param>
        /// <param name="query">The prepared query</param>
        /// <param name="values">The key-value pair of values to use when running the query</param>
        /// <returns>The Rowset object representing the result</returns>
        public IndexRowset PrepareIndexRowsetQuery(int indexField, string query, Dictionary <string, object> values)
        {
            try
            {
                MySqlConnection connection = null;
                // create the correct command
                MySqlCommand command = this.PrepareQuery(ref connection, query);

                // add values
                foreach (KeyValuePair <string, object> pair in values)
                {
                    command.Parameters.AddWithValue(pair.Key, pair.Value);
                }

                MySqlDataReader reader = command.ExecuteReader();

                using (connection)
                    using (reader)
                    {
                        // run the prepared statement
                        return(IndexRowset.FromMySqlDataReader(reader, indexField));
                    }
            }
            catch (Exception e)
            {
                Log.Error($"MySQL error: {e.Message}");
                throw;
            }
        }
Exemple #2
0
        public void Load(string service, string method, string query, CacheObjectType type)
        {
            Log.Debug($"Loading cache data for {service}::{method} of type {type}");

            // if the cache already exists do not generate it again!
            if (this.Exists(service, method) == true)
            {
                return;
            }

            try
            {
                MySqlConnection connection  = null;
                MySqlDataReader reader      = Database.Query(ref connection, query);
                PyDataType      cacheObject = null;

                using (connection)
                    using (reader)
                    {
                        switch (type)
                        {
                        case CacheObjectType.Rowset:
                            cacheObject = Rowset.FromMySqlDataReader(reader);
                            break;

                        case CacheObjectType.CRowset:
                            cacheObject = CRowset.FromMySqlDataReader(reader);
                            break;

                        case CacheObjectType.TupleSet:
                            cacheObject = TupleSet.FromMySqlDataReader(reader);
                            break;

                        case CacheObjectType.PackedRowList:
                            cacheObject = PyPackedRowList.FromMySqlDataReader(reader);
                            break;

                        case CacheObjectType.IntIntDict:
                            cacheObject = IntIntDictionary.FromMySqlDataReader(reader);
                            break;

                        case CacheObjectType.IndexRowset:
                            cacheObject = IndexRowset.FromMySqlDataReader(reader, 0);
                            break;
                        }

                        StoreCall(service, method, cacheObject, DateTime.UtcNow.ToFileTimeUtc());
                    }
            }
            catch (Exception)
            {
                Log.Error($"Cannot generate cache data for {service}::{method}");
                throw;
            }
        }
Exemple #3
0
        /// <summary>
        /// Helper method that queries the cached object and converts it to the proper type to be stored
        /// </summary>
        /// <param name="query">The query to run</param>
        /// <param name="type">The type of object to store</param>
        /// <returns>The final object to be used by the cache</returns>
        private PyDataType QueryCacheObject(string query, CacheObjectType type)
        {
            MySqlConnection connection = null;
            MySqlDataReader reader     = Database.Query(ref connection, query);

            using (connection)
                using (reader)
                {
                    return(type switch
                    {
                        CacheObjectType.Rowset => Rowset.FromMySqlDataReader(Database, reader),
                        CacheObjectType.CRowset => CRowset.FromMySqlDataReader(Database, reader),
                        CacheObjectType.TupleSet => TupleSet.FromMySqlDataReader(Database, reader),
                        CacheObjectType.PackedRowList => PyPackedRowList.FromMySqlDataReader(Database, reader),
                        CacheObjectType.IntIntDict => IntIntDictionary.FromMySqlDataReader(reader),
                        CacheObjectType.IndexRowset => IndexRowset.FromMySqlDataReader(Database, reader, 0),
                        _ => null
                    });
Exemple #4
0
        /// <summary>
        /// Runs one prepared query with the given values as parameters and returns an IndexRowset representing the result
        /// </summary>
        /// <param name="indexField">The position of the index field in the result</param>
        /// <param name="query">The prepared query</param>
        /// <returns>The Rowset object representing the result</returns>
        public IndexRowset PrepareIndexRowsetQuery(int indexField, string query)
        {
            try
            {
                MySqlConnection connection = null;
                // create the correct command
                MySqlCommand command = this.PrepareQuery(ref connection, query);

                MySqlDataReader reader = command.ExecuteReader();

                using (connection)
                    using (reader)
                    {
                        // run the prepared statement
                        return(IndexRowset.FromMySqlDataReader(reader, indexField));
                    }
            }
            catch (Exception e)
            {
                Log.Error($"MySQL error: {e.Message}");
                throw;
            }
        }