mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +08:00
Update MySql
This commit is contained in:
parent
f9bea8e5b2
commit
dfe4f4c213
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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…
Reference in New Issue
Block a user