mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-24 16:18:47 +08:00
Update Sqlite
This commit is contained in:
parent
6068fe29b6
commit
4ce9c9c0cf
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
@ -12,39 +13,21 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
string sql = @"SELECT
|
throw new NotSupportedException();
|
||||||
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
|
protected override string GetTableInfoListSql
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return @"select TABLE_NAME as Name,TABLE_COMMENT as Description from information_schema.tables
|
return @"select Name from sqlite_master where type='table' order by name;";
|
||||||
where TABLE_SCHEMA=(select database()) AND TABLE_TYPE='BASE TABLE'";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected override string GetViewInfoListSql
|
protected override string GetViewInfoListSql
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return @"select TABLE_NAME as Name,TABLE_COMMENT as Description from information_schema.tables
|
return @"select Name from sqlite_master where type='view' order by name;";
|
||||||
where TABLE_SCHEMA=(select database()) AND TABLE_TYPE='VIEW'
|
|
||||||
";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@ -179,6 +162,40 @@ namespace SqlSugar
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
public override List<DbColumnInfo> GetColumnInfosByTableName(string tableName)
|
||||||
|
{
|
||||||
|
string cacheKey = "DbMaintenanceProvider.GetColumnInfosByTableName." + this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
|
||||||
|
return this.Context.RewritableMethods.GetCacheInstance<List<DbColumnInfo>>().Func(cacheKey,
|
||||||
|
(cm, key) =>
|
||||||
|
{
|
||||||
|
return cm[cacheKey];
|
||||||
|
|
||||||
|
}, (cm, key) =>
|
||||||
|
{
|
||||||
|
List<DbColumnInfo> result = new List<DbColumnInfo>();
|
||||||
|
using (var dr = this.Context.Ado.GetDataReader("select * from " + tableName + " limit 0,1"))
|
||||||
|
{
|
||||||
|
var schemaTable = dr.GetSchemaTable();
|
||||||
|
foreach (DataRow row in schemaTable.Rows)
|
||||||
|
{
|
||||||
|
DbColumnInfo column = new DbColumnInfo()
|
||||||
|
{
|
||||||
|
TableName = tableName,
|
||||||
|
DataType = dr["DataTypeName"].ToString().Trim(),
|
||||||
|
IsNullable = (bool)dr["AllowDBNull"],
|
||||||
|
IsIdentity = (bool)dr["IsAutoIncrement"],
|
||||||
|
ColumnDescription = null,
|
||||||
|
DbColumnName = dr["ColumnName"].ToString(),
|
||||||
|
DefaultValue = dr["defultValue"].ToString(),
|
||||||
|
IsPrimarykey = (bool)dr["IsKey"],
|
||||||
|
Length = Convert.ToInt32(dr["ColumnSize"])
|
||||||
|
};
|
||||||
|
result.Add(column);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
}
|
||||||
public override bool CreateTable(string tableName, List<DbColumnInfo> columns)
|
public override bool CreateTable(string tableName, List<DbColumnInfo> columns)
|
||||||
{
|
{
|
||||||
if (columns.IsValuable())
|
if (columns.IsValuable())
|
||||||
@ -193,7 +210,8 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
string sql = GetCreateTableSql(tableName, columns);
|
string sql = GetCreateTableSql(tableName, columns);
|
||||||
string primaryKeyInfo = null;
|
string primaryKeyInfo = null;
|
||||||
if (columns.Any(it => it.IsIdentity)) {
|
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))));
|
primaryKeyInfo = string.Format(", Primary key({0})", string.Join(",", columns.Where(it => it.IsIdentity).Select(it => this.SqlBuilder.GetTranslationColumnName(it.DbColumnName))));
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -209,7 +227,8 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
string columnName = item.DbColumnName;
|
string columnName = item.DbColumnName;
|
||||||
string dataType = item.DataType;
|
string dataType = item.DataType;
|
||||||
if (dataType == "varchar"&& item.Length==0) {
|
if (dataType == "varchar" && item.Length == 0)
|
||||||
|
{
|
||||||
item.Length = 1;
|
item.Length = 1;
|
||||||
}
|
}
|
||||||
string dataSize = item.Length > 0 ? string.Format("({0})", item.Length) : null;
|
string dataSize = item.Length > 0 ? string.Format("({0})", item.Length) : null;
|
||||||
@ -231,6 +250,22 @@ namespace SqlSugar
|
|||||||
Check.ThrowNotSupportedException("MySql BackupDataBase NotSupported");
|
Check.ThrowNotSupportedException("MySql BackupDataBase NotSupported");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
private List<T> GetListOrCache<T>(string cacheKey, string sql)
|
||||||
|
{
|
||||||
|
return this.Context.RewritableMethods.GetCacheInstance<List<T>>().Func(cacheKey,
|
||||||
|
(cm, key) =>
|
||||||
|
{
|
||||||
|
return cm[cacheKey];
|
||||||
|
|
||||||
|
}, (cm, key) =>
|
||||||
|
{
|
||||||
|
var isEnableLogEvent = this.Context.Ado.IsEnableLogEvent;
|
||||||
|
this.Context.Ado.IsEnableLogEvent = false;
|
||||||
|
var reval = this.Context.Ado.SqlQuery<T>(sql);
|
||||||
|
this.Context.Ado.IsEnableLogEvent = isEnableLogEvent;
|
||||||
|
return reval;
|
||||||
|
});
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
return @"INSERT INTO {0}
|
return @"INSERT INTO {0}
|
||||||
({1})
|
({1})
|
||||||
VALUES
|
VALUES
|
||||||
({2}) ;SELECT LAST_INSERT_ID();";
|
({2}) ;SELECT LAST_INSERT_ROWID();";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
BIN
Src/Asp.Net/SqliteTest/DataBase/SqlSugar4xTest.sqlite
Normal file
BIN
Src/Asp.Net/SqliteTest/DataBase/SqlSugar4xTest.sqlite
Normal file
Binary file not shown.
@ -1,10 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
<ProjectGuid>d48622b3-f4cd-45cd-b1c9-868083037ecd</ProjectGuid>
|
<ProjectGuid>{D48622B3-F4CD-45CD-B1C9-868083037ECD}</ProjectGuid>
|
||||||
<OutputType>Library</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
<RootNamespace>SqliteTest</RootNamespace>
|
<RootNamespace>SqliteTest</RootNamespace>
|
||||||
@ -31,24 +31,29 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
|
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
|
|
||||||
|
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
|
|
||||||
<Reference Include="System.Net.Http" />
|
<Reference Include="System.Net.Http" />
|
||||||
|
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Class1.cs" />
|
<Compile Include="Class1.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="DataBase\SqlSugar4xTest.sqlite" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="x64\SQLite.Interop.dll">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
<Content Include="x86\SQLite.Interop.dll">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
@ -57,5 +62,4 @@
|
|||||||
<Target Name="AfterBuild">
|
<Target Name="AfterBuild">
|
||||||
</Target>
|
</Target>
|
||||||
-->
|
-->
|
||||||
|
|
||||||
</Project>
|
</Project>
|
Loading…
Reference in New Issue
Block a user