完成CodeFirst 根据代码注释,迁移到数据库备注

This commit is contained in:
28810 2019-06-17 12:04:31 +08:00
parent 5ce51bc310
commit 9e6b4fb52e
17 changed files with 157 additions and 57 deletions

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks> <TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
<Version>0.6.10</Version> <Version>0.6.11</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>YeXiangQin</Authors> <Authors>YeXiangQin</Authors>
<Description>FreeSql 扩展包,可实现【延时加载】属性.</Description> <Description>FreeSql 扩展包,可实现【延时加载】属性.</Description>

View File

@ -74,9 +74,9 @@
</summary> </summary>
</member> </member>
<member name="P:FreeSql.Tests.UnitTest1.Templates.Id"> <member name="P:FreeSql.Tests.UnitTest1.Templates.Id2">
<summary> <summary>
主键ID 测试中文重命名id
</summary> </summary>
</member> </member>
<member name="T:FreeSql.Tests.ExamPaper"> <member name="T:FreeSql.Tests.ExamPaper">

View File

@ -232,14 +232,13 @@ namespace FreeSql.Tests {
} }
public class Templates { public class Templates {
/// <summary> /// <summary>
/// 主键ID /// 测试中文重命名id
/// </summary> /// </summary>
[Column(IsPrimary = true)] [Column(IsPrimary = true, OldName = "Id")]
public Guid Id { get; set; } public Guid Id2 { get; set; }
public string Title { get; set; } public string Title { get; set; }
public DateTime AddTime { get; set; } = DateTime.Now; public DateTime AddTime { get; set; } = DateTime.Now;
public DateTime EditTime { get; set; } public DateTime EditTime { get; set; }
[Column(DbType = "text")]
public string Code { get; set; } public string Code { get; set; }
} }
public class TaskBuild { public class TaskBuild {
@ -270,20 +269,20 @@ namespace FreeSql.Tests {
[Fact] [Fact]
public void Test1() { public void Test1() {
var dkdkdkd = g.mysql.Select<Templates>().ToList(); var dkdkdkd = g.oracle.Select<Templates>().ToList();
var testaddlist = new List<NewsArticle>(); //var testaddlist = new List<NewsArticle>();
for(var a = 0; a < 133905; a++) { //for(var a = 0; a < 133905; a++) {
testaddlist.Add(new NewsArticle { // testaddlist.Add(new NewsArticle {
ArticleTitle = "testaddlist_topic" + a, // ArticleTitle = "testaddlist_topic" + a,
Hits = a, // Hits = a,
}); // });
} //}
g.sqlite.Insert<NewsArticle>(testaddlist) //g.sqlite.Insert<NewsArticle>(testaddlist)
//.NoneParameter() // //.NoneParameter()
.ExecuteAffrows(); // .ExecuteAffrows();
g.mysql.Aop.ParseExpression = (s, e) => { g.mysql.Aop.ParseExpression = (s, e) => {

View File

@ -39,6 +39,20 @@ public class g {
}); });
public static IFreeSql pgsql => pgsqlLazy.Value; 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=10")
.UseAutoSyncStructure(true)
.UseMonitorCommand(
cmd => {
Trace.WriteLine(cmd.CommandText);
}, //监听SQL命令对象在执行前
(cmd, traceLog) => {
Console.WriteLine(traceLog);
}) //监听SQL命令对象在执行后
.UseLazyLoading(true)
.Build());
public static IFreeSql sqlserver => sqlserverLazy.Value;
static Lazy<IFreeSql> oracleLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder() static Lazy<IFreeSql> oracleLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
.UseConnectionString(FreeSql.DataType.Oracle, "user id=user1;password=123456;data source=//127.0.0.1:1521/XE;Pooling=true;Max Pool Size=10") .UseConnectionString(FreeSql.DataType.Oracle, "user id=user1;password=123456;data source=//127.0.0.1:1521/XE;Pooling=true;Max Pool Size=10")
.UseAutoSyncStructure(true) .UseAutoSyncStructure(true)

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks> <TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
<Version>0.6.10</Version> <Version>0.6.11</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>YeXiangQin</Authors> <Authors>YeXiangQin</Authors>
<Description>FreeSql is the most convenient ORM in dotnet. It supports Mysql, Postgresql, SqlServer, Oracle and Sqlite.</Description> <Description>FreeSql is the most convenient ORM in dotnet. It supports Mysql, Postgresql, SqlServer, Oracle and Sqlite.</Description>

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>netstandard2.0;net452</TargetFrameworks> <TargetFrameworks>netstandard2.0;net452</TargetFrameworks>
<Version>0.6.10</Version> <Version>0.6.11</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>YeXiangQin</Authors> <Authors>YeXiangQin</Authors>
<Description>FreeSql 数据库实现,基于 MySql 5.6</Description> <Description>FreeSql 数据库实现,基于 MySql 5.6</Description>

View File

@ -152,7 +152,8 @@ select
a.column_name, a.column_name,
a.column_type, a.column_type,
case when a.is_nullable = 'YES' then 1 else 0 end 'is_nullable', case when a.is_nullable = 'YES' then 1 else 0 end 'is_nullable',
case when locate('auto_increment', a.extra) > 0 then 1 else 0 end 'is_identity' case when locate('auto_increment', a.extra) > 0 then 1 else 0 end 'is_identity',
a.column_comment 'comment'
from information_schema.columns a from information_schema.columns a
where a.table_schema in ({0}) and a.table_name in ({1})", tboldname ?? tbname); where a.table_schema in ({0}) and a.table_name in ({1})", tboldname ?? tbname);
var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql);
@ -164,7 +165,8 @@ where a.table_schema in ({0}) and a.table_name in ({1})", tboldname ?? tbname);
sqlType = a1, sqlType = a1,
is_nullable = string.Concat(a[2]) == "1", is_nullable = string.Concat(a[2]) == "1",
is_identity = string.Concat(a[3]) == "1", is_identity = string.Concat(a[3]) == "1",
is_unsigned = string.Concat(a[1]).EndsWith(" unsigned") is_unsigned = string.Concat(a[1]).EndsWith(" unsigned"),
comment = string.Concat(a[4])
}; };
}, StringComparer.CurrentCultureIgnoreCase); }, StringComparer.CurrentCultureIgnoreCase);
@ -174,18 +176,22 @@ where a.table_schema in ({0}) and a.table_name in ({1})", tboldname ?? tbname);
var isIdentityChanged = tbcol.Attribute.IsIdentity == true && tbcol.Attribute.DbType.IndexOf("AUTO_INCREMENT", StringComparison.CurrentCultureIgnoreCase) == -1; var isIdentityChanged = tbcol.Attribute.IsIdentity == true && tbcol.Attribute.DbType.IndexOf("AUTO_INCREMENT", StringComparison.CurrentCultureIgnoreCase) == -1;
if (tbstruct.TryGetValue(tbcol.Attribute.Name, out var tbstructcol) || if (tbstruct.TryGetValue(tbcol.Attribute.Name, out var tbstructcol) ||
string.IsNullOrEmpty(tbcol.Attribute.OldName) == false && tbstruct.TryGetValue(tbcol.Attribute.OldName, out tbstructcol)) { string.IsNullOrEmpty(tbcol.Attribute.OldName) == false && tbstruct.TryGetValue(tbcol.Attribute.OldName, out tbstructcol)) {
var isCommentChanged = tbstructcol.comment != (tbcol.Comment ?? "");
if ((tbcol.Attribute.DbType.IndexOf(" unsigned", StringComparison.CurrentCultureIgnoreCase) != -1) != tbstructcol.is_unsigned || if ((tbcol.Attribute.DbType.IndexOf(" unsigned", StringComparison.CurrentCultureIgnoreCase) != -1) != tbstructcol.is_unsigned ||
tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false || tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false ||
tbcol.Attribute.IsNullable != tbstructcol.is_nullable || tbcol.Attribute.IsNullable != tbstructcol.is_nullable ||
tbcol.Attribute.IsIdentity != tbstructcol.is_identity) { tbcol.Attribute.IsIdentity != tbstructcol.is_identity ||
isCommentChanged) {
sbalter.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" MODIFY ").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" ").Append(tbcol.Attribute.DbType); sbalter.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" MODIFY ").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" ").Append(tbcol.Attribute.DbType);
if (isCommentChanged) sbalter.Append(" COMMENT ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment ?? ""));
if (isIdentityChanged) sbalter.Append(" AUTO_INCREMENT").Append(existsPrimary == null ? "" : ", DROP PRIMARY KEY").Append(", ADD PRIMARY KEY(").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(")"); if (isIdentityChanged) sbalter.Append(" AUTO_INCREMENT").Append(existsPrimary == null ? "" : ", DROP PRIMARY KEY").Append(", ADD PRIMARY KEY(").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(")");
sbalter.Append(";\r\n"); sbalter.Append(";\r\n");
} }
if (tbstructcol.column == tbcol.Attribute.OldName) { if (string.Compare(tbstructcol.column, tbcol.Attribute.OldName, true) == 0) {
//修改列名 //修改列名
sbalter.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" CHANGE COLUMN ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.OldName)).Append(" ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" ").Append(tbcol.Attribute.DbType); sbalter.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" CHANGE COLUMN ").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" ").Append(tbcol.Attribute.DbType);
if (isIdentityChanged) sb.Append(" AUTO_INCREMENT").Append(existsPrimary == null ? "" : ", DROP PRIMARY KEY").Append(", ADD PRIMARY KEY(").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(")"); if (isCommentChanged) sbalter.Append(" COMMENT ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment ?? ""));
if (isIdentityChanged) sbalter.Append(" AUTO_INCREMENT").Append(existsPrimary == null ? "" : ", DROP PRIMARY KEY").Append(", ADD PRIMARY KEY(").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(")");
sbalter.Append(";\r\n"); sbalter.Append(";\r\n");
} }
continue; continue;
@ -193,6 +199,7 @@ where a.table_schema in ({0}) and a.table_name in ({1})", tboldname ?? tbname);
//添加列 //添加列
sbalter.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" ADD ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" ").Append(tbcol.Attribute.DbType); sbalter.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" ADD ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" ").Append(tbcol.Attribute.DbType);
if (tbcol.Attribute.IsNullable == false) sbalter.Append(" DEFAULT ").Append(_commonUtils.FormatSql("{0}", tbcol.Attribute.DbDefautValue)); if (tbcol.Attribute.IsNullable == false) sbalter.Append(" DEFAULT ").Append(_commonUtils.FormatSql("{0}", tbcol.Attribute.DbDefautValue));
if (string.IsNullOrEmpty(tbcol.Comment) == false) sbalter.Append(" COMMENT ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment ?? ""));
if (isIdentityChanged) sbalter.Append(" AUTO_INCREMENT").Append(existsPrimary == null ? "" : ", DROP PRIMARY KEY").Append(", ADD PRIMARY KEY(").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(")"); if (isIdentityChanged) sbalter.Append(" AUTO_INCREMENT").Append(existsPrimary == null ? "" : ", DROP PRIMARY KEY").Append(", ADD PRIMARY KEY(").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(")");
sbalter.Append(";\r\n"); sbalter.Append(";\r\n");
} }
@ -228,6 +235,7 @@ where a.constraint_schema IN ({0}) and a.table_name IN ({1})", tboldname ?? tbna
sb.Append(" \r\n ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" "); sb.Append(" \r\n ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" ");
sb.Append(tbcol.Attribute.DbType); sb.Append(tbcol.Attribute.DbType);
if (tbcol.Attribute.IsIdentity == true && tbcol.Attribute.DbType.IndexOf("AUTO_INCREMENT", StringComparison.CurrentCultureIgnoreCase) == -1) sb.Append(" AUTO_INCREMENT"); if (tbcol.Attribute.IsIdentity == true && tbcol.Attribute.DbType.IndexOf("AUTO_INCREMENT", StringComparison.CurrentCultureIgnoreCase) == -1) sb.Append(" AUTO_INCREMENT");
if (string.IsNullOrEmpty(tbcol.Comment) == false) sb.Append(" COMMENT ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment));
sb.Append(","); sb.Append(",");
} }
if (tb.Primarys.Any()) { if (tb.Primarys.Any()) {

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks> <TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
<Version>0.6.10</Version> <Version>0.6.11</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>YeXiangQin</Authors> <Authors>YeXiangQin</Authors>
<Description>FreeSql 数据库实现,基于 MySql 5.6</Description> <Description>FreeSql 数据库实现,基于 MySql 5.6</Description>

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks> <TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
<Version>0.6.10</Version> <Version>0.6.11</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>YeXiangQin</Authors> <Authors>YeXiangQin</Authors>
<Description>FreeSql 数据库实现,基于 Oracle 11</Description> <Description>FreeSql 数据库实现,基于 Oracle 11</Description>

View File

@ -112,6 +112,11 @@ namespace FreeSql.Oracle {
} }
sb.Remove(sb.Length - 1, 1); sb.Remove(sb.Length - 1, 1);
sb.Append("\r\n) \r\nLOGGING \r\nNOCOMPRESS \r\nNOCACHE\r\n';\r\n"); sb.Append("\r\n) \r\nLOGGING \r\nNOCOMPRESS \r\nNOCACHE\r\n';\r\n");
//备注
foreach (var tbcol in tb.Columns.Values) {
if (string.IsNullOrEmpty(tbcol.Comment) == false)
sb.Append("execute immediate 'COMMENT ON COLUMN ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}.{tbcol.Attribute.Name}")).Append(" IS ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment).Replace("'", "''")).Append("';\r\n");
}
continue; continue;
} }
//如果新表,旧表在一个模式下,直接修改表名 //如果新表,旧表在一个模式下,直接修改表名
@ -127,17 +132,19 @@ namespace FreeSql.Oracle {
//对比字段,只可以修改类型、增加字段、有限的修改字段名;保证安全不删除字段 //对比字段,只可以修改类型、增加字段、有限的修改字段名;保证安全不删除字段
var sql = _commonUtils.FormatSql($@" var sql = _commonUtils.FormatSql($@"
select select
column_name, a.column_name,
data_type, a.data_type,
data_length, a.data_length,
data_precision, a.data_precision,
data_scale, a.data_scale,
char_used, a.char_used,
case when nullable = 'Y' then 1 else 0 end, case when a.nullable = 'Y' then 1 else 0 end,
nvl((select 1 from user_sequences where sequence_name='{Utils.GetCsName((tboldname ?? tbname).Last())}_seq_'||all_tab_columns.column_name), 0), nvl((select 1 from user_sequences where sequence_name='{Utils.GetCsName((tboldname ?? tbname).Last())}_seq_'||a.column_name), 0),
nvl((select 1 from user_triggers where trigger_name='{Utils.GetCsName((tboldname ?? tbname).Last())}_seq_'||all_tab_columns.column_name||'TI'), 0) nvl((select 1 from user_triggers where trigger_name='{Utils.GetCsName((tboldname ?? tbname).Last())}_seq_'||a.column_name||'TI'), 0),
from all_tab_columns b.comments
where owner={{0}} and table_name={{1}}", tboldname ?? tbname); from all_tab_columns 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={{0}} and a.table_name={{1}}", tboldname ?? tbname);
var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql);
var tbstruct = ds.ToDictionary(a => string.Concat(a[0]), a => { var tbstruct = ds.ToDictionary(a => string.Concat(a[0]), a => {
var sqlType = GetOracleSqlTypeFullName(a); var sqlType = GetOracleSqlTypeFullName(a);
@ -145,7 +152,8 @@ where owner={{0}} and table_name={{1}}", tboldname ?? tbname);
column = string.Concat(a[0]), column = string.Concat(a[0]),
sqlType, sqlType,
is_nullable = string.Concat(a[6]) == "1", is_nullable = string.Concat(a[6]) == "1",
is_identity = string.Concat(a[7]) == "1" && string.Concat(a[8]) == "1" is_identity = string.Concat(a[7]) == "1" && string.Concat(a[8]) == "1",
comment = string.Concat(a[9])
}; };
}, StringComparer.CurrentCultureIgnoreCase); }, StringComparer.CurrentCultureIgnoreCase);
@ -153,7 +161,8 @@ where owner={{0}} and table_name={{1}}", tboldname ?? tbname);
foreach (var tbcol in tb.Columns.Values) { foreach (var tbcol in tb.Columns.Values) {
var dbtypeNoneNotNull = Regex.Replace(tbcol.Attribute.DbType, @"NOT\s+NULL", "NULL"); var dbtypeNoneNotNull = Regex.Replace(tbcol.Attribute.DbType, @"NOT\s+NULL", "NULL");
if (tbstruct.TryGetValue(tbcol.Attribute.Name, out var tbstructcol) || if (tbstruct.TryGetValue(tbcol.Attribute.Name, out var tbstructcol) ||
string.IsNullOrEmpty(tbcol.Attribute.OldName) == false && tbstruct.TryGetValue(tbcol.Attribute.OldName, out tbstructcol)) { string.IsNullOrEmpty(tbcol.Attribute.OldName) == false && tbstruct.TryGetValue(tbcol.Attribute.OldName, out tbstructcol)) {
var isCommentChanged = tbstructcol.comment != (tbcol.Comment ?? "");
if (tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false) if (tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false)
istmpatler = true; istmpatler = true;
//sbalter.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" MODIFY (").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" ").Append(dbtypeNoneNotNull).Append(")';\r\n"); //sbalter.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" MODIFY (").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" ").Append(dbtypeNoneNotNull).Append(")';\r\n");
@ -164,9 +173,11 @@ where owner={{0}} and table_name={{1}}", tboldname ?? tbname);
} }
if (tbcol.Attribute.IsIdentity != tbstructcol.is_identity) if (tbcol.Attribute.IsIdentity != tbstructcol.is_identity)
seqcols.Add((tbcol, tbname, tbcol.Attribute.IsIdentity == true)); seqcols.Add((tbcol, tbname, tbcol.Attribute.IsIdentity == true));
if (tbstructcol.column == tbcol.Attribute.OldName) if (string.Compare(tbstructcol.column, tbcol.Attribute.OldName, true) == 0)
//修改列名 //修改列名
sbalter.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" RENAME ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.OldName)).Append(" TO ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append("';\r\n"); sbalter.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" RENAME COLUMN ").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" TO ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append("';\r\n");
if (isCommentChanged)
sbalter.Append("execute immediate 'COMMENT ON COLUMN ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}.{tbcol.Attribute.Name}")).Append(" IS ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment ?? "").Replace("'", "''")).Append("';\r\n");
continue; continue;
} }
//添加列 //添加列
@ -176,6 +187,7 @@ where owner={{0}} and table_name={{1}}", tboldname ?? tbname);
sbalter.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" MODIFY ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" NOT NULL';\r\n"); sbalter.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" MODIFY ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" NOT NULL';\r\n");
} }
if (tbcol.Attribute.IsIdentity == true) seqcols.Add((tbcol, tbname, tbcol.Attribute.IsIdentity == true)); if (tbcol.Attribute.IsIdentity == true) seqcols.Add((tbcol, tbname, tbcol.Attribute.IsIdentity == true));
if (string.IsNullOrEmpty(tbcol.Comment) == false) sbalter.Append("execute immediate 'COMMENT ON COLUMN ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}.{tbcol.Attribute.Name}")).Append(" IS ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment ?? "").Replace("'", "''")).Append("';\r\n");
} }
var dsuksql = _commonUtils.FormatSql(@" var dsuksql = _commonUtils.FormatSql(@"
select select
@ -231,6 +243,11 @@ and a.owner in ({0}) and a.table_name in ({1})", tboldname ?? tbname);
} }
sb.Remove(sb.Length - 1, 1); sb.Remove(sb.Length - 1, 1);
sb.Append("\r\n) LOGGING \r\nNOCOMPRESS \r\nNOCACHE\r\n';\r\n"); sb.Append("\r\n) LOGGING \r\nNOCOMPRESS \r\nNOCACHE\r\n';\r\n");
//备注
foreach (var tbcol in tb.Columns.Values) {
if (string.IsNullOrEmpty(tbcol.Comment) == false)
sb.Append("execute immediate 'COMMENT ON COLUMN ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.FTmp_{tbname[1]}.{tbcol.Attribute.Name}")).Append(" IS ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment).Replace("'", "''")).Append("';\r\n");
}
sb.Append("execute immediate 'INSERT INTO ").Append(tmptablename).Append(" ("); sb.Append("execute immediate 'INSERT INTO ").Append(tmptablename).Append(" (");
foreach (var tbcol in tb.Columns.Values) foreach (var tbcol in tb.Columns.Values)
sb.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", "); sb.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", ");

