Skip to content

Commit

Permalink
adjust internal API
Browse files Browse the repository at this point in the history
  • Loading branch information
2881099 committed Dec 21, 2020
1 parent e5452ad commit c905278
Show file tree
Hide file tree
Showing 66 changed files with 151 additions and 151 deletions.
2 changes: 1 addition & 1 deletion FreeSql/Internal/CommonExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public bool ReadAnonymousField(List<SelectTableInfo> _tables, StringBuilder fiel
CsType = map[idx].Column.CsType,
MapType = map[idx].Column.Attribute.MapType
};
field.Append(", ").Append(_common.QuoteReadColumn(map[idx].Column, child.CsType, child.MapType, child.DbField));
field.Append(", ").Append(_common.RereadColumn(map[idx].Column, child.DbField));
if (index >= 0) field.Append(_common.FieldAsAlias($"as{++index}"));
parent.Childs.Add(child);
}
Expand Down
2 changes: 1 addition & 1 deletion FreeSql/Internal/CommonProvider/InsertOrUpdateProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public void WriteSourceSelectUnionAll(List<T1> source, StringBuilder sb, List<Db
else
{
object val = col.GetDbValue(d);
sb.Append(_commonUtils.GetNoneParamaterSqlValue(dbParams, "cu", col, col.Attribute.MapType, val));
sb.Append(_commonUtils.RewriteColumn(col, _commonUtils.GetNoneParamaterSqlValue(dbParams, "cu", col, col.Attribute.MapType, val)));
}
if (didx == 0) sb.Append(" as ").Append(col.Attribute.Name);
++colidx2;
Expand Down
4 changes: 2 additions & 2 deletions FreeSql/Internal/CommonProvider/InsertProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,8 @@ public string ToSqlValuesOrSelectUnionAllExtension102(bool isValues, Action<obje
if (val == null && col.Attribute.IsNullable == false) val = col.CsType == typeof(string) ? "" : Utils.GetDataReaderValue(col.CsType.NullableTypeOrThis(), null);//#384

var colsql = _noneParameter ? _commonUtils.GetNoneParamaterSqlValue(specialParams, _noneParameterFlag, col, col.Attribute.MapType, val) :
_commonUtils.QuoteWriteParamter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"{col.CsName}_{didx}"));
sb.Append(_commonUtils.QuoteWriteColumn(col, colsql));
_commonUtils.QuoteWriteParamterAdapter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"{col.CsName}_{didx}"));
sb.Append(_commonUtils.RewriteColumn(col, colsql));
if (_noneParameter == false)
_params[didx * colidx + colidx2] = _commonUtils.AppendParamter(null, $"{col.CsName}_{didx}", col, col.Attribute.MapType, val);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ public GetAllFieldExpressionTreeInfo GetAllFieldExpressionTreeLevelAll()
if (tbiindex > 0 && colidx == 0) field.Append("\r\n");
}
var quoteName = _commonUtils.QuoteSqlName(col.Attribute.Name);
field.Append(_commonUtils.QuoteReadColumn(col, col.CsType, col.Attribute.MapType, $"{tbi.Alias}.{quoteName}"));
field.Append(_commonUtils.RereadColumn(col, $"{tbi.Alias}.{quoteName}"));
++index;
if (dicfield.ContainsKey(quoteName)) field.Append(_commonUtils.FieldAsAlias($"as{index}"));
else dicfield.Add(quoteName, true);
Expand Down Expand Up @@ -555,7 +555,7 @@ public GetAllFieldExpressionTreeInfo GetAllFieldExpressionTreeLevel2()
{ //普通字段
if (index > 0) field.Append(", ");
var quoteName = _commonUtils.QuoteSqlName(col.Attribute.Name);
field.Append(_commonUtils.QuoteReadColumn(col, col.CsType, col.Attribute.MapType, $"{tb.Alias}.{quoteName}"));
field.Append(_commonUtils.RereadColumn(col, $"{tb.Alias}.{quoteName}"));
++index;
if (dicfield.ContainsKey(quoteName)) field.Append(_commonUtils.FieldAsAlias($"as{index}"));
else dicfield.Add(quoteName, true);
Expand All @@ -578,7 +578,7 @@ public GetAllFieldExpressionTreeInfo GetAllFieldExpressionTreeLevel2()
{
if (index > 0) field.Append(", ");
var quoteName = _commonUtils.QuoteSqlName(col2.Attribute.Name);
field.Append(_commonUtils.QuoteReadColumn(col2, col2.CsType, col2.Attribute.MapType, $"{tb2.Alias}.{quoteName}"));
field.Append(_commonUtils.RereadColumn(col2, $"{tb2.Alias}.{quoteName}"));
++index;
++otherindex;
if (dicfield.ContainsKey(quoteName)) field.Append(_commonUtils.FieldAsAlias($"as{index}"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ public ISelect<T1> IncludeMany<TNavigate>(Expression<Func<T1, IEnumerable<TNavig
Property = tbrefMid.Properties[col.CsName]
};
read.Childs.Add(child);
field.Append(", ").Append(_commonUtils.QuoteReadColumn(col, child.CsType, child.MapType, child.DbField));
field.Append(", ").Append(_commonUtils.RereadColumn(col, child.DbField));
}
otherData = new ReadAnonymousTypeAfInfo(read, field.ToString());
}
Expand Down
16 changes: 8 additions & 8 deletions FreeSql/Internal/CommonProvider/UpdateProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,8 @@ protected void SetPriv(ColumnInfo col, object value)
_set.Append(", ").Append(_commonUtils.QuoteSqlName(col.Attribute.Name)).Append(" = ");

var colsql = _noneParameter ? _commonUtils.GetNoneParamaterSqlValue(_params, "u", col, col.Attribute.MapType, val) :
_commonUtils.QuoteWriteParamter(col.Attribute.MapType, $"{_commonUtils.QuoteParamterName("p_")}{_params.Count}");
_set.Append(_commonUtils.QuoteWriteColumn(col, colsql));
_commonUtils.QuoteWriteParamterAdapter(col.Attribute.MapType, $"{_commonUtils.QuoteParamterName("p_")}{_params.Count}");
_set.Append(_commonUtils.RewriteColumn(col, colsql));
if (_noneParameter == false)
_commonUtils.AppendParamter(_params, null, col, col.Attribute.MapType, val);
}
Expand Down Expand Up @@ -599,7 +599,7 @@ protected string WhereCaseSource(string CsName, Func<string, string> thenValue)
var sb = new StringBuilder();

sb.Append(_commonUtils.QuoteSqlName(col.Attribute.Name)).Append(" = ");
sb.Append(thenValue(_commonUtils.GetNoneParamaterSqlValue(_paramsSource, "u", col, col.Attribute.MapType, col.GetDbValue(_source.First()))));
sb.Append(thenValue(_commonUtils.RewriteColumn(col, _commonUtils.GetNoneParamaterSqlValue(_paramsSource, "u", col, col.Attribute.MapType, col.GetDbValue(_source.First())))));

return sb.ToString();

Expand All @@ -623,7 +623,7 @@ protected string WhereCaseSource(string CsName, Func<string, string> thenValue)
ToSqlWhen(cwsb, _table.Primarys, d);
cwsb.Append(" THEN ");
var val = col.GetDbValue(d);
cwsb.Append(thenValue(_commonUtils.GetNoneParamaterSqlValue(_paramsSource, "u", col, col.Attribute.MapType, val)));
cwsb.Append(thenValue(_commonUtils.RewriteColumn(col, _commonUtils.GetNoneParamaterSqlValue(_paramsSource, "u", col, col.Attribute.MapType, val))));
if (val == null || val == DBNull.Value) nulls++;
}
cwsb.Append(" END");
Expand Down Expand Up @@ -697,8 +697,8 @@ public string ToSql()
var val = col.GetDbValue(_source.First());

