You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
bantflags/BantFlags/Data/MySqlExtensions.cs

44 lines
1.1 KiB

5 years ago
using MySql.Data.MySqlClient;
using System;
using System.Data;
namespace BantFlags.Data
{
public static class MySqlExtensions
{
public static Query CreateQuery(this MySqlConnection connection, string sql)
{
connection.EnsureConnectionIsOpen();
return new Query(new MySqlCommand(sql, connection));
}
public static Query UseStoredProcedure(this MySqlConnection connection, string sql)
{
connection.EnsureConnectionIsOpen();
return new Query(new MySqlCommand(sql, connection)
{
CommandType = CommandType.StoredProcedure
});
}
public static T GetValue<T>(this DataRow row, string column)
{
object value = row[column];
if (value == null || value == DBNull.Value)
return default;
return (T)value;
}
private static void EnsureConnectionIsOpen(this MySqlConnection connection)
{
if (connection.State != ConnectionState.Open)
{
connection.Open();
}
}
}
}