View File

@ -199,7 +199,7 @@ a.data_length,
a.data_precision, a.data_precision,
a.data_scale, a.data_scale,
a.char_used, a.char_used,
case when nullable = 'Y' then 1 else 0 end, case when a.nullable = 'Y' then 1 else 0 end,
nvl((select 1 from user_sequences where upper(sequence_name)=upper(a.table_name||'_seq_'||a.column_name)), 0), nvl((select 1 from user_sequences where upper(sequence_name)=upper(a.table_name||'_seq_'||a.column_name)), 0),
b.comments b.comments
from all_tab_cols a from all_tab_cols a

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks> <TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
<Version>0.6.10</Version> <Version>0.6.11</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>YeXiangQin</Authors> <Authors>YeXiangQin</Authors>
<Description>FreeSql 数据库实现,基于 PostgreSQL 9.5</Description> <Description>FreeSql 数据库实现,基于 PostgreSQL 9.5</Description>

View File

@ -155,6 +155,11 @@ namespace FreeSql.PostgreSQL {
} }
sb.Remove(sb.Length - 1, 1); sb.Remove(sb.Length - 1, 1);
sb.Append("\r\n) WITH (OIDS=FALSE);\r\n"); sb.Append("\r\n) WITH (OIDS=FALSE);\r\n");
//备注
foreach (var tbcol in tb.Columns.Values) {
if (string.IsNullOrEmpty(tbcol.Comment) == false)
sb.Append("COMMENT ON COLUMN ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}.{tbcol.Attribute.Name}")).Append(" IS ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment)).Append(";\r\n");
}
continue; continue;
} }
//如果新表,旧表在一个数据库和模式下,直接修改表名 //如果新表,旧表在一个数据库和模式下,直接修改表名
@ -176,7 +181,8 @@ case when a.atttypmod > 0 and a.atttypmod < 32767 then a.atttypmod - 4 else a.at
case when t.typelem > 0 and t.typinput::varchar = 'array_in' then t2.typname else t.typname end, case when t.typelem > 0 and t.typinput::varchar = 'array_in' then t2.typname else t.typname end,
case when a.attnotnull then '0' else '1' end as is_nullable, case when a.attnotnull then '0' else '1' end as is_nullable,
e.adsrc, e.adsrc,
a.attndims a.attndims,
d.description as comment
from pg_class c from pg_class c
inner join pg_attribute a on a.attnum > 0 and a.attrelid = c.oid inner join pg_attribute a on a.attnum > 0 and a.attrelid = c.oid
inner join pg_type t on t.oid = a.atttypid inner join pg_type t on t.oid = a.atttypid
@ -207,7 +213,8 @@ where ns.nspname = {0} and c.relname = {1}", tboldname ?? tbname);
max_length = long.Parse(string.Concat(a[2])), max_length = long.Parse(string.Concat(a[2])),
is_nullable = string.Concat(a[4]) == "1", is_nullable = string.Concat(a[4]) == "1",
is_identity = string.Concat(a[5]).StartsWith(@"nextval('") && string.Concat(a[5]).EndsWith(@"'::regclass)"), is_identity = string.Concat(a[5]).StartsWith(@"nextval('") && string.Concat(a[5]).EndsWith(@"'::regclass)"),
attndims attndims,
comment = string.Concat(a[7])
}; };
}, StringComparer.CurrentCultureIgnoreCase); }, StringComparer.CurrentCultureIgnoreCase);
@ -215,6 +222,7 @@ where ns.nspname = {0} and c.relname = {1}", tboldname ?? tbname);
foreach (var tbcol in tb.Columns.Values) { foreach (var tbcol in tb.Columns.Values) {
if (tbstruct.TryGetValue(tbcol.Attribute.Name, out var tbstructcol) || if (tbstruct.TryGetValue(tbcol.Attribute.Name, out var tbstructcol) ||
string.IsNullOrEmpty(tbcol.Attribute.OldName) == false && tbstruct.TryGetValue(tbcol.Attribute.OldName, out tbstructcol)) { string.IsNullOrEmpty(tbcol.Attribute.OldName) == false && tbstruct.TryGetValue(tbcol.Attribute.OldName, out tbstructcol)) {
var isCommentChanged = tbstructcol.comment != (tbcol.Comment ?? "");
if (tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false || if (tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false ||
tbcol.Attribute.DbType.Contains("[]") != (tbstructcol.attndims > 0)) tbcol.Attribute.DbType.Contains("[]") != (tbstructcol.attndims > 0))
sbalter.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" ALTER COLUMN ").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" TYPE ").Append(tbcol.Attribute.DbType.Split(' ').First()).Append(";\r\n"); sbalter.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" ALTER COLUMN ").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" TYPE ").Append(tbcol.Attribute.DbType.Split(' ').First()).Append(";\r\n");
@ -222,9 +230,11 @@ where ns.nspname = {0} and c.relname = {1}", tboldname ?? tbname);
sbalter.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" ALTER COLUMN ").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" ").Append(tbcol.Attribute.IsNullable == true ? "DROP" : "SET").Append(" NOT NULL;\r\n"); sbalter.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" ALTER COLUMN ").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" ").Append(tbcol.Attribute.IsNullable == true ? "DROP" : "SET").Append(" NOT NULL;\r\n");
if (tbcol.Attribute.IsIdentity != tbstructcol.is_identity) if (tbcol.Attribute.IsIdentity != tbstructcol.is_identity)
seqcols.Add((tbcol, tbname, tbcol.Attribute.IsIdentity == true)); seqcols.Add((tbcol, tbname, tbcol.Attribute.IsIdentity == true));
if (tbstructcol.column == tbcol.Attribute.OldName) if (string.Compare(tbstructcol.column, tbcol.Attribute.OldName, true) == 0)
//修改列名 //修改列名
sbalter.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" RENAME COLUMN ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.OldName)).Append(" TO ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(";\r\n"); sbalter.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" RENAME COLUMN ").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" TO ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(";\r\n");
if (isCommentChanged)
sbalter.Append("COMMENT ON COLUMN ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}.{tbcol.Attribute.Name}")).Append(" IS ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment)).Append(";\r\n");
continue; continue;
} }
//添加列 //添加列
@ -232,6 +242,7 @@ where ns.nspname = {0} and c.relname = {1}", tboldname ?? tbname);
sbalter.Append("UPDATE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" SET ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" = ").Append(_commonUtils.FormatSql("{0};\r\n", tbcol.Attribute.DbDefautValue)); sbalter.Append("UPDATE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" SET ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" = ").Append(_commonUtils.FormatSql("{0};\r\n", tbcol.Attribute.DbDefautValue));
if (tbcol.Attribute.IsNullable == false) sbalter.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" ALTER COLUMN ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" SET NOT NULL;\r\n"); if (tbcol.Attribute.IsNullable == false) sbalter.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" ALTER COLUMN ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" SET NOT NULL;\r\n");
if (tbcol.Attribute.IsIdentity == true) seqcols.Add((tbcol, tbname, tbcol.Attribute.IsIdentity == true)); if (tbcol.Attribute.IsIdentity == true) seqcols.Add((tbcol, tbname, tbcol.Attribute.IsIdentity == true));
if (string.IsNullOrEmpty(tbcol.Comment) == false) sbalter.Append("COMMENT ON COLUMN ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}.{tbcol.Attribute.Name}")).Append(" IS ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment)).Append(";\r\n");
} }
var dsuksql = _commonUtils.FormatSql(@" var dsuksql = _commonUtils.FormatSql(@"
select select
@ -288,6 +299,11 @@ where pg_namespace.nspname={0} and pg_class.relname={1} and pg_constraint.contyp
} }
sb.Remove(sb.Length - 1, 1); sb.Remove(sb.Length - 1, 1);
sb.Append("\r\n) WITH (OIDS=FALSE);\r\n"); sb.Append("\r\n) WITH (OIDS=FALSE);\r\n");
//备注
foreach (var tbcol in tb.Columns.Values) {
if (string.IsNullOrEmpty(tbcol.Comment) == false)
sb.Append("COMMENT ON COLUMN ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.FreeSqlTmp_{tbname[1]}.{tbcol.Attribute.Name}")).Append(" IS ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment)).Append(";\r\n");
}
sb.Append("INSERT INTO ").Append(tmptablename).Append(" ("); sb.Append("INSERT INTO ").Append(tmptablename).Append(" (");
foreach (var tbcol in tb.Columns.Values) foreach (var tbcol in tb.Columns.Values)
sb.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", "); sb.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", ");

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>netstandard2.0;net451</TargetFrameworks> <TargetFrameworks>netstandard2.0;net451</TargetFrameworks>
<Version>0.6.10</Version> <Version>0.6.11</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>YeXiangQin</Authors> <Authors>YeXiangQin</Authors>
<Description>FreeSql 数据库实现,基于 SqlServer 2005+并根据版本适配分页方法row_number 或 offset fetch next</Description> <Description>FreeSql 数据库实现,基于 SqlServer 2005+并根据版本适配分页方法row_number 或 offset fetch next</Description>

