From 8107ed3c447f80a4596b188ae06d6f04640e84c7 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sun, 9 Jul 2017 17:38:16 +0800 Subject: [PATCH] Update Sqlite --- .../Abstract/DbMaintenanceProvider/Methods.cs | 2 +- .../Sqlite/CodeFirst/SqliteCodeFirst.cs | 21 ++++++++++++++- .../Realization/Sqlite/DbBind/SqliteDbBind.cs | 2 +- .../DbMaintenance/SqliteDbMaintenance.cs | 23 ++++++++--------- Src/Asp.Net/SqliteTest/Config.cs | 2 +- .../SqliteTest/DataBase/SqlSugar4xTest.sqlite | Bin 73728 -> 73728 bytes Src/Asp.Net/SqliteTest/DataBase/X.sql | 24 ++++++++++++++++++ Src/Asp.Net/SqliteTest/Program.cs | 4 +-- Src/Asp.Net/SqliteTest/SqliteTest.csproj | 4 +-- 9 files changed, 61 insertions(+), 21 deletions(-) create mode 100644 Src/Asp.Net/SqliteTest/DataBase/X.sql diff --git a/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs b/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs index 845a454a8..9d77ee66a 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs @@ -192,7 +192,7 @@ namespace SqlSugar { oldTableName = this.SqlBuilder.GetTranslationTableName(oldTableName); newTableName = this.SqlBuilder.GetTranslationTableName(newTableName); - string sql = string.Format(this.BackupTableSql, maxBackupDataRows,newTableName , oldTableName); + string sql = string.Format(this.BackupTableSql,newTableName , oldTableName, maxBackupDataRows); this.Context.Ado.ExecuteCommand(sql); return true; } diff --git a/Src/Asp.Net/SqlSugar/Realization/Sqlite/CodeFirst/SqliteCodeFirst.cs b/Src/Asp.Net/SqlSugar/Realization/Sqlite/CodeFirst/SqliteCodeFirst.cs index 74c5aa1f8..e9919bf3e 100644 --- a/Src/Asp.Net/SqlSugar/Realization/Sqlite/CodeFirst/SqliteCodeFirst.cs +++ b/Src/Asp.Net/SqlSugar/Realization/Sqlite/CodeFirst/SqliteCodeFirst.cs @@ -7,9 +7,10 @@ namespace SqlSugar { public class SqliteCodeFirst : CodeFirstProvider { - public override void NoExistLogic(EntityInfo entityInfo) + public override void ExistLogic(EntityInfo entityInfo) { var tableName = GetTableName(entityInfo); + string backupName = tableName + DateTime.Now.ToString("yyyyMMddHHmmss"); Check.Exception(entityInfo.Columns.Where(it => it.IsPrimarykey).Count() > 1, "Use Code First ,The primary key must not exceed 1"); List columns = new List(); if (entityInfo.Columns.IsValuable()) @@ -20,6 +21,24 @@ namespace SqlSugar columns.Add(dbColumnInfo); } } + this.Context.DbMaintenance.BackupTable(tableName, backupName, int.MaxValue); + this.Context.DbMaintenance.DropTable(tableName); + this.Context.DbMaintenance.CreateTable(tableName,columns); + } + public override void NoExistLogic(EntityInfo entityInfo) + { + var tableName = GetTableName(entityInfo); + string backupName=tableName+DateTime.Now.ToString("yyyyMMddHHmmss"); + Check.Exception(entityInfo.Columns.Where(it => it.IsPrimarykey).Count() > 1, "Use Code First ,The primary key must not exceed 1"); + List columns = new List(); + if (entityInfo.Columns.IsValuable()) + { + foreach (var item in entityInfo.Columns.Where(it=>it.IsIgnore==false)) + { + DbColumnInfo dbColumnInfo = this.EntityColumnToDbColumn(entityInfo, tableName, item); + columns.Add(dbColumnInfo); + } + } this.Context.DbMaintenance.CreateTable(tableName, columns); } protected override DbColumnInfo EntityColumnToDbColumn(EntityInfo entityInfo, string tableName, EntityColumnInfo item) diff --git a/Src/Asp.Net/SqlSugar/Realization/Sqlite/DbBind/SqliteDbBind.cs b/Src/Asp.Net/SqlSugar/Realization/Sqlite/DbBind/SqliteDbBind.cs index df3183b35..c2a13e82a 100644 --- a/Src/Asp.Net/SqlSugar/Realization/Sqlite/DbBind/SqliteDbBind.cs +++ b/Src/Asp.Net/SqlSugar/Realization/Sqlite/DbBind/SqliteDbBind.cs @@ -30,8 +30,8 @@ namespace SqlSugar return new List>() { - new KeyValuePair("int",CSharpDataType.@int), new KeyValuePair("integer",CSharpDataType.@int), + new KeyValuePair("int",CSharpDataType.@int), new KeyValuePair("int32",CSharpDataType.@int), new KeyValuePair("integer32",CSharpDataType.@int), diff --git a/Src/Asp.Net/SqlSugar/Realization/Sqlite/DbMaintenance/SqliteDbMaintenance.cs b/Src/Asp.Net/SqlSugar/Realization/Sqlite/DbMaintenance/SqliteDbMaintenance.cs index abe7c3011..9a28732f1 100644 --- a/Src/Asp.Net/SqlSugar/Realization/Sqlite/DbMaintenance/SqliteDbMaintenance.cs +++ b/Src/Asp.Net/SqlSugar/Realization/Sqlite/DbMaintenance/SqliteDbMaintenance.cs @@ -89,7 +89,7 @@ namespace SqlSugar { get { - throw new NotSupportedException(); + return " CREATE TABLE {0} AS SELECT * FROM {1} limit 0,{2}"; } } protected override string DropTableSql @@ -110,7 +110,7 @@ namespace SqlSugar { get { - return "ALTER TABLE {0} drop primary key;"; + throw new NotSupportedException(); } } protected override string RenameColumnSql @@ -182,7 +182,7 @@ namespace SqlSugar this.Context.Ado.IsEnableLogEvent = oldIsEnableLog; return AdoCore.GetColumnInfosByTableName(tableName, reader); } - + }); } @@ -194,18 +194,16 @@ namespace SqlSugar { if (item.DbColumnName.Equals("GUID", StringComparison.CurrentCultureIgnoreCase)) { - item.Length = 10; + item.Length = 20; + } + if (item.IsIdentity && !item.IsPrimarykey) + { + item.IsPrimarykey = true; + Check.Exception(item.DataType == "integer", "Identity only integer type"); } } } 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; } @@ -223,12 +221,13 @@ namespace SqlSugar } string dataSize = item.Length > 0 ? string.Format("({0})", item.Length) : null; string nullType = item.IsNullable ? this.CreateTableNull : CreateTableNotNull; - string primaryKey = null; + string primaryKey = item.IsPrimarykey?this.CreateTablePirmaryKey: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)); + tableString = tableString.Replace("`", "\""); return tableString; } public override bool IsAnyConstraint(string constraintName) diff --git a/Src/Asp.Net/SqliteTest/Config.cs b/Src/Asp.Net/SqliteTest/Config.cs index f9eff003e..a9f84d953 100644 --- a/Src/Asp.Net/SqliteTest/Config.cs +++ b/Src/Asp.Net/SqliteTest/Config.cs @@ -8,6 +8,6 @@ namespace OrmTest { public class Config { - public static string ConnectionString = "DataSource=" + System.AppDomain.CurrentDomain.BaseDirectory + "DataBase\\SqlSugar4xTest.sqlite"; + public static string ConnectionString = "DataSource=F:\\MyOpenSource\\SqlSugar4.XNew\\SqlSugar\\Src\\Asp.Net\\SqliteTest\\DataBase\\\\SqlSugar4xTest.sqlite"; } } diff --git a/Src/Asp.Net/SqliteTest/DataBase/SqlSugar4xTest.sqlite b/Src/Asp.Net/SqliteTest/DataBase/SqlSugar4xTest.sqlite index 303fb68a98dc715077082121d571597afd67a03f..9e1add14f02e13560bdb806e68abcdab8271d8e8 100644 GIT binary patch literal 73728 zcmeI*O-~v@7{KvafiCz0YHWx#jU$&z)I_izdT3Irq#;GLh)p~hgtZb8A}o!kHrgKg z4Vrl9t>2`Fp85%TYtmDbUcA&(X91BVVvNB=^bdL1g_)gw=C@=XhzYK~iswv2ZWT+r zX;aRLL7{2lnUq3k9wEfAivD`MQ(LEs)0=j>(|)VQnECfs3KdR*vn_aFC;_q%@V z-qGXd-P?~u3jzora3=)%ldfNPVxkvMvOnqkd2x@M)w=TNo_}geTQ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