Browse Source

Update access

pull/14/head
sunkaixuan 3 years ago
parent
commit
da635e9a8f
  1. BIN
      Src/Asp.Net/AccessTest/Test.accdb
  2. 46
      Src/Asp.Net/SqlSugar.Access/Access/DbMaintenance/AccessDbMaintenance.cs
  3. 21
      Src/Asp.Net/SqlSugar.Access/Access/SqlBuilder/AccessInsertBuilder.cs
  4. 7
      Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs

BIN
Src/Asp.Net/AccessTest/Test.accdb

Binary file not shown.

46
Src/Asp.Net/SqlSugar.Access/Access/DbMaintenance/AccessDbMaintenance.cs

@ -437,9 +437,49 @@ namespace SqlSugar.Access
} }
public override List<DbColumnInfo> GetColumnInfosByTableName(string tableName, bool isCache = true) public override List<DbColumnInfo> GetColumnInfosByTableName(string tableName, bool isCache = true)
{ {
tableName = SqlBuilder.GetNoTranslationColumnName(tableName); List<DbColumnInfo> columns = new List<DbColumnInfo>();
var result= base.GetColumnInfosByTableName(tableName, isCache); var dt = this.Context.Ado.GetDataTable("select top 8 * from " +this.SqlBuilder.GetTranslationTableName(tableName));
return result; 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) public override bool RenameColumn(string tableName, string oldColumnName, string newColumnName)
{ {

21
Src/Asp.Net/SqlSugar.Access/Access/SqlBuilder/AccessInsertBuilder.cs

@ -8,6 +8,27 @@ namespace SqlSugar.Access
{ {
public class AccessInsertBuilder : InsertBuilder 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() public override string ToSqlString()
{ {
if (IsNoInsertNull) if (IsNoInsertNull)

7
Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs

@ -400,8 +400,15 @@ namespace SqlSugar
{ {
return false; return false;
} }
if (properyTypeName == null || dataType == null)
{
return properyTypeName != dataType; return properyTypeName != dataType;
} }
else
{
return properyTypeName.ToLower() != dataType.ToLower();
}
}
private static string GetType(string name) private static string GetType(string name)
{ {
if (name.IsContainsIn("UInt32", "UInt16", "UInt64")) if (name.IsContainsIn("UInt32", "UInt16", "UInt64"))

Loading…
Cancel
Save