Browse Source

Access,修正获取表名的 TableNames 方法。

master
王厅 1 month ago
parent
commit
a9b30cc32b
  1. 51
      Apewer.Source/Source/Access.cs
  2. 6
      Apewer.Source/Source/DbClient.cs

51
Apewer.Source/Source/Access.cs

@ -21,6 +21,9 @@ namespace Apewer.Source
/// <remarks>当操作系统启用随机化内存分配时,此方法可能会产生异常。</remarks>
public static string[] ParsePassword(string path) => AccessHelper.GetPassword(path);
/// <summary>数据库文件路径。</summary>
public virtual string Path { get; protected set; }
}
#if NETFRAMEWORK
@ -79,7 +82,33 @@ namespace Apewer.Source
public override string[] StoreNames() => throw new InvalidOperationException();
/// <summary></summary>
public override string[] TableNames() => QueryStrings("select name from msysobjects where type=1 and flags = 0");
public override string[] TableNames()
{
// QueryStrings("select name from msysobjects where type=1 and flags = 0");
Connect();
var schema = _conn.GetSchema("Tables");
using (var query = new Query(schema))
{
var json = query.ToJson();
var names = new List<string>();
for (var i = 0; i < query.Rows; i++)
{
var type = query.Text(i, "TABLE_TYPE");
var name = query.Text(i, "TABLE_NAME");
switch (type)
{
case "ACCESS TABLE":
case "SYSTEM TABLE":
break;
case "TABLE":
names.Add(name);
break;
}
}
names.Sort();
return names.ToArray();
}
}
/// <summary></summary>
public override string Insert(object record, string table = null, bool adjust = true)
@ -494,12 +523,18 @@ namespace Apewer.Source
/// <summary>创建 Access 类的新实例。</summary>
/// <exception cref="FileNotFoundException"></exception>
public AccessJet4(string path, string pass = null, string jo = null, Timeout timeout = null)
: base(GenerateCS(JetOleDB4, path, pass, jo), timeout) { }
: base(GenerateCS(JetOleDB4, path, pass, jo), timeout)
{
Path = path;
}
/// <summary>使用连接字符串创建数据库连接实例。</summary>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="ArgumentException"></exception>
public AccessJet4(IDbConnection connection, Timeout timeout = null) : base(connection, timeout) { }
public AccessJet4(IDbConnection connection, Timeout timeout = null) : base(connection, timeout)
{
Path = (connection as Access)?.Path;
}
}
@ -512,12 +547,18 @@ namespace Apewer.Source
/// <summary>创建 Access 类的新实例。</summary>
/// <exception cref="FileNotFoundException"></exception>
public AccessAce12(string path, string pass = null, string jo = null, Timeout timeout = null)
: base(GenerateCS(AceOleDB12, path, pass, jo), timeout) { }
: base(GenerateCS(AceOleDB12, path, pass, jo), timeout)
{
Path = path;
}
/// <summary>使用连接字符串创建数据库连接实例。</summary>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="ArgumentException"></exception>
public AccessAce12(IDbConnection connection, Timeout timeout = null) : base(connection, timeout) { }
public AccessAce12(IDbConnection connection, Timeout timeout = null) : base(connection, timeout)
{
Path = (connection as Access)?.Path;
}
}

6
Apewer.Source/Source/DbClient.cs

@ -102,7 +102,11 @@ namespace Apewer.Source
}
var connect = Connect();
if (connect.NotEmpty()) return connect;
if (connect.NotEmpty())
{
if (ThrowAdoException) throw new Exception(connect);
return connect;
}
try
{

Loading…
Cancel
Save