View File

@ -63,7 +63,37 @@ namespace FreeSql.SqlServer {
} }
return null; return null;
} }
void AddOrUpdateMS_Description(StringBuilder sb, string schema, string table, string column, string comment) {
if (string.IsNullOrEmpty(comment)) {
sb.AppendFormat(@"
IF ((SELECT COUNT(1) from fn_listextendedproperty('MS_Description',
'SCHEMA', N'{0}',
'TABLE', N'{1}',
'COLUMN', N'{2}')) > 0)
EXEC sp_dropextendedproperty @name = N'MS_Description'
, @level0type = 'SCHEMA', @level0name = N'{0}'
, @level1type = 'TABLE', @level1name = N'{1}'
, @level2type = 'COLUMN', @level2name = N'{2}'
", schema.Replace("'", "''"), table.Replace("'", "''"), column.Replace("'", "''"));
return;
}
sb.AppendFormat(@"
IF ((SELECT COUNT(1) from fn_listextendedproperty('MS_Description',
'SCHEMA', N'{0}',
'TABLE', N'{1}',
'COLUMN', N'{2}')) > 0)
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'{3}'
, @level0type = 'SCHEMA', @level0name = N'{0}'
, @level1type = 'TABLE', @level1name = N'{1}'
, @level2type = 'COLUMN', @level2name = N'{2}'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'{3}'
, @level0type = 'SCHEMA', @level0name = N'{0}'
, @level1type = 'TABLE', @level1name = N'{1}'
, @level2type = 'COLUMN', @level2name = N'{2}'
", schema.Replace("'", "''"), table.Replace("'", "''"), column.Replace("'", "''"), comment?.Replace("'", "''") ?? "");
}
public override string GetComparisonDDLStatements(params Type[] entityTypes) { public override string GetComparisonDDLStatements(params Type[] entityTypes) {
var conn = _orm.Ado.MasterPool.Get(TimeSpan.FromSeconds(5)); var conn = _orm.Ado.MasterPool.Get(TimeSpan.FromSeconds(5));
var database = conn.Value.Database; var database = conn.Value.Database;
@ -133,6 +163,11 @@ namespace FreeSql.SqlServer {
sb.Remove(sb.Length - 2, 2).Append("),"); sb.Remove(sb.Length - 2, 2).Append("),");
} }
sb.Remove(sb.Length - 1, 1).Append("\r\n);\r\n"); sb.Remove(sb.Length - 1, 1).Append("\r\n);\r\n");
//备注
foreach (var tbcol in tb.Columns.Values) {
if (string.IsNullOrEmpty(tbcol.Comment) == false)
AddOrUpdateMS_Description(sb, tbname[1], tbname[2], tbcol.Attribute.Name, tbcol.Comment);
}
continue; continue;
} }
//如果新表,旧表在一个数据库和模式下,直接修改表名 //如果新表,旧表在一个数据库和模式下,直接修改表名
@ -160,6 +195,7 @@ a.name 'Column'
else '' end as 'SqlType' else '' end as 'SqlType'
,case when a.is_nullable = 1 then '1' else '0' end 'IsNullable' ,case when a.is_nullable = 1 then '1' else '0' end 'IsNullable'
,case when a.is_identity = 1 then '1' else '0' end 'IsIdentity' ,case when a.is_identity = 1 then '1' else '0' end 'IsIdentity'
,c.value
from sys.columns a from sys.columns a
inner join sys.types b on b.user_type_id = a.user_type_id inner join sys.types b on b.user_type_id = a.user_type_id
left join sys.extended_properties AS c ON c.major_id = a.object_id AND c.minor_id = a.column_id left join sys.extended_properties AS c ON c.major_id = a.object_id AND c.minor_id = a.column_id
@ -172,23 +208,27 @@ use " + database, tboldname ?? tbname);
column = string.Concat(a[0]), column = string.Concat(a[0]),
sqlType = string.Concat(a[1]), sqlType = string.Concat(a[1]),
is_nullable = string.Concat(a[2]) == "1", is_nullable = string.Concat(a[2]) == "1",
is_identity = string.Concat(a[3]) == "1" is_identity = string.Concat(a[3]) == "1",
comment = string.Concat(a[4])
}, StringComparer.CurrentCultureIgnoreCase); }, StringComparer.CurrentCultureIgnoreCase);
if (istmpatler == false) { if (istmpatler == false) {
foreach (var tbcol in tb.Columns.Values) { foreach (var tbcol in tb.Columns.Values) {
if (tbstruct.TryGetValue(tbcol.Attribute.Name, out var tbstructcol) || if (tbstruct.TryGetValue(tbcol.Attribute.Name, out var tbstructcol) ||
string.IsNullOrEmpty(tbcol.Attribute.OldName) == false && tbstruct.TryGetValue(tbcol.Attribute.OldName, out tbstructcol)) { string.IsNullOrEmpty(tbcol.Attribute.OldName) == false && tbstruct.TryGetValue(tbcol.Attribute.OldName, out tbstructcol)) {
var isCommentChanged = tbstructcol.comment != (tbcol.Comment ?? "");
if (tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false || if (tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false ||
tbcol.Attribute.IsNullable != tbstructcol.is_nullable || tbcol.Attribute.IsNullable != tbstructcol.is_nullable ||
tbcol.Attribute.IsIdentity != tbstructcol.is_identity) { tbcol.Attribute.IsIdentity != tbstructcol.is_identity) {
istmpatler = true; istmpatler = true;
break; break;
} }
if (tbstructcol.column == tbcol.Attribute.OldName) { if (string.Compare(tbstructcol.column, tbcol.Attribute.OldName, true) == 0)
//修改列名 //修改列名
sbalter.Append(_commonUtils.FormatSql("EXEC sp_rename {0}, {1}, 'COLUMN';\r\n", $"{tbname[0]}.{tbname[1]}.{tbname[2]}.{tbcol.Attribute.OldName}", tbcol.Attribute.Name)); sbalter.Append(_commonUtils.FormatSql("EXEC sp_rename {0}, {1}, 'COLUMN';\r\n", $"{tbname[0]}.{tbname[1]}.{tbname[2]}.{tbstructcol.column}", tbcol.Attribute.Name));
} if (isCommentChanged)
//修改备备注
AddOrUpdateMS_Description(sbalter, tbname[1], tbname[2], tbcol.Attribute.Name, tbcol.Comment);
continue; continue;
} }
//添加列 //添加列
@ -199,6 +239,7 @@ use " + database, tboldname ?? tbname);
if (addcoldbdefault != null) sbalter.Append(_commonUtils.FormatSql(" default({0})", addcoldbdefault)); if (addcoldbdefault != null) sbalter.Append(_commonUtils.FormatSql(" default({0})", addcoldbdefault));
} }
sbalter.Append(";\r\n"); sbalter.Append(";\r\n");
if (string.IsNullOrEmpty(tbcol.Comment) == false) AddOrUpdateMS_Description(sbalter, tbname[1], tbname[2], tbcol.Attribute.Name, tbcol.Comment);
} }
var dsuksql = string.Format(@" var dsuksql = string.Format(@"
use [{0}]; use [{0}];
@ -265,6 +306,11 @@ use " + database, tboldname ?? tbname);
sb.Remove(sb.Length - 2, 2).Append("),"); sb.Remove(sb.Length - 2, 2).Append("),");
} }
sb.Remove(sb.Length - 1, 1).Append("\r\n);\r\n"); sb.Remove(sb.Length - 1, 1).Append("\r\n);\r\n");
//备注
foreach (var tbcol in tb.Columns.Values) {
if (string.IsNullOrEmpty(tbcol.Comment) == false)
AddOrUpdateMS_Description(sb, tbname[1], $"FreeSqlTmp_{tbname[2]}", tbcol.Attribute.Name, tbcol.Comment);
}
sb.Append("ALTER TABLE ").Append(tmptablename).Append(" SET (LOCK_ESCALATION = TABLE);\r\n"); sb.Append("ALTER TABLE ").Append(tmptablename).Append(" SET (LOCK_ESCALATION = TABLE);\r\n");
if (idents) sb.Append("SET IDENTITY_INSERT ").Append(tmptablename).Append(" ON;\r\n"); if (idents) sb.Append("SET IDENTITY_INSERT ").Append(tmptablename).Append(" ON;\r\n");
sb.Append("IF EXISTS(SELECT 1 FROM ").Append(tablename).Append(")\r\n"); sb.Append("IF EXISTS(SELECT 1 FROM ").Append(tablename).Append(")\r\n");

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks> <TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
<Version>0.6.10</Version> <Version>0.6.11</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>YeXiangQin</Authors> <Authors>YeXiangQin</Authors>
<Description>FreeSql 数据库实现,基于 Sqlite 3.0</Description> <Description>FreeSql 数据库实现,基于 Sqlite 3.0</Description>

View File

@ -152,7 +152,7 @@ namespace FreeSql.Sqlite {
istmpatler = true; istmpatler = true;
if (tbcol.Attribute.IsIdentity != tbstructcol.is_identity) if (tbcol.Attribute.IsIdentity != tbstructcol.is_identity)
istmpatler = true; istmpatler = true;
if (tbstructcol.column == tbcol.Attribute.OldName) if (string.Compare(tbstructcol.column, tbcol.Attribute.OldName, true) == 0)
//修改列名 //修改列名
istmpatler = true; istmpatler = true;
continue; continue;