Пример #1
0
        // -------------------------------------------------------------------------------
        // ExecuteReader
        // -------------------------------------------------------------------------------
        MySQLRowsReader ExecuteReader(MySqlConnection connection, MySqlTransaction transaction, string sql, params MySqlParameter[] args)
        {
            bool createLocalConnection = false;

            if (connection == null)
            {
                connection  = NewConnection();
                transaction = null;
                connection.Open();
                createLocalConnection = true;
            }
            MySQLRowsReader result = new MySQLRowsReader();

            using (MySqlCommand cmd = new MySqlCommand(sql, connection))
            {
                if (transaction != null)
                {
                    cmd.Transaction = transaction;
                }
                foreach (MySqlParameter arg in args)
                {
                    cmd.Parameters.Add(arg);
                }
                MySqlDataReader dataReader = cmd.ExecuteReader();
                result.Init(dataReader);
                dataReader.Close();
            }
            if (createLocalConnection)
            {
                connection.Close();
            }
            return(result);
        }
Пример #2
0
        // -------------------------------------------------------------------------------
        // ExecuteReader
        // -------------------------------------------------------------------------------
        MySQLRowsReader ExecuteReader(string sql, params MySqlParameter[] args)
        {
            MySqlConnection connection = NewConnection();

            connection.Open();
            MySQLRowsReader result = ExecuteReader(connection, null, sql, args);

            connection.Close();
            return(result);
        }
        /// <summary>
        /// Converts a mySQLRowsReader into a list of results of type T. Where T is a TableClass.
        /// </summary>
        public List <T> ConvertReader <T>(MySQLRowsReader reader)
        {
            if (reader.RowCount == 0)
            {
                return(null);
            }

            List <T> results = new List <T>();

            while (reader.Read())
            {
                TableMap map = GetTableMap <T>();

                for (int i = 0; i < map.rows.Length; i++)
                {
                    object obj = null;

                    if (map.rows[i].type == typeof(int))
                    {
                        obj = reader.GetInt32(map.rows[i].name);
                    }
                    else if (map.rows[i].type == typeof(bool))
                    {
                        obj = reader.GetBoolean(map.rows[i].name);
                    }
                    else if (map.rows[i].type == typeof(long))
                    {
                        obj = reader.GetInt64(map.rows[i].name);
                    }
                    else if (map.rows[i].type == typeof(string))
                    {
                        obj = reader.GetString(map.rows[i].name);
                    }
                    else if (map.rows[i].type == typeof(DateTime))
                    {
                        obj = reader.GetDateTime(map.rows[i].name);
                    }
                    else if (map.rows[i].type == typeof(float))
                    {
                        obj = reader.GetFloat(map.rows[i].name);
                    }
                    else if (map.rows[i].type == typeof(double))
                    {
                        obj = reader.GetDouble(map.rows[i].name);
                    }

                    map.UpdateValue(map.rows[i].name, obj);
                }

                results.Add(map.ToType <T>());
            }

            return(results);
        }
Пример #4
0
        // -------------------------------------------------------------------------------
        // Query
        // -------------------------------------------------------------------------------
        public override List <T> Query <T>(string query, params object[] args)
        {
            MySQLRowsReader reader = ExecuteReader(connection, null, dbCompat.GetConvertedQuery(query), dbCompat.GetConvertedParameters(args));

            return(dbCompat.ConvertReader <T>(reader));
        }