mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
CodeFirst adds database index and default value
This commit is contained in:
parent
70f7c85e46
commit
7ef0bce3d4
@ -116,6 +116,7 @@
|
|||||||
<Compile Include="OldTests\UnitTest\Update.cs" />
|
<Compile Include="OldTests\UnitTest\Update.cs" />
|
||||||
<Compile Include="UnitTest\Main.cs" />
|
<Compile Include="UnitTest\Main.cs" />
|
||||||
<Compile Include="UnitTest\UAdo.cs" />
|
<Compile Include="UnitTest\UAdo.cs" />
|
||||||
|
<Compile Include="UnitTest\UCodeFirst.cs" />
|
||||||
<Compile Include="UnitTest\UJson.cs" />
|
<Compile Include="UnitTest\UJson.cs" />
|
||||||
<Compile Include="UnitTest\Updateable.cs" />
|
<Compile Include="UnitTest\Updateable.cs" />
|
||||||
<Compile Include="UnitTest\UQueryable.cs" />
|
<Compile Include="UnitTest\UQueryable.cs" />
|
||||||
|
@ -25,6 +25,7 @@ namespace OrmTest
|
|||||||
});
|
});
|
||||||
public static void Init()
|
public static void Init()
|
||||||
{
|
{
|
||||||
|
CodeFirst();
|
||||||
Updateable();
|
Updateable();
|
||||||
Json();
|
Json();
|
||||||
Ado();
|
Ado();
|
||||||
|
26
Src/Asp.Net/MySqlTest/UnitTest/UCodeFirst.cs
Normal file
26
Src/Asp.Net/MySqlTest/UnitTest/UCodeFirst.cs
Normal file
@ -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<UnitCodeTest1>();
|
||||||
|
Db.CodeFirst.InitTables<UnitCodeTest1>();
|
||||||
|
}
|
||||||
|
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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -147,6 +147,7 @@
|
|||||||
<Compile Include="OldTest\UnitTest\Setting\MapTable.cs" />
|
<Compile Include="OldTest\UnitTest\Setting\MapTable.cs" />
|
||||||
<Compile Include="OldTest\UnitTest\Update.cs" />
|
<Compile Include="OldTest\UnitTest\Update.cs" />
|
||||||
<Compile Include="Models\CarType.cs" />
|
<Compile Include="Models\CarType.cs" />
|
||||||
|
<Compile Include="UnitTest\UCodeFirst.cs" />
|
||||||
<Compile Include="UnitTest\UAdo.cs" />
|
<Compile Include="UnitTest\UAdo.cs" />
|
||||||
<Compile Include="UnitTest\Updateable.cs" />
|
<Compile Include="UnitTest\Updateable.cs" />
|
||||||
<Compile Include="UnitTest\UQueryable.cs" />
|
<Compile Include="UnitTest\UQueryable.cs" />
|
||||||
|
@ -25,6 +25,7 @@ namespace OrmTest
|
|||||||
});
|
});
|
||||||
public static void Init()
|
public static void Init()
|
||||||
{
|
{
|
||||||
|
CodeFirst();
|
||||||
Updateable();
|
Updateable();
|
||||||
Json();
|
Json();
|
||||||
Ado();
|
Ado();
|
||||||
|
25
Src/Asp.Net/SqlServerTest/UnitTest/UCodeFirst.cs
Normal file
25
Src/Asp.Net/SqlServerTest/UnitTest/UCodeFirst.cs
Normal file
@ -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<UnitCodeTest1>();
|
||||||
|
}
|
||||||
|
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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -116,6 +116,8 @@ namespace SqlSugar
|
|||||||
NoExistLogic(entityInfo);
|
NoExistLogic(entityInfo);
|
||||||
|
|
||||||
this.Context.DbMaintenance.AddRemark(entityInfo);
|
this.Context.DbMaintenance.AddRemark(entityInfo);
|
||||||
|
this.Context.DbMaintenance.AddIndex(entityInfo);
|
||||||
|
this.Context.DbMaintenance.AddDefaultValue(entityInfo);
|
||||||
}
|
}
|
||||||
public virtual void NoExistLogic(EntityInfo entityInfo)
|
public virtual void NoExistLogic(EntityInfo entityInfo)
|
||||||
{
|
{
|
||||||
|
@ -292,6 +292,23 @@ namespace SqlSugar
|
|||||||
var dt=this.Context.Ado.GetDataTable(sql);
|
var dt=this.Context.Ado.GetDataTable(sql);
|
||||||
return dt.Rows != null && dt.Rows.Count > 0;
|
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)
|
public virtual bool AddRemark(EntityInfo entity)
|
||||||
{
|
{
|
||||||
var db = this.Context;
|
var db = this.Context;
|
||||||
@ -330,6 +347,54 @@ namespace SqlSugar
|
|||||||
return true;
|
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<DbColumnInfo> 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)
|
public virtual bool RenameTable(string oldTableName, string newTableName)
|
||||||
{
|
{
|
||||||
string sql = string.Format(this.RenameTableSql, oldTableName,newTableName);
|
string sql = string.Format(this.RenameTableSql, oldTableName,newTableName);
|
||||||
|
@ -32,6 +32,9 @@ namespace SqlSugar
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region DDL
|
#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 CreateDataBaseSql { get; }
|
||||||
protected abstract string AddColumnToTableSql { get; }
|
protected abstract string AddColumnToTableSql { get; }
|
||||||
protected abstract string AlterColumnToTableSql { get; }
|
protected abstract string AlterColumnToTableSql { get; }
|
||||||
|
@ -172,6 +172,7 @@ namespace SqlSugar
|
|||||||
column.IsJson = sugarColumn.IsJson;
|
column.IsJson = sugarColumn.IsJson;
|
||||||
column.NoSerialize = sugarColumn.NoSerialize;
|
column.NoSerialize = sugarColumn.NoSerialize;
|
||||||
column.DefaultValue = sugarColumn.DefaultValue;
|
column.DefaultValue = sugarColumn.DefaultValue;
|
||||||
|
column.IndexGroupNameList = sugarColumn.IndexGroupNameList;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -31,5 +31,6 @@ namespace SqlSugar
|
|||||||
public string SerializeDateTimeFormat { get; set; }
|
public string SerializeDateTimeFormat { get; set; }
|
||||||
public bool IsJson { get; set; }
|
public bool IsJson { get; set; }
|
||||||
public bool NoSerialize { get; set; }
|
public bool NoSerialize { get; set; }
|
||||||
|
public string[] IndexGroupNameList { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -157,6 +157,13 @@ namespace SqlSugar
|
|||||||
set { _DefaultValue = value; }
|
set { _DefaultValue = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string[] _IndexGroupNameList;
|
||||||
|
public string[] IndexGroupNameList
|
||||||
|
{
|
||||||
|
get { return _IndexGroupNameList; }
|
||||||
|
set { _IndexGroupNameList = value; }
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ namespace SqlSugar
|
|||||||
SqlSugarProvider Context { get; set; }
|
SqlSugarProvider Context { get; set; }
|
||||||
|
|
||||||
#region DML
|
#region DML
|
||||||
|
List<string> GetDataBaseList(SqlSugarClient db);
|
||||||
List<DbTableInfo> GetViewInfoList(bool isCache=true);
|
List<DbTableInfo> GetViewInfoList(bool isCache=true);
|
||||||
List<DbTableInfo> GetTableInfoList(bool isCache=true);
|
List<DbTableInfo> GetTableInfoList(bool isCache=true);
|
||||||
List<DbColumnInfo> GetColumnInfosByTableName(string tableName,bool isCache=true);
|
List<DbColumnInfo> GetColumnInfosByTableName(string tableName,bool isCache=true);
|
||||||
@ -26,6 +27,8 @@ namespace SqlSugar
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region DDL
|
#region DDL
|
||||||
|
bool AddDefaultValue(string tableName,string columnName,string defaultValue);
|
||||||
|
bool CreateIndex(string tableName, string [] columnNames);
|
||||||
bool DropTable(string tableName);
|
bool DropTable(string tableName);
|
||||||
bool TruncateTable(string tableName);
|
bool TruncateTable(string tableName);
|
||||||
bool TruncateTable<T>();
|
bool TruncateTable<T>();
|
||||||
@ -40,6 +43,10 @@ namespace SqlSugar
|
|||||||
bool DropColumn(string tableName,string columnName);
|
bool DropColumn(string tableName,string columnName);
|
||||||
bool RenameColumn(string tableName, string oldColumnName, string newColumnName);
|
bool RenameColumn(string tableName, string oldColumnName, string newColumnName);
|
||||||
bool AddRemark(EntityInfo entity);
|
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 AddColumnRemark(string columnName,string tableName,string description);
|
||||||
bool DeleteColumnRemark(string columnName, string tableName);
|
bool DeleteColumnRemark(string columnName, string tableName);
|
||||||
bool IsAnyColumnRemark(string columnName, string tableName);
|
bool IsAnyColumnRemark(string columnName, string tableName);
|
||||||
@ -60,7 +67,6 @@ namespace SqlSugar
|
|||||||
/// <param name="databaseDirectory"></param>
|
/// <param name="databaseDirectory"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
bool CreateDatabase(string databaseName,string databaseDirectory = null);
|
bool CreateDatabase(string databaseName,string databaseDirectory = null);
|
||||||
List<string> GetDataBaseList(SqlSugarClient db);
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -245,6 +245,29 @@ namespace SqlSugar
|
|||||||
return "alter table {0} rename {1}";
|
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
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
@ -397,7 +420,21 @@ namespace SqlSugar
|
|||||||
return false;
|
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)
|
public override bool IsAnyConstraint(string constraintName)
|
||||||
{
|
{
|
||||||
throw new NotSupportedException("MySql IsAnyConstraint NotSupportedException");
|
throw new NotSupportedException("MySql IsAnyConstraint NotSupportedException");
|
||||||
|
@ -51,6 +51,27 @@ namespace SqlSugar
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region DDL
|
#region DDL
|
||||||
|
protected override string IsAnyIndexSql
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected override string CreateIndexSql
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected override string AddDefaultValueSql
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
protected override string CreateDataBaseSql
|
protected override string CreateDataBaseSql
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@ -142,48 +163,6 @@ namespace SqlSugar
|
|||||||
return "ALTER TABLE {0} rename column {1} to {2}";
|
return "ALTER TABLE {0} rename column {1} to {2}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Check
|
|
||||||
protected override string CheckSystemTablePermissionsSql
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return "select t.table_name from user_tables t where rownum=1";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Scattered
|
|
||||||
protected override string CreateTableNull
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
protected override string CreateTableNotNull
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
protected override string CreateTablePirmaryKey
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return "PRIMARY KEY";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
protected override string CreateTableIdentity
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override string AddColumnRemarkSql
|
protected override string AddColumnRemarkSql
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@ -232,7 +211,8 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string RenameTableSql {
|
protected override string RenameTableSql
|
||||||
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return "alter table {0} rename to {1}";
|
return "alter table {0} rename to {1}";
|
||||||
@ -240,6 +220,47 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Check
|
||||||
|
protected override string CheckSystemTablePermissionsSql
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "select t.table_name from user_tables t where rownum=1";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Scattered
|
||||||
|
protected override string CreateTableNull
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected override string CreateTableNotNull
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected override string CreateTablePirmaryKey
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "PRIMARY KEY";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected override string CreateTableIdentity
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
public override bool CreateDatabase(string databaseDirectory = null)
|
public override bool CreateDatabase(string databaseDirectory = null)
|
||||||
{
|
{
|
||||||
|
@ -216,6 +216,27 @@ namespace SqlSugar
|
|||||||
|
|
||||||
protected override string RenameTableSql => "alter table 表名 {0} to {1}";
|
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
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
@ -173,48 +173,6 @@ namespace SqlSugar
|
|||||||
return "exec sp_rename '{0}.{1}','{2}','column';";
|
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
|
protected override string AddColumnRemarkSql
|
||||||
{
|
{
|
||||||
get
|
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
|
#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
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///by current connection string
|
///by current connection string
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -305,7 +329,8 @@ namespace SqlSugar
|
|||||||
var oldDatabaseName = this.Context.Ado.Connection.Database;
|
var oldDatabaseName = this.Context.Ado.Connection.Database;
|
||||||
var connection = this.Context.CurrentConnectionConfig.ConnectionString;
|
var connection = this.Context.CurrentConnectionConfig.ConnectionString;
|
||||||
connection = connection.Replace(oldDatabaseName, "master");
|
connection = connection.Replace(oldDatabaseName, "master");
|
||||||
var newDb = new SqlSugarClient(new ConnectionConfig() {
|
var newDb = new SqlSugarClient(new ConnectionConfig()
|
||||||
|
{
|
||||||
DbType = this.Context.CurrentConnectionConfig.DbType,
|
DbType = this.Context.CurrentConnectionConfig.DbType,
|
||||||
IsAutoCloseConnection = true,
|
IsAutoCloseConnection = true,
|
||||||
ConnectionString = connection
|
ConnectionString = connection
|
||||||
@ -365,7 +390,6 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool RenameColumn(string tableName, string oldColumnName, string newColumnName)
|
public override bool RenameColumn(string tableName, string oldColumnName, string newColumnName)
|
||||||
{
|
{
|
||||||
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
|
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
|
||||||
@ -375,5 +399,6 @@ namespace SqlSugar
|
|||||||
this.Context.Ado.ExecuteCommand(sql);
|
this.Context.Ado.ExecuteCommand(sql);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,47 +135,6 @@ namespace SqlSugar
|
|||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Check
|
|
||||||
protected override string CheckSystemTablePermissionsSql
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return "select Name from sqlite_master limit 0,1";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#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 "AUTOINCREMENT";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override string AddColumnRemarkSql
|
protected override string AddColumnRemarkSql
|
||||||
{
|
{
|
||||||
@ -232,6 +191,69 @@ namespace SqlSugar
|
|||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override string CreateIndexSql
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected override string AddDefaultValueSql
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected override string IsAnyIndexSql
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Check
|
||||||
|
protected override string CheckSystemTablePermissionsSql
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "select Name from sqlite_master limit 0,1";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#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 "AUTOINCREMENT";
|
||||||
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
Loading…
Reference in New Issue
Block a user