mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-11-08 18:34:55 +08:00
Update Gbase
This commit is contained in:
@@ -158,7 +158,7 @@ where a.tabtype in ('V') and not (a.tabname like 'sys%') AND a.tabname <>'dual'
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return "DROP TABLE {0}";
|
return "DROP TABLE IF EXISTS {0}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected override string DropColumnToTableSql
|
protected override string DropColumnToTableSql
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace SqlSugar.GBase
|
|||||||
public bool IsActionUpdateColumns { get; set; }
|
public bool IsActionUpdateColumns { get; set; }
|
||||||
|
|
||||||
private DataTable _schema = null;
|
private DataTable _schema = null;
|
||||||
|
private string _temp_table_prefix = "Temp_GBASE_C2B986DE_EF71_4173_8632_D615B2543D30";
|
||||||
public DbFastestProperties DbFastestProperties { get; set; } = new DbFastestProperties()
|
public DbFastestProperties DbFastestProperties { get; set; } = new DbFastestProperties()
|
||||||
{
|
{
|
||||||
IsMerge = true
|
IsMerge = true
|
||||||
@@ -40,12 +41,14 @@ namespace SqlSugar.GBase
|
|||||||
var dts = dt.Columns.Cast<DataColumn>().Select(it => sqlBuilder.GetTranslationColumnName(it.ColumnName)).ToList();
|
var dts = dt.Columns.Cast<DataColumn>().Select(it => sqlBuilder.GetTranslationColumnName(it.ColumnName)).ToList();
|
||||||
|
|
||||||
var oldTableName = dt.TableName;
|
var oldTableName = dt.TableName;
|
||||||
dt.TableName = "Temp" + SnowFlakeSingle.instance.getID().ToString();
|
dt.TableName = _temp_table_prefix + SnowFlakeSingle.instance.getID().ToString();
|
||||||
var sql = this.Context.Queryable<T>().AS(oldTableName).Where(it => false).Select(string.Join(",", dts)).ToSql().Key;
|
var sql = this.Context.Queryable<T>().AS(oldTableName).Where(it => false).Select(string.Join(",", dts)).ToSql().Key;
|
||||||
await this.Context.Ado.ExecuteCommandAsync($"CREATE TABLE {dt.TableName} AS {sql} ");
|
await this.Context.Ado.ExecuteCommandAsync($"CREATE TABLE {dt.TableName} AS {sql} ");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<int> ExecuteBulkCopyAsync(DataTable dt)
|
public async Task<int> ExecuteBulkCopyAsync(DataTable dt)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
foreach (var item in this.FastEntityInfo.Columns)
|
foreach (var item in this.FastEntityInfo.Columns)
|
||||||
{
|
{
|
||||||
@@ -73,12 +76,19 @@ namespace SqlSugar.GBase
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
this.DropTempTable(dt.TableName);
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<int> UpdateByTempAsync(string tableName, string tempName, string[] updateColumns, string[] whereColumns)
|
public async Task<int> UpdateByTempAsync(string tableName, string tempName, string[] updateColumns, string[] whereColumns)
|
||||||
{
|
{
|
||||||
Check.ArgumentNullException(!updateColumns.Any(), "update columns count is 0");
|
Check.ArgumentNullException(!updateColumns.Any(), "update columns count is 0");
|
||||||
Check.ArgumentNullException(!whereColumns.Any(), "where columns count is 0");
|
Check.ArgumentNullException(!whereColumns.Any(), "where columns count is 0");
|
||||||
|
try
|
||||||
|
{
|
||||||
var cn = this.Context.Ado.Connection as GbsConnection;
|
var cn = this.Context.Ado.Connection as GbsConnection;
|
||||||
Open(cn);
|
Open(cn);
|
||||||
|
|
||||||
@@ -104,10 +114,18 @@ WHEN MATCHED THEN
|
|||||||
|
|
||||||
return await this.Context.Ado.ExecuteCommandAsync(sql);
|
return await this.Context.Ado.ExecuteCommandAsync(sql);
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
this.DropTempTable(tempName);
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<int> Merge<T>(string tableName, DataTable dt, EntityInfo entityInfo, string[] whereColumns, string[] updateColumns, List<T> datas) where T : class, new()
|
public async Task<int> Merge<T>(string tableName, DataTable dt, EntityInfo entityInfo, string[] whereColumns, string[] updateColumns, List<T> datas) where T : class, new()
|
||||||
{
|
{
|
||||||
Check.Exception(this.FastEntityInfo.Columns.Any(it => it.OracleSequenceName.HasValue()), "The BulkMerge method cannot be used for sequence", "BulkMerge方法不能用序列");
|
Check.Exception(this.FastEntityInfo.Columns.Any(it => it.OracleSequenceName.HasValue()), "The BulkMerge method cannot be used for sequence", "BulkMerge方法不能用序列");
|
||||||
|
try
|
||||||
|
{
|
||||||
var sqlBuilder = this.Context.Queryable<object>().SqlBuilder;
|
var sqlBuilder = this.Context.Queryable<object>().SqlBuilder;
|
||||||
var insertColumns = entityInfo.Columns
|
var insertColumns = entityInfo.Columns
|
||||||
.Where(it => it.IsIgnore == false)
|
.Where(it => it.IsIgnore == false)
|
||||||
@@ -149,9 +167,14 @@ WHEN MATCHED THEN
|
|||||||
WHEN NOT MATCHED THEN
|
WHEN NOT MATCHED THEN
|
||||||
INSERT ({insertColumnsSqlTgt})
|
INSERT ({insertColumnsSqlTgt})
|
||||||
VALUES ({insertColumnsSqlsrc})";
|
VALUES ({insertColumnsSqlsrc})";
|
||||||
|
|
||||||
return await this.Context.Ado.ExecuteCommandAsync(sql);
|
return await this.Context.Ado.ExecuteCommandAsync(sql);
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
this.DropTempTable(dt.TableName);
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void SetupSchemaTable(GbsConnection cn, IDbTransaction transaction, string table_name)
|
private void SetupSchemaTable(GbsConnection cn, IDbTransaction transaction, string table_name)
|
||||||
{
|
{
|
||||||
@@ -360,5 +383,14 @@ WHEN NOT MATCHED THEN
|
|||||||
cn.Open();
|
cn.Open();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void DropTempTable(string tableName)
|
||||||
|
{
|
||||||
|
if (tableName.StartsWith(_temp_table_prefix))
|
||||||
|
{
|
||||||
|
// it is a temp table.
|
||||||
|
this.Context.DbMaintenance.DropTable(tableName);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user