Browse Source

Apewer-6.7.5

dev
王厅 2 years ago
parent
commit
246c609996
  1. 2
      Apewer/Apewer.props
  2. 11
      Apewer/Source/IQuery.cs
  3. 11
      Apewer/Source/Query.cs
  4. 86
      Apewer/Source/SourceUtility.cs
  5. 16
      Apewer/TextUtility.cs
  6. 23
      Apewer/Web/ApiProcessor.cs
  7. 12
      Apewer/_Extensions.cs
  8. 7
      ChangeLog.md

2
Apewer/Apewer.props

@ -9,7 +9,7 @@
<Description></Description>
<RootNamespace>Apewer</RootNamespace>
<Product>Apewer Libraries</Product>
<Version>6.7.4</Version>
<Version>6.7.5</Version>
</PropertyGroup>
<!-- 生成 -->

11
Apewer/Source/IQuery.cs

@ -31,17 +31,6 @@ namespace Apewer.Source
#region 读取 DateTime 对象。
/// <summary>获取默认表中第 0 行、第 0 列的单元格内容。</summary>
object Value();
/// <summary>获取默认表中指定行中第 0 列的内容。</summary>
/// <param name="rowIndex">行索引,从 0 开始。</param>
object Value(int rowIndex);
/// <summary>获取默认表中第 0 行指定列的内容。</summary>
/// <param name="columnName">列名称/字段名称,此名称不区分大小写。</param>
object Value(string columnName);
/// <summary>获取默认表中指定单元的内容。</summary>
/// <param name="rowIndex">行索引,从 0 开始。</param>
/// <param name="columnIndex">列索引,从 0 开始。</param>

11
Apewer/Source/Query.cs

@ -91,17 +91,6 @@ namespace Apewer.Source
#region Value
/// <summary>获取默认表中第 0 行、第 0 列的单元格内容。</summary>
public object Value() => Table.Value(0, 0);
/// <summary>获取默认表中指定行中第 0 列的内容。</summary>
/// <param name="rowIndex">行索引,从 0 开始。</param>
public object Value(int rowIndex) => Table.Value(rowIndex, 0);
/// <summary>获取默认表中第 0 行指定列的内容。</summary>
/// <param name="columnName">列名称/字段名称,此名称不区分大小写。</param>
public object Value(string columnName) => Table.Value(0, columnName);
/// <summary>获取默认表中指定单元格的内容。</summary>
/// <param name="rowIndex">行索引,从 0 开始。</param>
/// <param name="columnIndex">列索引,从 0 开始。</param>

