mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
Update MySql
This commit is contained in:
parent
f9bea8e5b2
commit
dfe4f4c213
@ -26,7 +26,7 @@ namespace OrmTest
|
|||||||
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();
|
||||||
|
@ -27,7 +27,7 @@ namespace OrmTest.UnitTest
|
|||||||
base.Check(@"INSERT INTO `STudent`
|
base.Check(@"INSERT INTO `STudent`
|
||||||
(`SchoolId`,`Name`,`CreateTime`)
|
(`SchoolId`,`Name`,`CreateTime`)
|
||||||
VALUES
|
VALUES
|
||||||
(@SchoolId,@Name,@CreateTime) ;SELECT SCOPE_IDENTITY();",
|
(@SchoolId,@Name,@CreateTime) ;SELECT LAST_INSERT_ID();",
|
||||||
new List<SugarParameter>() {
|
new List<SugarParameter>() {
|
||||||
new SugarParameter("@SchoolId",0),
|
new SugarParameter("@SchoolId",0),
|
||||||
new SugarParameter("@CreateTime",Convert.ToDateTime("2010-1-1")),
|
new SugarParameter("@CreateTime",Convert.ToDateTime("2010-1-1")),
|
||||||
@ -45,7 +45,7 @@ namespace OrmTest.UnitTest
|
|||||||
base.Check(@"INSERT INTO `STudent`
|
base.Check(@"INSERT INTO `STudent`
|
||||||
(`Name`)
|
(`Name`)
|
||||||
VALUES
|
VALUES
|
||||||
(@Name) ;SELECT SCOPE_IDENTITY();", new List<SugarParameter>() {
|
(@Name) ;SELECT LAST_INSERT_ID();", new List<SugarParameter>() {
|
||||||
new SugarParameter("@Name","jack")
|
new SugarParameter("@Name","jack")
|
||||||
}, t3.Key, t3.Value, "Insert t3 error");
|
}, t3.Key, t3.Value, "Insert t3 error");
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ namespace OrmTest.UnitTest
|
|||||||
base.Check(@"INSERT INTO `STudent`
|
base.Check(@"INSERT INTO `STudent`
|
||||||
(`SchoolId`,`CreateTime`)
|
(`SchoolId`,`CreateTime`)
|
||||||
VALUES
|
VALUES
|
||||||
(@SchoolId,@CreateTime) ;SELECT SCOPE_IDENTITY();",
|
(@SchoolId,@CreateTime) ;SELECT LAST_INSERT_ID();",
|
||||||
new List<SugarParameter>() {
|
new List<SugarParameter>() {
|
||||||
new SugarParameter("@SchoolId",0),
|
new SugarParameter("@SchoolId",0),
|
||||||
new SugarParameter("@CreateTime",Convert.ToDateTime("2010-1-1")),
|
new SugarParameter("@CreateTime",Convert.ToDateTime("2010-1-1")),
|
||||||
@ -64,10 +64,10 @@ namespace OrmTest.UnitTest
|
|||||||
|
|
||||||
//Ignore Name and TestId
|
//Ignore Name and TestId
|
||||||
var t5 = db.Insertable(insertObj).IgnoreColumns(it => it == "Name" || it == "TestId").With(SqlWith.UpdLock).ToSql();
|
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`)
|
(`SchoolId`,`CreateTime`)
|
||||||
VALUES
|
VALUES
|
||||||
(@SchoolId,@CreateTime) ;SELECT SCOPE_IDENTITY();",
|
(@SchoolId,@CreateTime) ;SELECT LAST_INSERT_ID();",
|
||||||
new List<SugarParameter>() {
|
new List<SugarParameter>() {
|
||||||
new SugarParameter("@SchoolId",0),
|
new SugarParameter("@SchoolId",0),
|
||||||
new SugarParameter("@CreateTime",Convert.ToDateTime("2010-1-1")),
|
new SugarParameter("@CreateTime",Convert.ToDateTime("2010-1-1")),
|
||||||
@ -75,10 +75,10 @@ new List<SugarParameter>() {
|
|||||||
);
|
);
|
||||||
//Use Lock
|
//Use Lock
|
||||||
var t6 = db.Insertable(insertObj).With(SqlWith.UpdLock).ToSql();
|
var t6 = db.Insertable(insertObj).With(SqlWith.UpdLock).ToSql();
|
||||||
base.Check(@"INSERT INTO `STudent` WITH(UPDLOCK)
|
base.Check(@"INSERT INTO `STudent`
|
||||||
(`SchoolId`,`Name`,`CreateTime`)
|
(`SchoolId`,`Name`,`CreateTime`)
|
||||||
VALUES
|
VALUES
|
||||||
(@SchoolId,@Name,@CreateTime) ;SELECT SCOPE_IDENTITY();",
|
(@SchoolId,@Name,@CreateTime) ;SELECT LAST_INSERT_ID();",
|
||||||
new List<SugarParameter>() {
|
new List<SugarParameter>() {
|
||||||
new SugarParameter("@SchoolId",0),
|
new SugarParameter("@SchoolId",0),
|
||||||
new SugarParameter("@CreateTime",Convert.ToDateTime("2010-1-1")),
|
new SugarParameter("@CreateTime",Convert.ToDateTime("2010-1-1")),
|
||||||
@ -91,7 +91,7 @@ new List<SugarParameter>() {
|
|||||||
base.Check(@"INSERT INTO `STudent`
|
base.Check(@"INSERT INTO `STudent`
|
||||||
(`ID`,`SchoolId`,`CreateTime`)
|
(`ID`,`SchoolId`,`CreateTime`)
|
||||||
VALUES
|
VALUES
|
||||||
(@ID,@SchoolId,@CreateTime) ;SELECT SCOPE_IDENTITY();",
|
(@ID,@SchoolId,@CreateTime) ;SELECT LAST_INSERT_ID();",
|
||||||
new List<SugarParameter>() {
|
new List<SugarParameter>() {
|
||||||
new SugarParameter("@SchoolId", 0),
|
new SugarParameter("@SchoolId", 0),
|
||||||
new SugarParameter("@ID", 0),
|
new SugarParameter("@ID", 0),
|
||||||
@ -120,7 +120,7 @@ new List<SugarParameter>() {
|
|||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -171,6 +171,7 @@ namespace SqlSugar
|
|||||||
|
|
||||||
public IDeleteable<T> With(string lockString)
|
public IDeleteable<T> With(string lockString)
|
||||||
{
|
{
|
||||||
|
if (this.Context.CurrentConnectionConfig.DbType == DbType.SqlServer)
|
||||||
DeleteBuilder.TableWithString = lockString;
|
DeleteBuilder.TableWithString = lockString;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,7 @@ namespace SqlSugar
|
|||||||
|
|
||||||
public IInsertable<T> With(string lockString)
|
public IInsertable<T> With(string lockString)
|
||||||
{
|
{
|
||||||
|
if (this.Context.CurrentConnectionConfig.DbType == DbType.SqlServer)
|
||||||
this.InsertBuilder.TableWithString = lockString;
|
this.InsertBuilder.TableWithString = lockString;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -165,7 +166,8 @@ namespace SqlSugar
|
|||||||
PropertyType = PubMethod.GetUnderType(column.PropertyInfo),
|
PropertyType = PubMethod.GetUnderType(column.PropertyInfo),
|
||||||
TableId = i
|
TableId = i
|
||||||
};
|
};
|
||||||
if (columnInfo.PropertyType.IsEnum) {
|
if (columnInfo.PropertyType.IsEnum)
|
||||||
|
{
|
||||||
columnInfo.Value = Convert.ToInt64(columnInfo.Value);
|
columnInfo.Value = Convert.ToInt64(columnInfo.Value);
|
||||||
}
|
}
|
||||||
insertItem.Add(columnInfo);
|
insertItem.Add(columnInfo);
|
||||||
|
@ -135,6 +135,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
public IUpdateable<T> With(string lockString)
|
public IUpdateable<T> With(string lockString)
|
||||||
{
|
{
|
||||||
|
if (this.Context.CurrentConnectionConfig.DbType == DbType.SqlServer)
|
||||||
this.UpdateBuilder.TableWithString = lockString;
|
this.UpdateBuilder.TableWithString = lockString;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -2,5 +2,26 @@
|
|||||||
{
|
{
|
||||||
public class MySqlInsertBuilder : InsertBuilder
|
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