mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-06-28 13:34:32 +08:00
Update MySql
This commit is contained in:
parent
9fc7cbb041
commit
6a08a439e1
@ -17,32 +17,32 @@ namespace OrmTest
|
|||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
// /***Unit Test***/
|
//// /***Unit Test***/
|
||||||
new Field(1).Init();
|
new Field(1).Init();
|
||||||
new Where(1).Init();
|
new Where(1).Init();
|
||||||
new Method(1).Init();
|
new Method(1).Init();
|
||||||
new JoinQuery(1).Init();
|
new JoinQuery(1).Init();
|
||||||
new SingleQuery(1).Init();
|
new SingleQuery(1).Init();
|
||||||
new SelectQuery(1).Init();
|
new SelectQuery(1).Init();
|
||||||
new AutoClose(1).Init();
|
new AutoClose(1).Init();
|
||||||
new Insert(1).Init();
|
new Insert(1).Init();
|
||||||
new Delete(1).Init();
|
new Delete(1).Init();
|
||||||
new Update(1).Init();
|
new Update(1).Init();
|
||||||
new Mapping(1).Init();
|
new Mapping(1).Init();
|
||||||
// new DataTest(1).Init();
|
new DataTest(1).Init();
|
||||||
|
|
||||||
// /***Performance Test***/
|
// /***Performance Test***/
|
||||||
// new SqlSugarPerformance(100).Select();
|
// new SqlSugarPerformance(100).Select();
|
||||||
|
|
||||||
/***Demo***/
|
/***Demo***/
|
||||||
OrmTest.Demo.Query.Init();
|
OrmTest.Demo.Query.Init();
|
||||||
//OrmTest.Demo.Insert.Init();
|
OrmTest.Demo.Insert.Init();
|
||||||
//OrmTest.Demo.Delete.Init();
|
OrmTest.Demo.Delete.Init();
|
||||||
//OrmTest.Demo.Update.Init();
|
OrmTest.Demo.Update.Init();
|
||||||
// OrmTest.Demo.DbFirst.Init();
|
OrmTest.Demo.DbFirst.Init();
|
||||||
//OrmTest.Demo.JoinSql.Init();
|
OrmTest.Demo.JoinSql.Init();
|
||||||
//OrmTest.Demo.Filter.Init();
|
OrmTest.Demo.Filter.Init();
|
||||||
//OrmTest.Demo.ComplexModel.Init();
|
OrmTest.Demo.ComplexModel.Init();
|
||||||
OrmTest.Demo.CodeFirst.Init();
|
OrmTest.Demo.CodeFirst.Init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ namespace OrmTest.UnitTest
|
|||||||
|
|
||||||
public void Init()
|
public void Init()
|
||||||
{
|
{
|
||||||
|
var guid = Guid.Parse("d8268a7e-a2d1-4329-9990-9bd801292415");
|
||||||
var db = GetInstance();
|
var db = GetInstance();
|
||||||
db.DbMaintenance.TruncateTable("DataTestInfo");
|
db.DbMaintenance.TruncateTable("DataTestInfo");
|
||||||
var insertObject = new DataTestInfo()
|
var insertObject = new DataTestInfo()
|
||||||
@ -27,8 +28,8 @@ namespace OrmTest.UnitTest
|
|||||||
Decimal2 = 2,
|
Decimal2 = 2,
|
||||||
Float1 = 3,
|
Float1 = 3,
|
||||||
Float2 = 4,
|
Float2 = 4,
|
||||||
Guid1 = Guid.Empty,
|
Guid1 = guid,
|
||||||
Guid2 = null,
|
Guid2 = guid,
|
||||||
Image1 = new byte[] { 1, 2 },
|
Image1 = new byte[] { 1, 2 },
|
||||||
Image2 = new byte[] { 2, 3 },
|
Image2 = new byte[] { 2, 3 },
|
||||||
Int2 = 6,
|
Int2 = 6,
|
||||||
@ -41,12 +42,13 @@ namespace OrmTest.UnitTest
|
|||||||
var id = db.Insertable<DataTestInfo>(insertObject).ExecuteReutrnIdentity();
|
var id = db.Insertable<DataTestInfo>(insertObject).ExecuteReutrnIdentity();
|
||||||
var data = db.Queryable<DataTestInfo>().InSingle(id);
|
var data = db.Queryable<DataTestInfo>().InSingle(id);
|
||||||
if (
|
if (
|
||||||
insertObject.Datetime1.ToString("yyyy-MM-dd HH:mm:ss") != data.Datetime1.ToString("yyyy-MM-dd HH:mm:ss") ||
|
insertObject.Datetime1.ToString("yyyy-MM-dd") != data.Datetime1.ToString("yyyy-MM-dd") ||
|
||||||
insertObject.Decimal1 != data.Decimal1 ||
|
insertObject.Decimal1 != data.Decimal1 ||
|
||||||
insertObject.Float1 != data.Float1 ||
|
insertObject.Float1 != data.Float1 ||
|
||||||
insertObject.Float2 != data.Float2 ||
|
insertObject.Float2 != data.Float2 ||
|
||||||
insertObject.Int2 != data.Int2 ||
|
insertObject.Int2 != data.Int2 ||
|
||||||
insertObject.Money1 != data.Money1 ||
|
insertObject.Money1 != data.Money1 ||
|
||||||
|
insertObject.Guid2!=data.Guid2||
|
||||||
string.Join(",", insertObject.Varbinary1) != string.Join(",", data.Varbinary1) ||
|
string.Join(",", insertObject.Varbinary1) != string.Join(",", data.Varbinary1) ||
|
||||||
insertObject.String != data.String)
|
insertObject.String != data.String)
|
||||||
{
|
{
|
||||||
@ -56,7 +58,7 @@ namespace OrmTest.UnitTest
|
|||||||
db.Updateable(data).ExecuteCommand();
|
db.Updateable(data).ExecuteCommand();
|
||||||
data = db.Queryable<DataTestInfo>().InSingle(id);
|
data = db.Queryable<DataTestInfo>().InSingle(id);
|
||||||
if (
|
if (
|
||||||
insertObject.Datetime1.ToString("yyyy-MM-dd HH:mm:ss") != data.Datetime1.ToString("yyyy-MM-dd HH:mm:ss") ||
|
insertObject.Datetime1.ToString("yyyy-MM-dd") != data.Datetime1.ToString("yyyy-MM-dd") ||
|
||||||
insertObject.Decimal1 != data.Decimal1 ||
|
insertObject.Decimal1 != data.Decimal1 ||
|
||||||
(insertObject.Float1+1) != data.Float1 ||
|
(insertObject.Float1+1) != data.Float1 ||
|
||||||
insertObject.Float2 != data.Float2 ||
|
insertObject.Float2 != data.Float2 ||
|
||||||
@ -70,7 +72,7 @@ namespace OrmTest.UnitTest
|
|||||||
}
|
}
|
||||||
public SqlSugarClient GetInstance()
|
public SqlSugarClient GetInstance()
|
||||||
{
|
{
|
||||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
|
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.MySql, IsAutoCloseConnection = true });
|
||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ namespace SqlSugar
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Public methods
|
#region Public methods
|
||||||
public string GetDbTypeName(string csharpTypeName)
|
public virtual string GetDbTypeName(string csharpTypeName)
|
||||||
{
|
{
|
||||||
if (csharpTypeName == PubConst.ByteArrayType.Name)
|
if (csharpTypeName == PubConst.ByteArrayType.Name)
|
||||||
{
|
{
|
||||||
|
@ -36,6 +36,8 @@ namespace SqlSugar
|
|||||||
private static readonly MethodInfo getInt32 = typeof(IDataRecord).GetMethod("GetInt32", new Type[] { typeof(int) });
|
private static readonly MethodInfo getInt32 = typeof(IDataRecord).GetMethod("GetInt32", new Type[] { typeof(int) });
|
||||||
private static readonly MethodInfo getInt64 = typeof(IDataRecord).GetMethod("GetInt64", new Type[] { typeof(int) });
|
private static readonly MethodInfo getInt64 = typeof(IDataRecord).GetMethod("GetInt64", new Type[] { typeof(int) });
|
||||||
private static readonly MethodInfo getString = typeof(IDataRecord).GetMethod("GetString", new Type[] { typeof(int) });
|
private static readonly MethodInfo getString = typeof(IDataRecord).GetMethod("GetString", new Type[] { typeof(int) });
|
||||||
|
private static readonly MethodInfo getStringGuid = typeof(IDataRecordExtensions).GetMethod("GetStringGuid");
|
||||||
|
private static readonly MethodInfo getConvertStringGuid = typeof(IDataRecordExtensions).GetMethod("GetConvertStringGuid");
|
||||||
private static readonly MethodInfo getEnum = typeof(IDataRecordExtensions).GetMethod("GetEnum");
|
private static readonly MethodInfo getEnum = typeof(IDataRecordExtensions).GetMethod("GetEnum");
|
||||||
private static readonly MethodInfo getConvertString = typeof(IDataRecordExtensions).GetMethod("GetConvertString");
|
private static readonly MethodInfo getConvertString = typeof(IDataRecordExtensions).GetMethod("GetConvertString");
|
||||||
private static readonly MethodInfo getConvertFloat = typeof(IDataRecordExtensions).GetMethod("GetConvertFloat");
|
private static readonly MethodInfo getConvertFloat = typeof(IDataRecordExtensions).GetMethod("GetConvertFloat");
|
||||||
@ -178,6 +180,9 @@ namespace SqlSugar
|
|||||||
case CSharpDataType.@string:
|
case CSharpDataType.@string:
|
||||||
CheckType(bind.StringThrow, bindProperyTypeName, validPropertyName, propertyName);
|
CheckType(bind.StringThrow, bindProperyTypeName, validPropertyName, propertyName);
|
||||||
method = getString;
|
method = getString;
|
||||||
|
if (bindProperyTypeName == "guid") {
|
||||||
|
method = getConvertStringGuid ;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case CSharpDataType.DateTime:
|
case CSharpDataType.DateTime:
|
||||||
CheckType(bind.DateThrow, bindProperyTypeName, validPropertyName, propertyName);
|
CheckType(bind.DateThrow, bindProperyTypeName, validPropertyName, propertyName);
|
||||||
@ -198,7 +203,7 @@ namespace SqlSugar
|
|||||||
case CSharpDataType.Guid:
|
case CSharpDataType.Guid:
|
||||||
CheckType(bind.GuidThrow, bindProperyTypeName, validPropertyName, propertyName);
|
CheckType(bind.GuidThrow, bindProperyTypeName, validPropertyName, propertyName);
|
||||||
if (bindProperyTypeName == "guid")
|
if (bindProperyTypeName == "guid")
|
||||||
method = isNullableType ? getConvertGuid : getGuid;
|
method = isNullableType ? getConvertStringGuid : getStringGuid;
|
||||||
break;
|
break;
|
||||||
case CSharpDataType.@byte:
|
case CSharpDataType.@byte:
|
||||||
method = isNullableType ? getConvertByte : getByte;
|
method = isNullableType ? getConvertByte : getByte;
|
||||||
|
@ -7,6 +7,23 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
public static partial class IDataRecordExtensions
|
public static partial class IDataRecordExtensions
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public static Guid GetStringGuid(this IDataRecord dr, int i)
|
||||||
|
{
|
||||||
|
var reval =Guid.Parse(dr.GetValue(i).ToString());
|
||||||
|
return reval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Guid? GetConvertStringGuid(this IDataRecord dr, int i)
|
||||||
|
{
|
||||||
|
if (dr.IsDBNull(i))
|
||||||
|
{
|
||||||
|
return Guid.Empty;
|
||||||
|
}
|
||||||
|
var reval = Guid.Parse(dr.GetValue(i).ToString());
|
||||||
|
return reval;
|
||||||
|
}
|
||||||
|
|
||||||
public static bool? GetConvertBoolean(this IDataRecord dr, int i)
|
public static bool? GetConvertBoolean(this IDataRecord dr, int i)
|
||||||
{
|
{
|
||||||
if (dr.IsDBNull(i))
|
if (dr.IsDBNull(i))
|
||||||
@ -57,7 +74,7 @@ namespace SqlSugar
|
|||||||
return reval;
|
return reval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static double? GetConvertDouble(this IDataRecord dr, int i)
|
public static double? GetConvertDouble(this IDataRecord dr, int i)
|
||||||
{
|
{
|
||||||
if (dr.IsDBNull(i))
|
if (dr.IsDBNull(i))
|
||||||
@ -124,7 +141,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
var reval =Convert.ToString(dr.GetValue(i));
|
var reval = Convert.ToString(dr.GetValue(i));
|
||||||
return reval;
|
return reval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +155,7 @@ namespace SqlSugar
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static T GetOther<T>(this IDataReader dr, int i)
|
public static T GetOther<T>(this IDataReader dr, int i)
|
||||||
{
|
{
|
||||||
return (T)Convert.ChangeType(dr.GetValue(i), typeof(T));
|
return (T)Convert.ChangeType(dr.GetValue(i), typeof(T));
|
||||||
}
|
}
|
||||||
@ -161,7 +178,7 @@ namespace SqlSugar
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static object GetEntity(this IDataReader dr, SqlSugarClient context)
|
public static object GetEntity(this IDataReader dr, SqlSugarClient context)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,28 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace SqlSugar
|
namespace SqlSugar
|
||||||
{
|
{
|
||||||
public class MySqlDbBind : DbBindProvider
|
public class MySqlDbBind : DbBindProvider
|
||||||
{
|
{
|
||||||
|
public override string GetDbTypeName(string csharpTypeName)
|
||||||
|
{
|
||||||
|
if (csharpTypeName == PubConst.ByteArrayType.Name)
|
||||||
|
{
|
||||||
|
return "blob";
|
||||||
|
}
|
||||||
|
if (csharpTypeName == "Int32")
|
||||||
|
csharpTypeName = "int";
|
||||||
|
if (csharpTypeName == "Int16")
|
||||||
|
csharpTypeName = "short";
|
||||||
|
if (csharpTypeName == "Int64")
|
||||||
|
csharpTypeName = "long";
|
||||||
|
if (csharpTypeName == "Boolean")
|
||||||
|
csharpTypeName = "bool";
|
||||||
|
var mappings = this.MappingTypes.Where(it => it.Value.ToString().Equals(csharpTypeName, StringComparison.CurrentCultureIgnoreCase));
|
||||||
|
return mappings.IsValuable() ? mappings.First().Key : "varchar";
|
||||||
|
}
|
||||||
public override List<KeyValuePair<string, CSharpDataType>> MappingTypes
|
public override List<KeyValuePair<string, CSharpDataType>> MappingTypes
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@ -50,5 +68,12 @@ namespace SqlSugar
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public override List<string> StringThrow
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return new List<string>() { "int32", "datetime", "decimal", "double", "byte"};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user