|
@ -398,15 +398,16 @@ namespace Apewer.Source |
|
|
/// <summary>简单查询:取结果中第 0 列所有单元格的文本形式,可指定查询后关闭服务器连接,返回结果中不包含无效文本。</summary>
|
|
|
/// <summary>简单查询:取结果中第 0 列所有单元格的文本形式,可指定查询后关闭服务器连接,返回结果中不包含无效文本。</summary>
|
|
|
/// <param name="source">数据库客户端。</param>
|
|
|
/// <param name="source">数据库客户端。</param>
|
|
|
/// <param name="sql">用于查询的 SQL 语句。</param>
|
|
|
/// <param name="sql">用于查询的 SQL 语句。</param>
|
|
|
|
|
|
/// <param name="parameters">SQL 参数。</param>
|
|
|
/// <exception cref="SqlException"></exception>
|
|
|
/// <exception cref="SqlException"></exception>
|
|
|
public static string[] Column(this IDbAdo source, string sql) |
|
|
public static string[] Column(this IDbAdo source, string sql, object parameters = null) |
|
|
{ |
|
|
{ |
|
|
if (source == null) return new string[0]; |
|
|
if (source == null) return new string[0]; |
|
|
|
|
|
|
|
|
var pool = null as string[]; |
|
|
var pool = null as string[]; |
|
|
var rows = 0; |
|
|
var rows = 0; |
|
|
var count = 0; |
|
|
var count = 0; |
|
|
using (var query = source.Query(sql)) |
|
|
using (var query = source.Query(sql, parameters)) |
|
|
{ |
|
|
{ |
|
|
if (!query.Success) throw new SqlException(query, sql); |
|
|
if (!query.Success) throw new SqlException(query, sql); |
|
|
|
|
|
|
|
@ -435,14 +436,15 @@ namespace Apewer.Source |
|
|
/// <summary>简单查询:取结果中第 0 行、第 0 列单元格中的文本,可指定查询后关闭服务器连接。</summary>
|
|
|
/// <summary>简单查询:取结果中第 0 行、第 0 列单元格中的文本,可指定查询后关闭服务器连接。</summary>
|
|
|
/// <param name="dbClient">数据库客户端。</param>
|
|
|
/// <param name="dbClient">数据库客户端。</param>
|
|
|
/// <param name="sql">用于查询的 SQL 语句。</param>
|
|
|
/// <param name="sql">用于查询的 SQL 语句。</param>
|
|
|
|
|
|
/// <param name="parameters">SQL 参数。</param>
|
|
|
/// <exception cref="ArgumentNullException"></exception>
|
|
|
/// <exception cref="ArgumentNullException"></exception>
|
|
|
/// <exception cref="SqlException"></exception>
|
|
|
/// <exception cref="SqlException"></exception>
|
|
|
public static string Cell(this IDbAdo dbClient, string sql) |
|
|
public static string Cell(this IDbAdo dbClient, string sql, object parameters = null) |
|
|
{ |
|
|
{ |
|
|
if (dbClient == null) throw new ArgumentNullException(nameof(dbClient)); |
|
|
if (dbClient == null) throw new ArgumentNullException(nameof(dbClient)); |
|
|
if (sql.IsEmpty()) throw new ArgumentNullException(nameof(sql)); |
|
|
if (sql.IsEmpty()) throw new ArgumentNullException(nameof(sql)); |
|
|
|
|
|
|
|
|
using (var query = dbClient.Query(sql)) |
|
|
using (var query = dbClient.Query(sql, parameters)) |
|
|
{ |
|
|
{ |
|
|
if (!query.Success) throw new SqlException(query, sql); |
|
|
if (!query.Success) throw new SqlException(query, sql); |
|
|
var value = TextUtility.Trim(query.Text(0, 0)); |
|
|
var value = TextUtility.Trim(query.Text(0, 0)); |
|
@ -479,7 +481,7 @@ namespace Apewer.Source |
|
|
var ps = Parameters(dbClient, sql, kvps); |
|
|
var ps = Parameters(dbClient, sql, kvps); |
|
|
return dbClient.Query(sql, ps); |
|
|
return dbClient.Query(sql, ps); |
|
|
} |
|
|
} |
|
|
|
|
|
else |
|
|
{ |
|
|
{ |
|
|
var ps = ParametersByProperites(dbClient, sql, parameters); |
|
|
var ps = ParametersByProperites(dbClient, sql, parameters); |
|
|
return dbClient.Query(sql, ps); |
|
|
return dbClient.Query(sql, ps); |
|
@ -522,6 +524,38 @@ namespace Apewer.Source |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>查询。</summary>
|
|
|
|
|
|
/// <param name="dbClient">数据库连接。</param>
|
|
|
|
|
|
/// <param name="sql">SQL 语句。</param>
|
|
|
|
|
|
/// <param name="parameters">参数容器,每个属性表示一个 SQL 参数。此方法将会自动补足参数名称的 @ 前缀。</param>
|
|
|
|
|
|
/// <exception cref="ArgumentNullException"></exception>
|
|
|
|
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
|
|
|
|
public static T[] Query<T>(this IDbOrm dbClient, string sql, object parameters = null) where T : class, new() |
|
|
|
|
|
{ |
|
|
|
|
|
if (dbClient == null) throw new ArgumentNullException(nameof(dbClient)); |
|
|
|
|
|
if (sql.IsEmpty()) throw new ArgumentNullException(nameof(sql)); |
|
|
|
|
|
|
|
|
|
|
|
if (dbClient is IDbAdo ado) |
|
|
|
|
|
{ |
|
|
|
|
|
if (parameters is IEnumerable<KeyValuePair<string, object>> kvps) |
|
|
|
|
|
{ |
|
|
|
|
|
var ps = Parameters(ado, sql, kvps); |
|
|
|
|
|
return dbClient.Query<T>(sql, ps); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
var ps = ParametersByProperites(ado, sql, parameters); |
|
|
|
|
|
return dbClient.Query<T>(sql, ps); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
throw new NotImplementedException($"连接未实现 {nameof(IDbAdo)} 接口,无法创建参数。"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
#region Execute
|
|
|
#region Execute
|
|
|