var colsql = _noneParameter ? _commonUtils.GetNoneParamaterSqlValue(_paramsSource, "u", col, col.Attribute.MapType, val) :
_commonUtils.QuoteWriteParamter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"p_{_paramsSource.Count}"));
_set.Append(_commonUtils.QuoteWriteColumn(col, colsql));
_commonUtils.QuoteWriteParamterAdapter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"p_{_paramsSource.Count}"));
_set.Append(_commonUtils.RewriteColumn(col, colsql));
if (_noneParameter == false)
_commonUtils.AppendParamter(_paramsSource, null, col, col.Attribute.MapType, val);
}
Expand Down Expand Up @@ -741,8 +741,8 @@ public string ToSql()
var val = col.GetDbValue(d);

var colsql = _noneParameter ? _commonUtils.GetNoneParamaterSqlValue(_paramsSource, "u", col, col.Attribute.MapType, val) :
_commonUtils.QuoteWriteParamter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"p_{_paramsSource.Count}"));
_set.Append(_commonUtils.QuoteWriteColumn(col, colsql));
_commonUtils.QuoteWriteParamterAdapter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"p_{_paramsSource.Count}"));
_set.Append(_commonUtils.RewriteColumn(col, colsql));
if (_noneParameter == false)
_commonUtils.AppendParamter(_paramsSource, null, col, col.Attribute.MapType, val);
if (val == null || val == DBNull.Value) nulls++;
Expand Down
26 changes: 13 additions & 13 deletions FreeSql/Internal/CommonUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ public static string[] GetSplitTableNames(string name, char leftQuote, char righ
public abstract string Div(string left, string right, Type leftType, Type rightType);
public abstract string Now { get; }
public abstract string NowUtc { get; }
public abstract string QuoteWriteParamter(Type type, string paramterName);
public abstract string QuoteWriteParamterAdapter(Type type, string paramterName);
protected abstract string QuoteReadColumnAdapter(Type type, Type mapType, string columnName);
public string QuoteWriteColumn(ColumnInfo col, string sql)
public string RewriteColumn(ColumnInfo col, string sql)
{
if (string.IsNullOrWhiteSpace(col?.Attribute.RewriteSql) == false)
return string.Format(col.Attribute.RereadSql, sql);
return sql;
}
public string QuoteReadColumn(ColumnInfo col, Type type, Type mapType, string columnName)
public string RereadColumn(ColumnInfo col, string columnName)
{
var result = QuoteReadColumnAdapter(type, mapType, columnName);
var result = QuoteReadColumnAdapter(col.CsType, col.Attribute.MapType, columnName);
if (string.IsNullOrWhiteSpace(col?.Attribute.RereadSql) == false)
return string.Format(col.Attribute.RereadSql, result);
return result;
Expand Down Expand Up @@ -281,7 +281,7 @@ public string WhereObject(TableInfo table, string aliasAndDot, object dywhere)
var pk1 = primarys.FirstOrDefault();
if (primarys.Length == 1 && (type == pk1.CsType || type.IsNumberType() && pk1.CsType.IsNumberType()))
{
return $"{aliasAndDot}{this.QuoteSqlName(pk1.Attribute.Name)} = {GetNoneParamaterSqlValue(null, null, pk1, pk1.Attribute.MapType, Utils.GetDataReaderValue(pk1.Attribute.MapType, dywhere))}";
return $"{aliasAndDot}{this.QuoteSqlName(pk1.Attribute.Name)} = {RewriteColumn(pk1, GetNoneParamaterSqlValue(null, null, pk1, pk1.Attribute.MapType, Utils.GetDataReaderValue(pk1.Attribute.MapType, dywhere)))}";
}
else if (primarys.Length > 0 && (type == table.Type || type.BaseType == table.Type))
{
Expand All @@ -291,14 +291,14 @@ public string WhereObject(TableInfo table, string aliasAndDot, object dywhere)
{
if (pkidx > 0) sb.Append(" AND ");
sb.Append(aliasAndDot).Append(this.QuoteSqlName(pk.Attribute.Name)).Append(" = ");
sb.Append(GetNoneParamaterSqlValue(null, null, pk, pk.Attribute.MapType, pk.GetDbValue(dywhere)));
sb.Append(RewriteColumn(pk, GetNoneParamaterSqlValue(null, null, pk, pk.Attribute.MapType, pk.GetDbValue(dywhere))));
++pkidx;
}
return sb.ToString();
}
else if (primarys.Length == 1 && type == typeof(string))
{
return $"{aliasAndDot}{this.QuoteSqlName(pk1.Attribute.Name)} = {GetNoneParamaterSqlValue(null, null, pk1, pk1.Attribute.MapType, Utils.GetDataReaderValue(pk1.Attribute.MapType, dywhere))}";
return $"{aliasAndDot}{this.QuoteSqlName(pk1.Attribute.Name)} = {RewriteColumn(pk1, GetNoneParamaterSqlValue(null, null, pk1, pk1.Attribute.MapType, Utils.GetDataReaderValue(pk1.Attribute.MapType, dywhere)))}";
}
else if (primarys.Length == 1 && dywhere is IEnumerable)
{
Expand All @@ -317,8 +317,8 @@ public string WhereObject(TableInfo table, string aliasAndDot, object dywhere)
var itype = i.GetType();
isEntityType = (itype == table.Type || itype.BaseType == table.Type);
}
if (isEntityType) sb.Append(GetNoneParamaterSqlValue(null, null, primarys[0], primarys[0].Attribute.MapType, primarys[0].GetDbValue(i)));
else sb.Append(GetNoneParamaterSqlValue(null, null, pk1, pk1.Attribute.MapType, Utils.GetDataReaderValue(pk1.Attribute.MapType, i)));
if (isEntityType) sb.Append(RewriteColumn(primarys[0], GetNoneParamaterSqlValue(null, null, primarys[0], primarys[0].Attribute.MapType, primarys[0].GetDbValue(i))));
else sb.Append(RewriteColumn(pk1, GetNoneParamaterSqlValue(null, null, pk1, pk1.Attribute.MapType, Utils.GetDataReaderValue(pk1.Attribute.MapType, i))));
++ieidx;
}
if (isAny == false) return "";
Expand Down Expand Up @@ -353,7 +353,7 @@ public string WhereObject(TableInfo table, string aliasAndDot, object dywhere)

if (psidx > 0) sb.Append(" AND ");
sb.Append(aliasAndDot).Append(this.QuoteSqlName(trycol.Attribute.Name)).Append(" = ");
sb.Append(GetNoneParamaterSqlValue(null, null, trycol, trycol.Attribute.MapType, Utils.GetDataReaderValue(trycol.Attribute.MapType, p.GetValue(dywhere, null))));
sb.Append(RewriteColumn(trycol, GetNoneParamaterSqlValue(null, null, trycol, trycol.Attribute.MapType, Utils.GetDataReaderValue(trycol.Attribute.MapType, p.GetValue(dywhere, null)))));
++psidx;
}
if (psidx == 0) return "";
Expand All @@ -374,8 +374,8 @@ public string WhereItems<TEntity>(TableInfo table, string aliasAndDot, IEnumerab
sbin.Append(aliasAndDot).Append(this.QuoteSqlName(pk1.Attribute.Name));
var indt = its.Select(a => pk1.GetDbValue(a)).Where(a => a != null).ToArray();
if (indt.Any() == false) return null;
if (indt.Length == 1) sbin.Append(" = ").Append(GetNoneParamaterSqlValue(null, null, pk1, pk1.Attribute.MapType, indt.First()));
else sbin.Append(" IN (").Append(string.Join(",", indt.Select(a => GetNoneParamaterSqlValue(null, null, pk1, pk1.Attribute.MapType, a)))).Append(')');
if (indt.Length == 1) sbin.Append(" = ").Append(RewriteColumn(pk1, GetNoneParamaterSqlValue(null, null, pk1, pk1.Attribute.MapType, indt.First())));
else sbin.Append(" IN (").Append(string.Join(",", indt.Select(a => RewriteColumn(pk1, GetNoneParamaterSqlValue(null, null, pk1, pk1.Attribute.MapType, a))))).Append(')');
return sbin.ToString();
}
var dicpk = its.Length > 5 ? new Dictionary<string, bool>() : null;
Expand All @@ -385,7 +385,7 @@ public string WhereItems<TEntity>(TableInfo table, string aliasAndDot, IEnumerab
{
var filter = "";
foreach (var pk in table.Primarys)
filter += $" AND {aliasAndDot}{this.QuoteSqlName(pk.Attribute.Name)} = {GetNoneParamaterSqlValue(null, null, pk, pk.Attribute.MapType, pk.GetDbValue(item))}";
filter += $" AND {aliasAndDot}{this.QuoteSqlName(pk.Attribute.Name)} = {RewriteColumn(pk, GetNoneParamaterSqlValue(null, null, pk, pk.Attribute.MapType, pk.GetDbValue(item)))}";
if (string.IsNullOrEmpty(filter)) continue;
if (sb != null)
{
Expand Down
4 changes: 2 additions & 2 deletions Providers/FreeSql.Provider.Dameng/Curd/DamengInsert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public override string ToSql()
if (val == null && col.Attribute.IsNullable == false) val = col.CsType == typeof(string) ? "" : Utils.GetDataReaderValue(col.CsType.NullableTypeOrThis(), null);//#384

var colsql = _noneParameter ? _commonUtils.GetNoneParamaterSqlValue(specialParams, _noneParameterFlag, col, col.Attribute.MapType, val) :
_commonUtils.QuoteWriteParamter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"{col.CsName}_{didx}"));
sb.Append(_commonUtils.QuoteWriteColumn(col, colsql));
_commonUtils.QuoteWriteParamterAdapter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"{col.CsName}_{didx}"));
sb.Append(_commonUtils.RewriteColumn(col, colsql));
if (_noneParameter == false)
_params[didx * colidx + colidx2] = _commonUtils.AppendParamter(null, $"{col.CsName}_{didx}", col, col.Attribute.MapType, val);
}
Expand Down
4 changes: 2 additions & 2 deletions Providers/FreeSql.Provider.Dameng/Curd/DamengUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ protected override void ToSqlCase(StringBuilder caseWhen, ColumnInfo[] primarys)
if (_table.Primarys.Length == 1)
{
var pk = _table.Primarys.First();
caseWhen.Append(_commonUtils.QuoteReadColumn(pk, pk.CsType, pk.Attribute.MapType, _commonUtils.QuoteSqlName(pk.Attribute.Name)));
caseWhen.Append(_commonUtils.RereadColumn(pk, _commonUtils.QuoteSqlName(pk.Attribute.Name)));
return;
}
caseWhen.Append("(");
var pkidx = 0;
foreach (var pk in _table.Primarys)
{
if (pkidx > 0) caseWhen.Append(" || '+' || ");
caseWhen.Append(_commonUtils.QuoteReadColumn(pk, pk.CsType, pk.Attribute.MapType, _commonUtils.QuoteSqlName(pk.Attribute.Name)));
caseWhen.Append(_commonUtils.RereadColumn(pk, _commonUtils.QuoteSqlName(pk.Attribute.Name)));
++pkidx;
}
caseWhen.Append(")");
Expand Down
2 changes: 1 addition & 1 deletion Providers/FreeSql.Provider.Dameng/DamengUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public override string TrimQuoteSqlName(string name)
public override string Now => "systimestamp";
public override string NowUtc => "getutcdate";

public override string QuoteWriteParamter(Type type, string paramterName) => paramterName;
public override string QuoteWriteParamterAdapter(Type type, string paramterName) => paramterName;
protected override string QuoteReadColumnAdapter(Type type, Type mapType, string columnName) => columnName;

public override string GetNoneParamaterSqlValue(List<DbParameter> specialParams, string specialParamFlag, ColumnInfo col, Type type, object value)
Expand Down
Loading

0 comments on commit c905278

Please sign in to comment.