diff --git a/Apewer/Apewer.props b/Apewer/Apewer.props
index 1b888ef..9aad0c6 100644
--- a/Apewer/Apewer.props
+++ b/Apewer/Apewer.props
@@ -9,7 +9,7 @@
Apewer
Apewer Libraries
- 6.7.4
+ 6.7.5
diff --git a/Apewer/Source/IQuery.cs b/Apewer/Source/IQuery.cs
index 33e5e19..2d768a4 100644
--- a/Apewer/Source/IQuery.cs
+++ b/Apewer/Source/IQuery.cs
@@ -31,17 +31,6 @@ namespace Apewer.Source
#region 读取 DateTime 对象。
- /// 获取默认表中第 0 行、第 0 列的单元格内容。
- object Value();
-
- /// 获取默认表中指定行中第 0 列的内容。
- /// 行索引,从 0 开始。
- object Value(int rowIndex);
-
- /// 获取默认表中第 0 行指定列的内容。
- /// 列名称/字段名称,此名称不区分大小写。
- object Value(string columnName);
-
/// 获取默认表中指定单元的内容。
/// 行索引,从 0 开始。
/// 列索引,从 0 开始。
diff --git a/Apewer/Source/Query.cs b/Apewer/Source/Query.cs
index 3db51bf..d1fc953 100644
--- a/Apewer/Source/Query.cs
+++ b/Apewer/Source/Query.cs
@@ -91,17 +91,6 @@ namespace Apewer.Source
#region Value
- /// 获取默认表中第 0 行、第 0 列的单元格内容。
- public object Value() => Table.Value(0, 0);
-
- /// 获取默认表中指定行中第 0 列的内容。
- /// 行索引,从 0 开始。
- public object Value(int rowIndex) => Table.Value(rowIndex, 0);
-
- /// 获取默认表中第 0 行指定列的内容。
- /// 列名称/字段名称,此名称不区分大小写。
- public object Value(string columnName) => Table.Value(0, columnName);
-
/// 获取默认表中指定单元格的内容。
/// 行索引,从 0 开始。
/// 列索引,从 0 开始。
diff --git a/Apewer/Source/SourceUtility.cs b/Apewer/Source/SourceUtility.cs
index cc49b54..55d2c42 100644
--- a/Apewer/Source/SourceUtility.cs
+++ b/Apewer/Source/SourceUtility.cs
@@ -416,14 +416,16 @@ namespace Apewer.Source
pool = new string[rows];
for (int i = 0; i < rows; i++)
{
- var cell = TextUtility.Trim(query.Text(i));
+ var cell = TextUtility.Trim(query.Text(i, 0));
if (string.IsNullOrEmpty(cell)) continue;
+
pool[count] = cell;
count++;
}
}
if (count < 1) return new string[0];
+ if (count == rows) return pool;
var array = new string[count];
Array.Copy(pool, 0, array, 0, count);
@@ -443,7 +445,7 @@ namespace Apewer.Source
using (var query = dbClient.Query(sql))
{
if (!query.Success) throw new SqlException(query, sql);
- var value = TextUtility.Trim(query.Text());
+ var value = TextUtility.Trim(query.Text(0, 0));
return value;
}
}
@@ -484,6 +486,42 @@ namespace Apewer.Source
}
}
+ /// 执行 SELECT 语句,获取查询结果。
+ /// 数据库连接。
+ /// 事务。
+ /// SQL 语句。
+ /// 参数。
+ /// 超时秒数。
+ /// 查询结果。
+ public static DataTable Query(this IDbConnection connection, IDbTransaction transaction, string sql, IEnumerable parameters = null, int timeout = 3600)
+ {
+ if (connection == null) throw new ArgumentNullException(nameof(connection));
+ if (string.IsNullOrEmpty(sql)) throw new ArgumentNullException(nameof(sql));
+
+ if (connection.State != ConnectionState.Open) connection.Open();
+ using (var command = connection.CreateCommand())
+ {
+ if (transaction != null) command.Transaction = transaction;
+ if (timeout > 0) command.CommandTimeout = timeout;
+ command.CommandText = sql;
+ if (parameters != null)
+ {
+ foreach (var parameter in parameters)
+ {
+ if (parameter == null) continue;
+ command.Parameters.Add(parameter);
+ }
+ }
+
+ using (var reader = command.ExecuteReader())
+ {
+ var table = new DataTable();
+ table.Load(reader);
+ return table;
+ }
+ }
+ }
+
#endregion
#region Execute
@@ -522,6 +560,38 @@ namespace Apewer.Source
}
}
+ /// 执行 SQL 语句,获取影响的行数。
+ /// 数据库连接。
+ /// 事务。
+ /// SQL 语句。
+ /// 参数。
+ /// 超时秒数。
+ /// 行数。
+ public static int Execute(this IDbConnection connection, IDbTransaction transaction, string sql, IEnumerable parameters = null, int timeout = 3600)
+ {
+ if (connection == null) throw new ArgumentNullException(nameof(connection));
+ if (string.IsNullOrEmpty(sql)) throw new ArgumentNullException(nameof(sql));
+
+ if (connection.State != ConnectionState.Open) connection.Open();
+ using (var command = connection.CreateCommand())
+ {
+ if (transaction != null) command.Transaction = transaction;
+ if (timeout > 0) command.CommandTimeout = timeout;
+ command.CommandText = sql;
+ if (parameters != null)
+ {
+ foreach (var parameter in parameters)
+ {
+ if (parameter == null) continue;
+ command.Parameters.Add(parameter);
+ }
+ }
+
+ var rows = command.ExecuteNonQuery();
+ return rows;
+ }
+ }
+
#endregion
#region Transaction
@@ -1024,37 +1094,37 @@ namespace Apewer.Source
}
/// 获取默认表中指定单元格的内容。从第 0 行第 0 列开始。
- public static Class DateTime(this DataTable table, int row = 0, int column = 0) => table == null ? null : ClockUtility.DateTime(table.Value(row, column));
+ public static Class DateTime(this DataTable table, int row, int column) => table == null ? null : ClockUtility.DateTime(table.Value(row, column));
/// 获取默认表中指定单元格的内容。从第 0 行开始。
public static Class DateTime(this DataTable table, int row, string column) => table == null ? null : ClockUtility.DateTime(table.Value(row, column));
/// 获取默认表中指定单元格的内容。从第 0 行第 0 列开始。
- public static Int32 Int32(this DataTable table, int row = 0, int column = 0) => table == null ? 0 : NumberUtility.Int32(table.Value(row, column));
+ public static Int32 Int32(this DataTable table, int row, int column) => table == null ? 0 : NumberUtility.Int32(table.Value(row, column));
/// 获取默认表中指定单元格的内容。从第 0 行开始。
public static Int32 Int32(this DataTable table, int row, string column) => table == null ? 0 : NumberUtility.Int32(table.Value(row, column));
/// 获取默认表中指定单元格的内容。从第 0 行第 0 列开始。
- public static Int64 Int64(this DataTable table, int row = 0, int column = 0) => table == null ? 0L : NumberUtility.Int64(table.Value(row, column));
+ public static Int64 Int64(this DataTable table, int row, int column) => table == null ? 0L : NumberUtility.Int64(table.Value(row, column));
/// 获取默认表中指定单元格的内容。从第 0 行开始。
public static Int64 Int64(this DataTable table, int row, string column) => table == null ? 0L : NumberUtility.Int64(table.Value(row, column));
/// 获取默认表中指定单元格的内容。从第 0 行第 0 列开始。
- public static Decimal Decimal(this DataTable table, int row = 0, int column = 0) => table == null ? 0M : NumberUtility.Decimal(table.Value(row, column));
+ public static Decimal Decimal(this DataTable table, int row, int column) => table == null ? 0M : NumberUtility.Decimal(table.Value(row, column));
/// 获取默认表中指定单元格的内容。从第 0 行开始。
public static Decimal Decimal(this DataTable table, int row, string column) => table == null ? 0M : NumberUtility.Decimal(table.Value(row, column));
/// 获取默认表中指定单元格的内容。从第 0 行第 0 列开始。>
- public static Double Double(this DataTable table, int row = 0, int column = 0) => table == null ? 0D : NumberUtility.Double(table.Value(row, column));
+ public static Double Double(this DataTable table, int row, int column) => table == null ? 0D : NumberUtility.Double(table.Value(row, column));
/// 获取默认表中指定单元格的内容。从第 0 行开始。>
public static Double Double(this DataTable table, int row, string column) => table == null ? 0D : NumberUtility.Double(table.Value(row, column));
/// 获取默认表中指定单元格的内容。从第 0 行第 0 列开始。
- public static string Text(this DataTable table, int row = 0, int column = 0) => table == null ? null : TextUtility.Text(table.Value(row, column));
+ public static string Text(this DataTable table, int row, int column) => table == null ? null : TextUtility.Text(table.Value(row, column));
/// 获取默认表中指定单元格的内容。从第 0 行开始。
public static string Text(this DataTable table, int row, string column) => table == null ? null : TextUtility.Text(table.Value(row, column));
diff --git a/Apewer/TextUtility.cs b/Apewer/TextUtility.cs
index 4133849..00cb80a 100644
--- a/Apewer/TextUtility.cs
+++ b/Apewer/TextUtility.cs
@@ -143,10 +143,20 @@ namespace Apewer
{
var first = cells[0];
if (first.IsNull()) return Empty;
- if (first is char[] chars) return new string(chars);
- if (first is object[] objects)
+ if (first is string str) return str ?? Empty;
+
+ if (first is IEnumerable chars)
+ {
+ var list = new List();
+ foreach (var @char in chars) list.Add(@char);
+ return new string(list.ToArray());
+ }
+
+ if (!first.GetType().IsValueType && first is IEnumerable enumerable)
{
- cells = objects;
+ var list = new List