mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-15 14:04:44 +08:00
Mysql batch insert \ bug
This commit is contained in:
parent
73b6e202fe
commit
3a03456593
@ -48,10 +48,10 @@ namespace OrmTest.Demo
|
||||
var insertObjs = new List<Student>();
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
insertObjs.Add(new Student() { Name = "name" + i });
|
||||
insertObjs.Add(new Student() { Name = "name\\'" + i });
|
||||
}
|
||||
var t10 = db.Insertable(insertObjs.ToArray()).InsertColumns(it => new { it.Name }).ExecuteCommand();
|
||||
|
||||
var t10 = db.Insertable(insertObjs.ToArray()).InsertColumns(it => new { it.Name }).ExecuteReturnIdentity();
|
||||
var data = db.Queryable<Student>().OrderBy(it=>it.Id,OrderByType.Desc).ToList();
|
||||
var t11 = db.Insertable(insertObjs.ToArray()).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
namespace SqlSugar
|
||||
using System;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class MySqlInsertBuilder : InsertBuilder
|
||||
{
|
||||
@ -23,5 +25,55 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
public override object FormatValue(object value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return "NULL";
|
||||
}
|
||||
else
|
||||
{
|
||||
var type = value.GetType();
|
||||
if (type == UtilConstants.DateType)
|
||||
{
|
||||
var date = value.ObjToDate();
|
||||
if (date < Convert.ToDateTime("1900-1-1"))
|
||||
{
|
||||
date = Convert.ToDateTime("1900-1-1");
|
||||
}
|
||||
return "'" + date.ToString("yyyy-MM-dd HH:mm:ss.fff") + "'";
|
||||
}
|
||||
else if (type == UtilConstants.ByteArrayType)
|
||||
{
|
||||
string bytesString = "0x" + BitConverter.ToString((byte[])value).Replace("-", "");
|
||||
return bytesString;
|
||||
}
|
||||
else if (type.IsEnum())
|
||||
{
|
||||
return Convert.ToInt64(value);
|
||||
}
|
||||
else if (type == UtilConstants.BoolType)
|
||||
{
|
||||
return value.ObjToBool() ? "1" : "0";
|
||||
}
|
||||
else if (type == UtilConstants.StringType || type == UtilConstants.ObjType)
|
||||
{
|
||||
return "N'" + GetString(value).ToSqlFilter() + "'";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "N'" + GetString(value) + "'";
|
||||
}
|
||||
}
|
||||
}
|
||||
private string GetString(object value)
|
||||
{
|
||||
var result = value.ToString();
|
||||
if (result.HasValue() && result.Contains("\\"))
|
||||
{
|
||||
result = result.Replace("\\", "\\\\");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
@ -87,5 +88,55 @@ namespace SqlSugar
|
||||
}
|
||||
return batchUpdateSql.ToString();
|
||||
}
|
||||
public override object FormatValue(object value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return "NULL";
|
||||
}
|
||||
else
|
||||
{
|
||||
var type = value.GetType();
|
||||
if (type == UtilConstants.DateType)
|
||||
{
|
||||
var date = value.ObjToDate();
|
||||
if (date < Convert.ToDateTime("1900-1-1"))
|
||||
{
|
||||
date = Convert.ToDateTime("1900-1-1");
|
||||
}
|
||||
return "'" + date.ToString("yyyy-MM-dd HH:mm:ss.fff") + "'";
|
||||
}
|
||||
else if (type == UtilConstants.ByteArrayType)
|
||||
{
|
||||
string bytesString = "0x" + BitConverter.ToString((byte[])value).Replace("-", "");
|
||||
return bytesString;
|
||||
}
|
||||
else if (type.IsEnum())
|
||||
{
|
||||
return Convert.ToInt64(value);
|
||||
}
|
||||
else if (type == UtilConstants.BoolType)
|
||||
{
|
||||
return value.ObjToBool() ? "1" : "0";
|
||||
}
|
||||
else if (type == UtilConstants.StringType || type == UtilConstants.ObjType)
|
||||
{
|
||||
return "N'" + GetString(value).ToSqlFilter() + "'";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "N'" + GetString(value) + "'";
|
||||
}
|
||||
}
|
||||
}
|
||||
private string GetString(object value)
|
||||
{
|
||||
var result = value.ToString();
|
||||
if (result.HasValue() && result.Contains("\\"))
|
||||
{
|
||||
result = result.Replace("\\", "\\\\");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user