diff --git a/Src/Asp.Net/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteInsertBuilder.cs b/Src/Asp.Net/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteInsertBuilder.cs index 2443772dc..b44adee88 100644 --- a/Src/Asp.Net/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteInsertBuilder.cs +++ b/Src/Asp.Net/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteInsertBuilder.cs @@ -57,10 +57,11 @@ namespace SqlSugar batchInsetrSql.Append(columnsString); batchInsetrSql.Append(") VALUES"); string insertColumns = ""; + int i = 0; foreach (var item in groupList) { batchInsetrSql.Append("("); - insertColumns = string.Join(",", item.Select(it => FormatValue(it.Value))); + insertColumns = string.Join(",", item.Select(it => FormatValue(i,it.DbColumnName,it.Value))); batchInsetrSql.Append(insertColumns); if (groupList.Last() == item) { @@ -70,6 +71,7 @@ namespace SqlSugar { batchInsetrSql.Append("), "); } + i++; } batchInsetrSql.AppendLine(";SELECT LAST_INSERT_ROWID();"); @@ -77,7 +79,7 @@ namespace SqlSugar return result; } } - public override object FormatValue(object value) + public object FormatValue(int i,string name,object value) { if (value == null) { @@ -101,8 +103,9 @@ namespace SqlSugar } else if (type == UtilConstants.ByteArrayType) { - string bytesString = "0x" + BitConverter.ToString((byte[])value).Replace("-", ""); - return bytesString; + var parameterName = this.Builder.SqlParameterKeyWord + name + i; + this.Parameters.Add(new SugarParameter(parameterName, value)); + return parameterName; } else if (type == UtilConstants.BoolType) { diff --git a/Src/Asp.Net/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteUpdateBuilder.cs b/Src/Asp.Net/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteUpdateBuilder.cs index c5e278d87..bcf2bde8e 100644 --- a/Src/Asp.Net/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteUpdateBuilder.cs +++ b/Src/Asp.Net/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteUpdateBuilder.cs @@ -10,29 +10,32 @@ namespace SqlSugar protected override string TomultipleSqlString(List> groupList) { StringBuilder sb = new StringBuilder(); + int i = 0; sb.AppendLine(string.Join("\r\n", groupList.Select(t => { var updateTable = string.Format("UPDATE {0} SET", base.GetTableNameStringNoWith); - var setValues = string.Join(",", t.Where(s => !s.IsPrimarykey).Select(m => GetOracleUpdateColums(m)).ToArray()); + var setValues = string.Join(",", t.Where(s => !s.IsPrimarykey).Select(m => GetOracleUpdateColums(i,m)).ToArray()); var pkList = t.Where(s => s.IsPrimarykey).ToList(); List whereList = new List(); foreach (var item in pkList) { var isFirst = pkList.First() == item; var whereString = ""; - whereString += GetOracleUpdateColums(item); + whereString += GetOracleUpdateColums(i,item); whereList.Add(whereString); } + i++; return string.Format("{0} {1} WHERE {2};", updateTable, setValues, string.Join("AND", whereList)); }).ToArray())); return sb.ToString(); } - private string GetOracleUpdateColums(DbColumnInfo m) + private string GetOracleUpdateColums(int i,DbColumnInfo m) { - return string.Format("\"{0}\"={1}", m.DbColumnName.ToUpper(), FormatValue(m.Value)); + return string.Format("\"{0}\"={1}", m.DbColumnName.ToUpper(), FormatValue(i,m.DbColumnName,m.Value)); } - public override object FormatValue(object value) + + public object FormatValue(int i,string name,object value) { if (value == null) { @@ -56,8 +59,9 @@ namespace SqlSugar } else if (type == UtilConstants.ByteArrayType) { - string bytesString = "0x" + BitConverter.ToString((byte[])value).Replace("-", ""); - return bytesString; + var parameterName = this.Builder.SqlParameterKeyWord + name + i; + this.Parameters.Add(new SugarParameter(parameterName, value)); + return parameterName; } else if (type == UtilConstants.BoolType) { diff --git a/Src/Asp.Net/SqliteTest/Bugs/BugTest.cs b/Src/Asp.Net/SqliteTest/Bugs/BugTest.cs index 91db98dcb..93c9a6ce5 100644 --- a/Src/Asp.Net/SqliteTest/Bugs/BugTest.cs +++ b/Src/Asp.Net/SqliteTest/Bugs/BugTest.cs @@ -1,50 +1,58 @@ -using SqlSugar; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +//using SqlSugar; +//using System; +//using System.Collections.Generic; +//using System.Linq; +//using System.Text; +//using System.Threading.Tasks; -namespace OrmTest.Test -{ - public class BugTest - { - public static void Init() - { - var db = GetInstance(); - db.CodeFirst.InitTables(); - List tl = new List(); - for (int i = 0; i < 10; i++) - { - InTest t = new InTest(); - t.name = "1"; - t.aa = new byte[] { 1, 32, 12, 33 }; - tl.Add(t); - } - db.Insertable(tl).ExecuteCommand(); - } - private static SqlSugarClient GetInstance() - { - return new SqlSugarClient(new ConnectionConfig() - { - DbType = SqlSugar.DbType.Sqlite, - ConnectionString = Config.ConnectionString, - InitKeyType = InitKeyType.Attribute, - IsAutoCloseConnection = true, - AopEvents = new AopEvents - { - OnLogExecuting = (sql, p) => - { - Console.WriteLine(sql); - Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value))); - } - } - }); - } - public class InTest - { - public byte[] aa { get; set; } - public string name { get; set; } - } - } -} +//namespace OrmTest.Test +//{ +// public class BugTest +// { +// public static void Init() +// { +// var db = GetInstance(); +// db.CodeFirst.InitTables(); +// List tl = new List(); +// for (int i = 0; i < 10; i++) +// { +// InTest t = new InTest(); +// t.name = "1"; +// t.aa = new byte[] {(byte) i, 32, 12, 33,12,11,11,11,11,11,11,11,11,11 }; +// tl.Add(t); +// } +// db.Insertable(tl).ExecuteCommand(); +// var xx= db.Queryable().ToList(); +// var xxxx = xx.Take(2).ToList(); +// foreach (var item in xxxx) +// { +// item.aa = new byte[] { (byte)21, 11, 3, 33, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11 }; +// } +// db.Updateable(xxxx).WhereColumns(it=>it.name).ExecuteCommand(); +// xx = db.Queryable().ToList(); +// } +// private static SqlSugarClient GetInstance() +// { +// return new SqlSugarClient(new ConnectionConfig() +// { +// DbType = SqlSugar.DbType.Sqlite, +// ConnectionString = Config.ConnectionString, +// InitKeyType = InitKeyType.Attribute, +// IsAutoCloseConnection = true, +// AopEvents = new AopEvents +// { +// OnLogExecuting = (sql, p) => +// { +// Console.WriteLine(sql); +// Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value))); +// } +// } +// }); +// } +// public class InTest +// { +// public byte[] aa { get; set; } +// public string name { get; set; } +// } +// } +//}