mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 10:08:19 +08:00
Update TDengine
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="TDengine.Ado.Data" Version="1.4.0" />
|
||||
<PackageReference Include="TDengine.Ado.Data" Version="1.6.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@@ -6,85 +6,10 @@ using System.Text;
|
||||
namespace SqlSugar.TDengine
|
||||
{
|
||||
public class TDengineCodeFirst : CodeFirstProvider
|
||||
{
|
||||
protected override void ExistLogicEnd(List<EntityColumnInfo> dbColumns)
|
||||
{
|
||||
foreach (EntityColumnInfo column in dbColumns)
|
||||
{
|
||||
if (column.DefaultValue != null)
|
||||
{
|
||||
this.Context.DbMaintenance.AddDefaultValue(column.DbTableName,column.DbColumnName,column.DefaultValue.ToSqlValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
public override void NoExistLogic(EntityInfo entityInfo)
|
||||
{
|
||||
var tableName = GetTableName(entityInfo);
|
||||
//Check.Exception(entityInfo.Columns.Where(it => it.IsPrimarykey).Count() > 1, "Use Code First ,The primary key must not exceed 1");
|
||||
List<DbColumnInfo> columns = new List<DbColumnInfo>();
|
||||
if (entityInfo.Columns.HasValue())
|
||||
{
|
||||
foreach (var item in entityInfo.Columns.Where(it=>it.IsIgnore==false))
|
||||
{
|
||||
DbColumnInfo dbColumnInfo = this.EntityColumnToDbColumn(entityInfo, tableName, item);
|
||||
columns.Add(dbColumnInfo);
|
||||
}
|
||||
if (entityInfo.IsCreateTableFiledSort)
|
||||
{
|
||||
columns = columns.OrderBy(c => c.CreateTableFieldSort).ToList();
|
||||
}
|
||||
}
|
||||
columns = columns.OrderBy(it => it.IsPrimarykey ? 0 : 1).ToList();
|
||||
this.Context.DbMaintenance.CreateTable(tableName, columns,true);
|
||||
}
|
||||
protected override DbColumnInfo EntityColumnToDbColumn(EntityInfo entityInfo, string tableName, EntityColumnInfo item)
|
||||
{
|
||||
var propertyType = UtilMethods.GetUnderType(item.PropertyInfo);
|
||||
var result = new DbColumnInfo()
|
||||
{
|
||||
TableId = entityInfo.Columns.IndexOf(item),
|
||||
DbColumnName = item.DbColumnName.HasValue() ? item.DbColumnName : item.PropertyName,
|
||||
IsPrimarykey = item.IsPrimarykey,
|
||||
IsIdentity = item.IsIdentity,
|
||||
TableName = tableName,
|
||||
IsNullable = item.IsNullable,
|
||||
DefaultValue = item.DefaultValue,
|
||||
ColumnDescription = item.ColumnDescription,
|
||||
Length = item.Length,
|
||||
CreateTableFieldSort = item.CreateTableFieldSort
|
||||
};
|
||||
if (propertyType == UtilConstants.DecType)
|
||||
{
|
||||
result.Scale = item.DecimalDigits;
|
||||
result.DecimalDigits = item.DecimalDigits;
|
||||
}
|
||||
GetDbType(item, propertyType, result);
|
||||
if (result.DataType.Equals("varchar", StringComparison.CurrentCultureIgnoreCase) && result.Length == 0)
|
||||
{
|
||||
result.Length = 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected override void ConvertColumns(List<DbColumnInfo> dbColumns)
|
||||
{
|
||||
foreach (var item in dbColumns)
|
||||
{
|
||||
if (item.DataType == "DateTime")
|
||||
{
|
||||
item.Length = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ChangeKey(EntityInfo entityInfo, string tableName, EntityColumnInfo item)
|
||||
{
|
||||
this.Context.DbMaintenance.UpdateColumn(tableName, EntityColumnToDbColumn(entityInfo, tableName, item));
|
||||
if (!item.IsPrimarykey)
|
||||
this.Context.DbMaintenance.DropConstraint(tableName,null);
|
||||
if (item.IsPrimarykey)
|
||||
this.Context.DbMaintenance.AddPrimaryKey(tableName, item.DbColumnName);
|
||||
}
|
||||
|
||||
throw new NotSupportedException("TDengine 暂时不支持CodeFirst等方法还在开发");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -19,35 +19,7 @@ namespace SqlSugar.TDengine
|
||||
{
|
||||
get
|
||||
{
|
||||
string schema = GetSchema();
|
||||
string sql = @"select cast (pclass.oid as int4) as TableId,cast(ptables.tablename as varchar) as TableName,
|
||||
pcolumn.column_name as DbColumnName,pcolumn.udt_name as DataType,
|
||||
CASE WHEN pcolumn.numeric_scale >0 THEN pcolumn.numeric_precision ELSE pcolumn.character_maximum_length END as Length,
|
||||
pcolumn.column_default as DefaultValue,
|
||||
pcolumn.numeric_scale as DecimalDigits,
|
||||
pcolumn.numeric_scale as Scale,
|
||||
col_description(pclass.oid, pcolumn.ordinal_position) as ColumnDescription,
|
||||
case when pkey.colname = pcolumn.column_name
|
||||
then true else false end as IsPrimaryKey,
|
||||
case when pcolumn.column_default like 'nextval%'
|
||||
then true else false end as IsIdentity,
|
||||
case when pcolumn.is_nullable = 'YES'
|
||||
then true else false end as IsNullable
|
||||
from (select * from pg_tables where upper(tablename) = upper('{0}') and schemaname='" + schema + @"') ptables inner join pg_class pclass
|
||||
on ptables.tablename = pclass.relname inner join (SELECT *
|
||||
FROM information_schema.columns
|
||||
) pcolumn on pcolumn.table_name = ptables.tablename
|
||||
left join (
|
||||
select pg_class.relname,pg_attribute.attname as colname from
|
||||
pg_constraint inner join pg_class
|
||||
on pg_constraint.conrelid = pg_class.oid
|
||||
inner join pg_attribute on pg_attribute.attrelid = pg_class.oid
|
||||
and pg_attribute.attnum = pg_constraint.conkey[1]
|
||||
inner join pg_type on pg_type.oid = pg_attribute.atttypid
|
||||
where pg_constraint.contype='p'
|
||||
) pkey on pcolumn.table_name = pkey.relname
|
||||
order by table_catalog, table_schema, ordinal_position";
|
||||
return sql;
|
||||
throw new NotSupportedException("TDengineCode暂时不支持DbFirst等方法,还在开发");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,7 +184,7 @@ namespace SqlSugar.TDengine
|
||||
{
|
||||
get
|
||||
{
|
||||
return "select 1 from information_schema.columns limit 1 offset 0";
|
||||
throw new NotSupportedException("TDengine 暂时不支持DbFirst等方法,还在开发");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
@@ -10,14 +10,14 @@ namespace SqlSugar.TDengine
|
||||
{
|
||||
get
|
||||
{
|
||||
return "\"";
|
||||
return "`";
|
||||
}
|
||||
}
|
||||
public override string SqlTranslationRight
|
||||
{
|
||||
get
|
||||
{
|
||||
return "\"";
|
||||
return "`";
|
||||
}
|
||||
}
|
||||
public override string SqlDateNow
|
||||
@@ -80,7 +80,7 @@ namespace SqlSugar.TDengine
|
||||
var mappingInfo = context
|
||||
.MappingTables
|
||||
.FirstOrDefault(it => it.EntityName.Equals(name, StringComparison.CurrentCultureIgnoreCase));
|
||||
if (mappingInfo == null && name.Contains(".") && name.Contains("\""))
|
||||
if (mappingInfo == null && name.Contains(".") && name.Contains("`"))
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
@@ -13,14 +13,14 @@ namespace SqlSugar.TDengine
|
||||
{
|
||||
get
|
||||
{
|
||||
return "\"";
|
||||
return "`";
|
||||
}
|
||||
}
|
||||
public override string SqlTranslationRight
|
||||
{
|
||||
get
|
||||
{
|
||||
return "\"";
|
||||
return "`";
|
||||
}
|
||||
}
|
||||
public override string GetTranslationText(string name)
|
@@ -15,14 +15,14 @@ namespace SqlSugar.TDengine
|
||||
return @"INSERT INTO {0}
|
||||
({1})
|
||||
VALUES
|
||||
({2}) returning $PrimaryKey";
|
||||
({2}) ";
|
||||
}
|
||||
else
|
||||
{
|
||||
return @"INSERT INTO {0}
|
||||
({1})
|
||||
VALUES
|
||||
({2}) ;";
|
||||
({2})";
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -76,7 +76,7 @@ namespace SqlSugar.TDengine
|
||||
}
|
||||
public override void SetCommandToAdapter(IDataAdapter dataAdapter, DbCommand command)
|
||||
{
|
||||
((TDengineDataAdapter)dataAdapter).SelectCommand = (TDengineCommand)command;
|
||||
((SqlSugar.TDengineCore.TDengineDataAdapter)dataAdapter).SelectCommand = (TDengineCommand)command;
|
||||
}
|
||||
/// <summary>
|
||||
/// if mysql return MySqlParameter[] pars
|
||||
@@ -94,7 +94,7 @@ namespace SqlSugar.TDengine
|
||||
if (parameter.Value == null) parameter.Value = DBNull.Value;
|
||||
|
||||
var sqlParameter = new TDengineParameter(parameter.ParameterName,parameter.Value,parameter.DbType,0);
|
||||
result[0]=sqlParameter;
|
||||
result[i]=sqlParameter;
|
||||
i++;
|
||||
}
|
||||
return result;
|
||||
|
Reference in New Issue
Block a user