mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-18 20:08:15 +08:00
✨ support provider、Extensions Exceptions 多语言
This commit is contained in:
@ -40,7 +40,7 @@ namespace FreeSql.SqlServer.Curd
|
||||
}
|
||||
var sql = sb.ToString();
|
||||
var validx = sql.IndexOf(" WHERE ");
|
||||
if (validx == -1) throw new ArgumentException("找不到 WHERE ");
|
||||
if (validx == -1) throw new ArgumentException(CoreStrings.S_NotFound_Name("WHERE"));
|
||||
sql = sb.Clear().Append(sql.Substring(0, validx))
|
||||
.Append(sbret)
|
||||
.Append(sql.Substring(validx)).ToString();
|
||||
@ -97,7 +97,7 @@ namespace FreeSql.SqlServer.Curd
|
||||
}
|
||||
var sql = sb.ToString();
|
||||
var validx = sql.IndexOf(" WHERE ");
|
||||
if (validx == -1) throw new ArgumentException("找不到 WHERE ");
|
||||
if (validx == -1) throw new ArgumentException(CoreStrings.S_NotFound_Name("WHERE"));
|
||||
sql = sb.Clear().Append(sql.Substring(0, validx))
|
||||
.Append(sbret)
|
||||
.Append(sql.Substring(validx)).ToString();
|
||||
|
@ -74,14 +74,14 @@ namespace FreeSql.SqlServer.Curd
|
||||
if ((_commonUtils as SqlServerUtils).ServerVersion > 10)
|
||||
{
|
||||
var validx = sql.IndexOf(") VALUES");
|
||||
if (validx == -1) throw new ArgumentException("找不到 VALUES");
|
||||
if (validx == -1) throw new ArgumentException(CoreStrings.S_NotFound_Name("VALUES"));
|
||||
sb.Insert(0, sql.Substring(0, validx + 1));
|
||||
sb.Append(sql.Substring(validx + 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
var validx = sql.IndexOf(") SELECT ");
|
||||
if (validx == -1) throw new ArgumentException("找不到 SELECT");
|
||||
if (validx == -1) throw new ArgumentException(CoreStrings.S_NotFound_Name("SELECT"));
|
||||
sb.Insert(0, sql.Substring(0, validx + 1));
|
||||
sb.Append(sql.Substring(validx + 1));
|
||||
}
|
||||
@ -158,14 +158,14 @@ namespace FreeSql.SqlServer.Curd
|
||||
if ((_commonUtils as SqlServerUtils).ServerVersion > 10)
|
||||
{
|
||||
var validx = sql.IndexOf(") VALUES");
|
||||
if (validx == -1) throw new ArgumentException("找不到 VALUES");
|
||||
if (validx == -1) throw new ArgumentException(CoreStrings.S_NotFound_Name("VALUES"));
|
||||
sb.Insert(0, sql.Substring(0, validx + 1));
|
||||
sb.Append(sql.Substring(validx + 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
var validx = sql.IndexOf(") SELECT ");
|
||||
if (validx == -1) throw new ArgumentException("找不到 SELECT");
|
||||
if (validx == -1) throw new ArgumentException(CoreStrings.S_NotFound_Name("SELECT"));
|
||||
sb.Insert(0, sql.Substring(0, validx + 1));
|
||||
sb.Append(sql.Substring(validx + 1));
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ namespace FreeSql.SqlServer.Curd
|
||||
}
|
||||
var sql = sb.ToString();
|
||||
var validx = sql.IndexOf(" \r\nWHERE ");
|
||||
if (validx == -1) throw new ArgumentException("找不到 WHERE ");
|
||||
if (validx == -1) throw new ArgumentException(CoreStrings.S_NotFound_Name("WHERE"));
|
||||
sql = sb.Clear().Append(sql.Substring(0, validx))
|
||||
.Append(sbret)
|
||||
.Append(sql.Substring(validx)).ToString();
|
||||
@ -140,7 +140,7 @@ namespace FreeSql.SqlServer.Curd
|
||||
}
|
||||
var sql = sb.ToString();
|
||||
var validx = sql.IndexOf(" \r\nWHERE ");
|
||||
if (validx == -1) throw new ArgumentException("找不到 WHERE ");
|
||||
if (validx == -1) throw new ArgumentException(CoreStrings.S_NotFound_Name("WHERE"));
|
||||
sql = sb.Clear().Append(sql.Substring(0, validx))
|
||||
.Append(sbret)
|
||||
.Append(sql.Substring(validx)).ToString();
|
||||
|
@ -29,12 +29,12 @@ namespace FreeSql.SqlServer
|
||||
return;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(masterConnectionString))
|
||||
MasterPool = new SqlServerConnectionPool("主库", masterConnectionString, null, null);
|
||||
MasterPool = new SqlServerConnectionPool(CoreStrings.S_MasterDatabase, masterConnectionString, null, null);
|
||||
if (slaveConnectionStrings != null)
|
||||
{
|
||||
foreach (var slaveConnectionString in slaveConnectionStrings)
|
||||
{
|
||||
var slavePool = new SqlServerConnectionPool($"从库{SlavePools.Count + 1}", slaveConnectionString, () => Interlocked.Decrement(ref slaveUnavailables), () => Interlocked.Increment(ref slaveUnavailables));
|
||||
var slavePool = new SqlServerConnectionPool($"{CoreStrings.S_SlaveDatabase}{SlavePools.Count + 1}", slaveConnectionString, () => Interlocked.Decrement(ref slaveUnavailables), () => Interlocked.Increment(ref slaveUnavailables));
|
||||
SlavePools.Add(slavePool);
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ namespace FreeSql.SqlServer
|
||||
{
|
||||
|
||||
internal SqlServerConnectionPool _pool;
|
||||
public string Name { get; set; } = "SqlServer SqlConnection 对象池";
|
||||
public string Name { get; set; } = $"SqlServer SqlConnection {CoreStrings.S_ObjectPool}";
|
||||
public int PoolSize { get; set; } = 100;
|
||||
public TimeSpan SyncGetTimeout { get; set; } = TimeSpan.FromSeconds(10);
|
||||
public TimeSpan IdleTimeout { get; set; } = TimeSpan.FromSeconds(20);
|
||||
@ -126,8 +126,8 @@ namespace FreeSql.SqlServer
|
||||
|
||||
if (obj.Value == null)
|
||||
{
|
||||
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
|
||||
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
|
||||
_pool.SetUnavailable(new Exception(CoreStrings.S_ConnectionStringError), obj.LastGetTimeCopy);
|
||||
throw new Exception(CoreStrings.S_ConnectionStringError_Check(this.Name));
|
||||
}
|
||||
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && obj.Value.Ping() == false)
|
||||
@ -156,8 +156,8 @@ namespace FreeSql.SqlServer
|
||||
|
||||
if (obj.Value == null)
|
||||
{
|
||||
_pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
|
||||
throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
|
||||
_pool.SetUnavailable(new Exception(CoreStrings.S_ConnectionStringError), obj.LastGetTimeCopy);
|
||||
throw new Exception(CoreStrings.S_ConnectionStringError_Check(this.Name));
|
||||
}
|
||||
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false)
|
||||
|
@ -152,8 +152,8 @@ ELSE
|
||||
{
|
||||
if (sb.Length > 0) sb.Append("\r\n");
|
||||
var tb = _commonUtils.GetTableByEntity(obj.entityType);
|
||||
if (tb == null) throw new Exception($"类型 {obj.entityType.FullName} 不可迁移");
|
||||
if (tb.Columns.Any() == false) throw new Exception($"类型 {obj.entityType.FullName} 不可迁移,可迁移属性0个");
|
||||
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.entityType.FullName));
|
||||
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.entityType.FullName));
|
||||
var tbname = _commonUtils.SplitTableName(tb.DbName);
|
||||
if (tbname?.Length == 1) tbname = new[] { database, "dbo", tbname[0] };
|
||||
if (tbname?.Length == 2) tbname = new[] { database, tbname[0], tbname[1] };
|
||||
|
@ -73,7 +73,7 @@ public static partial class FreeSqlSqlServerGlobalExtensions
|
||||
public static void ExecuteSqlBulkCopy<T>(this IInsert<T> that, SqlBulkCopyOptions copyOptions = SqlBulkCopyOptions.Default, int? batchSize = null, int? bulkCopyTimeout = null) where T : class
|
||||
{
|
||||
var insert = that as FreeSql.SqlServer.Curd.SqlServerInsert<T>;
|
||||
if (insert == null) throw new Exception("ExecuteSqlBulkCopy 是 FreeSql.Provider.SqlServer 特有的功能");
|
||||
if (insert == null) throw new Exception(CoreStrings.S_Features_Unique("ExecuteSqlBulkCopy", "SqlServer"));
|
||||
|
||||
var dt = that.ToDataTable();
|
||||
if (dt.Rows.Count == 0) return;
|
||||
@ -139,7 +139,7 @@ public static partial class FreeSqlSqlServerGlobalExtensions
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException("ExecuteSqlBulkCopy 未实现错误,请反馈给作者");
|
||||
throw new NotImplementedException($"ExecuteSqlBulkCopy {CoreStrings.S_Not_Implemented_FeedBack}");
|
||||
}
|
||||
}
|
||||
finally
|
||||
@ -152,7 +152,7 @@ public static partial class FreeSqlSqlServerGlobalExtensions
|
||||
async public static Task ExecuteSqlBulkCopyAsync<T>(this IInsert<T> that, SqlBulkCopyOptions copyOptions = SqlBulkCopyOptions.Default, int? batchSize = null, int? bulkCopyTimeout = null, CancellationToken cancellationToken = default) where T : class
|
||||
{
|
||||
var insert = that as FreeSql.SqlServer.Curd.SqlServerInsert<T>;
|
||||
if (insert == null) throw new Exception("ExecuteSqlBulkCopyAsync 是 FreeSql.Provider.SqlServer 特有的功能");
|
||||
if (insert == null) throw new Exception(CoreStrings.S_Features_Unique("ExecuteSqlBulkCopyAsync", "SqlServer"));
|
||||
|
||||
var dt = that.ToDataTable();
|
||||
if (dt.Rows.Count == 0) return;
|
||||
@ -218,7 +218,7 @@ public static partial class FreeSqlSqlServerGlobalExtensions
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException("ExecuteSqlBulkCopyAsync 未实现错误,请反馈给作者");
|
||||
throw new NotImplementedException($"ExecuteSqlBulkCopyAsync {CoreStrings.S_Not_Implemented_FeedBack}");
|
||||
}
|
||||
}
|
||||
finally
|
||||
|
Reference in New Issue
Block a user