mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +08:00
Update mysql bulk copy support byte[]
This commit is contained in:
parent
1498647513
commit
1e2ee8ccf8
34
Src/Asp.NetCore2/SqlSugar/OnlyCore/MySqlFastBuilder.cs
Normal file
34
Src/Asp.NetCore2/SqlSugar/OnlyCore/MySqlFastBuilder.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using MySqlConnector;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public partial class MySqlFastBuilder : FastBuilder, IFastBuilder
|
||||
{
|
||||
private async Task<int> MySqlConnectorBulkCopy(DataTable dt)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.Context.Open();
|
||||
var tran = (MySqlTransaction)this.Context.Ado.Transaction;
|
||||
var connection = (MySqlConnection)this.Context.Ado.Connection;
|
||||
MySqlBulkCopy bulkCopy = new MySqlBulkCopy(connection, tran);
|
||||
bulkCopy.DestinationTableName= dt.TableName;
|
||||
await bulkCopy.WriteToServerAsync(dt);
|
||||
return dt.Rows.Count;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
CloseDb();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -11,12 +11,15 @@ using System.Threading.Tasks;
|
||||
namespace SqlSugar
|
||||
{
|
||||
|
||||
public class MySqlFastBuilder:FastBuilder,IFastBuilder
|
||||
public partial class MySqlFastBuilder:FastBuilder,IFastBuilder
|
||||
{
|
||||
public override string UpdateSql { get; set; } = @"UPDATE {1} TM INNER JOIN {2} TE ON {3} SET {0} ";
|
||||
public async Task<int> ExecuteBulkCopyAsync(DataTable dt)
|
||||
{
|
||||
|
||||
{
|
||||
if (dt.Columns.Cast<DataColumn>().Any(it => it.DataType == UtilConstants.ByteArrayType))
|
||||
{
|
||||
return await MySqlConnectorBulkCopy(dt);
|
||||
}
|
||||
var dllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bulkcopyfiles");
|
||||
DirectoryInfo dir = new DirectoryInfo(dllPath);
|
||||
if (!dir.Exists)
|
||||
|
Loading…
Reference in New Issue
Block a user