[improv] MySql和SQLite增加读取精度位数和默认值
This commit is contained in:
parent
70df4522c4
commit
7fea91cbba
|
@ -363,7 +363,7 @@ internal class HanaMetaData : RemoteDbMetaData
|
|||
|
||||
#region 架构
|
||||
|
||||
protected override List<IDataTable> OnGetTables(String[] names)
|
||||
protected override List<IDataTable> OnGetTables(String[]? names)
|
||||
{
|
||||
var ss = Database.CreateSession();
|
||||
var db = Database.DatabaseName;
|
||||
|
@ -401,13 +401,14 @@ internal class HanaMetaData : RemoteDbMetaData
|
|||
field.ColumnName = dc["Field"] + "";
|
||||
field.RawType = dc["Type"] + "";
|
||||
field.Description = dc["Comment"] + "";
|
||||
field.DefaultValue = dc["Default"] as String;
|
||||
|
||||
if (dc["Extra"] + "" == "auto_increment") field.Identity = true;
|
||||
if (dc["Key"] + "" == "PRI") field.PrimaryKey = true;
|
||||
if (dc["Null"] + "" == "YES") field.Nullable = true;
|
||||
|
||||
field.Length = field.RawType.Substring("(", ")").ToInt();
|
||||
field.DataType = GetDataType(field);
|
||||
field.DataType = GetDataType(field)!;
|
||||
|
||||
if (field.DataType == null)
|
||||
{
|
||||
|
|
|
@ -342,19 +342,23 @@ internal class HighGoMetaData : RemoteDbMetaData
|
|||
{
|
||||
var field = table.CreateColumn();
|
||||
|
||||
field.ColumnName = $"{dc["ColumnName"]}";
|
||||
field.RawType = $"{dc["DataType"]}";
|
||||
field.Description = $"{dc["ColumnDescription"]}";
|
||||
field.ColumnName = dc["ColumnName"] + "";
|
||||
field.RawType = dc["DataType"] as String;
|
||||
field.Description = dc["ColumnDescription"] as String;
|
||||
//field.DefaultValue = dc["Default"] as String;
|
||||
|
||||
field.Identity = dc["IsIdentity"].ToBoolean();
|
||||
field.PrimaryKey = dc["IsPrimaryKey"].ToBoolean();
|
||||
field.Nullable = dc["IsNullable"].ToBoolean();
|
||||
|
||||
//field.Precision = dc["Precision"].ToInt();
|
||||
//field.Scale = dc["Scale"].ToInt();
|
||||
field.Length = dc["Length"].ToInt();
|
||||
|
||||
var type = GetDataType(field);
|
||||
field.DataType = type;
|
||||
field.DataType = GetDataType(field)!;
|
||||
|
||||
field.Fix();
|
||||
|
||||
table.Columns.Add(field);
|
||||
}
|
||||
}
|
||||
|
@ -430,7 +434,8 @@ internal class HighGoMetaData : RemoteDbMetaData
|
|||
public override String DropTableDescriptionSQL(IDataTable table) => $"COMMENT ON TABLE {FormatName(table)} IS NULL";
|
||||
public override String AddColumnDescriptionSQL(IDataColumn field)
|
||||
{
|
||||
if (String.IsNullOrEmpty(field.Description)) { return null; };
|
||||
if (String.IsNullOrEmpty(field.Description)) { return null; }
|
||||
;
|
||||
return $"COMMENT ON COLUMN {FormatName(field.Table)}.{FormatName(field)} IS '{field.Description}'";
|
||||
}
|
||||
public override String DropColumnDescriptionSQL(IDataColumn field) => $"COMMENT ON COLUMN {FormatName(field.Table)}.{FormatName(field)} IS NULL";
|
||||
|
|
|
@ -372,16 +372,20 @@ internal class KingBaseMetaData : RemoteDbMetaData
|
|||
field.ColumnName = $"{dc["ColumnName"]}";
|
||||
field.RawType = $"{dc["DataType"]}";
|
||||
field.Description = $"{dc["ColumnDescription"]}";
|
||||
//field.DefaultValue = dc["Default"] as String;
|
||||
|
||||
field.Identity = dc["IsIdentity"].ToBoolean();
|
||||
field.PrimaryKey = dc["IsPrimaryKey"].ToBoolean();
|
||||
field.Nullable = dc["IsNullable"].ToBoolean();
|
||||
|
||||
//field.Precision = dc["Precision"].ToInt();
|
||||
//field.Scale = dc["Scale"].ToInt();
|
||||
field.Length = dc["Length"].ToInt();
|
||||
|
||||
var type = GetDataType(field);
|
||||
field.DataType = type;
|
||||
field.DataType = GetDataType(field)!;
|
||||
|
||||
field.Fix();
|
||||
|
||||
table.Columns.Add(field);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -479,8 +479,19 @@ internal class MySqlMetaData : RemoteDbMetaData
|
|||
if (dc["COLUMN_KEY"] + "" == "PRI") field.PrimaryKey = true;
|
||||
if (dc["IS_NULLABLE"] + "" == "YES") field.Nullable = true;
|
||||
|
||||
// 精度 与 位数
|
||||
field.Precision = dc["NUMERIC_PRECISION"].ToInt();
|
||||
field.Scale = dc["NUMERIC_SCALE"].ToInt();
|
||||
field.DefaultValue = dc["COLUMN_DEFAULT"] as String;
|
||||
|
||||
field.Length = field.RawType.Substring("(", ")").ToInt();
|
||||
|
||||
// 在MySql8.0中,COLUMN_TYPE取得的类型,数字类型已经没有圆括号精度,需要额外处理
|
||||
//if (field.Length == 0 && field.RawType.EqualIgnoreCase("int", "bigint", "tinyint", "datetime"))
|
||||
//{
|
||||
// field.Precision = dc["NUMERIC_PRECISION"].ToInt();
|
||||
//}
|
||||
|
||||
var type = GetDataType(field);
|
||||
if (type == null)
|
||||
{
|
||||
|
@ -508,13 +519,14 @@ internal class MySqlMetaData : RemoteDbMetaData
|
|||
field.ColumnName = dc["Field"] + "";
|
||||
field.RawType = dc["Type"] + "";
|
||||
field.Description = dc["Comment"] + "";
|
||||
field.DefaultValue = dc["Default"] as String;
|
||||
|
||||
if (dc["Extra"] + "" == "auto_increment") field.Identity = true;
|
||||
if (dc["Key"] + "" == "PRI") field.PrimaryKey = true;
|
||||
if (dc["Null"] + "" == "YES") field.Nullable = true;
|
||||
|
||||
field.Length = field.RawType.Substring("(", ")").ToInt();
|
||||
field.DataType = GetDataType(field);
|
||||
field.DataType = GetDataType(field)!;
|
||||
|
||||
if (field.DataType == null)
|
||||
{
|
||||
|
|
|
@ -550,7 +550,7 @@ internal class SQLiteMetaData : FileDbMetaData
|
|||
}
|
||||
|
||||
static readonly Regex _reg = new("""(?:^|,)\s*("[^"]+"|\[\w+\]|\w+)\s*(\w+(?:\(\d+(?:,\s*\d+)?\))?)\s*([^,]*)?""",
|
||||
RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline | RegexOptions.IgnoreCase);
|
||||
RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline | RegexOptions.IgnoreCase);
|
||||
public void ParseColumns(IDataTable table, String sqlCreateTable)
|
||||
{
|
||||
if (sqlCreateTable.StartsWithIgnoreCase("create table"))
|
||||
|
@ -604,7 +604,7 @@ internal class SQLiteMetaData : FileDbMetaData
|
|||
field.Scale = ns[1];
|
||||
}
|
||||
}
|
||||
field.DataType = GetDataType(field);
|
||||
field.DataType = GetDataType(field)!;
|
||||
|
||||
// 如果数据库里面是integer或者autoincrement,识别类型是Int64,又是自增,则改为Int32,保持与大多数数据库的兼容
|
||||
if (field.Identity && field.DataType == typeof(Int64) && field.RawType.EqualIgnoreCase("integer", "autoincrement"))
|
||||
|
@ -659,12 +659,13 @@ internal class SQLiteMetaData : FileDbMetaData
|
|||
foreach (var row in ds.Rows)
|
||||
{
|
||||
var field = table.CreateColumn();
|
||||
field.ColumnName = row[1].ToString().Replace(" ", "");
|
||||
field.RawType = row[2].ToString().Replace(" ", "");//去除所有空格
|
||||
field.ColumnName = row[1]!.ToString().Replace(" ", "");
|
||||
field.RawType = row[2]!.ToString().Replace(" ", "");//去除所有空格
|
||||
field.Nullable = row[3].ToInt() != 1;
|
||||
field.DefaultValue = row[4] as String;
|
||||
field.PrimaryKey = row[5].ToInt() == 1;
|
||||
|
||||
field.DataType = GetDataType(field);
|
||||
field.DataType = GetDataType(field)!;
|
||||
if (field.DataType == null)
|
||||
{
|
||||
if (field.RawType.StartsWithIgnoreCase("varchar2", "nvarchar2")) field.DataType = typeof(String);
|
||||
|
|
|
@ -211,12 +211,12 @@ partial class DbMetaData
|
|||
// 长度
|
||||
field.Length = GetDataRowValue<Int32>(dr, "CHARACTER_MAXIMUM_LENGTH", "LENGTH", "COLUMN_SIZE");
|
||||
|
||||
if (field is XField fi)
|
||||
//if (field is XField fi)
|
||||
{
|
||||
// 精度 与 位数
|
||||
fi.Precision = GetDataRowValue<Int32>(dr, "NUMERIC_PRECISION", "DATETIME_PRECISION", "PRECISION");
|
||||
fi.Scale = GetDataRowValue<Int32>(dr, "NUMERIC_SCALE", "SCALE");
|
||||
if (field.Length == 0) field.Length = fi.Precision;
|
||||
field.Precision = GetDataRowValue<Int32>(dr, "NUMERIC_PRECISION", "DATETIME_PRECISION", "PRECISION");
|
||||
field.Scale = GetDataRowValue<Int32>(dr, "NUMERIC_SCALE", "SCALE");
|
||||
if (field.Length == 0) field.Length = field.Precision;
|
||||
}
|
||||
|
||||
// 允许空
|
||||
|
@ -231,6 +231,9 @@ partial class DbMetaData
|
|||
if (!String.IsNullOrEmpty(str)) field.Nullable = "Y".EqualIgnoreCase(str);
|
||||
}
|
||||
|
||||
// 默认值
|
||||
field.DefaultValue = GetDataRowValue<String>(dr, "COLUMN_DEFAULT");
|
||||
|
||||
// 描述
|
||||
field.Description = GetDataRowValue<String>(dr, "DESCRIPTION");
|
||||
|
||||
|
@ -421,7 +424,7 @@ partial class DbMetaData
|
|||
{
|
||||
case "Int64":
|
||||
type = typeof(Int64);
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
type = typeof(Int32);
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue