|
|
|
@ -2,6 +2,7 @@ |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Data; |
|
|
|
using System.Reflection; |
|
|
|
using System.Runtime.InteropServices.ComTypes; |
|
|
|
using System.Text; |
|
|
|
|
|
|
|
namespace Apewer.Source |
|
|
|
@ -598,7 +599,6 @@ namespace Apewer.Source |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>查询。</summary>
|
|
|
|
/// <param name="dbClient">数据库连接。</param>
|
|
|
|
/// <param name="sql">SQL 语句。</param>
|
|
|
|
@ -629,6 +629,353 @@ namespace Apewer.Source |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#if !NET20
|
|
|
|
|
|
|
|
/// <summary>执行查询,将结果输出为元组数组。</summary>
|
|
|
|
/// <typeparam name="T">元组中的值类型。</typeparam>
|
|
|
|
/// <param name="dbClient">数据库连接。</param>
|
|
|
|
/// <param name="sql">SQL 语句。</param>
|
|
|
|
/// <param name="parameters">SQL 参数。</param>
|
|
|
|
/// <param name="getValue">获取第一个值的回调函数。</param>
|
|
|
|
/// <returns>由元组组成的数组。</returns>
|
|
|
|
/// <exception cref="ArgumentNullException"></exception>
|
|
|
|
/// <exception cref="SqlException"></exception>
|
|
|
|
public static Tuple<T>[] Query<T>(this IDbAdo dbClient, string sql, object parameters, Func<object, T> getValue) |
|
|
|
{ |
|
|
|
if (dbClient == null) throw new ArgumentNullException(nameof(dbClient)); |
|
|
|
if (sql.IsEmpty()) throw new ArgumentNullException(nameof(sql)); |
|
|
|
if (getValue == null) throw new ArgumentNullException(nameof(getValue)); |
|
|
|
|
|
|
|
using (var query = dbClient.Query(sql, parameters)) |
|
|
|
{ |
|
|
|
if (!query.Success) throw new SqlException(query, sql); |
|
|
|
|
|
|
|
var tuples = new Tuple<T>[query.Rows]; |
|
|
|
for (var i = 0; i < query.Rows; i++) |
|
|
|
{ |
|
|
|
var value1 = getValue(query.Value(i, 0)); |
|
|
|
tuples[i] = new Tuple<T>(value1); |
|
|
|
} |
|
|
|
return tuples; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>执行查询,将结果输出为元组数组。</summary>
|
|
|
|
/// <param name="dbClient">数据库连接。</param>
|
|
|
|
/// <param name="sql">SQL 语句。</param>
|
|
|
|
/// <param name="parameters">SQL 参数。</param>
|
|
|
|
/// <param name="getValue1">获取第一个值的回调函数。</param>
|
|
|
|
/// <param name="getValue2">获取第二个值的回调函数。</param>
|
|
|
|
/// <returns>由元组组成的数组。</returns>
|
|
|
|
/// <exception cref="ArgumentNullException"></exception>
|
|
|
|
/// <exception cref="SqlException"></exception>
|
|
|
|
public static Tuple<T1, T2>[] Query<T1, T2>(this IDbAdo dbClient, string sql, object parameters, |
|
|
|
Func<object, T1> getValue1, |
|
|
|
Func<object, T2> getValue2) |
|
|
|
{ |
|
|
|
if (dbClient == null) throw new ArgumentNullException(nameof(dbClient)); |
|
|
|
if (sql.IsEmpty()) throw new ArgumentNullException(nameof(sql)); |
|
|
|
if (getValue1 == null) throw new ArgumentNullException(nameof(getValue1)); |
|
|
|
if (getValue2 == null) throw new ArgumentNullException(nameof(getValue2)); |
|
|
|
|
|
|
|
using (var query = dbClient.Query(sql, parameters)) |
|
|
|
{ |
|
|
|
if (!query.Success) throw new SqlException(query, sql); |
|
|
|
|
|
|
|
var tuples = new Tuple<T1, T2>[query.Rows]; |
|
|
|
for (var i = 0; i < query.Rows; i++) |
|
|
|
{ |
|
|
|
var v1 = getValue1(query.Value(i, 0)); |
|
|
|
var v2 = getValue2(query.Value(i, 1)); |
|
|
|
tuples[i] = new Tuple<T1, T2>(v1, v2); |
|
|
|
} |
|
|
|
return tuples; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>执行查询,将结果输出为元组数组。</summary>
|
|
|
|
/// <param name="dbClient">数据库连接。</param>
|
|
|
|
/// <param name="sql">SQL 语句。</param>
|
|
|
|
/// <param name="parameters">SQL 参数。</param>
|
|
|
|
/// <param name="getValue1">获取第一个值的回调函数。</param>
|
|
|
|
/// <param name="getValue2">获取第二个值的回调函数。</param>
|
|
|
|
/// <param name="getValue3">获取第三个值的回调函数。</param>
|
|
|
|
/// <returns>由元组组成的数组。</returns>
|
|
|
|
/// <exception cref="ArgumentNullException"></exception>
|
|
|
|
/// <exception cref="SqlException"></exception>
|
|
|
|
public static Tuple<T1, T2, T3>[] Query<T1, T2, T3>(this IDbAdo dbClient, string sql, object parameters, |
|
|
|
Func<object, T1> getValue1, |
|
|
|
Func<object, T2> getValue2, |
|
|
|
Func<object, T3> getValue3) |
|
|
|
{ |
|
|
|
if (dbClient == null) throw new ArgumentNullException(nameof(dbClient)); |
|
|
|
if (sql.IsEmpty()) throw new ArgumentNullException(nameof(sql)); |
|
|
|
if (getValue1 == null) throw new ArgumentNullException(nameof(getValue1)); |
|
|
|
if (getValue2 == null) throw new ArgumentNullException(nameof(getValue2)); |
|
|
|
if (getValue3 == null) throw new ArgumentNullException(nameof(getValue3)); |
|
|
|
|
|
|
|
using (var query = dbClient.Query(sql, parameters)) |
|
|
|
{ |
|
|
|
if (!query.Success) throw new SqlException(query, sql); |
|
|
|
|
|
|
|
var tuples = new Tuple<T1, T2, T3>[query.Rows]; |
|
|
|
for (var i = 0; i < query.Rows; i++) |
|
|
|
{ |
|
|
|
var v1 = getValue1(query.Value(i, 0)); |
|
|
|
var v2 = getValue2(query.Value(i, 1)); |
|
|
|
var v3 = getValue3(query.Value(i, 2)); |
|
|
|
tuples[i] = new Tuple<T1, T2, T3>(v1, v2, v3); |
|
|
|
} |
|
|
|
return tuples; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>执行查询,将结果输出为元组数组。</summary>
|
|
|
|
/// <param name="dbClient">数据库连接。</param>
|
|
|
|
/// <param name="sql">SQL 语句。</param>
|
|
|
|
/// <param name="parameters">SQL 参数。</param>
|
|
|
|
/// <param name="getValue1">获取第一个值的回调函数。</param>
|
|
|
|
/// <param name="getValue2">获取第二个值的回调函数。</param>
|
|
|
|
/// <param name="getValue3">获取第三个值的回调函数。</param>
|
|
|
|
/// <param name="getValue4">获取第四个值的回调函数。</param>
|
|
|
|
/// <returns>由元组组成的数组。</returns>
|
|
|
|
/// <exception cref="ArgumentNullException"></exception>
|
|
|
|
/// <exception cref="SqlException"></exception>
|
|
|
|
public static Tuple<T1, T2, T3, T4>[] Query<T1, T2, T3, T4>(this IDbAdo dbClient, string sql, object parameters, |
|
|
|
Func<object, T1> getValue1, |
|
|
|
Func<object, T2> getValue2, |
|
|
|
Func<object, T3> getValue3, |
|
|
|
Func<object, T4> getValue4) |
|
|
|
{ |
|
|
|
if (dbClient == null) throw new ArgumentNullException(nameof(dbClient)); |
|
|
|
if (sql.IsEmpty()) throw new ArgumentNullException(nameof(sql)); |
|
|
|
if (getValue1 == null) throw new ArgumentNullException(nameof(getValue1)); |
|
|
|
if (getValue2 == null) throw new ArgumentNullException(nameof(getValue2)); |
|
|
|
if (getValue3 == null) throw new ArgumentNullException(nameof(getValue3)); |
|
|
|
if (getValue4 == null) throw new ArgumentNullException(nameof(getValue4)); |
|
|
|
|
|
|
|
using (var query = dbClient.Query(sql, parameters)) |
|
|
|
{ |
|
|
|
if (!query.Success) throw new SqlException(query, sql); |
|
|
|
|
|
|
|
var tuples = new Tuple<T1, T2, T3, T4>[query.Rows]; |
|
|
|
for (var i = 0; i < query.Rows; i++) |
|
|
|
{ |
|
|
|
var v1 = getValue1(query.Value(i, 0)); |
|
|
|
var v2 = getValue2(query.Value(i, 1)); |
|
|
|
var v3 = getValue3(query.Value(i, 2)); |
|
|
|
var v4 = getValue4(query.Value(i, 3)); |
|
|
|
tuples[i] = new Tuple<T1, T2, T3, T4>(v1, v2, v3, v4); |
|
|
|
} |
|
|
|
return tuples; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>执行查询,将结果输出为元组数组。</summary>
|
|
|
|
/// <param name="dbClient">数据库连接。</param>
|
|
|
|
/// <param name="sql">SQL 语句。</param>
|
|
|
|
/// <param name="parameters">SQL 参数。</param>
|
|
|
|
/// <param name="getValue1">获取第一个值的回调函数。</param>
|
|
|
|
/// <param name="getValue2">获取第二个值的回调函数。</param>
|
|
|
|
/// <param name="getValue3">获取第三个值的回调函数。</param>
|
|
|
|
/// <param name="getValue4">获取第四个值的回调函数。</param>
|
|
|
|
/// <param name="getValue5">获取第五个值的回调函数。</param>
|
|
|
|
/// <returns>由元组组成的数组。</returns>
|
|
|
|
/// <exception cref="ArgumentNullException"></exception>
|
|
|
|
/// <exception cref="SqlException"></exception>
|
|
|
|
public static Tuple<T1, T2, T3, T4, T5>[] Query<T1, T2, T3, T4, T5>(this IDbAdo dbClient, string sql, object parameters, |
|
|
|
Func<object, T1> getValue1, |
|
|
|
Func<object, T2> getValue2, |
|
|
|
Func<object, T3> getValue3, |
|
|
|
Func<object, T4> getValue4, |
|
|
|
Func<object, T5> getValue5) |
|
|
|
{ |
|
|
|
if (dbClient == null) throw new ArgumentNullException(nameof(dbClient)); |
|
|
|
if (sql.IsEmpty()) throw new ArgumentNullException(nameof(sql)); |
|
|
|
if (getValue1 == null) throw new ArgumentNullException(nameof(getValue1)); |
|
|
|
if (getValue2 == null) throw new ArgumentNullException(nameof(getValue2)); |
|
|
|
if (getValue3 == null) throw new ArgumentNullException(nameof(getValue3)); |
|
|
|
if (getValue4 == null) throw new ArgumentNullException(nameof(getValue4)); |
|
|
|
if (getValue5 == null) throw new ArgumentNullException(nameof(getValue5)); |
|
|
|
|
|
|
|
using (var query = dbClient.Query(sql, parameters)) |
|
|
|
{ |
|
|
|
if (!query.Success) throw new SqlException(query, sql); |
|
|
|
|
|
|
|
var tuples = new Tuple<T1, T2, T3, T4, T5>[query.Rows]; |
|
|
|
for (var i = 0; i < query.Rows; i++) |
|
|
|
{ |
|
|
|
var v1 = getValue1(query.Value(i, 0)); |
|
|
|
var v2 = getValue2(query.Value(i, 1)); |
|
|
|
var v3 = getValue3(query.Value(i, 2)); |
|
|
|
var v4 = getValue4(query.Value(i, 3)); |
|
|
|
var v5 = getValue5(query.Value(i, 4)); |
|
|
|
tuples[i] = new Tuple<T1, T2, T3, T4, T5>(v1, v2, v3, v4, v5); |
|
|
|
} |
|
|
|
return tuples; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>执行查询,将结果输出为元组数组。</summary>
|
|
|
|
/// <param name="dbClient">数据库连接。</param>
|
|
|
|
/// <param name="sql">SQL 语句。</param>
|
|
|
|
/// <param name="parameters">SQL 参数。</param>
|
|
|
|
/// <param name="getValue1">获取第一个值的回调函数。</param>
|
|
|
|
/// <param name="getValue2">获取第二个值的回调函数。</param>
|
|
|
|
/// <param name="getValue3">获取第三个值的回调函数。</param>
|
|
|
|
/// <param name="getValue4">获取第四个值的回调函数。</param>
|
|
|
|
/// <param name="getValue5">获取第五个值的回调函数。</param>
|
|
|
|
/// <param name="getValue6">获取第六个值的回调函数。</param>
|
|
|
|
/// <returns>由元组组成的数组。</returns>
|
|
|
|
/// <exception cref="ArgumentNullException"></exception>
|
|
|
|
/// <exception cref="SqlException"></exception>
|
|
|
|
public static Tuple<T1, T2, T3, T4, T5, T6>[] Query<T1, T2, T3, T4, T5, T6>(this IDbAdo dbClient, string sql, object parameters, |
|
|
|
Func<object, T1> getValue1, |
|
|
|
Func<object, T2> getValue2, |
|
|
|
Func<object, T3> getValue3, |
|
|
|
Func<object, T4> getValue4, |
|
|
|
Func<object, T5> getValue5, |
|
|
|
Func<object, T6> getValue6) |
|
|
|
{ |
|
|
|
if (dbClient == null) throw new ArgumentNullException(nameof(dbClient)); |
|
|
|
if (sql.IsEmpty()) throw new ArgumentNullException(nameof(sql)); |
|
|
|
if (getValue1 == null) throw new ArgumentNullException(nameof(getValue1)); |
|
|
|
if (getValue2 == null) throw new ArgumentNullException(nameof(getValue2)); |
|
|
|
if (getValue3 == null) throw new ArgumentNullException(nameof(getValue3)); |
|
|
|
if (getValue4 == null) throw new ArgumentNullException(nameof(getValue4)); |
|
|
|
if (getValue5 == null) throw new ArgumentNullException(nameof(getValue5)); |
|
|
|
if (getValue6 == null) throw new ArgumentNullException(nameof(getValue6)); |
|
|
|
|
|
|
|
using (var query = dbClient.Query(sql, parameters)) |
|
|
|
{ |
|
|
|
if (!query.Success) throw new SqlException(query, sql); |
|
|
|
|
|
|
|
var tuples = new Tuple<T1, T2, T3, T4, T5, T6>[query.Rows]; |
|
|
|
for (var i = 0; i < query.Rows; i++) |
|
|
|
{ |
|
|
|
var v1 = getValue1(query.Value(i, 0)); |
|
|
|
var v2 = getValue2(query.Value(i, 1)); |
|
|
|
var v3 = getValue3(query.Value(i, 2)); |
|
|
|
var v4 = getValue4(query.Value(i, 3)); |
|
|
|
var v5 = getValue5(query.Value(i, 4)); |
|
|
|
var v6 = getValue6(query.Value(i, 5)); |
|
|
|
tuples[i] = new Tuple<T1, T2, T3, T4, T5, T6>(v1, v2, v3, v4, v5, v6); |
|
|
|
} |
|
|
|
return tuples; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>执行查询,将结果输出为元组数组。</summary>
|
|
|
|
/// <param name="dbClient">数据库连接。</param>
|
|
|
|
/// <param name="sql">SQL 语句。</param>
|
|
|
|
/// <param name="parameters">SQL 参数。</param>
|
|
|
|
/// <param name="getValue1">获取第一个值的回调函数。</param>
|
|
|
|
/// <param name="getValue2">获取第二个值的回调函数。</param>
|
|
|
|
/// <param name="getValue3">获取第三个值的回调函数。</param>
|
|
|
|
/// <param name="getValue4">获取第四个值的回调函数。</param>
|
|
|
|
/// <param name="getValue5">获取第五个值的回调函数。</param>
|
|
|
|
/// <param name="getValue6">获取第六个值的回调函数。</param>
|
|
|
|
/// <param name="getValue7">获取第七个值的回调函数。</param>
|
|
|
|
/// <returns>由元组组成的数组。</returns>
|
|
|
|
/// <exception cref="ArgumentNullException"></exception>
|
|
|
|
/// <exception cref="SqlException"></exception>
|
|
|
|
public static Tuple<T1, T2, T3, T4, T5, T6, T7>[] Query<T1, T2, T3, T4, T5, T6, T7>(this IDbAdo dbClient, string sql, object parameters, |
|
|
|
Func<object, T1> getValue1, |
|
|
|
Func<object, T2> getValue2, |
|
|
|
Func<object, T3> getValue3, |
|
|
|
Func<object, T4> getValue4, |
|
|
|
Func<object, T5> getValue5, |
|
|
|
Func<object, T6> getValue6, |
|
|
|
Func<object, T7> getValue7) |
|
|
|
{ |
|
|
|
if (dbClient == null) throw new ArgumentNullException(nameof(dbClient)); |
|
|
|
if (sql.IsEmpty()) throw new ArgumentNullException(nameof(sql)); |
|
|
|
if (getValue1 == null) throw new ArgumentNullException(nameof(getValue1)); |
|
|
|
if (getValue2 == null) throw new ArgumentNullException(nameof(getValue2)); |
|
|
|
if (getValue3 == null) throw new ArgumentNullException(nameof(getValue3)); |
|
|
|
if (getValue4 == null) throw new ArgumentNullException(nameof(getValue4)); |
|
|
|
if (getValue5 == null) throw new ArgumentNullException(nameof(getValue5)); |
|
|
|
if (getValue6 == null) throw new ArgumentNullException(nameof(getValue6)); |
|
|
|
if (getValue7 == null) throw new ArgumentNullException(nameof(getValue7)); |
|
|
|
|
|
|
|
using (var query = dbClient.Query(sql, parameters)) |
|
|
|
{ |
|
|
|
if (!query.Success) throw new SqlException(query, sql); |
|
|
|
|
|
|
|
var tuples = new Tuple<T1, T2, T3, T4, T5, T6, T7>[query.Rows]; |
|
|
|
for (var i = 0; i < query.Rows; i++) |
|
|
|
{ |
|
|
|
var v1 = getValue1(query.Value(i, 0)); |
|
|
|
var v2 = getValue2(query.Value(i, 1)); |
|
|
|
var v3 = getValue3(query.Value(i, 2)); |
|
|
|
var v4 = getValue4(query.Value(i, 3)); |
|
|
|
var v5 = getValue5(query.Value(i, 4)); |
|
|
|
var v6 = getValue6(query.Value(i, 5)); |
|
|
|
var v7 = getValue7(query.Value(i, 6)); |
|
|
|
tuples[i] = new Tuple<T1, T2, T3, T4, T5, T6, T7>(v1, v2, v3, v4, v5, v6, v7); |
|
|
|
} |
|
|
|
return tuples; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>执行查询,将结果输出为元组数组。</summary>
|
|
|
|
/// <param name="dbClient">数据库连接。</param>
|
|
|
|
/// <param name="sql">SQL 语句。</param>
|
|
|
|
/// <param name="parameters">SQL 参数。</param>
|
|
|
|
/// <param name="getValue1">获取第一个值的回调函数。</param>
|
|
|
|
/// <param name="getValue2">获取第二个值的回调函数。</param>
|
|
|
|
/// <param name="getValue3">获取第三个值的回调函数。</param>
|
|
|
|
/// <param name="getValue4">获取第四个值的回调函数。</param>
|
|
|
|
/// <param name="getValue5">获取第五个值的回调函数。</param>
|
|
|
|
/// <param name="getValue6">获取第六个值的回调函数。</param>
|
|
|
|
/// <param name="getValue7">获取第七个值的回调函数。</param>
|
|
|
|
/// <param name="getValue8">获取第八个值的回调函数。</param>
|
|
|
|
/// <returns>由元组组成的数组。</returns>
|
|
|
|
/// <exception cref="ArgumentNullException"></exception>
|
|
|
|
/// <exception cref="SqlException"></exception>
|
|
|
|
public static Tuple<T1, T2, T3, T4, T5, T6, T7, T8>[] Query<T1, T2, T3, T4, T5, T6, T7, T8>(this IDbAdo dbClient, string sql, object parameters, |
|
|
|
Func<object, T1> getValue1, |
|
|
|
Func<object, T2> getValue2, |
|
|
|
Func<object, T3> getValue3, |
|
|
|
Func<object, T4> getValue4, |
|
|
|
Func<object, T5> getValue5, |
|
|
|
Func<object, T6> getValue6, |
|
|
|
Func<object, T7> getValue7, |
|
|
|
Func<object, T8> getValue8) |
|
|
|
{ |
|
|
|
if (dbClient == null) throw new ArgumentNullException(nameof(dbClient)); |
|
|
|
if (sql.IsEmpty()) throw new ArgumentNullException(nameof(sql)); |
|
|
|
if (getValue1 == null) throw new ArgumentNullException(nameof(getValue1)); |
|
|
|
if (getValue2 == null) throw new ArgumentNullException(nameof(getValue2)); |
|
|
|
if (getValue3 == null) throw new ArgumentNullException(nameof(getValue3)); |
|
|
|
if (getValue4 == null) throw new ArgumentNullException(nameof(getValue4)); |
|
|
|
if (getValue5 == null) throw new ArgumentNullException(nameof(getValue5)); |
|
|
|
if (getValue6 == null) throw new ArgumentNullException(nameof(getValue6)); |
|
|
|
if (getValue7 == null) throw new ArgumentNullException(nameof(getValue7)); |
|
|
|
if (getValue8 == null) throw new ArgumentNullException(nameof(getValue8)); |
|
|
|
|
|
|
|
using (var query = dbClient.Query(sql, parameters)) |
|
|
|
{ |
|
|
|
if (!query.Success) throw new SqlException(query, sql); |
|
|
|
|
|
|
|
var tuples = new Tuple<T1, T2, T3, T4, T5, T6, T7, T8>[query.Rows]; |
|
|
|
for (var i = 0; i < query.Rows; i++) |
|
|
|
{ |
|
|
|
var v1 = getValue1(query.Value(i, 0)); |
|
|
|
var v2 = getValue2(query.Value(i, 1)); |
|
|
|
var v3 = getValue3(query.Value(i, 2)); |
|
|
|
var v4 = getValue4(query.Value(i, 3)); |
|
|
|
var v5 = getValue5(query.Value(i, 4)); |
|
|
|
var v6 = getValue6(query.Value(i, 5)); |
|
|
|
var v7 = getValue7(query.Value(i, 6)); |
|
|
|
var v8 = getValue8(query.Value(i, 7)); |
|
|
|
tuples[i] = new Tuple<T1, T2, T3, T4, T5, T6, T7, T8>(v1, v2, v3, v4, v5, v6, v7, v8); |
|
|
|
} |
|
|
|
return tuples; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|