mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
Update Doris database
This commit is contained in:
parent
1aaa865940
commit
2c8bc264b3
@ -7,6 +7,22 @@ namespace SqlSugar
|
||||
internal class DorisHelper
|
||||
{
|
||||
|
||||
public static List<DbColumnInfo> GetColumns(List<DbColumnInfo> colums)
|
||||
{
|
||||
foreach (var item in colums)
|
||||
{
|
||||
if (item.DataType?.Contains("(") == true)
|
||||
{
|
||||
item.DataType = item.DataType.Substring(0, item.DataType.IndexOf("("));
|
||||
}
|
||||
if (item.DataType == "tinyint" && item.Length == 4)
|
||||
{
|
||||
item.Length = 1;
|
||||
}
|
||||
}
|
||||
return colums;
|
||||
}
|
||||
|
||||
public static bool IsDoris(ISqlSugarClient context)
|
||||
{
|
||||
return context.CurrentConnectionConfig?.MoreSettings?.DatabaseModel == DbType.Doris;
|
||||
|
@ -40,6 +40,10 @@ namespace SqlSugar
|
||||
LOCATE( 'unsigned',COLUMN_type ) >0 as IsUnsigned
|
||||
FROM
|
||||
Information_schema.columns where TABLE_NAME='{0}' and TABLE_SCHEMA=(select database()) ORDER BY ordinal_position";
|
||||
if (DorisHelper.IsDoris(this.Context))
|
||||
{
|
||||
sql = sql.Replace("CASE WHEN left(COLUMN_TYPE,LOCATE('(',COLUMN_TYPE)-1)='' THEN COLUMN_TYPE ELSE left(COLUMN_TYPE,LOCATE('(',COLUMN_TYPE)-1) END AS DataType", "COLUMN_TYPE AS DataType ");
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
}
|
||||
@ -283,7 +287,18 @@ namespace SqlSugar
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
#region Methods
|
||||
public override List<DbColumnInfo> GetColumnInfosByTableName(string tableName, bool isCache = true)
|
||||
{
|
||||
if (DorisHelper.IsDoris(this.Context))
|
||||
{
|
||||
var colums = base.GetColumnInfosByTableName(tableName, isCache);
|
||||
colums= DorisHelper.GetColumns(colums);
|
||||
return colums;
|
||||
}
|
||||
return base.GetColumnInfosByTableName(tableName, isCache);
|
||||
}
|
||||
|
||||
public override bool SetAutoIncrementInitialValue(string tableName, int initialValue)
|
||||
{
|
||||
initialValue++;
|
||||
@ -579,9 +594,14 @@ WHERE EVENT_OBJECT_TABLE = '" + tableName + "'");
|
||||
public override bool UpdateColumn(string tableName, DbColumnInfo column)
|
||||
{
|
||||
ConvertCreateColumnInfo(column);
|
||||
if (DorisHelper.IsDoris(this.Context))
|
||||
{
|
||||
return DorisUpadteColumns(ref tableName, column);
|
||||
}
|
||||
return base.UpdateColumn(tableName, column);
|
||||
}
|
||||
|
||||
|
||||
protected override string GetSize(DbColumnInfo item)
|
||||
{
|
||||
string dataSize = null;
|
||||
@ -712,6 +732,29 @@ WHERE EVENT_OBJECT_TABLE = '" + tableName + "'");
|
||||
#endregion
|
||||
|
||||
#region Helper
|
||||
|
||||
private bool DorisUpadteColumns(ref string tableName, DbColumnInfo column)
|
||||
{
|
||||
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
|
||||
var columName = this.SqlBuilder.GetTranslationTableName(column.DbColumnName);
|
||||
string sql = GetUpdateColumnSql(tableName, column)
|
||||
.Replace("change column", " MODIFY COLUMN")
|
||||
.Replace("DEFAULT NULL ", " NULL ")
|
||||
.Replace($"{columName} {columName}", columName);
|
||||
try
|
||||
{
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (ex.Message == "errCode = 2, detailMessage = Nothing is changed. please check your alter stmt.")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private bool ContainsCharSet(string charset)
|
||||
{
|
||||
if (this.Context.CurrentConnectionConfig.ConnectionString.ObjToString().ToLower().Contains(charset))
|
||||
|
Loading…
Reference in New Issue
Block a user