mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 18:52:50 +08:00
- 修复 SqlServer 支持 Chinese_PRC_CS_AS 区分小大写;#684
This commit is contained in:
parent
2dd722e507
commit
d93fd91eed
@ -128,7 +128,7 @@ namespace FreeSql.Tests.Odbc.SqlServer
|
||||
//Assert.Equal(9989, g.sqlserver.Insert<Topic>(items).NoneParameter().ExecuteAffrows());
|
||||
|
||||
var dt1 = select.Limit(10).ToDataTable();
|
||||
var dt2 = select.Limit(10).ToDataTable("id, getdate()");
|
||||
var dt2 = select.Limit(10).ToDataTable("Id, getdate()");
|
||||
var dt3 = select.Limit(10).ToDataTable(a => new { a.Id, a.Type.Name, now = DateTime.Now });
|
||||
}
|
||||
class TestDto
|
||||
@ -899,7 +899,7 @@ WHERE (((cast(a.[Id] as nvarchar(100))) in (SELECT b.[Title]
|
||||
public void AsTable()
|
||||
{
|
||||
|
||||
var listt = select.AsTable((a, b) => "(select * from tb_topic22 where clicks > 10)").Page(1, 10).ToList();
|
||||
var listt = select.AsTable((a, b) => "(select * from tb_topic22 where Clicks > 10)").Page(1, 10).ToList();
|
||||
|
||||
Func<Type, string, string> tableRule = (type, oldname) =>
|
||||
{
|
||||
|
@ -180,10 +180,10 @@ namespace FreeSql.Tests.Odbc.SqlServer
|
||||
g.sqlserver.Insert<Topic>().AppendData(new Topic()).ExecuteAffrows();
|
||||
|
||||
var items = g.sqlserver.Select<Topic>().Limit(2).ToList();
|
||||
g.sqlserver.Update<Topic>(items).SetRaw("title='test'").ExecuteUpdated();
|
||||
g.sqlserver.Update<Topic>(items).SetRaw("Title='test'").ExecuteUpdated();
|
||||
|
||||
items = g.sqlserver.Select<Topic>().Limit(2).ToList();
|
||||
var result = g.sqlserver.Update<Topic>(items).SetRaw("title='test'").ExecuteUpdatedAsync().Result;
|
||||
var result = g.sqlserver.Update<Topic>(items).SetRaw("Title='test'").ExecuteUpdatedAsync().Result;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -19,7 +19,7 @@ public class g
|
||||
public static IFreeSql mysql => mysqlLazy.Value;
|
||||
|
||||
static Lazy<IFreeSql> sqlserverLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
||||
.UseConnectionString(FreeSql.DataType.OdbcSqlServer, "Driver={SQL Server};Server=.;Persist Security Info=False;Trusted_Connection=Yes;Integrated Security=True;DATABASE=freesqlTest_odbc;Pooling=true;Max pool size=3")
|
||||
.UseConnectionString(FreeSql.DataType.OdbcSqlServer, "Driver={SQL Server};Server=.;Persist Security Info=False;Trusted_Connection=Yes;Integrated Security=True;DATABASE=issues684_odbc;Pooling=true;Max pool size=3")
|
||||
//.UseConnectionFactory(FreeSql.DataType.OdbcSqlServer, () => new System.Data.Odbc.OdbcConnection("Driver={SQL Server};Server=.;Persist Security Info=False;Trusted_Connection=Yes;Integrated Security=True;DATABASE=freesqlTest_odbc;Pooling=true;"))
|
||||
//.UseConnectionString(FreeSql.DataType.OdbcSqlServer, "Driver={SQL Server};Server=192.168.164.129;Persist Security Info=False;Trusted_Connection=Yes;UID=sa;PWD=123456;DATABASE=ds_shop;")
|
||||
//.UseConnectionFactory(FreeSql.DataType.OdbcSqlServer, () => new System.Data.Odbc.OdbcConnection("Driver={SQL Server};Server=192.168.164.129;Persist Security Info=False;Trusted_Connection=Yes;UID=sa;PWD=123456;DATABASE=ds_shop;"))
|
||||
|
@ -145,7 +145,7 @@ namespace FreeSql.Tests.SqlServer
|
||||
//Assert.Equal(9989, g.sqlserver.Insert<Topic>(items).NoneParameter().ExecuteAffrows());
|
||||
|
||||
var dt1 = select.Limit(10).ToDataTable();
|
||||
var dt2 = select.Limit(10).ToDataTable("id, getdate()");
|
||||
var dt2 = select.Limit(10).ToDataTable("Id, getdate()");
|
||||
var dt3 = select.Limit(10).ToDataTable(a => new { a.Id, a.Type.Name, now = DateTime.Now });
|
||||
}
|
||||
class TestDto
|
||||
@ -609,9 +609,9 @@ namespace FreeSql.Tests.SqlServer
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
query = select.Where("a.clicks > 100 and a.id = @id", new { id = 10 });
|
||||
query = select.Where("a.Clicks > 100 and a.Id = @id", new { id = 10 });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a WHERE (a.clicks > 100 and a.id = @id)", sql);
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a WHERE (a.Clicks > 100 and a.Id = @id)", sql);
|
||||
query.ToList();
|
||||
}
|
||||
[Fact]
|
||||
@ -657,9 +657,9 @@ namespace FreeSql.Tests.SqlServer
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
query = select.WhereIf(true, "a.clicks > 100 and a.id = @id", new { id = 10 });
|
||||
query = select.WhereIf(true, "a.Clicks > 100 and a.Id = @id", new { id = 10 });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a WHERE (a.clicks > 100 and a.id = @id)", sql);
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a WHERE (a.Clicks > 100 and a.Id = @id)", sql);
|
||||
query.ToList();
|
||||
|
||||
// ==========================================WhereIf(false)
|
||||
@ -704,7 +704,7 @@ namespace FreeSql.Tests.SqlServer
|
||||
query2.ToList();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||
query = select.WhereIf(false, "a.clicks > 100 and a.id = @id", new { id = 10 });
|
||||
query = select.WhereIf(false, "a.Clicks > 100 and a.Id = @id", new { id = 10 });
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a", sql);
|
||||
query.ToList();
|
||||
@ -955,7 +955,7 @@ WHERE (((cast(a.[Id] as nvarchar(100))) in (SELECT b.[Title]
|
||||
public void AsTable()
|
||||
{
|
||||
|
||||
var listt = select.AsTable((a, b) => "(select * from tb_topic22 where clicks > 10)").Page(1, 10).ToList();
|
||||
var listt = select.AsTable((a, b) => "(select * from tb_topic22 where Clicks > 10)").Page(1, 10).ToList();
|
||||
|
||||
Func<Type, string, string> tableRule = (type, oldname) =>
|
||||
{
|
||||
@ -1053,8 +1053,8 @@ WHERE (((cast(a.[Id] as nvarchar(100))) in (SELECT b.[Title]
|
||||
});
|
||||
|
||||
var testUnionAll = select
|
||||
.WithSql("SELECT * FROM [tb_topic22] where id = @id1", new { id1 = 10 })
|
||||
.WithSql("SELECT * FROM [tb_topic22] where id = @id2", new { id2 = 11 })
|
||||
.WithSql("SELECT * FROM [tb_topic22] where Id = @id1", new { id1 = 10 })
|
||||
.WithSql("SELECT * FROM [tb_topic22] where Id = @id2", new { id2 = 11 })
|
||||
.ToSql(a => new
|
||||
{
|
||||
a.Id,
|
||||
@ -1062,8 +1062,8 @@ WHERE (((cast(a.[Id] as nvarchar(100))) in (SELECT b.[Title]
|
||||
});
|
||||
|
||||
var testUnionAllToList = select
|
||||
.WithSql("SELECT * FROM [tb_topic22] where id = @id1", new { id1 = 10 })
|
||||
.WithSql("SELECT * FROM [tb_topic22] where id = @id2", new { id2 = 11 })
|
||||
.WithSql("SELECT * FROM [tb_topic22] where Id = @id1", new { id1 = 10 })
|
||||
.WithSql("SELECT * FROM [tb_topic22] where Id = @id2", new { id2 = 11 })
|
||||
.ToList(a => new
|
||||
{
|
||||
a.Id,
|
||||
@ -1071,13 +1071,13 @@ WHERE (((cast(a.[Id] as nvarchar(100))) in (SELECT b.[Title]
|
||||
});
|
||||
|
||||
var testUnionAll2 = g.sqlite.Select<object>()
|
||||
.WithSql("SELECT * FROM [tb_topic22] where id = 10")
|
||||
.WithSql("SELECT * FROM [tb_topic22] where id = 11")
|
||||
.WithSql("SELECT * FROM [tb_topic22] where Id = 10")
|
||||
.WithSql("SELECT * FROM [tb_topic22] where Id = 11")
|
||||
.ToDataTable("*");
|
||||
|
||||
var multiWithSql = g.sqlite.Select<TestInclude_OneToManyModel1, TestInclude_OneToManyModel2, TestInclude_OneToManyModel3>()
|
||||
.WithSql(
|
||||
"select * from TestInclude_OneToManyModel1 where id=@id1",
|
||||
"select * from TestInclude_OneToManyModel1 where Id=@id1",
|
||||
"select * from TestInclude_OneToManyModel2 where model2id=@id2",
|
||||
null,
|
||||
new { id1 = 10, id2 = 11, id3 = 13 }
|
||||
|
@ -193,10 +193,10 @@ namespace FreeSql.Tests.SqlServer
|
||||
g.sqlserver.Insert<Topic>().AppendData(new Topic()).ExecuteAffrows();
|
||||
|
||||
var items = g.sqlserver.Select<Topic>().Limit(2).ToList();
|
||||
g.sqlserver.Update<Topic>(items).SetRaw("title='test'").ExecuteUpdated();
|
||||
g.sqlserver.Update<Topic>(items).SetRaw("Title='test'").ExecuteUpdated();
|
||||
|
||||
items = g.sqlserver.Select<Topic>().Limit(2).ToList();
|
||||
var result = g.sqlserver.Update<Topic>(items).SetRaw("title='test'").ExecuteUpdatedAsync().Result;
|
||||
var result = g.sqlserver.Update<Topic>(items).SetRaw("Title='test'").ExecuteUpdatedAsync().Result;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -131,12 +131,12 @@ namespace FreeSql.Tests.SqlServer
|
||||
|
||||
var t4 = g.sqlserver.Ado.Query<(int, int, string, string DateTime)>("select * from xxx");
|
||||
|
||||
var t5 = g.sqlserver.Ado.Query<dynamic>("select * from xxx where Id = @Id",
|
||||
var t5 = g.sqlserver.Ado.Query<dynamic>("select * from xxx where Id = @id",
|
||||
new Dictionary<string, object> { ["id"] = 1 });
|
||||
|
||||
var t6 = g.sqlserver.Ado.Query<xxx>("select * from xxx where id in @ids", new { ids = new[] { 1, 2, 3 } });
|
||||
var t6 = g.sqlserver.Ado.Query<xxx>("select * from xxx where Id in @ids", new { ids = new[] { 1, 2, 3 } });
|
||||
|
||||
var t7 = g.sqlserver.Ado.Query<xxx>("select * from xxx where title in @titles", new { titles = new[] { "title1", "title2", "title2" } });
|
||||
var t7 = g.sqlserver.Ado.Query<xxx>("select * from xxx where Title in @titles", new { titles = new[] { "title1", "title2", "title2" } });
|
||||
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ public class g
|
||||
public static IFreeSql pgsql => pgsqlLazy.Value;
|
||||
|
||||
static Lazy<IFreeSql> sqlserverLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
||||
.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=3")
|
||||
.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=issues684;Pooling=true;Max Pool Size=3")
|
||||
.UseAutoSyncStructure(true)
|
||||
.UseMonitorCommand(
|
||||
cmd => Trace.WriteLine("\r\n线程" + Thread.CurrentThread.ManagedThreadId + ": " + cmd.CommandText) //监听SQL命令对象,在执行前
|
||||
|
@ -254,17 +254,17 @@ ELSE
|
||||
var sql = string.Format(@"
|
||||
use [{0}];
|
||||
select
|
||||
a.name 'Column'
|
||||
a.name 'column'
|
||||
,b.name + case
|
||||
when b.name in ('Char', 'VarChar', 'NChar', 'NVarChar', 'Binary', 'VarBinary') then '(' +
|
||||
when b.name in ('char', 'varchar', 'nchar', 'nvarchar', 'binary', 'varbinary') then '(' +
|
||||
case when a.max_length = -1 then 'MAX'
|
||||
when b.name in ('NChar', 'NVarchar') then cast(a.max_length / 2 as varchar)
|
||||
when b.name in ('nchar', 'nvarchar') then cast(a.max_length / 2 as varchar)
|
||||
else cast(a.max_length as varchar) end + ')'
|
||||
when b.name in ('Numeric', 'Decimal') then '(' + cast(a.precision as varchar) + ',' + cast(a.scale as varchar) + ')'
|
||||
else '' end as 'SqlType'
|
||||
,case when a.is_nullable = 1 then '1' else '0' end 'IsNullable'
|
||||
,case when a.is_identity = 1 then '1' else '0' end 'IsIdentity'
|
||||
,(select value from sys.extended_properties where major_id = a.object_id AND minor_id = a.column_id AND name = 'MS_Description') 'Comment'
|
||||
when b.name in ('numeric', 'decimal') then '(' + cast(a.precision as varchar) + ',' + cast(a.scale as varchar) + ')'
|
||||
else '' end as 'sqltype'
|
||||
,case when a.is_nullable = 1 then '1' else '0' end 'isnullable'
|
||||
,case when a.is_identity = 1 then '1' else '0' end 'isidentity'
|
||||
,(select value from sys.extended_properties where major_id = a.object_id AND minor_id = a.column_id AND name = 'MS_Description') 'comment'
|
||||
from sys.columns a
|
||||
inner join sys.types b on b.user_type_id = a.user_type_id
|
||||
left join sys.tables d on d.object_id = a.object_id
|
||||
|
@ -164,35 +164,35 @@ use [{olddatabase}];
|
||||
use [{db}];
|
||||
select * from (
|
||||
select
|
||||
a.Object_id
|
||||
,b.name 'Owner'
|
||||
,a.name 'Name'
|
||||
,(select value from sys.extended_properties where major_id = a.object_id AND minor_id = 0 AND name = 'MS_Description') 'Comment'
|
||||
a.object_id
|
||||
,b.name 'owner'
|
||||
,a.name 'name'
|
||||
,(select value from sys.extended_properties where major_id = a.object_id AND minor_id = 0 AND name = 'MS_Description') 'comment'
|
||||
,'TABLE' type
|
||||
from sys.tables a
|
||||
inner join sys.schemas b on b.schema_id = a.schema_id
|
||||
where not(b.name = 'dbo' and a.name = 'sysdiagrams')
|
||||
union all
|
||||
select
|
||||
a.Object_id
|
||||
,b.name 'Owner'
|
||||
,a.name 'Name'
|
||||
,(select value from sys.extended_properties where major_id = a.object_id AND minor_id = 0 AND name = 'MS_Description') 'Comment'
|
||||
a.object_id
|
||||
,b.name 'owner'
|
||||
,a.name 'name'
|
||||
,(select value from sys.extended_properties where major_id = a.object_id AND minor_id = 0 AND name = 'MS_Description') 'comment'
|
||||
,'VIEW' type
|
||||
from sys.views a
|
||||
inner join sys.schemas b on b.schema_id = a.schema_id
|
||||
union all
|
||||
select
|
||||
a.Object_id
|
||||
,b.name 'Owner'
|
||||
,a.name 'Name'
|
||||
,(select value from sys.extended_properties where major_id = a.object_id AND minor_id = 0 AND name = 'MS_Description') 'Comment'
|
||||
a.object_id
|
||||
,b.name 'owner'
|
||||
,a.name 'name'
|
||||
,(select value from sys.extended_properties where major_id = a.object_id AND minor_id = 0 AND name = 'MS_Description') 'comment'
|
||||
,'StoreProcedure' type
|
||||
from sys.procedures a
|
||||
inner join sys.schemas b on b.schema_id = a.schema_id
|
||||
where a.type = 'P' and charindex('diagram', a.name) = 0
|
||||
) ft_dbf{(tbname == null ? "" : _commonUtils.FormatSql(" where lower([owner])={0} and lower([Name])={1}", new[] { tbname[1], tbname[2] }))}
|
||||
order by type desc, [owner], [Name];
|
||||
) ft_dbf{(tbname == null ? "" : _commonUtils.FormatSql(" where lower([owner])={0} and lower([name])={1}", new[] { tbname[1], tbname[2] }))}
|
||||
order by type desc, [owner], [name];
|
||||
use [{olddatabase}];
|
||||
";
|
||||
var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql);
|
||||
@ -261,21 +261,21 @@ use [{olddatabase}];
|
||||
|
||||
select
|
||||
isnull(e.name,'') + '.' + isnull(d.name,'')
|
||||
,a.Object_id
|
||||
,a.name 'Column'
|
||||
,b.name 'Type'
|
||||
,a.object_id
|
||||
,a.name 'column'
|
||||
,b.name 'type'
|
||||
,case
|
||||
when b.name in ('Text', 'NText', 'Image') then -1
|
||||
when b.name in ('NChar', 'NVarchar') then a.max_length / 2
|
||||
else a.max_length end 'Length'
|
||||
when b.name in ('text', 'ntext', 'image') then -1
|
||||
when b.name in ('nchar', 'nvarchar') then a.max_length / 2
|
||||
else a.max_length end 'length'
|
||||
,b.name + case
|
||||
when b.name in ('Char', 'VarChar', 'NChar', 'NVarChar', 'Binary', 'VarBinary') then '(' +
|
||||
when b.name in ('char', 'varchar', 'nchar', 'nvarchar', 'binary', 'varbinary') then '(' +
|
||||
case when a.max_length = -1 then 'MAX'
|
||||
when b.name in ('NChar', 'NVarchar') then cast(a.max_length / 2 as varchar)
|
||||
when b.name in ('nchar', 'nvarchar') then cast(a.max_length / 2 as varchar)
|
||||
else cast(a.max_length as varchar) end + ')'
|
||||
when b.name in ('Numeric', 'Decimal') then '(' + cast(a.precision as varchar) + ',' + cast(a.scale as varchar) + ')'
|
||||
else '' end as 'SqlType'
|
||||
,( select value from sys.extended_properties where major_id = a.object_id AND minor_id = a.column_id AND name = 'MS_Description') 'Comment'
|
||||
when b.name in ('numeric', 'decimal') then '(' + cast(a.precision as varchar) + ',' + cast(a.scale as varchar) + ')'
|
||||
else '' end as 'sqltype'
|
||||
,( select value from sys.extended_properties where major_id = a.object_id AND minor_id = a.column_id AND name = 'MS_Description') 'comment'
|
||||
{0} a
|
||||
inner join sys.types b on b.user_type_id = a.user_type_id
|
||||
left join sys.tables d on d.object_id = a.object_id
|
||||
@ -283,9 +283,9 @@ left join sys.schemas e on e.schema_id = d.schema_id{2}
|
||||
where {1}
|
||||
";
|
||||
sql = string.Format(tsql_place, @"
|
||||
,a.is_nullable 'IsNullable'
|
||||
,a.is_identity 'IsIdentity'
|
||||
,f.text as 'DefaultValue'
|
||||
,a.is_nullable 'isnullable'
|
||||
,a.is_identity 'isidentity'
|
||||
,f.text as 'defaultvalue'
|
||||
from sys.columns", loc8.ToString().Replace("a.table_name", "a.object_id"), @"
|
||||
left join syscomments f on f.id = a.default_object_id
|
||||
");
|
||||
@ -295,9 +295,9 @@ left join syscomments f on f.id = a.default_object_id
|
||||
string.Format(tsql_place.Replace(
|
||||
" select value from sys.extended_properties where major_id = a.object_id AND minor_id = a.column_id",
|
||||
" select value from sys.extended_properties where major_id = a.object_id AND minor_id = a.parameter_id"), @"
|
||||
,cast(0 as bit) 'IsNullable'
|
||||
,a.is_output 'IsIdentity'
|
||||
,'' as 'DefaultValue'
|
||||
,cast(0 as bit) 'isnullable'
|
||||
,a.is_output 'isidentity'
|
||||
,'' as 'defaultvalue'
|
||||
from sys.parameters", loc88.ToString().Replace("a.table_name", "a.object_id"), "");
|
||||
}
|
||||
sql = $"use [{db}];{sql};use [{olddatabase}]; ";
|
||||
@ -340,13 +340,13 @@ from sys.parameters", loc88.ToString().Replace("a.table_name", "a.object_id"), "
|
||||
sql = $@"
|
||||
use [{db}];
|
||||
select
|
||||
a.object_id 'Object_id'
|
||||
,c.name 'Column'
|
||||
,b.name 'Index_id'
|
||||
,b.is_unique 'IsUnique'
|
||||
,b.is_primary_key 'IsPrimaryKey'
|
||||
,cast(case when b.type_desc = 'CLUSTERED' then 1 else 0 end as bit) 'IsClustered'
|
||||
,case when a.is_descending_key = 1 then 1 else 0 end 'IsDesc'
|
||||
a.object_id 'object_id'
|
||||
,c.name 'column'
|
||||
,b.name 'index_id'
|
||||
,b.is_unique 'isunique'
|
||||
,b.is_primary_key 'isprimarykey'
|
||||
,cast(case when b.type_desc = 'CLUSTERED' then 1 else 0 end as bit) 'isclustered'
|
||||
,case when a.is_descending_key = 1 then 1 else 0 end 'isdesc'
|
||||
from sys.index_columns a
|
||||
inner join sys.indexes b on b.object_id = a.object_id and b.index_id = a.index_id
|
||||
left join sys.columns c on c.object_id = a.object_id and c.column_id = a.column_id
|
||||
@ -408,14 +408,14 @@ use [{olddatabase}];
|
||||
sql = $@"
|
||||
use [{db}];
|
||||
select
|
||||
b.object_id 'Object_id'
|
||||
,c.name 'Column'
|
||||
,e.name 'FKId'
|
||||
b.object_id 'object_id'
|
||||
,c.name 'column'
|
||||
,e.name 'fkid'
|
||||
,a.referenced_object_id
|
||||
,cast(1 as bit) 'IsForeignKey'
|
||||
,d.name 'Referenced_Column'
|
||||
,null 'Referenced_Sln'
|
||||
,null 'Referenced_Table'
|
||||
,cast(1 as bit) 'isforeignkey'
|
||||
,d.name 'referenced_column'
|
||||
,null 'referenced_sln'
|
||||
,null 'referenced_table'
|
||||
from sys.foreign_key_columns a
|
||||
inner join sys.tables b on b.object_id = a.parent_object_id
|
||||
inner join sys.columns c on c.object_id = a.parent_object_id and c.column_id = a.parent_column_id
|
||||
|
@ -253,17 +253,17 @@ ELSE
|
||||
var sql = string.Format(@"
|
||||
use [{0}];
|
||||
select
|
||||
a.name 'Column'
|
||||
a.name 'column'
|
||||
,b.name + case
|
||||
when b.name in ('Char', 'VarChar', 'NChar', 'NVarChar', 'Binary', 'VarBinary') then '(' +
|
||||
when b.name in ('char', 'varchar', 'nchar', 'nvarchar', 'binary', 'varbinary') then '(' +
|
||||
case when a.max_length = -1 then 'MAX'
|
||||
when b.name in ('NChar', 'NVarchar') then cast(a.max_length / 2 as varchar)
|
||||
when b.name in ('nchar', 'nvarchar') then cast(a.max_length / 2 as varchar)
|
||||
else cast(a.max_length as varchar) end + ')'
|
||||
when b.name in ('Numeric', 'Decimal') then '(' + cast(a.precision as varchar) + ',' + cast(a.scale as varchar) + ')'
|
||||
else '' end as 'SqlType'
|
||||
,case when a.is_nullable = 1 then '1' else '0' end 'IsNullable'
|
||||
,case when a.is_identity = 1 then '1' else '0' end 'IsIdentity'
|
||||
,(select value from sys.extended_properties where major_id = a.object_id AND minor_id = a.column_id AND name = 'MS_Description') 'Comment'
|
||||
when b.name in ('numeric', 'decimal') then '(' + cast(a.precision as varchar) + ',' + cast(a.scale as varchar) + ')'
|
||||
else '' end as 'sqltype'
|
||||
,case when a.is_nullable = 1 then '1' else '0' end 'isnullable'
|
||||
,case when a.is_identity = 1 then '1' else '0' end 'isidentity'
|
||||
,(select value from sys.extended_properties where major_id = a.object_id AND minor_id = a.column_id AND name = 'MS_Description') 'comment'
|
||||
from sys.columns a
|
||||
inner join sys.types b on b.user_type_id = a.user_type_id
|
||||
left join sys.tables d on d.object_id = a.object_id
|
||||
|
@ -167,35 +167,35 @@ use [{olddatabase}];
|
||||
use [{db}];
|
||||
select * from (
|
||||
select
|
||||
a.Object_id
|
||||
,b.name 'Owner'
|
||||
,a.name 'Name'
|
||||
,(select value from sys.extended_properties where major_id = a.object_id AND minor_id = 0 AND name = 'MS_Description') 'Comment'
|
||||
a.object_id
|
||||
,b.name 'owner'
|
||||
,a.name 'name'
|
||||
,(select value from sys.extended_properties where major_id = a.object_id AND minor_id = 0 AND name = 'MS_Description') 'comment'
|
||||
,'TABLE' type
|
||||
from sys.tables a
|
||||
inner join sys.schemas b on b.schema_id = a.schema_id
|
||||
where not(b.name = 'dbo' and a.name = 'sysdiagrams')
|
||||
union all
|
||||
select
|
||||
a.Object_id
|
||||
,b.name 'Owner'
|
||||
,a.name 'Name'
|
||||
,(select value from sys.extended_properties where major_id = a.object_id AND minor_id = 0 AND name = 'MS_Description') 'Comment'
|
||||
a.object_id
|
||||
,b.name 'owner'
|
||||
,a.name 'name'
|
||||
,(select value from sys.extended_properties where major_id = a.object_id AND minor_id = 0 AND name = 'MS_Description') 'comment'
|
||||
,'VIEW' type
|
||||
from sys.views a
|
||||
inner join sys.schemas b on b.schema_id = a.schema_id
|
||||
union all
|
||||
select
|
||||
a.Object_id
|
||||
,b.name 'Owner'
|
||||
,a.name 'Name'
|
||||
,(select value from sys.extended_properties where major_id = a.object_id AND minor_id = 0 AND name = 'MS_Description') 'Comment'
|
||||
a.object_id
|
||||
,b.name 'owner'
|
||||
,a.name 'name'
|
||||
,(select value from sys.extended_properties where major_id = a.object_id AND minor_id = 0 AND name = 'MS_Description') 'comment'
|
||||
,'StoreProcedure' type
|
||||
from sys.procedures a
|
||||
inner join sys.schemas b on b.schema_id = a.schema_id
|
||||
where a.type = 'P' and charindex('diagram', a.name) = 0
|
||||
) ft_dbf{(tbname == null ? "" : _commonUtils.FormatSql(" where lower([owner])={0} and lower([Name])={1}", new[] { tbname[1], tbname[2] }))}
|
||||
order by type desc, [owner], [Name];
|
||||
) ft_dbf{(tbname == null ? "" : _commonUtils.FormatSql(" where lower([owner])={0} and lower([name])={1}", new[] { tbname[1], tbname[2] }))}
|
||||
order by type desc, [owner], [name];
|
||||
use [{olddatabase}];
|
||||
";
|
||||
var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql);
|
||||
@ -264,21 +264,21 @@ use [{olddatabase}];
|
||||
|
||||
select
|
||||
isnull(e.name,'') + '.' + isnull(d.name,'')
|
||||
,a.Object_id
|
||||
,a.name 'Column'
|
||||
,b.name 'Type'
|
||||
,a.object_id
|
||||
,a.name 'column'
|
||||
,b.name 'type'
|
||||
,case
|
||||
when b.name in ('Text', 'NText', 'Image') then -1
|
||||
when b.name in ('NChar', 'NVarchar') then a.max_length / 2
|
||||
else a.max_length end 'Length'
|
||||
when b.name in ('text', 'ntext', 'image') then -1
|
||||
when b.name in ('nchar', 'nvarchar') then a.max_length / 2
|
||||
else a.max_length end 'length'
|
||||
,b.name + case
|
||||
when b.name in ('Char', 'VarChar', 'NChar', 'NVarChar', 'Binary', 'VarBinary') then '(' +
|
||||
when b.name in ('char', 'varchar', 'nchar', 'nvarchar', 'binary', 'varbinary') then '(' +
|
||||
case when a.max_length = -1 then 'MAX'
|
||||
when b.name in ('NChar', 'NVarchar') then cast(a.max_length / 2 as varchar)
|
||||
when b.name in ('nchar', 'nvarchar') then cast(a.max_length / 2 as varchar)
|
||||
else cast(a.max_length as varchar) end + ')'
|
||||
when b.name in ('Numeric', 'Decimal') then '(' + cast(a.precision as varchar) + ',' + cast(a.scale as varchar) + ')'
|
||||
else '' end as 'SqlType'
|
||||
,( select value from sys.extended_properties where major_id = a.object_id AND minor_id = a.column_id AND name = 'MS_Description') 'Comment'
|
||||
when b.name in ('numeric', 'decimal') then '(' + cast(a.precision as varchar) + ',' + cast(a.scale as varchar) + ')'
|
||||
else '' end as 'sqltype'
|
||||
,( select value from sys.extended_properties where major_id = a.object_id AND minor_id = a.column_id AND name = 'MS_Description') 'comment'
|
||||
{0} a
|
||||
inner join sys.types b on b.user_type_id = a.user_type_id
|
||||
left join sys.tables d on d.object_id = a.object_id
|
||||
@ -286,9 +286,9 @@ left join sys.schemas e on e.schema_id = d.schema_id{2}
|
||||
where {1}
|
||||
";
|
||||
sql = string.Format(tsql_place, @"
|
||||
,a.is_nullable 'IsNullable'
|
||||
,a.is_identity 'IsIdentity'
|
||||
,f.text as 'DefaultValue'
|
||||
,a.is_nullable 'isnullable'
|
||||
,a.is_identity 'isidentity'
|
||||
,f.text as 'defaultvalue'
|
||||
from sys.columns", loc8.ToString().Replace("a.table_name", "a.object_id"), @"
|
||||
left join syscomments f on f.id = a.default_object_id
|
||||
");
|
||||
@ -298,9 +298,9 @@ left join syscomments f on f.id = a.default_object_id
|
||||
string.Format(tsql_place.Replace(
|
||||
" select value from sys.extended_properties where major_id = a.object_id AND minor_id = a.column_id",
|
||||
" select value from sys.extended_properties where major_id = a.object_id AND minor_id = a.parameter_id"), @"
|
||||
,cast(0 as bit) 'IsNullable'
|
||||
,a.is_output 'IsIdentity'
|
||||
,'' as 'DefaultValue'
|
||||
,cast(0 as bit) 'isnullable'
|
||||
,a.is_output 'isidentity'
|
||||
,'' as 'defaultvalue'
|
||||
from sys.parameters", loc88.ToString().Replace("a.table_name", "a.object_id"), "");
|
||||
}
|
||||
sql = $"use [{db}];{sql};use [{olddatabase}]; ";
|
||||
@ -343,13 +343,13 @@ from sys.parameters", loc88.ToString().Replace("a.table_name", "a.object_id"), "
|
||||
sql = $@"
|
||||
use [{db}];
|
||||
select
|
||||
a.object_id 'Object_id'
|
||||
,c.name 'Column'
|
||||
,b.name 'Index_id'
|
||||
,b.is_unique 'IsUnique'
|
||||
,b.is_primary_key 'IsPrimaryKey'
|
||||
,cast(case when b.type_desc = 'CLUSTERED' then 1 else 0 end as bit) 'IsClustered'
|
||||
,case when a.is_descending_key = 1 then 1 else 0 end 'IsDesc'
|
||||
a.object_id 'object_id'
|
||||
,c.name 'column'
|
||||
,b.name 'index_id'
|
||||
,b.is_unique 'isunique'
|
||||
,b.is_primary_key 'isprimarykey'
|
||||
,cast(case when b.type_desc = 'CLUSTERED' then 1 else 0 end as bit) 'isclustered'
|
||||
,case when a.is_descending_key = 1 then 1 else 0 end 'isdesc'
|
||||
from sys.index_columns a
|
||||
inner join sys.indexes b on b.object_id = a.object_id and b.index_id = a.index_id
|
||||
left join sys.columns c on c.object_id = a.object_id and c.column_id = a.column_id
|
||||
@ -411,14 +411,14 @@ use [{olddatabase}];
|
||||
sql = $@"
|
||||
use [{db}];
|
||||
select
|
||||
b.object_id 'Object_id'
|
||||
,c.name 'Column'
|
||||
,e.name 'FKId'
|
||||
b.object_id 'object_id'
|
||||
,c.name 'column'
|
||||
,e.name 'fkid'
|
||||
,a.referenced_object_id
|
||||
,cast(1 as bit) 'IsForeignKey'
|
||||
,d.name 'Referenced_Column'
|
||||
,null 'Referenced_Sln'
|
||||
,null 'Referenced_Table'
|
||||
,cast(1 as bit) 'isforeignkey'
|
||||
,d.name 'referenced_column'
|
||||
,null 'referenced_sln'
|
||||
,null 'referenced_table'
|
||||
from sys.foreign_key_columns a
|
||||
inner join sys.tables b on b.object_id = a.parent_object_id
|
||||
inner join sys.columns c on c.object_id = a.parent_object_id and c.column_id = a.parent_column_id
|
||||
|
Loading…
x
Reference in New Issue
Block a user