- 增加 DbFirst 获取字段的默认值信息;

This commit is contained in:
28810
2020-04-13 19:00:22 +08:00
parent 44638a1e97
commit 5e336a0173
13 changed files with 110 additions and 26 deletions

View File

@ -250,6 +250,25 @@ where a.owner in ({0})", databaseIn);
}
loc8.Append(")");
_orm.Ado.ExecuteNonQuery(CommandType.Text, @"
CREATE OR REPLACE FUNCTION FREESQL_LONG_TO_CHAR_DEFAULT
(
TABLE_NAME VARCHAR,
COLUMN VARCHAR2
)
RETURN VARCHAR AS
TEXT_C1 VARCHAR2(32767);
SQL_CUR VARCHAR2(2000);
BEGIN
DBMS_OUTPUT.ENABLE(BUFFER_SIZE => NULL);
SQL_CUR := 'SELECT T.DATA_DEFAULT FROM USER_TAB_COLUMNS T WHERE T.TABLE_NAME = '''||TABLE_NAME||''' AND T.COLUMN_NAME='''||COLUMN||'''';
DBMS_OUTPUT.PUT_LINE(SQL_CUR);
EXECUTE IMMEDIATE SQL_CUR
INTO TEXT_C1;
TEXT_C1 := SUBSTR(TEXT_C1, 1, 4000);
RETURN TEXT_C1;
END;");
sql = string.Format(@"
select
a.owner || '.' || a.table_name,
@ -261,7 +280,8 @@ a.data_scale,
a.char_used,
case when a.nullable = 'N' then 0 else 1 end,
nvl((select 1 from user_sequences where upper(sequence_name)=upper(a.table_name||'_seq_'||a.column_name) and rownum < 2), 0),
b.comments
to_char(b.comments),
nvl(FREESQL_LONG_TO_CHAR_DEFAULT(a.table_name, a.column_name),'')
from all_tab_cols a
left join all_col_comments b on b.owner = a.owner and b.table_name = a.table_name and b.column_name = a.column_name
where a.owner in ({1}) and {0}
@ -272,7 +292,7 @@ where a.owner in ({1}) and {0}
var ds2 = new List<object[]>();
foreach (var row in ds)
{
var ds2item = new object[8];
var ds2item = new object[9];
ds2item[0] = row[0];
ds2item[1] = row[1];
ds2item[2] = Regex.Replace(string.Concat(row[2]), @"\(\d+\)", "");
@ -280,6 +300,7 @@ where a.owner in ({1}) and {0}
ds2item[5] = string.Concat(row[7]);
ds2item[6] = string.Concat(row[8]);
ds2item[7] = string.Concat(row[9]);
ds2item[8] = string.Concat(row[10]);
ds2.Add(ds2item);
}
foreach (var row in ds2)
@ -294,6 +315,7 @@ where a.owner in ({1}) and {0}
bool is_nullable = string.Concat(row[5]) == "1";
bool is_identity = string.Concat(row[6]) == "1";
string comment = string.Concat(row[7]);
string defaultValue = string.Concat(row[8]);
if (max_length == 0) max_length = -1;
if (database.Length == 1)
{
@ -309,7 +331,8 @@ where a.owner in ({1}) and {0}
DbTypeText = type,
DbTypeTextFull = sqlType,
Table = loc2[table_id],
Coment = comment
Coment = comment,
DefaultValue = defaultValue
});
loc3[table_id][column].DbType = this.GetDbType(loc3[table_id][column]);
loc3[table_id][column].CsType = this.GetCsTypeInfo(loc3[table_id][column]);