mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 04:18:16 +08:00
【测试】三大数据库,添加所有类型数据null/非空,后查询正常
This commit is contained in:
@ -38,7 +38,7 @@ namespace FreeSql.Internal.CommonProvider {
|
||||
if (e == null) return;
|
||||
string log = $"{pool.Policy.Name}数据库出错(执行SQL)〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓\r\n{cmd.CommandText}\r\n";
|
||||
foreach (DbParameter parm in cmd.Parameters)
|
||||
log += parm.ParameterName.PadRight(20, ' ') + " = " + (parm.Value ?? "NULL") + "\r\n";
|
||||
log += parm.ParameterName.PadRight(20, ' ') + " = " + ((parm.Value ?? DBNull.Value) == DBNull.Value ? "NULL" : parm.Value) + "\r\n";
|
||||
|
||||
log += e.Message;
|
||||
_log.LogError(log);
|
||||
|
@ -75,8 +75,8 @@ namespace FreeSql.Internal.CommonProvider {
|
||||
foreach (var col in _table.Columns.Values)
|
||||
if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name) == false) {
|
||||
if (colidx2 > 0) sb.Append(", ");
|
||||
sb.Append(_commonUtils.QuoteParamterName(col.CsName)).Append(didx);
|
||||
_params[didx * colidx + colidx2] = _commonUtils.AppendParamter(null, $"{col.CsName}{didx}", _table.Properties.TryGetValue(col.CsName, out var tryp) ? tryp.GetValue(d) : DBNull.Value);
|
||||
sb.Append(_commonUtils.QuoteWriteParamter(col.CsType, $"{_commonUtils.QuoteParamterName(col.CsName)}{didx}"));
|
||||
_params[didx * colidx + colidx2] = _commonUtils.AppendParamter(null, $"{col.CsName}{didx}", col.CsType, _table.Properties.TryGetValue(col.CsName, out var tryp) ? tryp.GetValue(d) : null);
|
||||
++colidx2;
|
||||
}
|
||||
sb.Append(")");
|
||||
|
@ -187,7 +187,7 @@ namespace FreeSql.Internal.CommonProvider {
|
||||
if (tb.Table.ColumnsByCs.TryGetValue(p.Name, out var col)) { //普通字段
|
||||
if (index > 0) field.Append(", ");
|
||||
var quoteName = _commonUtils.QuoteSqlName(col.Attribute.Name);
|
||||
field.Append(tb.Alias).Append(".").Append(quoteName);
|
||||
field.Append(_commonUtils.QuoteReadColumn(col.CsType, $"{tb.Alias}.{quoteName}"));
|
||||
++index;
|
||||
if (dicfield.ContainsKey(quoteName)) field.Append(" as").Append(index);
|
||||
else dicfield.Add(quoteName, true);
|
||||
@ -200,7 +200,7 @@ namespace FreeSql.Internal.CommonProvider {
|
||||
foreach (var col2 in tb2.Table.Columns.Values) {
|
||||
if (index > 0) field.Append(", ");
|
||||
var quoteName = _commonUtils.QuoteSqlName(col2.Attribute.Name);
|
||||
field.Append(tb2.Alias).Append(".").Append(quoteName);
|
||||
field.Append(_commonUtils.QuoteReadColumn(col.CsType, $"{tb2.Alias}.{quoteName}"));
|
||||
++index;
|
||||
if (dicfield.ContainsKey(quoteName)) field.Append(" as").Append(index);
|
||||
else dicfield.Add(quoteName, true);
|
||||
|
@ -52,10 +52,12 @@ namespace FreeSql.Internal.CommonProvider {
|
||||
}
|
||||
|
||||
public IUpdate<T1> Set<TMember>(Expression<Func<T1, TMember>> column, TMember value) {
|
||||
var col = _commonExpression.ExpressionSelectColumn_MemberAccess(null, null, SelectTableInfoType.From, column?.Body, true);
|
||||
if (string.IsNullOrEmpty(col)) return this;
|
||||
_set.Append(", ").Append(col).Append(" = ").Append(_commonUtils.QuoteParamterName("p_")).Append(_params.Count);
|
||||
_commonUtils.AppendParamter(_params, null, value);
|
||||
var cols = new List<SelectColumnInfo>();
|
||||
_commonExpression.ExpressionSelectColumn_MemberAccess(null, cols, SelectTableInfoType.From, column?.Body, true);
|
||||
if (cols.Count != 1) return this;
|
||||
var col = cols.First();
|
||||
_set.Append(", ").Append(_commonUtils.QuoteSqlName(col.Column.Attribute.Name)).Append(" = ").Append(_commonUtils.QuoteWriteParamter(col.Column.CsType, $"{_commonUtils.QuoteParamterName("p_")}{_params.Count}"));
|
||||
_commonUtils.AppendParamter(_params, null, col.Column.CsType, value);
|
||||
//foreach (var t in _source) Utils.FillPropertyValue(t, tryf.CsName, value);
|
||||
return this;
|
||||
}
|
||||
@ -111,8 +113,8 @@ namespace FreeSql.Internal.CommonProvider {
|
||||
foreach (var col in _table.Columns.Values) {
|
||||
if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.CsName) == false) {
|
||||
if (colidx > 0) sb.Append(", ");
|
||||
sb.Append(_commonUtils.QuoteSqlName(col.Attribute.Name)).Append(" = ").Append(_commonUtils.QuoteParamterName($"p_{_paramsSource.Count}"));
|
||||
_commonUtils.AppendParamter(_paramsSource, null, _table.Properties.TryGetValue(col.CsName, out var tryp) ? tryp.GetValue(_source.First()) : DBNull.Value);
|
||||
sb.Append(_commonUtils.QuoteSqlName(col.Attribute.Name)).Append(" = ").Append(_commonUtils.QuoteWriteParamter(col.CsType, _commonUtils.QuoteParamterName($"p_{_paramsSource.Count}")));
|
||||
_commonUtils.AppendParamter(_paramsSource, null, col.CsType, _table.Properties.TryGetValue(col.CsName, out var tryp) ? tryp.GetValue(_source.First()) : null);
|
||||
++colidx;
|
||||
}
|
||||
}
|
||||
@ -151,8 +153,8 @@ namespace FreeSql.Internal.CommonProvider {
|
||||
// ++pkidx;
|
||||
//}
|
||||
//if (_table.Primarys.Length > 1) sb.Append(")");
|
||||
sb.Append(" THEN ").Append(_commonUtils.QuoteParamterName($"p_{_paramsSource.Count}"));
|
||||
_commonUtils.AppendParamter(_paramsSource, null, _table.Properties.TryGetValue(col.CsName, out var tryp) ? tryp.GetValue(d) : DBNull.Value);
|
||||
sb.Append(" THEN ").Append(_commonUtils.QuoteWriteParamter(col.CsType, _commonUtils.QuoteParamterName($"p_{_paramsSource.Count}")));
|
||||
_commonUtils.AppendParamter(_paramsSource, null, col.CsType, _table.Properties.TryGetValue(col.CsName, out var tryp) ? tryp.GetValue(d) : DBNull.Value);
|
||||
}
|
||||
sb.Append(" END");
|
||||
++colidx;
|
||||
|
Reference in New Issue
Block a user