Browse Source

Update MySql

pull/12/MERGE
sunkaixuan 8 years ago
parent
commit
6a08a439e1
  1. 44
      Src/Asp.Net/MySqlTest/Program.cs
  2. 12
      Src/Asp.Net/MySqlTest/UnitTest/DataTest.cs
  3. 2
      Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/DbBindProvider.cs
  4. 7
      Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataReaderEntityBuilder.cs
  5. 19
      Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataRecordExtensions.cs
  6. 25
      Src/Asp.Net/SqlSugar/Realization/MySql/DbBind/MySqlDbBind.cs

44
Src/Asp.Net/MySqlTest/Program.cs

@ -17,32 +17,32 @@ namespace OrmTest
{
static void Main(string[] args)
{
// /***Unit Test***/
new Field(1).Init();
new Where(1).Init();
new Method(1).Init();
new JoinQuery(1).Init();
new SingleQuery(1).Init();
new SelectQuery(1).Init();
new AutoClose(1).Init();
new Insert(1).Init();
new Delete(1).Init();
new Update(1).Init();
new Mapping(1).Init();
// new DataTest(1).Init();
//// /***Unit Test***/
new Field(1).Init();
new Where(1).Init();
new Method(1).Init();
new JoinQuery(1).Init();
new SingleQuery(1).Init();
new SelectQuery(1).Init();
new AutoClose(1).Init();
new Insert(1).Init();
new Delete(1).Init();
new Update(1).Init();
new Mapping(1).Init();
new DataTest(1).Init();
// /***Performance Test***/
// new SqlSugarPerformance(100).Select();
// /***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();
}
}

12
Src/Asp.Net/MySqlTest/UnitTest/DataTest.cs

@ -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;
}
}

2
Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/DbBindProvider.cs

@ -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)
{

7
Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataReaderEntityBuilder.cs

@ -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;

19
Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataRecordExtensions.cs

@ -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))
@ -124,7 +141,7 @@ namespace SqlSugar
{
return null;
}
var reval =Convert.ToString(dr.GetValue(i));
var reval = Convert.ToString(dr.GetValue(i));
return reval;
}

25
Src/Asp.Net/SqlSugar/Realization/MySql/DbBind/MySqlDbBind.cs

@ -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…
Cancel
Save