86
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
}
}
/// <summary>执行 SELECT 语句,获取查询结果。</summary>
/// <param name="connection">数据库连接。</param>
/// <param name="transaction">事务。</param>
/// <param name="sql">SQL 语句。</param>
/// <param name="parameters">参数。</param>
/// <param name="timeout">超时秒数。</param>
/// <returns>查询结果。</returns>
public static DataTable Query(this IDbConnection connection, IDbTransaction transaction, string sql, IEnumerable<IDbDataParameter> 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
}
}
/// <summary>执行 SQL 语句,获取影响的行数。</summary>
/// <param name="connection">数据库连接。</param>
/// <param name="transaction">事务。</param>
/// <param name="sql">SQL 语句。</param>
/// <param name="parameters">参数。</param>
/// <param name="timeout">超时秒数。</param>
/// <returns>行数。</returns>
public static int Execute(this IDbConnection connection, IDbTransaction transaction, string sql, IEnumerable<IDbDataParameter> 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
}
/// <summary>获取默认表中指定单元格的内容。从第 0 行第 0 列开始。</summary>
public static Class<DateTime> DateTime(this DataTable table, int row = 0, int column = 0) => table == null ? null : ClockUtility.DateTime(table.Value(row, column));
public static Class<DateTime> DateTime(this DataTable table, int row, int column) => table == null ? null : ClockUtility.DateTime(table.Value(row, column));
/// <summary>获取默认表中指定单元格的内容。从第 0 行开始。</summary>
public static Class<DateTime> DateTime(this DataTable table, int row, string column) => table == null ? null : ClockUtility.DateTime(table.Value(row, column));
/// <summary>获取默认表中指定单元格的内容。从第 0 行第 0 列开始。</summary>
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));
/// <summary>获取默认表中指定单元格的内容。从第 0 行开始。</summary>
public static Int32 Int32(this DataTable table, int row, string column) => table == null ? 0 : NumberUtility.Int32(table.Value(row, column));
/// <summary>获取默认表中指定单元格的内容。从第 0 行第 0 列开始。</summary>
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));
/// <summary>获取默认表中指定单元格的内容。从第 0 行开始。</summary>
public static Int64 Int64(this DataTable table, int row, string column) => table == null ? 0L : NumberUtility.Int64(table.Value(row, column));
/// <summary>获取默认表中指定单元格的内容。从第 0 行第 0 列开始。</summary>
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));
/// <summary>获取默认表中指定单元格的内容。从第 0 行开始。</summary>
public static Decimal Decimal(this DataTable table, int row, string column) => table == null ? 0M : NumberUtility.Decimal(table.Value(row, column));
/// <summary>获取默认表中指定单元格的内容。从第 0 行第 0 列开始。</summary>>
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));
/// <summary>获取默认表中指定单元格的内容。从第 0 行开始。</summary>>
public static Double Double(this DataTable table, int row, string column) => table == null ? 0D : NumberUtility.Double(table.Value(row, column));
/// <summary>获取默认表中指定单元格的内容。从第 0 行第 0 列开始。</summary>
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));
/// <summary>获取默认表中指定单元格的内容。从第 0 行开始。</summary>
public static string Text(this DataTable table, int row, string column) => table == null ? null : TextUtility.Text(table.Value(row, column));

16
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<char> chars)
{
var list = new List<char>();
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<object>();
foreach (var item in enumerable) list.Add(item);
cells = list.ToArray();
continue;
}
break;

23
Apewer/Web/ApiProcessor.cs

@ -26,6 +26,7 @@ namespace Apewer.Web
internal ApiProcessor(ApiContext context)
{
if (context == null) throw new ArgumentNullException(nameof(context));
_context = context;
}
@ -518,11 +519,14 @@ namespace Apewer.Web
var preWrite = provider.PreWrite();
if (!string.IsNullOrEmpty(preWrite)) return;
var responsePreOutput = response.PreOutput;
if (responsePreOutput != null)
if (response != null)
{
var @continue = responsePreOutput.Invoke(_context);
if (!@continue) return;
var responsePreOutput = response.PreOutput;
if (responsePreOutput != null)
{
var @continue = responsePreOutput.Invoke(_context);
if (!@continue) return;
}
}
var invokerPreOutput = _context.Invoker.PreOutput;
@ -556,11 +560,14 @@ namespace Apewer.Web
var preWrite = provider.PreWrite();
if (!string.IsNullOrEmpty(preWrite)) return;
var responsePreOutput = response.PreOutput;
if (responsePreOutput != null)
if (response != null)
{
var @continue = responsePreOutput.Invoke(_context);
if (!@continue) return;
var responsePreOutput = response.PreOutput;
if (responsePreOutput != null)
{
var @continue = responsePreOutput.Invoke(_context);
if (!@continue) return;
}
}
var invokerPreOutput = _context.Invoker.PreOutput;

12
Apewer/_Extensions.cs

