本文整理汇总了C#中MySql.Data.MySqlClient.MySqlConnection.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# MySqlConnection.Execute方法的具体用法?C# MySqlConnection.Execute怎么用?C# MySqlConnection.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MySql.Data.MySqlClient.MySqlConnection
的用法示例。
在下文中一共展示了MySqlConnection.Execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateAccount
public static void CreateAccount(string accountName, string friendlyName, string adminPassword, string adminEmail, int planType)
{
using (var ts = new TransactionScope())
{
using (MySqlConnection sqlConnection = new MySqlConnection(UtilityHelper.GetConnectionString()))
{
string salt = Guid.NewGuid().ToString();
sqlConnection.Open();
sqlConnection.Execute(@"insert into Account(Name,FriendlyName,IsActive,PlanType) values (@Name,@FriendlyName,@IsActive,@PlanType)", new { Name = accountName, FriendlyName = friendlyName, IsActive = true, PlanType = planType });
sqlConnection.Execute(@"insert into User(Username,Account,Password,Salt,IsActive,IsAdmin,Email) values (@Username,@Account,@Password,@Salt,@IsActive,@IsAdmin,@Email)", new { Username = "administrator", Account = accountName, Password = UtilityHelper.HashPassword(adminPassword, salt), Salt = salt, IsActive = true, IsAdmin = true, Email = adminEmail });
}
ts.Complete();
}
}
示例2: RunBeforeAnyTests
public void RunBeforeAnyTests()
{
using (var mySqlConnection = new MySqlConnection("Server=localhost;Port=3306;uid=root;password=password!"))
{
mySqlConnection.Execute(string.Format("CREATE DATABASE IF NOT EXISTS `{0}`", DatabaseName));
}
Container = new Castle.Windsor.WindsorContainer();
DapperConfiguration
.Use()
.UseClassMapper(typeof(AutoClassMapper<>))
.UseContainer<ContainerForWindsor>(cfg => cfg.UseExisting(Container))
.UseSqlDialect(new MySqlDialect())
.WithDefaultConnectionStringNamed("__DefaultMySql")
.FromAssembly("Dapper.Extensions.Linq.Test.Entities")
.FromAssembly("Dapper.Extensions.Linq.Test.Maps")
.Build();
var connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["__DefaultMySql"].ConnectionString);
var files = new List<string>
{
ReadScriptFile("CreateAnimalTable"),
ReadScriptFile("CreateFooTable"),
ReadScriptFile("CreateMultikeyTable"),
ReadScriptFile("CreatePersonTable"),
ReadScriptFile("CreateCarTable"),
ReadScriptFile("CreatePhoneTable")
};
foreach (var setupFile in files)
{
connection.Execute(setupFile);
}
}
示例3: CreateOfficeDepartment
public void CreateOfficeDepartment(DepartmentToUser departmentToUser)
{
using (MySqlConnection db = new MySqlConnection(ConfigurationValues.GroveHillConnection))
{
departmentToUser.UniqueID = Guid.NewGuid().ToString();
try
{
const string query = "insert into officenames(UniqueID,Name,Department)"
+ " values(@UniqueID,@Name,@Department)";
int rowsAffectd = db.Execute(query, new
{
@UniqueID = departmentToUser.UniqueID,
@Name = departmentToUser.Name,
@Department = departmentToUser.Department
});
int r = 5;
}
catch (Exception er)
{
string s1 = er.ToString();
//Log.LogMessage(er.ToString());
}
}
}
示例4: AddBlock
public void AddBlock(IShare share)
{
try
{
if (!IsEnabled)
return;
using (var connection = new MySqlConnection(_mySqlProvider.ConnectionString))
{
connection.Execute(
@"INSERT INTO Block(Height, BlockHash, TxHash, Amount, CreatedAt) VALUES (@height, @blockHash, @txHash, @amount, @createdAt)",
new
{
height = share.Block.Height,
blockHash = share.BlockHash.ToHexString(),
txHash = share.Block.Tx.First(),
amount = (decimal)share.GenerationTransaction.TotalAmount,
createdAt = share.Block.Time.UnixTimestampToDateTime()
});
}
}
catch (Exception e)
{
_logger.Error("An exception occured while adding block; {0:l}", e.Message);
}
}
示例5: CreateDatabaseIfNeeded
private void CreateDatabaseIfNeeded()
{
using (var conn = new MySqlConnection(_connectionString))
conn.Execute($"CREATE DATABASE IF NOT EXISTS {_databaseName}");
using (var conn = OpenConnection())
{
if (!DoesTableExists(conn, "EndpointConfig"))
CreateEndpointConfig(conn);
if (!DoesColumnExists(conn, "EndpointConfig", "Tags"))
CreateColumn(conn, "EndpointConfig", "Tags", "varchar(4096)");
if (!DoesColumnExists(conn, "EndpointConfig", "Password"))
CreateColumn(conn, "EndpointConfig", "Password", "varchar(64)");
var date = DateTime.UtcNow;
if (!DoesColumnExists(conn, "EndpointConfig", "RegisteredOnUtc"))
CreateColumnAndSetValue(conn, "EndpointConfig", "RegisteredOnUtc", "datetime not null", date);
if (!DoesColumnExists(conn, "EndpointConfig", "RegistrationUpdatedOnUtc"))
CreateColumnAndSetValue(conn, "EndpointConfig", "RegistrationUpdatedOnUtc", "datetime not null", date);
if (!DoesColumnExists(conn, "EndpointConfig", "MonitorTag"))
CreateColumn(conn, "EndpointConfig", "MonitorTag", "varchar(1024) default 'default'");
if (!DoesTableExists(conn, "EndpointStats"))
CreateEndpointStats(conn);
if (!DoesTableExists(conn, "HealthMonitorTypes"))
CreateHealthMonitorTypesTable(conn);
if (!DoesIndexExists(conn, "EndpointStats", "EndpointStats_EndpointIdCheckTimeUtc_idx"))
CreateEndpointStatsIndex(conn);
if (!DoesIndexExists(conn, "EndpointConfig", "EndpointConfig_MonitorTag_idx"))
CreateMonitorTagIndex(conn);
if (!DoesIndexExists(conn, "EndpointConfig", "EndpointConfig_MonitorType_idx"))
CreateMonitorTypeIndex(conn);
}
}
示例6: UpdateBlock
public void UpdateBlock(IPersistedBlock block)
{
try
{
if (!IsEnabled)
return;
using (var connection = new MySqlConnection(_mySqlProvider.ConnectionString))
{
connection.Execute(
@"UPDATE Block SET Orphaned = @orphaned, Confirmed = @confirmed, Accounted = @accounted, Reward = @reward WHERE Height = @height",
new
{
orphaned = block.Status == BlockStatus.Orphaned,
confirmed = block.Status == BlockStatus.Confirmed,
accounted = block.Accounted,
reward = block.Reward,
height = block.Height
});
}
}
catch (Exception e)
{
_logger.Error("An exception occured while updating block; {0:l}", e.Message);
}
}
示例7: AddPayment
public void AddPayment(IPayment payment)
{
try
{
if (!IsEnabled)
return;
using (var connection = new MySqlConnection(_mySqlProvider.ConnectionString))
{
connection.Execute(
@"INSERT INTO Payment(Block, AccountId, Amount, CreatedAt) VALUES(@blockId, @accountId, @amount, @createdAt)",
new
{
blockId = payment.BlockId,
accountId = payment.AccountId,
amount = payment.Amount,
createdAt = DateTime.Now
});
}
}
catch (Exception e)
{
_logger.Error("An exception occured while committing payment; {0:l}", e.Message);
}
}
示例8: GetValidatedUser
public static DataModel.User GetValidatedUser(string username, string password, string account)
{
using (MySqlConnection sqlConnection = new MySqlConnection(UtilityHelper.GetConnectionString()))
{
sqlConnection.Open();
DataModel.User userObj = sqlConnection.Query<DataModel.User>("Select * from User where [email protected] and [email protected]", new { Username = username, Account = account }).FirstOrDefault();
if (userObj != null)
{
if (string.IsNullOrEmpty(userObj.Salt))
{
if (password.Equals(userObj.Password))
{
string salt = Guid.NewGuid().ToString();
sqlConnection.Execute(@"update User set [email protected], [email protected] where [email protected] and [email protected]", new { Salt = salt, Password = UtilityHelper.HashPassword(userObj.Password, salt), Username = username, Account = account });
return userObj;
}
}
else
{
password=UtilityHelper.HashPassword(password,userObj.Salt);
if (password.Equals(userObj.Password))
{
return userObj;
}
}
}
}
return null;
}
示例9: Activate
public void Activate(Promocion p)
{
using (MySqlConnection conn = new MySqlConnection(Constants.QueryConn))
{
try
{
conn.Open();
var platos = GetPlatosByPromo(p);
PlatoDao platoDao = new PlatoDao();
foreach (var pl in platos)
{
var plato = platoDao.GetOne(pl.Plato_Id);
if (plato.Estado != "DISPONIBLE")
{
throw new DataException("No se puede marcar como DISPONIBLE una promoción que contiene platos NO DISPONIBLES");
}
}
if (conn.Execute(Constants.ActivatePromo, p, null, null, CommandType.Text) == -1)
{
throw new DataException("No se actualizó la promoción como DISPONIBLE");
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
conn.Close();
}
}
}
示例10: InsertSiteCatUrlTableAusYp
//***************************************************Australia***************************************
//Australia Yellow Pages Category
#region --For InsertSiteCatUrlTableAusYp
public int InsertSiteCatUrlTableAusYp(string SiteName, string SiteUrl, string Category, DateTime CrawlDate, string Status)
{
using (MySqlConnection conn = new MySqlConnection(BG_Db_Class.getConnectionString()))
try
{
{
if (conn.State != ConnectionState.Open)
try
{
conn.Open();
}
catch (MySqlException ex)
{
throw (ex);
}
int rowAffected = conn.Execute(@"INSERT INTO Bus_Data_AusYPCatUrl(SiteName,Url,Category,date,Status) VALUES(@SiteName,@SiteUrl,@Category,@date,@Status)", new { SiteName = SiteName, SiteUrl = SiteUrl, Category = Category, date = CrawlDate, Status = Status });
return rowAffected;
}
}
catch (Exception ex)
{
return 0;
}
finally
{
conn.Close();
}
}
示例11: DeleteUser
public static void DeleteUser(string account, string username)
{
using (MySqlConnection sqlConnection = new MySqlConnection(UtilityHelper.GetConnectionString()))
{
sqlConnection.Open();
sqlConnection.Execute(@"update User set IsActive=false where [email protected] and [email protected]", new { Username = username, Account = account });
}
}
示例12: CreateUser
public static void CreateUser(string username, string accountName, string password, string email, bool? isAdmin)
{
using (MySqlConnection sqlConnection = new MySqlConnection(UtilityHelper.GetConnectionString()))
{
string salt = Guid.NewGuid().ToString();
sqlConnection.Open();
sqlConnection.Execute(@"insert into User(Username,Account,Password,Salt,IsActive,IsAdmin,Email) values (@Username,@Account,@Password,@Salt,@IsActive,@IsAdmin,@Email)", new { Username = username, Account = accountName, Password = UtilityHelper.HashPassword(password, salt), Salt = salt, IsActive = true, IsAdmin = isAdmin, Email = email });
}
}
示例13: DeleteCoord
public bool DeleteCoord(int id)
{
using (var cn = new MySqlConnection(_connectionString))
{
const string sql = "DELETE FROM `geopoints` WHERE `ID`[email protected];";
return cn.Execute(sql, new {ID = id}) > 0;
}
}
示例14: DeleteAllPlatos
public int DeleteAllPlatos(Promocion p, MySqlConnection conn, MySqlTransaction trans)
{
try
{
return conn.Execute(Constants.DeletePlatosByPromo, p, trans, null, CommandType.Text);
}
catch (Exception ex)
{
throw ex;
}
}
示例15: DeleteImage
/// <summary>
/// Deletes an image from the DB
/// </summary>
/// <param name="imageId">The Id of the image to delete</param>
public void DeleteImage(int imageId)
{
using (var connection = new MySqlConnection(Common.ConnectionString))
{
connection.Open();
connection.Execute("osae_sp_image_delete",
new { pimage_id = imageId },
commandType: CommandType.StoredProcedure);
}
}