Browse Source

Update MySql

pull/12/MERGE
sunkaixuan 8 years ago
parent
commit
dfe4f4c213
  1. 2
      Src/Asp.Net/MySqlTest/Program.cs
  2. 18
      Src/Asp.Net/MySqlTest/UnitTest/Insert.cs
  3. 3
      Src/Asp.Net/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs
  4. 6
      Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs
  5. 3
      Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs
  6. 21
      Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlInsertBuilder.cs

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

@ -26,7 +26,7 @@ namespace OrmTest
new SelectQuery(1).Init();
new AutoClose(1).Init();
new Insert(1).Init();
// new Delete(1).Init();
new Delete(1).Init();
// new Update(1).Init();
// new Mapping(1).Init();
// new DataTest(1).Init();

18
Src/Asp.Net/MySqlTest/UnitTest/Insert.cs

@ -27,7 +27,7 @@ namespace OrmTest.UnitTest
base.Check(@"INSERT INTO `STudent`
(`SchoolId`,`Name`,`CreateTime`)
VALUES
(@SchoolId,@Name,@CreateTime) ;SELECT SCOPE_IDENTITY();",
(@SchoolId,@Name,@CreateTime) ;SELECT LAST_INSERT_ID();",
new List<SugarParameter>() {
new SugarParameter("@SchoolId",0),
new SugarParameter("@CreateTime",Convert.ToDateTime("2010-1-1")),
@ -45,7 +45,7 @@ namespace OrmTest.UnitTest
base.Check(@"INSERT INTO `STudent`
(`Name`)
VALUES
(@Name) ;SELECT SCOPE_IDENTITY();", new List<SugarParameter>() {
(@Name) ;SELECT LAST_INSERT_ID();", new List<SugarParameter>() {
new SugarParameter("@Name","jack")
}, t3.Key, t3.Value, "Insert t3 error");
@ -55,7 +55,7 @@ namespace OrmTest.UnitTest
base.Check(@"INSERT INTO `STudent`
(`SchoolId`,`CreateTime`)
VALUES
(@SchoolId,@CreateTime) ;SELECT SCOPE_IDENTITY();",
(@SchoolId,@CreateTime) ;SELECT LAST_INSERT_ID();",
new List<SugarParameter>() {
new SugarParameter("@SchoolId",0),
new SugarParameter("@CreateTime",Convert.ToDateTime("2010-1-1")),
@ -64,10 +64,10 @@ namespace OrmTest.UnitTest
//Ignore Name and TestId
var t5 = db.Insertable(insertObj).IgnoreColumns(it => it == "Name" || it == "TestId").With(SqlWith.UpdLock).ToSql();
base.Check(@"INSERT INTO `STudent` WITH(UPDLOCK)
base.Check(@"INSERT INTO `STudent`
(`SchoolId`,`CreateTime`)
VALUES
(@SchoolId,@CreateTime) ;SELECT SCOPE_IDENTITY();",
(@SchoolId,@CreateTime) ;SELECT LAST_INSERT_ID();",
new List<SugarParameter>() {
new SugarParameter("@SchoolId",0),
new SugarParameter("@CreateTime",Convert.ToDateTime("2010-1-1")),
@ -75,10 +75,10 @@ new List<SugarParameter>() {
);
//Use Lock
var t6 = db.Insertable(insertObj).With(SqlWith.UpdLock).ToSql();
base.Check(@"INSERT INTO `STudent` WITH(UPDLOCK)
base.Check(@"INSERT INTO `STudent`
(`SchoolId`,`Name`,`CreateTime`)
VALUES
(@SchoolId,@Name,@CreateTime) ;SELECT SCOPE_IDENTITY();",
(@SchoolId,@Name,@CreateTime) ;SELECT LAST_INSERT_ID();",
new List<SugarParameter>() {
new SugarParameter("@SchoolId",0),
new SugarParameter("@CreateTime",Convert.ToDateTime("2010-1-1")),
@ -91,7 +91,7 @@ new List<SugarParameter>() {
base.Check(@"INSERT INTO `STudent`
(`ID`,`SchoolId`,`CreateTime`)
VALUES
(@ID,@SchoolId,@CreateTime) ;SELECT SCOPE_IDENTITY();",
(@ID,@SchoolId,@CreateTime) ;SELECT LAST_INSERT_ID();",
new List<SugarParameter>() {
new SugarParameter("@SchoolId", 0),
new SugarParameter("@ID", 0),
@ -120,7 +120,7 @@ new List<SugarParameter>() {
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;
}
}

3
Src/Asp.Net/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs

@ -171,7 +171,8 @@ namespace SqlSugar
public IDeleteable<T> With(string lockString)
{
DeleteBuilder.TableWithString = lockString;
if (this.Context.CurrentConnectionConfig.DbType == DbType.SqlServer)
DeleteBuilder.TableWithString = lockString;
return this;
}

6
Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs

@ -92,7 +92,8 @@ namespace SqlSugar
public IInsertable<T> With(string lockString)
{
this.InsertBuilder.TableWithString = lockString;
if (this.Context.CurrentConnectionConfig.DbType == DbType.SqlServer)
this.InsertBuilder.TableWithString = lockString;
return this;
}
@ -165,7 +166,8 @@ namespace SqlSugar
PropertyType = PubMethod.GetUnderType(column.PropertyInfo),
TableId = i
};
if (columnInfo.PropertyType.IsEnum) {
if (columnInfo.PropertyType.IsEnum)
{
columnInfo.Value = Convert.ToInt64(columnInfo.Value);
}
insertItem.Add(columnInfo);

3
Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs

@ -135,7 +135,8 @@ namespace SqlSugar
}
public IUpdateable<T> With(string lockString)
{
this.UpdateBuilder.TableWithString = lockString;
if (this.Context.CurrentConnectionConfig.DbType == DbType.SqlServer)
this.UpdateBuilder.TableWithString = lockString;
return this;
}

21
Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlInsertBuilder.cs

@ -2,5 +2,26 @@
{
public class MySqlInsertBuilder : InsertBuilder
{
public override string SqlTemplate
{
get
{
if (IsReturnIdentity)
{
return @"INSERT INTO {0}
({1})
VALUES
({2}) ;SELECT LAST_INSERT_ID();";
}
else
{
return @"INSERT INTO {0}
({1})
VALUES
({2}) ;";
}
}
}
}
}

Loading…
Cancel
Save