From 7ef0bce3d473e7ebb1cb9e441be714daf42187aa Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sun, 26 May 2019 17:07:09 +0800 Subject: [PATCH] CodeFirst adds database index and default value --- Src/Asp.Net/MySqlTest/MySqlTest.csproj | 1 + Src/Asp.Net/MySqlTest/UnitTest/Main.cs | 1 + Src/Asp.Net/MySqlTest/UnitTest/UCodeFirst.cs | 26 ++++ .../SqlServerTest/SqlServerTest.csproj | 1 + Src/Asp.Net/SqlServerTest/UnitTest/Main.cs | 1 + .../SqlServerTest/UnitTest/UCodeFirst.cs | 25 ++++ .../CodeFirstProvider/CodeFirstProvider.cs | 2 + .../Abstract/DbMaintenanceProvider/Methods.cs | 65 ++++++++++ .../DbMaintenanceProvider/Properties.cs | 3 + .../EntityMaintenance/EntityMaintenance.cs | 1 + .../SqlSugar/Entities/EntityColumnInfo.cs | 1 + .../Entities/Mapping/SugarMappingAttribute.cs | 7 ++ .../SqlSugar/Interface/IDbMaintenance.cs | 8 +- .../MySql/DbMaintenance/MySqlDbMaintenance.cs | 39 +++++- .../DbMaintenance/OracleDbMaintenance.cs | 85 ++++++++----- .../DbMaintenance/PostgreSQLDbMaintenance.cs | 21 ++++ .../DbMaintenance/SqlServerDbMaintenance.cs | 117 +++++++++++------- .../DbMaintenance/SqliteDbMaintenance.cs | 72 +++++++---- 18 files changed, 371 insertions(+), 105 deletions(-) create mode 100644 Src/Asp.Net/MySqlTest/UnitTest/UCodeFirst.cs create mode 100644 Src/Asp.Net/SqlServerTest/UnitTest/UCodeFirst.cs diff --git a/Src/Asp.Net/MySqlTest/MySqlTest.csproj b/Src/Asp.Net/MySqlTest/MySqlTest.csproj index 22706799c..60561f472 100644 --- a/Src/Asp.Net/MySqlTest/MySqlTest.csproj +++ b/Src/Asp.Net/MySqlTest/MySqlTest.csproj @@ -116,6 +116,7 @@ + diff --git a/Src/Asp.Net/MySqlTest/UnitTest/Main.cs b/Src/Asp.Net/MySqlTest/UnitTest/Main.cs index 5be151e53..7d21995af 100644 --- a/Src/Asp.Net/MySqlTest/UnitTest/Main.cs +++ b/Src/Asp.Net/MySqlTest/UnitTest/Main.cs @@ -25,6 +25,7 @@ namespace OrmTest }); public static void Init() { + CodeFirst(); Updateable(); Json(); Ado(); diff --git a/Src/Asp.Net/MySqlTest/UnitTest/UCodeFirst.cs b/Src/Asp.Net/MySqlTest/UnitTest/UCodeFirst.cs new file mode 100644 index 000000000..65a088715 --- /dev/null +++ b/Src/Asp.Net/MySqlTest/UnitTest/UCodeFirst.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OrmTest +{ + public partial class NewUnitTest + { + public static void CodeFirst() + { + if (Db.DbMaintenance.IsAnyTable("UnitCodeTest1", false)) + Db.DbMaintenance.DropTable("UnitCodeTest1"); + Db.CodeFirst.InitTables(); + Db.CodeFirst.InitTables(); + } + public class UnitCodeTest1 + { + [SqlSugar.SugarColumn(IndexGroupNameList = new string[] { "group1" })] + public int Id { get; set; } + [SqlSugar.SugarColumn(DefaultValue = "now()", IndexGroupNameList = new string[] { "group1" })] + public DateTime? CreateDate { get; set; } + } + } +} diff --git a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj index e3a53f90e..4e859d9c3 100644 --- a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj +++ b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj @@ -147,6 +147,7 @@ + diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/Main.cs b/Src/Asp.Net/SqlServerTest/UnitTest/Main.cs index 69c16dd21..b1a9c37ac 100644 --- a/Src/Asp.Net/SqlServerTest/UnitTest/Main.cs +++ b/Src/Asp.Net/SqlServerTest/UnitTest/Main.cs @@ -25,6 +25,7 @@ namespace OrmTest }); public static void Init() { + CodeFirst(); Updateable(); Json(); Ado(); diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/UCodeFirst.cs b/Src/Asp.Net/SqlServerTest/UnitTest/UCodeFirst.cs new file mode 100644 index 000000000..3c853a7d5 --- /dev/null +++ b/Src/Asp.Net/SqlServerTest/UnitTest/UCodeFirst.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OrmTest +{ + public partial class NewUnitTest + { + public static void CodeFirst() + { + if (Db.DbMaintenance.IsAnyTable("UnitCodeTest1", false)) + Db.DbMaintenance.DropTable("UnitCodeTest1"); + Db.CodeFirst.InitTables(); + } + public class UnitCodeTest1 + { + [SqlSugar.SugarColumn(IndexGroupNameList = new string[] { "group1" })] + public int Id { get; set; } + [SqlSugar.SugarColumn(DefaultValue="getdate()", IndexGroupNameList =new string[] {"group1" } )] + public DateTime? CreateDate { get; set; } + } + } +} diff --git a/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs index 12880b07b..1ec62ee80 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs @@ -116,6 +116,8 @@ namespace SqlSugar NoExistLogic(entityInfo); this.Context.DbMaintenance.AddRemark(entityInfo); + this.Context.DbMaintenance.AddIndex(entityInfo); + this.Context.DbMaintenance.AddDefaultValue(entityInfo); } public virtual void NoExistLogic(EntityInfo entityInfo) { diff --git a/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs b/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs index d6d61670b..a8cbb98de 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs @@ -292,6 +292,23 @@ namespace SqlSugar var dt=this.Context.Ado.GetDataTable(sql); return dt.Rows != null && dt.Rows.Count > 0; } + public virtual bool AddDefaultValue(string tableName, string columnName, string defaultValue) + { + string sql = string.Format(AddDefaultValueSql, tableName, columnName,defaultValue); + this.Context.Ado.ExecuteCommand(sql); + return true; + } + public virtual bool CreateIndex(string tableName, string[] columnNames) + { + string sql = string.Format(CreateIndexSql,tableName,string.Join(",",columnNames), string.Join("_", columnNames)); + this.Context.Ado.ExecuteCommand(sql); + return true; + } + public virtual bool IsAnyIndex(string indexName) + { + string sql = string.Format(this.IsAnyIndexSql, indexName); + return this.Context.Ado.GetInt(sql)>0; + } public virtual bool AddRemark(EntityInfo entity) { var db = this.Context; @@ -330,6 +347,54 @@ namespace SqlSugar return true; } + public virtual void AddIndex(EntityInfo entityInfo) + { + var db = this.Context; + var columns = entityInfo.Columns.Where(it => it.IsIgnore == false).ToList(); + var indexColumns = columns.Where(it => it.IndexGroupNameList.HasValue()).ToList(); + if (indexColumns.HasValue()) + { + var groups = indexColumns.SelectMany(it => it.IndexGroupNameList).GroupBy(it => it).Select(it=>it.Key).ToList(); + foreach (var item in groups) + { + var columnNames = indexColumns.Where(it => it.IndexGroupNameList.Any(i => i.Equals(item, StringComparison.CurrentCultureIgnoreCase))).Select(it=>it.DbColumnName).ToArray(); + var indexName = string.Format("Index_{0}_{1}",entityInfo.DbTableName, string.Join("_", columnNames)); + if (!IsAnyIndex(indexName)) + { + CreateIndex(entityInfo.DbTableName, columnNames); + } + } + } + } + + protected virtual bool IsAnyDefaultValue(string tableName, string columnName,List columns) + { + var defaultValue = columns.Where(it => it.DbColumnName.Equals(columnName, StringComparison.CurrentCultureIgnoreCase)).First().DefaultValue; + return defaultValue.HasValue(); + } + + public virtual bool IsAnyDefaultValue(string tableName, string columnName) + { + return IsAnyDefaultValue(tableName, columnName, this.GetColumnInfosByTableName(tableName, false)); + } + + public virtual void AddDefaultValue(EntityInfo entityInfo) + { + var dbColumns=this.GetColumnInfosByTableName(entityInfo.DbTableName, false); + var db = this.Context; + var columns = entityInfo.Columns.Where(it => it.IsIgnore == false).ToList(); + foreach (var item in columns) + { + if (item.DefaultValue.HasValue()) + { + if (!IsAnyDefaultValue(entityInfo.DbTableName,item.DbColumnName,dbColumns)) + { + this.AddDefaultValue(entityInfo.DbTableName, item.DbColumnName, item.DefaultValue); + } + } + } + } + public virtual bool RenameTable(string oldTableName, string newTableName) { string sql = string.Format(this.RenameTableSql, oldTableName,newTableName); diff --git a/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Properties.cs b/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Properties.cs index 0823ee8a5..c0e2eb7d9 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Properties.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Properties.cs @@ -32,6 +32,9 @@ namespace SqlSugar #endregion #region DDL + protected abstract string CreateIndexSql { get; } + protected abstract string IsAnyIndexSql { get; } + protected abstract string AddDefaultValueSql { get; } protected abstract string CreateDataBaseSql { get; } protected abstract string AddColumnToTableSql { get; } protected abstract string AlterColumnToTableSql { get; } diff --git a/Src/Asp.Net/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs b/Src/Asp.Net/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs index 354c6158d..7fde61823 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs @@ -172,6 +172,7 @@ namespace SqlSugar column.IsJson = sugarColumn.IsJson; column.NoSerialize = sugarColumn.NoSerialize; column.DefaultValue = sugarColumn.DefaultValue; + column.IndexGroupNameList = sugarColumn.IndexGroupNameList; } else { diff --git a/Src/Asp.Net/SqlSugar/Entities/EntityColumnInfo.cs b/Src/Asp.Net/SqlSugar/Entities/EntityColumnInfo.cs index 3501b0cfa..22a50e7a4 100644 --- a/Src/Asp.Net/SqlSugar/Entities/EntityColumnInfo.cs +++ b/Src/Asp.Net/SqlSugar/Entities/EntityColumnInfo.cs @@ -31,5 +31,6 @@ namespace SqlSugar public string SerializeDateTimeFormat { get; set; } public bool IsJson { get; set; } public bool NoSerialize { get; set; } + public string[] IndexGroupNameList { get; set; } } } diff --git a/Src/Asp.Net/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs b/Src/Asp.Net/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs index 3b0af737a..4c4dcd526 100644 --- a/Src/Asp.Net/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs +++ b/Src/Asp.Net/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs @@ -157,6 +157,13 @@ namespace SqlSugar set { _DefaultValue = value; } } + private string[] _IndexGroupNameList; + public string[] IndexGroupNameList + { + get { return _IndexGroupNameList; } + set { _IndexGroupNameList = value; } + } + } } diff --git a/Src/Asp.Net/SqlSugar/Interface/IDbMaintenance.cs b/Src/Asp.Net/SqlSugar/Interface/IDbMaintenance.cs index 935733331..0cb175aca 100644 --- a/Src/Asp.Net/SqlSugar/Interface/IDbMaintenance.cs +++ b/Src/Asp.Net/SqlSugar/Interface/IDbMaintenance.cs @@ -9,6 +9,7 @@ namespace SqlSugar SqlSugarProvider Context { get; set; } #region DML + List GetDataBaseList(SqlSugarClient db); List GetViewInfoList(bool isCache=true); List GetTableInfoList(bool isCache=true); List GetColumnInfosByTableName(string tableName,bool isCache=true); @@ -26,6 +27,8 @@ namespace SqlSugar #endregion #region DDL + bool AddDefaultValue(string tableName,string columnName,string defaultValue); + bool CreateIndex(string tableName, string [] columnNames); bool DropTable(string tableName); bool TruncateTable(string tableName); bool TruncateTable(); @@ -40,6 +43,10 @@ namespace SqlSugar bool DropColumn(string tableName,string columnName); bool RenameColumn(string tableName, string oldColumnName, string newColumnName); bool AddRemark(EntityInfo entity); + void AddIndex(EntityInfo entityInfo); + void AddDefaultValue(EntityInfo entityInfo); + bool IsAnyDefaultValue(string tableName, string columnName); + bool IsAnyIndex(string indexName); bool AddColumnRemark(string columnName,string tableName,string description); bool DeleteColumnRemark(string columnName, string tableName); bool IsAnyColumnRemark(string columnName, string tableName); @@ -60,7 +67,6 @@ namespace SqlSugar /// /// bool CreateDatabase(string databaseName,string databaseDirectory = null); - List GetDataBaseList(SqlSugarClient db); #endregion } } diff --git a/Src/Asp.Net/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs b/Src/Asp.Net/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs index adcaac3a2..adc296588 100644 --- a/Src/Asp.Net/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs +++ b/Src/Asp.Net/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs @@ -245,6 +245,29 @@ namespace SqlSugar return "alter table {0} rename {1}"; } } + + protected override string CreateIndexSql + { + get + { + return "CREATE INDEX Index_{0}_{2} ON {0} ({1})"; + } + } + + protected override string AddDefaultValueSql + { + get + { + return "ALTER TABLE {0} ALTER COLUMN {1} SET DEFAULT '{2}'"; + } + } + protected override string IsAnyIndexSql + { + get + { + return "SELECT count(*) FROM information_schema.statistics WHERE index_name = '{0}'"; + } + } #endregion #region Methods @@ -397,7 +420,21 @@ namespace SqlSugar return false; } } - + public override bool AddDefaultValue(string tableName, string columnName, string defaultValue) + { + if (defaultValue.ToLower().IsIn("now()", "current_timestamp")) + { + string template = "ALTER table {0} CHANGE COLUMN {1} {1} {3} default {2}"; + var dbColumnInfo=this.Context.DbMaintenance.GetColumnInfosByTableName(tableName).First(it => it.DbColumnName.Equals(columnName, StringComparison.CurrentCultureIgnoreCase)); + string sql = string.Format(template, tableName, columnName, defaultValue, dbColumnInfo.DataType); + this.Context.Ado.ExecuteCommand(sql); + return true; + } + else + { + return base.AddDefaultValue(tableName,columnName,defaultValue); + } + } public override bool IsAnyConstraint(string constraintName) { throw new NotSupportedException("MySql IsAnyConstraint NotSupportedException"); diff --git a/Src/Asp.Net/SqlSugar/Realization/Oracle/DbMaintenance/OracleDbMaintenance.cs b/Src/Asp.Net/SqlSugar/Realization/Oracle/DbMaintenance/OracleDbMaintenance.cs index d2a91087d..a3acc6c7c 100644 --- a/Src/Asp.Net/SqlSugar/Realization/Oracle/DbMaintenance/OracleDbMaintenance.cs +++ b/Src/Asp.Net/SqlSugar/Realization/Oracle/DbMaintenance/OracleDbMaintenance.cs @@ -51,6 +51,27 @@ namespace SqlSugar #endregion #region DDL + protected override string IsAnyIndexSql + { + get + { + return ""; + } + } + protected override string CreateIndexSql + { + get + { + return ""; + } + } + protected override string AddDefaultValueSql + { + get + { + return ""; + } + } protected override string CreateDataBaseSql { get @@ -142,100 +163,100 @@ namespace SqlSugar return "ALTER TABLE {0} rename column {1} to {2}"; } } - #endregion - - #region Check - protected override string CheckSystemTablePermissionsSql + protected override string AddColumnRemarkSql { get { - return "select t.table_name from user_tables t where rownum=1"; + return "comment on column {1}.{0} is '{2}'"; } } - #endregion - #region Scattered - protected override string CreateTableNull + protected override string DeleteColumnRemarkSql { get { - return ""; + return "comment on column {1}.{0} is ''"; } } - protected override string CreateTableNotNull + + protected override string IsAnyColumnRemarkSql { get { - return ""; + return "select * from user_col_comments where Table_Name='{1}' AND COLUMN_NAME='{0}' order by column_name"; } } - protected override string CreateTablePirmaryKey + + protected override string AddTableRemarkSql { get { - return "PRIMARY KEY"; + return "comment on table {0} is '{1}'"; } } - protected override string CreateTableIdentity + + protected override string DeleteTableRemarkSql { get { - return ""; + return "comment on table {0} is ''"; } } - protected override string AddColumnRemarkSql + protected override string IsAnyTableRemarkSql { get { - return "comment on column {1}.{0} is '{2}'"; + return "select * from user_tab_comments where Table_Name='{0}'order by Table_Name"; } } - protected override string DeleteColumnRemarkSql + protected override string RenameTableSql { get { - return "comment on column {1}.{0} is ''"; + return "alter table {0} rename to {1}"; } } + #endregion - protected override string IsAnyColumnRemarkSql + #region Check + protected override string CheckSystemTablePermissionsSql { get { - return "select * from user_col_comments where Table_Name='{1}' AND COLUMN_NAME='{0}' order by column_name"; + return "select t.table_name from user_tables t where rownum=1"; } } + #endregion - protected override string AddTableRemarkSql + #region Scattered + protected override string CreateTableNull { get { - return "comment on table {0} is '{1}'"; + return ""; } } - - protected override string DeleteTableRemarkSql + protected override string CreateTableNotNull { get { - return "comment on table {0} is ''"; + return ""; } } - - protected override string IsAnyTableRemarkSql + protected override string CreateTablePirmaryKey { get { - return "select * from user_tab_comments where Table_Name='{0}'order by Table_Name"; + return "PRIMARY KEY"; } } - - protected override string RenameTableSql { + protected override string CreateTableIdentity + { get { - return "alter table {0} rename to {1}"; + return ""; } } #endregion diff --git a/Src/Asp.Net/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLDbMaintenance.cs b/Src/Asp.Net/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLDbMaintenance.cs index 90ae042c6..60b861050 100644 --- a/Src/Asp.Net/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLDbMaintenance.cs +++ b/Src/Asp.Net/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLDbMaintenance.cs @@ -216,6 +216,27 @@ namespace SqlSugar protected override string RenameTableSql => "alter table 表名 {0} to {1}"; + protected override string CreateIndexSql + { + get + { + return ""; + } + } + protected override string AddDefaultValueSql + { + get + { + return ""; + } + } + protected override string IsAnyIndexSql + { + get + { + return "select count(*) from sys.indexes where name='{0}'"; + } + } #endregion #region Methods diff --git a/Src/Asp.Net/SqlSugar/Realization/SqlServer/DbMaintenance/SqlServerDbMaintenance.cs b/Src/Asp.Net/SqlSugar/Realization/SqlServer/DbMaintenance/SqlServerDbMaintenance.cs index 7481a5316..20716c14e 100644 --- a/Src/Asp.Net/SqlSugar/Realization/SqlServer/DbMaintenance/SqlServerDbMaintenance.cs +++ b/Src/Asp.Net/SqlSugar/Realization/SqlServer/DbMaintenance/SqlServerDbMaintenance.cs @@ -173,48 +173,6 @@ namespace SqlSugar return "exec sp_rename '{0}.{1}','{2}','column';"; } } - #endregion - - #region Check - protected override string CheckSystemTablePermissionsSql - { - get - { - return "select top 1 id from sysobjects"; - } - } - #endregion - - #region Scattered - protected override string CreateTableNull - { - get - { - return "NULL"; - } - } - protected override string CreateTableNotNull - { - get - { - return "NOT NULL"; - } - } - protected override string CreateTablePirmaryKey - { - get - { - return "PRIMARY KEY"; - } - } - protected override string CreateTableIdentity - { - get - { - return "IDENTITY(1,1)"; - } - } - protected override string AddColumnRemarkSql { get @@ -287,7 +245,73 @@ namespace SqlSugar } } + protected override string CreateIndexSql + { + get + { + return "CREATE NONCLUSTERED INDEX Index_{0}_{2} ON {0}({1})"; + } + } + protected override string AddDefaultValueSql + { + get + { + return "alter table {0} ADD DEFAULT '{2}' FOR {1}"; + } + } + protected override string IsAnyIndexSql + { + get + { + return "select count(*) from sys.indexes where name='{0}'"; + } + } + #endregion + + #region Check + protected override string CheckSystemTablePermissionsSql + { + get + { + return "select top 1 id from sysobjects"; + } + } + #endregion + + #region Scattered + protected override string CreateTableNull + { + get + { + return "NULL"; + } + } + protected override string CreateTableNotNull + { + get + { + return "NOT NULL"; + } + } + protected override string CreateTablePirmaryKey + { + get + { + return "PRIMARY KEY"; + } + } + protected override string CreateTableIdentity + { + get + { + return "IDENTITY(1,1)"; + } + } + #endregion + + #region Methods + /// ///by current connection string /// @@ -305,7 +329,8 @@ namespace SqlSugar var oldDatabaseName = this.Context.Ado.Connection.Database; var connection = this.Context.CurrentConnectionConfig.ConnectionString; connection = connection.Replace(oldDatabaseName, "master"); - var newDb = new SqlSugarClient(new ConnectionConfig() { + var newDb = new SqlSugarClient(new ConnectionConfig() + { DbType = this.Context.CurrentConnectionConfig.DbType, IsAutoCloseConnection = true, ConnectionString = connection @@ -353,7 +378,7 @@ namespace SqlSugar var pkColumns = columns.Where(it => it.IsPrimarykey).ToList(); if (pkColumns.Count > 1) { - this.Context.DbMaintenance.AddPrimaryKeys(tableName, pkColumns.Select(it=>it.DbColumnName).ToArray()); + this.Context.DbMaintenance.AddPrimaryKeys(tableName, pkColumns.Select(it => it.DbColumnName).ToArray()); } else { @@ -365,7 +390,6 @@ namespace SqlSugar } return true; } - public override bool RenameColumn(string tableName, string oldColumnName, string newColumnName) { tableName = this.SqlBuilder.GetTranslationTableName(tableName); @@ -374,6 +398,7 @@ namespace SqlSugar string sql = string.Format(this.RenameColumnSql, tableName, oldColumnName, newColumnName); this.Context.Ado.ExecuteCommand(sql); return true; - } + } + #endregion } } diff --git a/Src/Asp.Net/SqlSugar/Realization/Sqlite/DbMaintenance/SqliteDbMaintenance.cs b/Src/Asp.Net/SqlSugar/Realization/Sqlite/DbMaintenance/SqliteDbMaintenance.cs index a32fc1c90..b20c133ad 100644 --- a/Src/Asp.Net/SqlSugar/Realization/Sqlite/DbMaintenance/SqliteDbMaintenance.cs +++ b/Src/Asp.Net/SqlSugar/Realization/Sqlite/DbMaintenance/SqliteDbMaintenance.cs @@ -135,49 +135,48 @@ namespace SqlSugar throw new NotSupportedException(); } } - #endregion - #region Check - protected override string CheckSystemTablePermissionsSql + protected override string AddColumnRemarkSql { get { - return "select Name from sqlite_master limit 0,1"; + throw new NotSupportedException(); } } - #endregion - #region Scattered - protected override string CreateTableNull + protected override string DeleteColumnRemarkSql { get { - return "NULL"; + throw new NotSupportedException(); } } - protected override string CreateTableNotNull + + protected override string IsAnyColumnRemarkSql { get { - return "NOT NULL"; + throw new NotSupportedException(); } } - protected override string CreateTablePirmaryKey + + protected override string AddTableRemarkSql { get { - return "PRIMARY KEY"; + throw new NotSupportedException(); } } - protected override string CreateTableIdentity + + protected override string DeleteTableRemarkSql { get { - return "AUTOINCREMENT"; + throw new NotSupportedException(); } } - protected override string AddColumnRemarkSql + protected override string IsAnyTableRemarkSql { get { @@ -185,7 +184,7 @@ namespace SqlSugar } } - protected override string DeleteColumnRemarkSql + protected override string RenameTableSql { get { @@ -193,43 +192,66 @@ namespace SqlSugar } } - protected override string IsAnyColumnRemarkSql + protected override string CreateIndexSql { get { throw new NotSupportedException(); } } - - protected override string AddTableRemarkSql + protected override string AddDefaultValueSql { get { throw new NotSupportedException(); } } - - protected override string DeleteTableRemarkSql + protected override string IsAnyIndexSql { get { throw new NotSupportedException(); } } + #endregion - protected override string IsAnyTableRemarkSql + #region Check + protected override string CheckSystemTablePermissionsSql { get { - throw new NotSupportedException(); + return "select Name from sqlite_master limit 0,1"; } } + #endregion - protected override string RenameTableSql + #region Scattered + protected override string CreateTableNull { get { - throw new NotSupportedException(); + return "NULL"; + } + } + protected override string CreateTableNotNull + { + get + { + return "NOT NULL"; + } + } + protected override string CreateTablePirmaryKey + { + get + { + return "PRIMARY KEY"; + } + } + protected override string CreateTableIdentity + { + get + { + return "AUTOINCREMENT"; } } #endregion