From da635e9a8fc7a9b20413797de16ea28dd57ed9b2 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sun, 20 Feb 2022 22:37:22 +0800 Subject: [PATCH] Update access --- Src/Asp.Net/AccessTest/Test.accdb | Bin 491520 -> 491520 bytes .../DbMaintenance/AccessDbMaintenance.cs | 46 ++++++++++++++++-- .../Access/SqlBuilder/AccessInsertBuilder.cs | 21 ++++++++ .../CodeFirstProvider/CodeFirstProvider.cs | 9 +++- 4 files changed, 72 insertions(+), 4 deletions(-) diff --git a/Src/Asp.Net/AccessTest/Test.accdb b/Src/Asp.Net/AccessTest/Test.accdb index 99bf99ba7003a4de9ae069530a97f26cea8fa1e2..73895f8e7646dc9c6d0bc25c734df71890219d84 100644 GIT binary patch delta 53 zcmZo@kZWj=+rY%fD6m*yW1wOtefi?lgHUXwK0p>OVmNo&_HUYM60_-9VjBMLQ J1K3~d0|0nf4KDxy delta 56 zcmZo@kZWj=+rY%f$hKLK?>*yW1wOtefi?lgHUXwK0p>OVmNo&_HUYM60_-9V)58N; Mc(*GCu;14Q0HkdWZ2$lO diff --git a/Src/Asp.Net/SqlSugar.Access/Access/DbMaintenance/AccessDbMaintenance.cs b/Src/Asp.Net/SqlSugar.Access/Access/DbMaintenance/AccessDbMaintenance.cs index cacc47eca..fad996fcf 100644 --- a/Src/Asp.Net/SqlSugar.Access/Access/DbMaintenance/AccessDbMaintenance.cs +++ b/Src/Asp.Net/SqlSugar.Access/Access/DbMaintenance/AccessDbMaintenance.cs @@ -437,9 +437,49 @@ namespace SqlSugar.Access } public override List GetColumnInfosByTableName(string tableName, bool isCache = true) { - tableName = SqlBuilder.GetNoTranslationColumnName(tableName); - var result= base.GetColumnInfosByTableName(tableName, isCache); - return result; + List columns = new List(); + var dt = this.Context.Ado.GetDataTable("select top 8 * from " +this.SqlBuilder.GetTranslationTableName(tableName)); + var oleDb = (this.Context.Ado.Connection as OleDbConnection); + DataTable columnTable = oleDb.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, new object[] { null, null,tableName, null }); + DataTable Pk = oleDb.GetOleDbSchemaTable(OleDbSchemaGuid.Primary_Keys, new string[] { null, null, tableName }); + foreach (DataRow dr in columnTable.Rows) + { + DbColumnInfo info = new DbColumnInfo(); + info.TableName = tableName; + info.DbColumnName = dr["COLUMN_NAME"] + ""; + info.IsNullable = Convert.ToBoolean(dr["IS_NULLABLE"]); + info.DataType = dt.Columns[info.DbColumnName].DataType.Name; + if (info.DataType.EqualCase( "int32")) + { + info.DataType = "int"; + } + else if (info.DataType.EqualCase("int64")) + { + info.DataType = "long"; + } + if (info.DataType.EqualCase("string") ) + { + info.Length = dr["CHARACTER_MAXIMUM_LENGTH"].ObjToInt(); + } + if (info.DataType.EqualCase("Decimal")) + { + info.Length = dr["numeric_precision"].ObjToInt(); + info.Scale=info.DecimalDigits = dr["numeric_scale"].ObjToInt(); + } + foreach (DataRow pkRow in Pk.Rows) + { + if (pkRow["COLUMN_NAME"].ObjToString() == dr["COLUMN_NAME"].ObjToString()) + { + info.IsPrimarykey = true; + if (info.DataType == "int") + { + info.IsIdentity = true; + } + } + } + columns.Add(info); + } + return columns; } public override bool RenameColumn(string tableName, string oldColumnName, string newColumnName) { diff --git a/Src/Asp.Net/SqlSugar.Access/Access/SqlBuilder/AccessInsertBuilder.cs b/Src/Asp.Net/SqlSugar.Access/Access/SqlBuilder/AccessInsertBuilder.cs index 2126e2ea8..d8d132a1a 100644 --- a/Src/Asp.Net/SqlSugar.Access/Access/SqlBuilder/AccessInsertBuilder.cs +++ b/Src/Asp.Net/SqlSugar.Access/Access/SqlBuilder/AccessInsertBuilder.cs @@ -8,6 +8,27 @@ namespace SqlSugar.Access { public class AccessInsertBuilder : InsertBuilder { + public override string SqlTemplate + { + get + { + if (IsReturnIdentity) + { + return @"INSERT INTO {0} + ({1}) + VALUES + ({2}) ;"; + } + else + { + return @"INSERT INTO {0} + ({1}) + VALUES + ({2}) ;"; + + } + } + } public override string ToSqlString() { if (IsNoInsertNull) diff --git a/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs index bbdeba555..ea3c6f3d3 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs @@ -400,7 +400,14 @@ namespace SqlSugar { return false; } - return properyTypeName != dataType; + if (properyTypeName == null || dataType == null) + { + return properyTypeName != dataType; + } + else + { + return properyTypeName.ToLower() != dataType.ToLower(); + } } private static string GetType(string name) {