mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-10-15 18:55:07 +08:00
Update MySqlConnector
This commit is contained in:
@@ -8,7 +8,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar.MySqlConnector
|
||||
namespace SqlSugar.MySqlConnector
|
||||
{
|
||||
|
||||
public class MySqlFastBuilder:FastBuilder,IFastBuilder
|
||||
@@ -44,7 +44,7 @@ namespace SqlSugar.MySqlConnector
|
||||
TableName = dt.TableName,
|
||||
Local = true,
|
||||
};
|
||||
if (this.CharacterSet.HasValue())
|
||||
if (this.CharacterSet.HasValue())
|
||||
{
|
||||
bulk.CharacterSet = this.CharacterSet;
|
||||
}
|
||||
@@ -58,7 +58,14 @@ namespace SqlSugar.MySqlConnector
|
||||
}
|
||||
catch (MySqlException ex)
|
||||
{
|
||||
throw ex;
|
||||
if (ex.Message == "The used command is not allowed with this MySQL version")
|
||||
{
|
||||
Check.ExceptionEasy("connection string add : AllowLoadLocalInfile=true", "BulkCopy MySql连接字符串需要添加 AllowLoadLocalInfile=true; 添加后如果还不行Mysql数据库执行一下 SET GLOBAL local_infile=1 ");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@@ -27,7 +27,8 @@ namespace SqlSugar.MySqlConnector
|
||||
}
|
||||
}
|
||||
}
|
||||
public override object FormatValue(object value)
|
||||
int i = 0;
|
||||
public object FormatValue(object value,string name)
|
||||
{
|
||||
var n = "N";
|
||||
if (this.Context.CurrentConnectionConfig.MoreSettings != null && this.Context.CurrentConnectionConfig.MoreSettings.DisableNvarchar)
|
||||
@@ -44,9 +45,9 @@ namespace SqlSugar.MySqlConnector
|
||||
if (type == UtilConstants.DateType)
|
||||
{
|
||||
var date = value.ObjToDate();
|
||||
if (date < Convert.ToDateTime("1900-1-1"))
|
||||
if (date < UtilMethods.GetMinDate(this.Context.CurrentConnectionConfig))
|
||||
{
|
||||
date = Convert.ToDateTime("1900-1-1");
|
||||
date = UtilMethods.GetMinDate(this.Context.CurrentConnectionConfig);
|
||||
}
|
||||
return "'" + date.ToString("yyyy-MM-dd HH:mm:ss.fff") + "'";
|
||||
}
|
||||
@@ -72,7 +73,10 @@ namespace SqlSugar.MySqlConnector
|
||||
}
|
||||
else if (type == UtilConstants.StringType || type == UtilConstants.ObjType)
|
||||
{
|
||||
return n+"'" + GetString(value).ToSqlFilter() + "'";
|
||||
++i;
|
||||
var parameterName = this.Builder.SqlParameterKeyWord + name + i;
|
||||
this.Parameters.Add(new SugarParameter(parameterName, value));
|
||||
return parameterName;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -102,6 +106,7 @@ namespace SqlSugar.MySqlConnector
|
||||
if (isSingle)
|
||||
{
|
||||
string columnParametersString = string.Join(",", this.DbColumnInfoList.Select(it => Builder.SqlParameterKeyWord + it.DbColumnName));
|
||||
ActionMinDate();
|
||||
return string.Format(SqlTemplate, GetTableNameString, columnsString, columnParametersString);
|
||||
}
|
||||
else
|
||||
@@ -115,7 +120,7 @@ namespace SqlSugar.MySqlConnector
|
||||
foreach (var item in groupList)
|
||||
{
|
||||
batchInsetrSql.Append("(");
|
||||
insertColumns = string.Join(",", item.Select(it => FormatValue(it.Value)));
|
||||
insertColumns = string.Join(",", item.Select(it => FormatValue(it.Value,it.PropertyName)));
|
||||
batchInsetrSql.Append(insertColumns);
|
||||
if (groupList.Last() == item)
|
||||
{
|
||||
|
@@ -59,7 +59,7 @@ namespace SqlSugar.MySqlConnector
|
||||
{
|
||||
updateTable.Append(SqlTemplateBatchUnion);
|
||||
}
|
||||
updateTable.Append("\r\n SELECT " + string.Join(",", columns.Select(it => string.Format(SqlTemplateBatchSelect, FormatValue(it.Value),this.Builder.GetTranslationColumnName(it.DbColumnName)))));
|
||||
updateTable.Append("\r\n SELECT " + string.Join(",", columns.Select(it => string.Format(SqlTemplateBatchSelect, FormatValue(it.Value,it.PropertyName),this.Builder.GetTranslationColumnName(it.DbColumnName)))));
|
||||
++i;
|
||||
}
|
||||
pageIndex++;
|
||||
@@ -89,7 +89,8 @@ namespace SqlSugar.MySqlConnector
|
||||
}
|
||||
return batchUpdateSql.ToString();
|
||||
}
|
||||
public override object FormatValue(object value)
|
||||
int i = 0;
|
||||
public object FormatValue(object value,string name)
|
||||
{
|
||||
var n = "N";
|
||||
if (this.Context.CurrentConnectionConfig.MoreSettings != null&&this.Context.CurrentConnectionConfig.MoreSettings.DisableNvarchar)
|
||||
@@ -106,9 +107,9 @@ namespace SqlSugar.MySqlConnector
|
||||
if (type == UtilConstants.DateType)
|
||||
{
|
||||
var date = value.ObjToDate();
|
||||
if (date < Convert.ToDateTime("1900-1-1"))
|
||||
if (date < UtilMethods.GetMinDate(this.Context.CurrentConnectionConfig))
|
||||
{
|
||||
date = Convert.ToDateTime("1900-1-1");
|
||||
date = UtilMethods.GetMinDate(this.Context.CurrentConnectionConfig);
|
||||
}
|
||||
return "'" + date.ToString("yyyy-MM-dd HH:mm:ss.fff") + "'";
|
||||
}
|
||||
@@ -142,7 +143,10 @@ namespace SqlSugar.MySqlConnector
|
||||
}
|
||||
else if (type == UtilConstants.StringType || type == UtilConstants.ObjType)
|
||||
{
|
||||
return n+"'" + GetString(value).ToSqlFilter() + "'";
|
||||
++i;
|
||||
var parameterName = this.Builder.SqlParameterKeyWord + name + i;
|
||||
this.Parameters.Add(new SugarParameter(parameterName, value));
|
||||
return parameterName;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Reference in New Issue
Block a user