Browse Source

Update Sqlite

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
8107ed3c44
  1. 2
      Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs
  2. 21
      Src/Asp.Net/SqlSugar/Realization/Sqlite/CodeFirst/SqliteCodeFirst.cs
  3. 2
      Src/Asp.Net/SqlSugar/Realization/Sqlite/DbBind/SqliteDbBind.cs
  4. 23
      Src/Asp.Net/SqlSugar/Realization/Sqlite/DbMaintenance/SqliteDbMaintenance.cs
  5. 2
      Src/Asp.Net/SqliteTest/Config.cs
  6. BIN
      Src/Asp.Net/SqliteTest/DataBase/SqlSugar4xTest.sqlite
  7. 24
      Src/Asp.Net/SqliteTest/DataBase/X.sql
  8. 4
      Src/Asp.Net/SqliteTest/Program.cs
  9. 4
      Src/Asp.Net/SqliteTest/SqliteTest.csproj

2
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;
}

21
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<DbColumnInfo> columns = new List<DbColumnInfo>();
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<DbColumnInfo> columns = new List<DbColumnInfo>();
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)

2
Src/Asp.Net/SqlSugar/Realization/Sqlite/DbBind/SqliteDbBind.cs

@ -30,8 +30,8 @@ namespace SqlSugar
return new List<KeyValuePair<string, CSharpDataType>>()
{
new KeyValuePair<string, CSharpDataType>("int",CSharpDataType.@int),
new KeyValuePair<string, CSharpDataType>("integer",CSharpDataType.@int),
new KeyValuePair<string, CSharpDataType>("int",CSharpDataType.@int),
new KeyValuePair<string, CSharpDataType>("int32",CSharpDataType.@int),
new KeyValuePair<string, CSharpDataType>("integer32",CSharpDataType.@int),

23
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)

2
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";
}
}

BIN
Src/Asp.Net/SqliteTest/DataBase/SqlSugar4xTest.sqlite

Binary file not shown.

24
Src/Asp.Net/SqliteTest/DataBase/X.sql

@ -0,0 +1,24 @@
/*
Navicat SQLite Data Transfer
Source Server : x
Source Server Version : 30714
Source Host : :0
Target Server Type : SQLite
Target Server Version : 30714
File Encoding : 65001
Date: 2017-07-09 17:02:41
*/
PRAGMA foreign_keys = OFF;
-- ----------------------------
-- Table structure for X
-- ----------------------------
DROP TABLE IF EXISTS "main"."X";
CREATE TABLE "X" (
"T" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
"x" time
);

4
Src/Asp.Net/SqliteTest/Program.cs

@ -39,11 +39,11 @@ namespace OrmTest
//OrmTest.Demo.Insert.Init();
//OrmTest.Demo.Delete.Init();
//OrmTest.Demo.Update.Init();
OrmTest.Demo.DbFirst.Init();
//OrmTest.Demo.DbFirst.Init();
//OrmTest.Demo.JoinSql.Init();
//OrmTest.Demo.Filter.Init();
//OrmTest.Demo.ComplexModel.Init();
//OrmTest.Demo.CodeFirst.Init();
OrmTest.Demo.CodeFirst.Init();
}
}
}

4
Src/Asp.Net/SqliteTest/SqliteTest.csproj

@ -91,9 +91,7 @@
<Compile Include="UnitTest\Update.cs" />
</ItemGroup>
<ItemGroup>
<None Include="DataBase\SqlSugar4xTest.sqlite">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="DataBase\SqlSugar4xTest.sqlite" />
</ItemGroup>
<ItemGroup>
<Content Include="OtherDll\SyntacticSugar.dll" />

Loading…
Cancel
Save