Skip to content

Commit

Permalink
增加 Column.Unique 唯一键 #42
Browse files Browse the repository at this point in the history
  • Loading branch information
28810 authored and 28810 committed Apr 26, 2019
1 parent 5bb90a9 commit 45b785f
Show file tree
Hide file tree
Showing 18 changed files with 300 additions and 46 deletions.
19 changes: 19 additions & 0 deletions FreeSql.Tests/MySql/MySqlCodeFirstTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@
namespace FreeSql.Tests.MySql {
public class MySqlCodeFirstTest {

[Fact]
public void AddUniques() {
var sql = g.mysql.CodeFirst.GetComparisonDDLStatements<AddUniquesInfo>();
g.mysql.CodeFirst.SyncStructure<AddUniquesInfo>();
}
[Table(Name = "AddUniquesInfo", OldName = "AddUniquesInfo2")]
class AddUniquesInfo {
public Guid id { get; set; }
[Column(Unique = "uk_phone")]
public string phone { get; set; }

[Column(Unique = "uk_group_index")]
public string group { get; set; }
[Column(Unique = "uk_group_index11")]
public int index { get; set; }
[Column(Unique = "uk_group_index222")]
public string index22 { get; set; }
}

[Fact]
public void AddField() {
var sql = g.mysql.CodeFirst.GetComparisonDDLStatements<TopicAddField>();
Expand Down
18 changes: 18 additions & 0 deletions FreeSql.Tests/Oracle/OracleCodeFirstTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@
namespace FreeSql.Tests.Oracle {
public class OracleCodeFirstTest {

[Fact]
public void AddUniques() {
var sql = g.oracle.CodeFirst.GetComparisonDDLStatements<AddUniquesInfo>();
g.oracle.CodeFirst.SyncStructure<AddUniquesInfo>();
}
[Table(Name = "AddUniquesInfo", OldName = "AddUniquesInfo2")]
class AddUniquesInfo {
public Guid id { get; set; }
[Column(Unique = "uk_phone")]
public string phone { get; set; }

[Column(Unique = "uk_group_index")]
public string group { get; set; }
[Column(Unique = "uk_group_index11")]
public int index { get; set; }
[Column(Unique = "uk_group_index222")]
public string index22 { get; set; }
}
[Fact]
public void AddField() {
var sql = g.oracle.CodeFirst.GetComparisonDDLStatements<TopicAddField>();
Expand Down
19 changes: 19 additions & 0 deletions FreeSql.Tests/PostgreSQL/PostgreSQLCodeFirstTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,25 @@
namespace FreeSql.Tests.PostgreSQL {
public class PostgreSQLCodeFirstTest {

[Fact]
public void AddUniques() {
var sql = g.pgsql.CodeFirst.GetComparisonDDLStatements<AddUniquesInfo>();
g.pgsql.CodeFirst.SyncStructure<AddUniquesInfo>();
}
[Table(Name = "AddUniquesInfo", OldName = "AddUniquesInfo2")]
class AddUniquesInfo {
public Guid id { get; set; }
[Column(Unique = "uk_phone")]
public string phone { get; set; }

[Column(Unique = "uk_group_index")]
public string group { get; set; }
[Column(Unique = "uk_group_index11")]
public int index { get; set; }
[Column(Unique = "uk_group_index222")]
public string index22 { get; set; }
}

[Fact]
public void AddField() {
var sql = g.pgsql.CodeFirst.GetComparisonDDLStatements<TopicAddField>();
Expand Down
19 changes: 19 additions & 0 deletions FreeSql.Tests/SqlServer/SqlServerCodeFirstTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ public SqlServerCodeFirstTest(SqlServerFixture sqlserverFixture)
_sqlserverFixture = sqlserverFixture;
}

[Fact]
public void AddUniques() {
var sql = _sqlserverFixture.SqlServer.CodeFirst.GetComparisonDDLStatements<AddUniquesInfo>();
_sqlserverFixture.SqlServer.CodeFirst.SyncStructure<AddUniquesInfo>();
}
[Table(Name = "AddUniquesInfo", OldName = "AddUniquesInfo2")]
class AddUniquesInfo {
public Guid id { get; set; }
[Column(Unique = "uk_phone")]
public string phone { get; set; }

[Column(Unique = "uk_group_index")]
public string group { get; set; }
[Column(Unique = "uk_group_index11")]
public int index { get; set; }
[Column(Unique = "uk_group_index222")]
public string index22 { get; set; }
}

[Fact]
public void AddField() {
var sql = _sqlserverFixture.SqlServer.CodeFirst.GetComparisonDDLStatements<TopicAddField>();
Expand Down
2 changes: 1 addition & 1 deletion FreeSql.Tests/SqlServer/SqlServerDbFirstTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void GetDatabases() {
[Fact]
public void GetTablesByDatabase() {

var t2 = _sqlserverFixture.SqlServer.DbFirst.GetTablesByDatabase(_sqlserverFixture.SqlServer.DbFirst.GetDatabases()[0]);
var t2 = _sqlserverFixture.SqlServer.DbFirst.GetTablesByDatabase();

}
}
Expand Down
19 changes: 19 additions & 0 deletions FreeSql.Tests/Sqlite/SqliteCodeFirstTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@ namespace FreeSql.Tests.Sqlite {
public class SqliteCodeFirstTest {


[Fact]
public void AddUniques() {
var sql = g.sqlite.CodeFirst.GetComparisonDDLStatements<AddUniquesInfo>();
g.sqlite.CodeFirst.SyncStructure<AddUniquesInfo>();
}
[Table(Name = "AddUniquesInfo2", OldName = "AddUniquesInfo")]
class AddUniquesInfo {
public Guid id { get; set; }
[Column(Unique = "uk_phone")]
public string phone { get; set; }

[Column(Unique = "uk_group_index")]
public string group { get; set; }
[Column(Unique = "uk_group_index111")]
public int index { get; set; }
[Column(Unique = "uk_group_index222")]
public string index22 { get; set; }
}

public class Topic {
public Guid Id { get; set; }
public string Title { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Text.RegularExpressions;

namespace FreeSql.Internal.CommonProvider {
Expand All @@ -10,10 +11,12 @@ public string Addslashes(string filter, params object[] parms) {
var nparms = new object[parms.Length];
for (int a = 0; a < parms.Length; a++) {
if (parms[a] == null)
filter = Regex.Replace(filter, @"\s*(=|IN)\s*\{" + a + @"\}", " IS {" + a + "}", RegexOptions.IgnoreCase);
filter = _dicAddslashesReplaceIsNull.GetOrAdd(a, b => new Regex(@"\s*(=|IN)\s*\{" + b + @"\}", RegexOptions.IgnoreCase | RegexOptions.Compiled))
.Replace(filter, $" IS {{{a}}}");
nparms[a] = AddslashesProcessParam(parms[a], null);
}
try { string ret = string.Format(filter, nparms); return ret; } catch { return filter; }
}
static ConcurrentDictionary<int, Regex> _dicAddslashesReplaceIsNull = new ConcurrentDictionary<int, Regex>();
}
}
3 changes: 3 additions & 0 deletions FreeSql/Internal/CommonUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ internal ColumnAttribute GetEntityColumnAttribute(Type type, PropertyInfo proto)
if (trycol._IsNullable != null) attr._IsNullable = trycol.IsNullable;
if (trycol._IsIgnore != null) attr._IsIgnore = trycol.IsIgnore;
if (trycol._IsVersion != null) attr._IsVersion = trycol.IsVersion;
if (!string.IsNullOrEmpty(trycol.Unique)) attr.Unique = trycol.Unique;
if (trycol.MapType != null) attr.MapType = trycol.MapType;
if (trycol.DbDefautValue != null) attr.DbDefautValue = trycol.DbDefautValue;
}
Expand All @@ -116,6 +117,7 @@ internal ColumnAttribute GetEntityColumnAttribute(Type type, PropertyInfo proto)
if (tryattr._IsNullable != null) attr._IsNullable = tryattr.IsNullable;
if (tryattr._IsIgnore != null) attr._IsIgnore = tryattr.IsIgnore;
if (tryattr._IsVersion != null) attr._IsVersion = tryattr.IsVersion;
if (!string.IsNullOrEmpty(tryattr.Unique)) attr.Unique = tryattr.Unique;
if (tryattr.MapType != null) attr.MapType = tryattr.MapType;
if (tryattr.DbDefautValue != null) attr.DbDefautValue = tryattr.DbDefautValue;
}
Expand All @@ -128,6 +130,7 @@ internal ColumnAttribute GetEntityColumnAttribute(Type type, PropertyInfo proto)
if (attr._IsNullable != null) ret = attr;
if (attr._IsIgnore != null) ret = attr;
if (attr._IsVersion != null) ret = attr;
if (!string.IsNullOrEmpty(attr.Unique)) ret = attr;
if (attr.MapType != null) ret = attr;
if (attr.DbDefautValue != null) ret = attr;
if (ret != null && ret.MapType == null) ret.MapType = proto.PropertyType;
Expand Down
21 changes: 16 additions & 5 deletions FreeSql/Internal/UtilsExpressionTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ public class Utils {

static ConcurrentDictionary<DataType, ConcurrentDictionary<Type, TableInfo>> _cacheGetTableByEntity = new ConcurrentDictionary<DataType, ConcurrentDictionary<Type, TableInfo>>();
internal static void RemoveTableByEntity(Type entity, CommonUtils common) {
if (entity.FullName.StartsWith("<>f__AnonymousType")) return;
if (entity.FullName.StartsWith("<>f__AnonymousType") ||
entity.IsValueType ||
entity.IsNullableType() ||
entity.NullableTypeOrThis() == typeof(BigInteger)
) return;
var tbc = _cacheGetTableByEntity.GetOrAdd(common._orm.Ado.DataType, k1 => new ConcurrentDictionary<Type, TableInfo>()); //区分数据库类型缓存
if (tbc.TryRemove(entity, out var trytb) && trytb?.TypeLazy != null) tbc.TryRemove(trytb.TypeLazy, out var trylz);
}
Expand Down Expand Up @@ -75,6 +79,7 @@ internal static TableInfo GetTableByEntity(Type entity, CommonUtils common) {
IsNullable = tp.Value.isnullable ?? true,
IsPrimary = false,
IsIgnore = false,
Unique = null,
MapType = p.PropertyType
};
if (colattr._IsNullable == null) colattr._IsNullable = tp?.isnullable;
Expand All @@ -84,8 +89,14 @@ internal static TableInfo GetTableByEntity(Type entity, CommonUtils common) {
if (tp != null && tp.Value.isnullable == null) colattr.IsNullable = tp.Value.dbtypeFull.Contains("NOT NULL") == false;
if (colattr.DbType?.Contains("NOT NULL") == true) colattr.IsNullable = false;
if (string.IsNullOrEmpty(colattr.Name)) colattr.Name = p.Name;
if (common.CodeFirst.IsSyncStructureToLower) colattr.Name = colattr.Name.ToLower();
if (common.CodeFirst.IsSyncStructureToUpper) colattr.Name = colattr.Name.ToUpper();
if (common.CodeFirst.IsSyncStructureToLower) {
colattr.Name = colattr.Name.ToLower();
if (!string.IsNullOrEmpty(colattr.Unique)) colattr.Unique = colattr.Unique.ToLower();
}
if (common.CodeFirst.IsSyncStructureToUpper) {
colattr.Name = colattr.Name.ToUpper();
if (!string.IsNullOrEmpty(colattr.Unique)) colattr.Unique = colattr.Unique.ToUpper();
}

if ((colattr.IsNullable != true || colattr.IsIdentity == true || colattr.IsPrimary == true) && colattr.DbType.Contains("NOT NULL") == false) {
colattr.IsNullable = false;
Expand Down Expand Up @@ -177,8 +188,8 @@ internal static TableInfo GetTableByEntity(Type entity, CommonUtils common) {
} catch { }
trytb.Primarys = trytb.Columns.Values.Where(a => a.Attribute.IsPrimary == true).ToArray();
}
trytb.Uniques = trytb.Columns.Values.Where(a => !string.IsNullOrEmpty(a.Attribute.Unique))
.ToDictionary(a => a.Attribute.Unique, a => trytb.Columns.Values.Where(b => b.Attribute.Unique == a.Attribute.Unique).ToList());
trytb.Uniques = trytb.Columns.Values.Where(a => !string.IsNullOrEmpty(a.Attribute.Unique)).Select(a => a.Attribute.Unique).Distinct()
.ToDictionary(a => a, a => trytb.Columns.Values.Where(b => b.Attribute.Unique == a).ToList());
tbc.AddOrUpdate(entity, trytb, (oldkey, oldval) => trytb);

#region 查找导航属性的关系、virtual 属性延时加载,动态产生新的重写类
Expand Down
43 changes: 34 additions & 9 deletions FreeSql/MySql/MySqlCodeFirst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,17 @@ public string GetComparisonDDLStatements(params Type[] entityTypes) {
if (tbcol.Attribute.IsIdentity == true && tbcol.Attribute.DbType.IndexOf("AUTO_INCREMENT", StringComparison.CurrentCultureIgnoreCase) == -1) sb.Append(" AUTO_INCREMENT");
sb.Append(",");
}
if (tb.Primarys.Any() == false)
sb.Remove(sb.Length - 1, 1);
else {
if (tb.Primarys.Any()) {
sb.Append(" \r\n PRIMARY KEY (");
foreach (var tbcol in tb.Primarys) sb.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", ");
sb.Remove(sb.Length - 2, 2).Append(")");
sb.Remove(sb.Length - 2, 2).Append("),");
}
foreach (var uk in tb.Uniques) {
sb.Append(" \r\n UNIQUE KEY ").Append(_commonUtils.QuoteSqlName(uk.Key)).Append("(");
foreach (var tbcol in uk.Value) sb.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", ");
sb.Remove(sb.Length - 2, 2).Append("),");
}
sb.Remove(sb.Length - 1, 1);
sb.Append("\r\n) Engine=InnoDB CHARACTER SET utf8;\r\n");
continue;
}
Expand Down Expand Up @@ -176,7 +180,7 @@ from information_schema.columns a
}, StringComparer.CurrentCultureIgnoreCase);

if (istmpatler == false) {
var existsPrimary = ExecuteScalar(tbname[0], "select 1 from INFORMATION_SCHEMA.KEY_COLUMN_USAGE where table_schema={0} and table_name={1} limit 1".FormatMySql(tbname));
var existsPrimary = ExecuteScalar(tbname[0], "select 1 from information_schema.key_column_usage where table_schema={0} and table_name={1} and constraint_name = 'PRIMARY' limit 1".FormatMySql(tbname));
foreach (var tbcol in tb.Columns.Values) {
var isIdentityChanged = tbcol.Attribute.IsIdentity == true && tbcol.Attribute.DbType.IndexOf("AUTO_INCREMENT", StringComparison.CurrentCultureIgnoreCase) == -1;
if (tbstruct.TryGetValue(tbcol.Attribute.Name, out var tbstructcol) ||
Expand All @@ -202,6 +206,23 @@ from information_schema.columns a
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");
}
var dsuksql = @"
select
a.column_name,
a.constraint_name 'index_id'
from information_schema.key_column_usage a
where a.constraint_schema IN ({0}) and a.table_name IN ({1})".FormatMySql(tboldname ?? tbname);
var dsuk = _orm.Ado.ExecuteArray(CommandType.Text, dsuksql).Select(a => new[] { string.Concat(a[0]), string.Concat(a[1]) });
foreach (var uk in tb.Uniques) {
if (uk.Key == "PRIMARY" || string.IsNullOrEmpty(uk.Key) || uk.Value.Any() == false) continue;
var dsukfind1 = dsuk.Where(a => string.Compare(a[1], uk.Key, true) == 0).ToArray();
if (dsukfind1.Any() == false || dsukfind1.Length != uk.Value.Count || dsukfind1.Where(a => uk.Value.Where(b => string.Compare(b.Attribute.Name, a[0], true) == 0).Any()).Count() != uk.Value.Count) {
if (dsukfind1.Any()) sbalter.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" DROP INDEX ").Append(_commonUtils.QuoteSqlName(uk.Key)).Append(";\r\n");
sbalter.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" ADD CONSTRAINT ").Append(_commonUtils.QuoteSqlName(uk.Key)).Append(" UNIQUE(");
foreach (var tbcol in uk.Value) sbalter.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", ");
sbalter.Remove(sbalter.Length - 2, 2).Append(");\r\n");
}
}
}
if (istmpatler == false) {
sb.Append(sbalter);
Expand All @@ -219,13 +240,17 @@ from information_schema.columns a
if (tbcol.Attribute.IsIdentity == true && tbcol.Attribute.DbType.IndexOf("AUTO_INCREMENT", StringComparison.CurrentCultureIgnoreCase) == -1) sb.Append(" AUTO_INCREMENT");
sb.Append(",");
}
if (tb.Primarys.Any() == false)
sb.Remove(sb.Length - 1, 1);
else {
if (tb.Primarys.Any()) {
sb.Append(" \r\n PRIMARY KEY (");
foreach (var tbcol in tb.Primarys) sb.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", ");
sb.Remove(sb.Length - 2, 2).Append(")");
sb.Remove(sb.Length - 2, 2).Append("),");
}
foreach (var uk in tb.Uniques) {
sb.Append(" \r\n UNIQUE KEY ").Append(_commonUtils.QuoteSqlName(uk.Key)).Append("(");
foreach (var tbcol in uk.Value) sb.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", ");
sb.Remove(sb.Length - 2, 2).Append("),");
}
sb.Remove(sb.Length - 1, 1);
sb.Append("\r\n) Engine=InnoDB CHARACTER SET utf8;\r\n");
sb.Append("INSERT INTO ").Append(tmptablename).Append(" (");
foreach (var tbcol in tb.Columns.Values)
Expand Down
2 changes: 1 addition & 1 deletion FreeSql/MySql/MySqlDbFirst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ where a.constraint_schema in ({1}) and a.table_name in ({0}) and isnull(position
if (!loc10.TryGetValue(index_id, out loc11))
loc10.Add(index_id, loc11 = new List<DbColumnInfo>());
loc11.Add(loc9);
if (is_unique) {
if (is_unique && !is_primary_key) {
if (!uniqueColumns.TryGetValue(table_id, out loc10))
uniqueColumns.Add(table_id, loc10 = new Dictionary<string, List<DbColumnInfo>>());
if (!loc10.TryGetValue(index_id, out loc11))
Expand Down
48 changes: 40 additions & 8 deletions FreeSql/Oracle/OracleCodeFirst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,17 @@ public string GetComparisonDDLStatements(params Type[] entityTypes) {
sb.Append(" \r\n ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" ").Append(tbcol.Attribute.DbType).Append(",");
if (tbcol.Attribute.IsIdentity == true) seqcols.Add((tbcol, tbname, true));
}
if (tb.Primarys.Any() == false)
sb.Remove(sb.Length - 1, 1);
else {
if (tb.Primarys.Any()) {
sb.Append(" \r\n CONSTRAINT ").Append(tbname[0]).Append("_").Append(tbname[1]).Append("_pk1 PRIMARY KEY (");
foreach (var tbcol in tb.Primarys) sb.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", ");
sb.Remove(sb.Length - 2, 2).Append(")");
sb.Remove(sb.Length - 2, 2).Append("),");
}
foreach (var uk in tb.Uniques) {
sb.Append(" \r\n CONSTRAINT ").Append(_commonUtils.QuoteSqlName(uk.Key)).Append(" UNIQUE (");
foreach (var tbcol in uk.Value) sb.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", ");
sb.Remove(sb.Length - 2, 2).Append("),");
}
sb.Remove(sb.Length - 1, 1);
sb.Append("\r\n) \r\nLOGGING \r\nNOCOMPRESS \r\nNOCACHE\r\n';\r\n");
continue;
}
Expand Down Expand Up @@ -185,6 +189,30 @@ from all_tab_columns
}
if (tbcol.Attribute.IsIdentity == true) seqcols.Add((tbcol, tbname, tbcol.Attribute.IsIdentity == true));
}
var dsuksql = @"
select
c.column_name,
c.constraint_name
from
all_constraints a,
all_cons_columns c
where
a.constraint_name = c.constraint_name
and a.owner = c.owner
and a.table_name = c.table_name
and a.constraint_type in ('U')
and a.owner in ({0}) and a.table_name in ({1})".FormatMySql(tboldname ?? tbname);
var dsuk = _orm.Ado.ExecuteArray(CommandType.Text, dsuksql).Select(a => new[] { string.Concat(a[0]), string.Concat(a[1]) });
foreach (var uk in tb.Uniques) {
if (string.IsNullOrEmpty(uk.Key) || uk.Value.Any() == false) continue;
var dsukfind1 = dsuk.Where(a => string.Compare(a[1], uk.Key, true) == 0).ToArray();
if (dsukfind1.Any() == false || dsukfind1.Length != uk.Value.Count || dsukfind1.Where(a => uk.Value.Where(b => string.Compare(b.Attribute.Name, a[0], true) == 0).Any()).Count() != uk.Value.Count) {
if (dsukfind1.Any()) sbalter.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" DROP CONSTRAINT ").Append(_commonUtils.QuoteSqlName(uk.Key)).Append("';\r\n");
sbalter.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" ADD CONSTRAINT ").Append(_commonUtils.QuoteSqlName(uk.Key)).Append(" UNIQUE(");
foreach (var tbcol in uk.Value) sbalter.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", ");
sbalter.Remove(sbalter.Length - 2, 2).Append(")';\r\n");
}
}
}
if (istmpatler == false) {
sb.Append(sbalter);
Expand All @@ -203,13 +231,17 @@ from all_tab_columns
sb.Append(" \r\n ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" ").Append(tbcol.Attribute.DbType).Append(",");
if (tbcol.Attribute.IsIdentity == true) seqcols.Add((tbcol, tbname, true));
}
if (tb.Primarys.Any() == false)
sb.Remove(sb.Length - 1, 1);
else {
if (tb.Primarys.Any()) {
sb.Append(" \r\n CONSTRAINT ").Append(tbname[0]).Append("_").Append(tbname[1]).Append("_pk2 PRIMARY KEY (");
foreach (var tbcol in tb.Primarys) sb.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", ");
sb.Remove(sb.Length - 2, 2).Append(")");
sb.Remove(sb.Length - 2, 2).Append("),");
}
foreach (var uk in tb.Uniques) {
sb.Append(" \r\n CONSTRAINT ").Append(_commonUtils.QuoteSqlName(uk.Key)).Append(" UNIQUE (");
foreach (var tbcol in uk.Value) sb.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", ");
sb.Remove(sb.Length - 2, 2).Append("),");
}
sb.Remove(sb.Length - 1, 1);
sb.Append("\r\n) LOGGING \r\nNOCOMPRESS \r\nNOCACHE\r\n';\r\n");
sb.Append("execute immediate 'INSERT INTO ").Append(tmptablename).Append(" (");
foreach (var tbcol in tb.Columns.Values)
Expand Down
Loading

0 comments on commit 45b785f

Please sign in to comment.