@ -558,37 +558,37 @@ public static class Extensions
#region Source
/// <summary>获取默认表中指定单元格的内容。从第 0 行第 0 列开始。</summary>
public static Class<DateTime> DateTime(this IQuery @this, int row = 0, int column = 0) => @this == null ? null : ClockUtility.DateTime(@this.Value(row, column));
public static Class<DateTime> DateTime(this IQuery @this, int row, int column) => @this == null ? null : ClockUtility.DateTime(@this.Value(row, column));
/// <summary>获取默认表中指定单元格的内容。从第 0 行开始。</summary>
public static Class<DateTime> DateTime(this IQuery @this, int row, string column) => @this == null ? null : ClockUtility.DateTime(@this.Value(row, column));
/// <summary>获取默认表中指定单元格的内容。从第 0 行第 0 列开始。</summary>
public static Int32 Int32(this IQuery @this, int row = 0, int column = 0) => @this == null ? 0 : NumberUtility.Int32(@this.Value(row, column));
public static Int32 Int32(this IQuery @this, int row, int column) => @this == null ? 0 : NumberUtility.Int32(@this.Value(row, column));
/// <summary>获取默认表中指定单元格的内容。从第 0 行开始。</summary>
public static Int32 Int32(this IQuery @this, int row, string column) => @this == null ? 0 : NumberUtility.Int32(@this.Value(row, column));
/// <summary>获取默认表中指定单元格的内容。从第 0 行第 0 列开始。</summary>
public static Int64 Int64(this IQuery @this, int row = 0, int column = 0) => @this == null ? 0L : NumberUtility.Int64(@this.Value(row, column));
public static Int64 Int64(this IQuery @this, int row, int column) => @this == null ? 0L : NumberUtility.Int64(@this.Value(row, column));
/// <summary>获取默认表中指定单元格的内容。从第 0 行开始。</summary>
public static Int64 Int64(this IQuery @this, int row, string column) => @this == null ? 0L : NumberUtility.Int64(@this.Value(row, column));
/// <summary>获取默认表中指定单元格的内容。从第 0 行第 0 列开始。</summary>
public static Decimal Decimal(this IQuery @this, int row = 0, int column = 0) => @this == null ? 0M : NumberUtility.Decimal(@this.Value(row, column));
public static Decimal Decimal(this IQuery @this, int row, int column) => @this == null ? 0M : NumberUtility.Decimal(@this.Value(row, column));
/// <summary>获取默认表中指定单元格的内容。从第 0 行开始。</summary>
public static Decimal Decimal(this IQuery @this, int row, string column) => @this == null ? 0M : NumberUtility.Decimal(@this.Value(row, column));
/// <summary>获取默认表中指定单元格的内容。从第 0 行第 0 列开始。</summary>>
public static Double Double(this IQuery @this, int row = 0, int column = 0) => @this == null ? 0D : NumberUtility.Double(@this.Value(row, column));
public static Double Double(this IQuery @this, int row, int column) => @this == null ? 0D : NumberUtility.Double(@this.Value(row, column));
/// <summary>获取默认表中指定单元格的内容。从第 0 行开始。</summary>>
public static Double Double(this IQuery @this, int row, string column) => @this == null ? 0D : NumberUtility.Double(@this.Value(row, column));
/// <summary>获取默认表中指定单元格的内容。从第 0 行第 0 列开始。</summary>
public static string Text(this IQuery @this, int row = 0, int column = 0) => @this == null ? null : TextUtility.Text(@this.Value(row, column));
public static string Text(this IQuery @this, int row, int column) => @this == null ? null : TextUtility.Text(@this.Value(row, column));
/// <summary>获取默认表中指定单元格的内容。从第 0 行开始。</summary>
public static string Text(this IQuery @this, int row, string column) => @this == null ? null : TextUtility.Text(@this.Value(row, column));

7
ChangeLog.md

@ -1,6 +1,13 @@

### 最新提交
### 6.7.5
- 问题修正
- Query:删除了一些访问单元格的重载方法,减少歧义;
- Source:增加 IDbConnection 的扩展方法 Query 和 Execute;
- TextUtility:修正 Join 无法解析 Lis<string> 的问题;
- Web:修正 Response 无效时会抛出 NULL 引用的问题。
### 6.7.4
- 问题修正
- Source:修正了 Timeout 的默认值,已经改为连接 5 秒,查询、执行 3600 秒。

Loading…
Cancel
Save