From 15241cd4db4290c2591ca730b8bb7097938a3809 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Thu, 11 Jan 2018 17:34:06 +0800 Subject: [PATCH] - --- .../Abstract/DbMaintenanceProvider/Methods.cs | 2 +- .../SqlSugar/Interface/IDbMaintenance.cs | 2 +- .../MySql/DbMaintenance/MySqlDbMaintenance.cs | 2 +- .../DbMaintenance/PostgreSQLMaintenance.cs | 236 ------------------ .../DbMaintenance/SqliteDbMaintenance.cs | 2 +- Src/Asp.Net/SqlSugar/SqlSugar.csproj | 2 +- 6 files changed, 5 insertions(+), 241 deletions(-) delete mode 100644 Src/Asp.Net/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLMaintenance.cs diff --git a/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs b/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs index 1b2e636f8..925505fca 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs @@ -141,7 +141,7 @@ namespace SqlSugar this.Context.Ado.ExecuteCommand(sql); return true; } - public virtual bool CreateTable(string tableName, List columns) + public virtual bool CreateTable(string tableName, List columns, bool isCreatePrimaryKey = true) { tableName = this.SqlBuilder.GetTranslationTableName(tableName); string sql = GetCreateTableSql(tableName, columns); diff --git a/Src/Asp.Net/SqlSugar/Interface/IDbMaintenance.cs b/Src/Asp.Net/SqlSugar/Interface/IDbMaintenance.cs index b491d86d5..8307f952c 100644 --- a/Src/Asp.Net/SqlSugar/Interface/IDbMaintenance.cs +++ b/Src/Asp.Net/SqlSugar/Interface/IDbMaintenance.cs @@ -28,7 +28,7 @@ namespace SqlSugar #region DDL bool DropTable(string tableName); bool TruncateTable(string tableName); - bool CreateTable(string tableName, List columns); + bool CreateTable(string tableName, List columns,bool isCreatePrimaryKey=true); bool AddColumn(string tableName, DbColumnInfo column); bool UpdateColumn(string tableName, DbColumnInfo column); bool AddPrimaryKey(string tableName,string columnName); diff --git a/Src/Asp.Net/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs b/Src/Asp.Net/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs index b2874a4a3..30a416a66 100644 --- a/Src/Asp.Net/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs +++ b/Src/Asp.Net/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs @@ -179,7 +179,7 @@ namespace SqlSugar #endregion #region Methods - public override bool CreateTable(string tableName, List columns) + public override bool CreateTable(string tableName, List columns, bool isCreatePrimaryKey = true) { if (columns.HasValue()) { diff --git a/Src/Asp.Net/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLMaintenance.cs b/Src/Asp.Net/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLMaintenance.cs deleted file mode 100644 index 3127f1164..000000000 --- a/Src/Asp.Net/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLMaintenance.cs +++ /dev/null @@ -1,236 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace SqlSugar -{ - public class PostgreSQLDbMaintenance : DbMaintenanceProvider - { - #region DML - protected override string GetColumnInfosByTableNameSql - { - get - { - string sql = @"SELECT - 0 as TableId, - TABLE_NAME as TableName, - column_name AS DbColumnName, - CASE WHEN left(COLUMN_TYPE,LOCATE('(',COLUMN_TYPE)-1)='' THEN COLUMN_TYPE ELSE left(COLUMN_TYPE,LOCATE('(',COLUMN_TYPE)-1) END AS DataType, - CAST(SUBSTRING(COLUMN_TYPE,LOCATE('(',COLUMN_TYPE)+1,LOCATE(')',COLUMN_TYPE)-LOCATE('(',COLUMN_TYPE)-1) AS signed) AS Length, - column_default AS `DefaultValue`, - column_comment AS `ColumnDescription`, - CASE WHEN COLUMN_KEY = 'PRI' - THEN true ELSE false END AS `IsPrimaryKey`, - CASE WHEN EXTRA='auto_increment' THEN true ELSE false END as IsIdentity, - CASE WHEN is_nullable = 'YES' - THEN true ELSE false END AS `IsNullable` - FROM - Information_schema.columns where TABLE_NAME='{0}' and TABLE_SCHEMA=(select database()) ORDER BY TABLE_NAME"; - return sql; - } - } - protected override string GetTableInfoListSql - { - get - { - return @"select TABLE_NAME as Name,TABLE_COMMENT as Description from information_schema.tables - where TABLE_SCHEMA=(select database()) AND TABLE_TYPE='BASE TABLE'"; - } - } - protected override string GetViewInfoListSql - { - get - { - return @"select TABLE_NAME as Name,TABLE_COMMENT as Description from information_schema.tables - where TABLE_SCHEMA=(select database()) AND TABLE_TYPE='VIEW' - "; - } - } - #endregion - - #region DDL - protected override string AddPrimaryKeySql - { - get - { - return "ALTER TABLE {0} ADD PRIMARY KEY({2}) /*{1}*/"; - } - } - protected override string AddColumnToTableSql - { - get - { - return "ALTER TABLE {0} ADD {1} {2}{3} {4} {5} {6}"; - } - } - protected override string AlterColumnToTableSql - { - get - { - // return "ALTER TABLE {0} ALTER COLUMN {1} {2}{3} {4} {5} {6}"; - return "alter table {0} change column {1} {1} {2}{3} {4} {5} {6}"; - } - } - protected override string BackupDataBaseSql - { - get - { - return "mysqldump.exe {0} -uroot -p > {1} "; - } - } - protected override string CreateTableSql - { - get - { - return "CREATE TABLE {0}(\r\n{1} $PrimaryKey)"; - } - } - protected override string CreateTableColumn - { - get - { - return "{0} {1}{2} {3} {4} {5}"; - } - } - protected override string TruncateTableSql - { - get - { - return "TRUNCATE TABLE {0}"; - } - } - protected override string BackupTableSql - { - get - { - return "SELECT * INTO {1} FROM {2} limit 0,{0}"; - } - } - protected override string DropTableSql - { - get - { - return "DROP TABLE {0}"; - } - } - protected override string DropColumnToTableSql - { - get - { - return "ALTER TABLE {0} DROP COLUMN {1}"; - } - } - protected override string DropConstraintSql - { - get - { - return "ALTER TABLE {0} drop primary key;"; - } - } - protected override string RenameColumnSql - { - get - { - return "exec sp_rename '{0}.{1}','{2}','column';"; - } - } - #endregion - - #region Check - protected override string CheckSystemTablePermissionsSql - { - get - { - return "select 1 from Information_schema.columns limit 0,1"; - } - } - #endregion - - #region Scattered - protected override string CreateTableNull - { - get - { - return "DEFAULT NULL"; - } - } - protected override string CreateTableNotNull - { - get - { - return "NOT NULL"; - } - } - protected override string CreateTablePirmaryKey - { - get - { - return "PRIMARY KEY"; - } - } - protected override string CreateTableIdentity - { - get - { - return "AUTO_INCREMENT"; - } - } - #endregion - - #region Methods - public override bool CreateTable(string tableName, List columns) - { - if (columns.HasValue()) - { - foreach (var item in columns) - { - if (item.DbColumnName.Equals("GUID",StringComparison.CurrentCultureIgnoreCase)&&item.Length==0) - { - item.Length = 10; - } - } - } - string sql = GetCreateTableSql(tableName, columns); - string primaryKeyInfo = null; - if (columns.Any(it => it.IsIdentity)) { - primaryKeyInfo =string.Format( ", Primary key({0})",string.Join(",",columns.Where(it=>it.IsIdentity).Select(it=>this.SqlBuilder.GetTranslationColumnName(it.DbColumnName)))); - - } - sql = sql.Replace("$PrimaryKey", primaryKeyInfo); - this.Context.Ado.ExecuteCommand(sql); - return true; - } - protected override string GetCreateTableSql(string tableName, List columns) - { - List columnArray = new List(); - Check.Exception(columns.IsNullOrEmpty(), "No columns found "); - foreach (var item in columns) - { - string columnName = item.DbColumnName; - string dataType = item.DataType; - if (dataType == "varchar"&& item.Length==0) { - item.Length = 1; - } - string dataSize = item.Length > 0 ? string.Format("({0})", item.Length) : null; - string nullType = item.IsNullable ? this.CreateTableNull : CreateTableNotNull; - string primaryKey = null; - string identity = item.IsIdentity ? this.CreateTableIdentity : null; - string addItem = string.Format(this.CreateTableColumn, this.SqlBuilder.GetTranslationColumnName(columnName), dataType, dataSize, nullType, primaryKey, identity); - columnArray.Add(addItem); - } - string tableString = string.Format(this.CreateTableSql, this.SqlBuilder.GetTranslationTableName(tableName), string.Join(",\r\n", columnArray)); - return tableString; - } - public override bool IsAnyConstraint(string constraintName) - { - throw new NotSupportedException("MySql IsAnyConstraint NotSupportedException"); - } - public override bool BackupDataBase(string databaseName, string fullFileName) - { - Check.ThrowNotSupportedException("MySql BackupDataBase NotSupported"); - return false; - } - #endregion - } -} diff --git a/Src/Asp.Net/SqlSugar/Realization/Sqlite/DbMaintenance/SqliteDbMaintenance.cs b/Src/Asp.Net/SqlSugar/Realization/Sqlite/DbMaintenance/SqliteDbMaintenance.cs index dc1a60652..87532703c 100644 --- a/Src/Asp.Net/SqlSugar/Realization/Sqlite/DbMaintenance/SqliteDbMaintenance.cs +++ b/Src/Asp.Net/SqlSugar/Realization/Sqlite/DbMaintenance/SqliteDbMaintenance.cs @@ -201,7 +201,7 @@ namespace SqlSugar }); } - public override bool CreateTable(string tableName, List columns) + public override bool CreateTable(string tableName, List columns, bool isCreatePrimaryKey = true) { if (columns.HasValue()) { diff --git a/Src/Asp.Net/SqlSugar/SqlSugar.csproj b/Src/Asp.Net/SqlSugar/SqlSugar.csproj index 8bc5889b8..e85903075 100644 --- a/Src/Asp.Net/SqlSugar/SqlSugar.csproj +++ b/Src/Asp.Net/SqlSugar/SqlSugar.csproj @@ -112,7 +112,6 @@ - @@ -275,6 +274,7 @@ +