Update MySqlConnector

This commit is contained in:
sunkaixuan 2022-09-15 00:25:08 +08:00
parent 4919022178
commit 1c81b67871
5 changed files with 28 additions and 6 deletions

View File

@ -25,6 +25,10 @@ namespace SqlSugar.MySqlConnector
DbColumnInfo dbColumnInfo = this.EntityColumnToDbColumn(entityInfo, tableName, item); DbColumnInfo dbColumnInfo = this.EntityColumnToDbColumn(entityInfo, tableName, item);
columns.Add(dbColumnInfo); columns.Add(dbColumnInfo);
} }
if (entityInfo.IsCreateTableFiledSort)
{
columns = columns.OrderBy(c => c.CreateTableFieldSort).ToList();
}
} }
this.Context.DbMaintenance.CreateTable(tableName, columns,true); this.Context.DbMaintenance.CreateTable(tableName, columns,true);
} }
@ -42,7 +46,8 @@ namespace SqlSugar.MySqlConnector
DefaultValue = item.DefaultValue, DefaultValue = item.DefaultValue,
ColumnDescription = item.ColumnDescription, ColumnDescription = item.ColumnDescription,
Length = item.Length, Length = item.Length,
DecimalDigits=item.DecimalDigits DecimalDigits=item.DecimalDigits,
CreateTableFieldSort = item.CreateTableFieldSort
}; };
GetDbType(item, propertyType, result); GetDbType(item, propertyType, result);
if (result.DataType.Equals("varchar", StringComparison.CurrentCultureIgnoreCase) && result.Length == 0) if (result.DataType.Equals("varchar", StringComparison.CurrentCultureIgnoreCase) && result.Length == 0)

View File

@ -269,7 +269,7 @@ namespace SqlSugar.MySqlConnector
{ {
get get
{ {
return "SELECT count(*) FROM information_schema.statistics WHERE index_name = '{0}'"; return "SELECT count(*) FROM information_schema.statistics WHERE index_name = '{0}' and index_schema = '{1}'";
} }
} }
#endregion #endregion
@ -308,7 +308,9 @@ namespace SqlSugar.MySqlConnector
} }
var oldDatabaseName = this.Context.Ado.Connection.Database; var oldDatabaseName = this.Context.Ado.Connection.Database;
var connection = this.Context.CurrentConnectionConfig.ConnectionString; var connection = this.Context.CurrentConnectionConfig.ConnectionString;
Check.Exception(Regex.Split(connection,oldDatabaseName).Length > 2, "The user name and password cannot be the same as the database name "); Check.ExceptionEasy(Regex.Split(connection,oldDatabaseName).Length > 2
, "The user name and password cannot be the same as the database name ",
" 创建数据库失败, 请换一个库名,库名不能 password 或者 username 有重叠 ");
connection = connection.Replace(oldDatabaseName, "mysql"); connection = connection.Replace(oldDatabaseName, "mysql");
var newDb = new SqlSugarClient(new ConnectionConfig() var newDb = new SqlSugarClient(new ConnectionConfig()
{ {

View File

@ -176,7 +176,7 @@ namespace SqlSugar.MySqlConnector
{ {
sb.Append(row[colum].ObjToDate().ToString("yyyy-MM-dd HH:mm:ss.fff")); sb.Append(row[colum].ObjToDate().ToString("yyyy-MM-dd HH:mm:ss.fff"));
} }
else if (colum.DataType == UtilConstants.DateType && row[colum] != null && row[colum] == DBNull.Value) else if (row[colum] == null || row[colum] == DBNull.Value)
{ {
sb.Append("NULL"); sb.Append("NULL");
} }

View File

@ -14,6 +14,10 @@ namespace SqlSugar.MySqlConnector
} }
public class MySqlMethod : DefaultDbMethod, IDbMethods public class MySqlMethod : DefaultDbMethod, IDbMethods
{ {
public override string GetStringJoinSelector(string result, string separator)
{
return $"group_concat({result} separator '{separator}') ";
}
public override string DateDiff(MethodCallExpressionModel model) public override string DateDiff(MethodCallExpressionModel model)
{ {
var parameter = model.Args[0]; var parameter = model.Args[0];
@ -146,7 +150,14 @@ namespace SqlSugar.MySqlConnector
{ {
var parameter = model.Args[0]; var parameter = model.Args[0];
var parameter1 = model.Args[1]; var parameter1 = model.Args[1];
return string.Format("IFNULL({0},{1})", parameter.MemberName, parameter1.MemberName); if (parameter1.MemberValue is bool)
{
return string.Format("IFNULL(CAST({0} as SIGNED),{1})", parameter.MemberName, parameter1.MemberName);
}
else
{
return string.Format("IFNULL({0},{1})", parameter.MemberName, parameter1.MemberName);
}
} }
public override string GetDate() public override string GetDate()
{ {

View File

@ -53,6 +53,10 @@ namespace SqlSugar.MySqlConnector
} }
else if (Skip != null && Take != null) else if (Skip != null && Take != null)
{ {
if (Skip == 0 && Take == 1 && this.OrderByValue == "ORDER BY NOW() ")
{
this.OrderByValue = null;
}
if (this.OrderByValue == "ORDER BY ") this.OrderByValue += GetSelectValue.Split(',')[0]; if (this.OrderByValue == "ORDER BY ") this.OrderByValue += GetSelectValue.Split(',')[0];
result = string.Format(PageTempalte, GetSelectValue, GetTableNameString, GetWhereValueString, GetGroupByString + HavingInfos, GetOrderByString, Skip.ObjToInt() > 0 ? Skip.ObjToInt() : 0, Take); result = string.Format(PageTempalte, GetSelectValue, GetTableNameString, GetWhereValueString, GetGroupByString + HavingInfos, GetOrderByString, Skip.ObjToInt() > 0 ? Skip.ObjToInt() : 0, Take);
} }
@ -111,7 +115,7 @@ namespace SqlSugar.MySqlConnector
} }
public override string ToCountSql(string sql) public override string ToCountSql(string sql)
{ {
if (this.GroupByValue.HasValue()) if (this.GroupByValue.HasValue()||this.IsDistinct)
{ {
return base.ToCountSql(sql); return base.ToCountSql(sql);
} }