mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
Update Sqlite
This commit is contained in:
parent
d9866b8064
commit
8107ed3c44
@ -192,7 +192,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
oldTableName = this.SqlBuilder.GetTranslationTableName(oldTableName);
|
oldTableName = this.SqlBuilder.GetTranslationTableName(oldTableName);
|
||||||
newTableName = this.SqlBuilder.GetTranslationTableName(newTableName);
|
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);
|
this.Context.Ado.ExecuteCommand(sql);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,10 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
public class SqliteCodeFirst : CodeFirstProvider
|
public class SqliteCodeFirst : CodeFirstProvider
|
||||||
{
|
{
|
||||||
public override void NoExistLogic(EntityInfo entityInfo)
|
public override void ExistLogic(EntityInfo entityInfo)
|
||||||
{
|
{
|
||||||
var tableName = GetTableName(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");
|
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>();
|
List<DbColumnInfo> columns = new List<DbColumnInfo>();
|
||||||
if (entityInfo.Columns.IsValuable())
|
if (entityInfo.Columns.IsValuable())
|
||||||
@ -20,6 +21,24 @@ namespace SqlSugar
|
|||||||
columns.Add(dbColumnInfo);
|
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);
|
this.Context.DbMaintenance.CreateTable(tableName, columns);
|
||||||
}
|
}
|
||||||
protected override DbColumnInfo EntityColumnToDbColumn(EntityInfo entityInfo, string tableName, EntityColumnInfo item)
|
protected override DbColumnInfo EntityColumnToDbColumn(EntityInfo entityInfo, string tableName, EntityColumnInfo item)
|
||||||
|
@ -30,8 +30,8 @@ namespace SqlSugar
|
|||||||
return new List<KeyValuePair<string, CSharpDataType>>()
|
return new List<KeyValuePair<string, CSharpDataType>>()
|
||||||
{
|
{
|
||||||
|
|
||||||
new KeyValuePair<string, CSharpDataType>("int",CSharpDataType.@int),
|
|
||||||
new KeyValuePair<string, CSharpDataType>("integer",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>("int32",CSharpDataType.@int),
|
||||||
new KeyValuePair<string, CSharpDataType>("integer32",CSharpDataType.@int),
|
new KeyValuePair<string, CSharpDataType>("integer32",CSharpDataType.@int),
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
throw new NotSupportedException();
|
return " CREATE TABLE {0} AS SELECT * FROM {1} limit 0,{2}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected override string DropTableSql
|
protected override string DropTableSql
|
||||||
@ -110,7 +110,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return "ALTER TABLE {0} drop primary key;";
|
throw new NotSupportedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected override string RenameColumnSql
|
protected override string RenameColumnSql
|
||||||
@ -182,7 +182,7 @@ namespace SqlSugar
|
|||||||
this.Context.Ado.IsEnableLogEvent = oldIsEnableLog;
|
this.Context.Ado.IsEnableLogEvent = oldIsEnableLog;
|
||||||
return AdoCore.GetColumnInfosByTableName(tableName, reader);
|
return AdoCore.GetColumnInfosByTableName(tableName, reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,18 +194,16 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
if (item.DbColumnName.Equals("GUID", StringComparison.CurrentCultureIgnoreCase))
|
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 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);
|
this.Context.Ado.ExecuteCommand(sql);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -223,12 +221,13 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
string dataSize = item.Length > 0 ? string.Format("({0})", item.Length) : null;
|
string dataSize = item.Length > 0 ? string.Format("({0})", item.Length) : null;
|
||||||
string nullType = item.IsNullable ? this.CreateTableNull : CreateTableNotNull;
|
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 identity = item.IsIdentity ? this.CreateTableIdentity : null;
|
||||||
string addItem = string.Format(this.CreateTableColumn, this.SqlBuilder.GetTranslationColumnName(columnName), dataType, dataSize, nullType, primaryKey, identity);
|
string addItem = string.Format(this.CreateTableColumn, this.SqlBuilder.GetTranslationColumnName(columnName), dataType, dataSize, nullType, primaryKey, identity);
|
||||||
columnArray.Add(addItem);
|
columnArray.Add(addItem);
|
||||||
}
|
}
|
||||||
string tableString = string.Format(this.CreateTableSql, this.SqlBuilder.GetTranslationTableName(tableName), string.Join(",\r\n", columnArray));
|
string tableString = string.Format(this.CreateTableSql, this.SqlBuilder.GetTranslationTableName(tableName), string.Join(",\r\n", columnArray));
|
||||||
|
tableString = tableString.Replace("`", "\"");
|
||||||
return tableString;
|
return tableString;
|
||||||
}
|
}
|
||||||
public override bool IsAnyConstraint(string constraintName)
|
public override bool IsAnyConstraint(string constraintName)
|
||||||
|
@ -8,6 +8,6 @@ namespace OrmTest
|
|||||||
{
|
{
|
||||||
public class Config
|
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";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
24
Src/Asp.Net/SqliteTest/DataBase/X.sql
Normal file
24
Src/Asp.Net/SqliteTest/DataBase/X.sql
Normal file
@ -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
|
||||||
|
);
|
@ -39,11 +39,11 @@ namespace OrmTest
|
|||||||
//OrmTest.Demo.Insert.Init();
|
//OrmTest.Demo.Insert.Init();
|
||||||
//OrmTest.Demo.Delete.Init();
|
//OrmTest.Demo.Delete.Init();
|
||||||
//OrmTest.Demo.Update.Init();
|
//OrmTest.Demo.Update.Init();
|
||||||
OrmTest.Demo.DbFirst.Init();
|
//OrmTest.Demo.DbFirst.Init();
|
||||||
//OrmTest.Demo.JoinSql.Init();
|
//OrmTest.Demo.JoinSql.Init();
|
||||||
//OrmTest.Demo.Filter.Init();
|
//OrmTest.Demo.Filter.Init();
|
||||||
//OrmTest.Demo.ComplexModel.Init();
|
//OrmTest.Demo.ComplexModel.Init();
|
||||||
//OrmTest.Demo.CodeFirst.Init();
|
OrmTest.Demo.CodeFirst.Init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,9 +91,7 @@
|
|||||||
<Compile Include="UnitTest\Update.cs" />
|
<Compile Include="UnitTest\Update.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="DataBase\SqlSugar4xTest.sqlite">
|
<None Include="DataBase\SqlSugar4xTest.sqlite" />
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="OtherDll\SyntacticSugar.dll" />
|
<Content Include="OtherDll\SyntacticSugar.dll" />
|
||||||
|
Loading…
Reference in New Issue
Block a user