mirror of
https://github.com/cq-panda/Vue.NetCore.git
synced 2026-10-16 21:13:22 +08:00
增加sugar版达梦数据库的支持
This commit is contained in:
@@ -156,7 +156,94 @@ DISTINCT
|
||||
table_name = ?tableName {GetMysqlTableSchema()};";
|
||||
}
|
||||
|
||||
private string GetDMOwner()
|
||||
{
|
||||
try
|
||||
{
|
||||
string dbName = DBServerProvider.GetConnectionString().Split("schema=")[1].Split(";")[0]?.Trim();
|
||||
return dbName;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"获取达梦数据库名异常:{ex.Message}");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取达梦表结构信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private string GetDMModelInfo(string connection)
|
||||
{
|
||||
return $@"SELECT DISTINCT
|
||||
IF(DATA_PRECISION IS NOT NULL, CONCAT(DATA_PRECISION,',',DATA_SCALE),'') as Prec_Scale,
|
||||
CASE
|
||||
WHEN data_type IN( 'BIT', 'BOOL','bit', 'bool') THEN 'bool'
|
||||
WHEN data_type in('smallint','SMALLINT') THEN 'short'
|
||||
WHEN data_type in('tinyint', 'TINYINT') THEN 'sbyte'
|
||||
WHEN data_type IN('MEDIUMINT','mediumint', 'int','INT','year', 'Year') THEN 'int'
|
||||
WHEN data_type in ( 'BIGINT','bigint') THEN 'bigint'
|
||||
WHEN data_type IN('FLOAT', 'DECIMAL','float', 'decimal') THEN 'decimal'
|
||||
WHEN data_type IN( 'DOUBLE', 'double') THEN 'double'
|
||||
WHEN data_type IN('CHAR', 'VARCHAR', 'TINY TEXT', 'TEXT', 'MEDIUMTEXT', 'LONGTEXT', 'TINYBLOB', 'BLOB', 'MEDIUMBLOB', 'LONGBLOB', 'Time','char', 'varchar', 'tiny text', 'text', 'mediumtext', 'longtext', 'tinyblob', 'blob', 'mediumblob', 'longblob', 'time') THEN 'nvarchar'
|
||||
WHEN data_type IN('Date', 'DateTime', 'TimeStamp','date', 'datetime', 'timestamp') THEN 'datetime' ELSE 'nvarchar'
|
||||
END AS ColumnType,
|
||||
Column_Name AS ColumnName
|
||||
FROM user_tab_columns
|
||||
WHERE table_name = :tableName {GetDMOwner()} ";
|
||||
}
|
||||
private string GetDMStructure(string tableName, string connection)
|
||||
{
|
||||
return $@"SELECT DISTINCT
|
||||
tc.COLUMN_NAME AS ColumnName,
|
||||
'{tableName}' as tableName,
|
||||
IFNULL(col.COMMENTS,'') AS ColumnCnName,
|
||||
CASE
|
||||
WHEN data_type IN( 'BIT', 'BOOL', 'bit', 'bool') THEN
|
||||
'bool'
|
||||
WHEN data_type in('smallint','SMALLINT') THEN 'short'
|
||||
WHEN data_type in('tinyint','TINYINT') THEN 'sbyte'
|
||||
WHEN data_type IN('MEDIUMINT','mediumint', 'int','INT','year', 'Year') THEN
|
||||
'int'
|
||||
WHEN data_type in ( 'BIGINT','bigint') THEN
|
||||
'bigint'
|
||||
WHEN data_type IN('FLOAT', 'DOUBLE', 'DECIMAL','float', 'double', 'decimal') THEN
|
||||
'decimal'
|
||||
WHEN data_type IN('CHAR', 'VARCHAR', 'TINY TEXT', 'TEXT', 'MEDIUMTEXT', 'LONGTEXT', 'TINYBLOB', 'BLOB', 'MEDIUMBLOB', 'LONGBLOB', 'Time','char', 'varchar', 'tiny text', 'text', 'mediumtext', 'longtext', 'tinyblob', 'blob', 'mediumblob', 'longblob', 'time') THEN
|
||||
'string'
|
||||
WHEN data_type IN('Date', 'DateTime', 'TimeStamp','date', 'datetime', 'timestamp') THEN
|
||||
'DateTime' ELSE 'string'
|
||||
END AS ColumnType,
|
||||
case WHEN DATA_LENGTH>8000 THEN 0 ELSE DATA_LENGTH end AS Maxlength,
|
||||
CASE
|
||||
WHEN c.constraint_type='P' THEN
|
||||
1 ELSE 0
|
||||
END AS IsKey,
|
||||
CASE
|
||||
WHEN tc.Column_Name IN( 'CreateID', 'ModifyID', '' )
|
||||
OR c.constraint_type='P' THEN
|
||||
0 ELSE 1
|
||||
END AS IsDisplay,
|
||||
1 AS IsColumnData,
|
||||
120 AS ColumnWidth,
|
||||
0 AS OrderNo,
|
||||
CASE
|
||||
WHEN NULLABLE = 'NO' THEN
|
||||
0 ELSE 1
|
||||
END AS IsNull,
|
||||
CASE
|
||||
WHEN c.constraint_type='P' THEN
|
||||
1 ELSE 0
|
||||
END AS IsReadDataset
|
||||
FROM
|
||||
user_tab_columns tc
|
||||
INNER JOIN dba_tables t ON tc.TABLE_NAME=t.TABLE_NAME
|
||||
LEFT JOIN dba_cons_columns cons ON tc.COLUMN_NAME=cons.COLUMN_NAME AND tc.TABLE_NAME=cons.TABLE_NAME
|
||||
LEFT JOIN dba_constraints c ON c.constraint_name=cons.constraint_name
|
||||
LEFT JOIN user_col_comments col ON tc.TABLE_NAME=col.TABLE_NAME AND tc.COLUMN_NAME=col.COLUMN_NAME
|
||||
|
||||
WHERE tc.table_name = :tableName {GetDMOwner(connection)} ";
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取SqlServer表结构信息
|
||||
/// </summary>
|
||||
@@ -298,6 +385,9 @@ DISTINCT
|
||||
case "PgSql":
|
||||
sql = GetPgSqlModelInfo();
|
||||
break;
|
||||
case "DM":
|
||||
sql = GetDMModelInfo();
|
||||
break;
|
||||
default:
|
||||
sql = GetSqlServerModelInfo();
|
||||
break;
|
||||
@@ -360,6 +450,10 @@ DISTINCT
|
||||
{
|
||||
sql = GetMySqlStructure(tableName);
|
||||
}
|
||||
else if (DBType.Name.ToLower() == DbCurrentType.DM.ToString().ToLower())
|
||||
{
|
||||
sql = GetDMStructure(tableName);
|
||||
}
|
||||
else if (DBType.Name.ToLower() == DbCurrentType.PgSql.ToString().ToLower())
|
||||
{
|
||||
sql = GetPgSqlStructure(tableName);
|
||||
|
||||
@@ -63,6 +63,10 @@ namespace VOL.Core.DbSqlSugar
|
||||
{
|
||||
return DbType.PostgreSQL;
|
||||
}
|
||||
else if (Const.DBType.Name == DbCurrentType.DM.ToString())
|
||||
{
|
||||
return DbType.Dm;
|
||||
}
|
||||
throw new Exception("未实现数据库");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VOL.Core.Configuration;
|
||||
using VOL.Core.Const;
|
||||
using VOL.Core.DBManager;
|
||||
using VOL.Core.DbSqlSugar;
|
||||
using VOL.Core.Enums;
|
||||
@@ -34,7 +35,8 @@ namespace VOL.Core.DBManager
|
||||
MoreSettings = new ConnMoreSettings()
|
||||
{
|
||||
PgSqlIsAutoToLower = false
|
||||
}
|
||||
},
|
||||
ConfigureExternalServices = GetConfigureExternalServices(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -78,5 +80,20 @@ namespace VOL.Core.DBManager
|
||||
});
|
||||
return services;
|
||||
}
|
||||
private static ConfigureExternalServices GetConfigureExternalServices()
|
||||
{
|
||||
//https://www.donet5.com/Home/Doc?typeId=1182
|
||||
return new ConfigureExternalServices()
|
||||
{
|
||||
EntityService = (property, column) =>
|
||||
{
|
||||
if (DBType.Name == "DM")
|
||||
{
|
||||
// var attributes = property.GetCustomAttributes(true);//get all attributes
|
||||
column.DbColumnName = property.Name.ToUpper();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace VOL.Core.Enums
|
||||
Default = 0,
|
||||
MySql = 1,
|
||||
MsSql = 2,//2020.08.08修改sqlserver拼写
|
||||
PgSql = 3
|
||||
PgSql = 3,
|
||||
DM=4
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user