mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-30 12:47:57 +08:00
Update MySql
This commit is contained in:
parent
9fc7cbb041
commit
6a08a439e1
@ -17,7 +17,7 @@ namespace OrmTest
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
// /***Unit Test***/
|
||||
//// /***Unit Test***/
|
||||
new Field(1).Init();
|
||||
new Where(1).Init();
|
||||
new Method(1).Init();
|
||||
@ -29,20 +29,20 @@ namespace OrmTest
|
||||
new Delete(1).Init();
|
||||
new Update(1).Init();
|
||||
new Mapping(1).Init();
|
||||
// new DataTest(1).Init();
|
||||
new DataTest(1).Init();
|
||||
|
||||
// /***Performance Test***/
|
||||
// new SqlSugarPerformance(100).Select();
|
||||
|
||||
/***Demo***/
|
||||
OrmTest.Demo.Query.Init();
|
||||
//OrmTest.Demo.Insert.Init();
|
||||
//OrmTest.Demo.Delete.Init();
|
||||
//OrmTest.Demo.Update.Init();
|
||||
// OrmTest.Demo.DbFirst.Init();
|
||||
//OrmTest.Demo.JoinSql.Init();
|
||||
//OrmTest.Demo.Filter.Init();
|
||||
//OrmTest.Demo.ComplexModel.Init();
|
||||
OrmTest.Demo.Insert.Init();
|
||||
OrmTest.Demo.Delete.Init();
|
||||
OrmTest.Demo.Update.Init();
|
||||
OrmTest.Demo.DbFirst.Init();
|
||||
OrmTest.Demo.JoinSql.Init();
|
||||
OrmTest.Demo.Filter.Init();
|
||||
OrmTest.Demo.ComplexModel.Init();
|
||||
OrmTest.Demo.CodeFirst.Init();
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ namespace OrmTest.UnitTest
|
||||
|
||||
public void Init()
|
||||
{
|
||||
var guid = Guid.Parse("d8268a7e-a2d1-4329-9990-9bd801292415");
|
||||
var db = GetInstance();
|
||||
db.DbMaintenance.TruncateTable("DataTestInfo");
|
||||
var insertObject = new DataTestInfo()
|
||||
@ -27,8 +28,8 @@ namespace OrmTest.UnitTest
|
||||
Decimal2 = 2,
|
||||
Float1 = 3,
|
||||
Float2 = 4,
|
||||
Guid1 = Guid.Empty,
|
||||
Guid2 = null,
|
||||
Guid1 = guid,
|
||||
Guid2 = guid,
|
||||
Image1 = new byte[] { 1, 2 },
|
||||
Image2 = new byte[] { 2, 3 },
|
||||
Int2 = 6,
|
||||
@ -41,12 +42,13 @@ namespace OrmTest.UnitTest
|
||||
var id = db.Insertable<DataTestInfo>(insertObject).ExecuteReutrnIdentity();
|
||||
var data = db.Queryable<DataTestInfo>().InSingle(id);
|
||||
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.Float1 != data.Float1 ||
|
||||
insertObject.Float2 != data.Float2 ||
|
||||
insertObject.Int2 != data.Int2 ||
|
||||
insertObject.Money1 != data.Money1 ||
|
||||
insertObject.Guid2!=data.Guid2||
|
||||
string.Join(",", insertObject.Varbinary1) != string.Join(",", data.Varbinary1) ||
|
||||
insertObject.String != data.String)
|
||||
{
|
||||
@ -56,7 +58,7 @@ namespace OrmTest.UnitTest
|
||||
db.Updateable(data).ExecuteCommand();
|
||||
data = db.Queryable<DataTestInfo>().InSingle(id);
|
||||
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.Float1+1) != data.Float1 ||
|
||||
insertObject.Float2 != data.Float2 ||
|
||||
@ -70,7 +72,7 @@ namespace OrmTest.UnitTest
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Public methods
|
||||
public string GetDbTypeName(string csharpTypeName)
|
||||
public virtual string GetDbTypeName(string csharpTypeName)
|
||||
{
|
||||
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 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 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 getConvertString = typeof(IDataRecordExtensions).GetMethod("GetConvertString");
|
||||
private static readonly MethodInfo getConvertFloat = typeof(IDataRecordExtensions).GetMethod("GetConvertFloat");
|
||||
@ -178,6 +180,9 @@ namespace SqlSugar
|
||||
case CSharpDataType.@string:
|
||||
CheckType(bind.StringThrow, bindProperyTypeName, validPropertyName, propertyName);
|
||||
method = getString;
|
||||
if (bindProperyTypeName == "guid") {
|
||||
method = getConvertStringGuid ;
|
||||
}
|
||||
break;
|
||||
case CSharpDataType.DateTime:
|
||||
CheckType(bind.DateThrow, bindProperyTypeName, validPropertyName, propertyName);
|
||||
@ -198,7 +203,7 @@ namespace SqlSugar
|
||||
case CSharpDataType.Guid:
|
||||
CheckType(bind.GuidThrow, bindProperyTypeName, validPropertyName, propertyName);
|
||||
if (bindProperyTypeName == "guid")
|
||||
method = isNullableType ? getConvertGuid : getGuid;
|
||||
method = isNullableType ? getConvertStringGuid : getStringGuid;
|
||||
break;
|
||||
case CSharpDataType.@byte:
|
||||
method = isNullableType ? getConvertByte : getByte;
|
||||
|
@ -7,6 +7,23 @@ namespace SqlSugar
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (dr.IsDBNull(i))
|
||||
|
@ -1,10 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
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
|
||||
{
|
||||
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