mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 12:28:15 +08:00
完成v0.3.17所有数据库的测试
This commit is contained in:
@ -15,6 +15,7 @@ namespace FreeSql.Sqlite.Curd {
|
||||
_orm.CodeFirst.SyncStructure(_tables.Select(a => a.Table.Type).ToArray());
|
||||
|
||||
var sb = new StringBuilder();
|
||||
var sbnav = new StringBuilder();
|
||||
sb.Append(_select).Append(field).Append(" \r\nFROM ");
|
||||
var tbsjoin = _tables.Where(a => a.Type != SelectTableInfoType.From).ToArray();
|
||||
var tbsfrom = _tables.Where(a => a.Type == SelectTableInfoType.From).ToArray();
|
||||
@ -22,9 +23,15 @@ namespace FreeSql.Sqlite.Curd {
|
||||
sb.Append(_commonUtils.QuoteSqlName(tableRuleInvoke(tbsfrom[a].Table.Type, tbsfrom[a].Table.DbName))).Append(" ").Append(tbsfrom[a].Alias);
|
||||
if (tbsjoin.Length > 0) {
|
||||
//如果存在 join 查询,则处理 from t1, t2 改为 from t1 inner join t2 on 1 = 1
|
||||
for (var b = 1; b < tbsfrom.Length; b++)
|
||||
sb.Append(" \r\nLEFT JOIN ").Append(_commonUtils.QuoteSqlName(tableRuleInvoke(tbsfrom[b].Table.Type, tbsfrom[b].Table.DbName))).Append(" ").Append(tbsfrom[b].Alias).Append(" ON 1 = 1");
|
||||
for (var b = 1; b < tbsfrom.Length; b++) {
|
||||
sb.Append(" \r\nLEFT JOIN ").Append(_commonUtils.QuoteSqlName(tableRuleInvoke(tbsfrom[b].Table.Type, tbsfrom[b].Table.DbName))).Append(" ").Append(tbsfrom[b].Alias);
|
||||
if (string.IsNullOrEmpty(tbsfrom[b].NavigateCondition) && string.IsNullOrEmpty(tbsfrom[b].On)) sb.Append(" ON 1 = 1");
|
||||
else sb.Append(" ON ").Append(tbsfrom[b].NavigateCondition ?? tbsfrom[b].On);
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
if (!string.IsNullOrEmpty(tbsfrom[a].NavigateCondition)) sbnav.Append(" AND (").Append(tbsfrom[a].NavigateCondition).Append(")");
|
||||
if (!string.IsNullOrEmpty(tbsfrom[a].On)) sbnav.Append(" AND (").Append(tbsfrom[a].On).Append(")");
|
||||
}
|
||||
if (a < tbsfrom.Length - 1) sb.Append(", ");
|
||||
}
|
||||
@ -41,21 +48,19 @@ namespace FreeSql.Sqlite.Curd {
|
||||
sb.Append(" \r\nRIGHT JOIN ");
|
||||
break;
|
||||
}
|
||||
sb.Append(_commonUtils.QuoteSqlName(tableRuleInvoke(tb.Table.Type, tb.Table.DbName))).Append(" ").Append(tb.Alias).Append(" ON ").Append(tb.On);
|
||||
sb.Append(_commonUtils.QuoteSqlName(tableRuleInvoke(tb.Table.Type, tb.Table.DbName))).Append(" ").Append(tb.Alias).Append(" ON ").Append(tb.On ?? tb.NavigateCondition);
|
||||
if (!string.IsNullOrEmpty(tb.On) && !string.IsNullOrEmpty(tb.NavigateCondition)) sbnav.Append(" AND (").Append(tb.NavigateCondition).Append(")");
|
||||
}
|
||||
if (_join.Length > 0) sb.Append(_join);
|
||||
|
||||
var sbqf = new StringBuilder();
|
||||
sbnav.Append(_where);
|
||||
foreach (var tb in _tables) {
|
||||
if (tb.Type == SelectTableInfoType.Parent) continue;
|
||||
if (string.IsNullOrEmpty(tb.Table.SelectFilter) == false)
|
||||
sbqf.Append(" AND (").Append(tb.Table.SelectFilter.Replace("a.", $"{tb.Alias}.")).Append(")");
|
||||
sbnav.Append(" AND (").Append(tb.Table.SelectFilter.Replace("a.", $"{tb.Alias}.")).Append(")");
|
||||
}
|
||||
if (_where.Length > 0) {
|
||||
sb.Append(" \r\nWHERE ").Append(_where.ToString().Substring(5));
|
||||
if (sbqf.Length > 0) sb.Append(sbqf.ToString());
|
||||
} else {
|
||||
if (sbqf.Length > 0) sb.Append(" \r\nWHERE ").Append(sbqf.Remove(0, 5));
|
||||
if (sbnav.Length > 0) {
|
||||
sb.Append(" \r\nWHERE ").Append(sbnav.Remove(0, 5));
|
||||
}
|
||||
if (string.IsNullOrEmpty(_groupby) == false) {
|
||||
sb.Append(_groupby);
|
||||
@ -66,6 +71,7 @@ namespace FreeSql.Sqlite.Curd {
|
||||
if (_skip > 0 || _limit > 0)
|
||||
sb.Append(" \r\nlimit ").Append(Math.Max(0, _skip)).Append(",").Append(_limit > 0 ? _limit : -1);
|
||||
|
||||
sbnav.Clear();
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ namespace FreeSql.Sqlite {
|
||||
if (param == null) return "NULL";
|
||||
if (param is bool || param is bool?)
|
||||
return (bool)param ? 1 : 0;
|
||||
else if (param is string)
|
||||
else if (param is string || param is char)
|
||||
return string.Concat("'", param.ToString().Replace("'", "''"), "'");
|
||||
else if (param is Enum)
|
||||
return ((Enum)param).ToInt64();
|
||||
|
@ -17,23 +17,26 @@ namespace FreeSql.Sqlite {
|
||||
switch (exp.NodeType) {
|
||||
case ExpressionType.Convert:
|
||||
var operandExp = (exp as UnaryExpression)?.Operand;
|
||||
switch (exp.Type.NullableTypeOrThis().ToString()) {
|
||||
case "System.Boolean": return $"({getExp(operandExp)} not in ('0','false'))";
|
||||
case "System.Byte": return $"cast({getExp(operandExp)} as int2)";
|
||||
case "System.Char": return $"substr(cast({getExp(operandExp)} as character), 1, 1)";
|
||||
case "System.DateTime": return $"datetime({getExp(operandExp)})";
|
||||
case "System.Decimal": return $"cast({getExp(operandExp)} as decimal(36,18))";
|
||||
case "System.Double": return $"cast({getExp(operandExp)} as double)";
|
||||
case "System.Int16":
|
||||
case "System.Int32":
|
||||
case "System.Int64":
|
||||
case "System.SByte": return $"cast({getExp(operandExp)} as smallint)";
|
||||
case "System.Single": return $"cast({getExp(operandExp)} as float)";
|
||||
case "System.String": return $"cast({getExp(operandExp)} as character)";
|
||||
case "System.UInt16": return $"cast({getExp(operandExp)} as unsigned)";
|
||||
case "System.UInt32": return $"cast({getExp(operandExp)} as decimal(10,0))";
|
||||
case "System.UInt64": return $"cast({getExp(operandExp)} as decimal(21,0))";
|
||||
case "System.Guid": return $"substr(cast({getExp(operandExp)} as character), 1, 36)";
|
||||
var gentype = exp.Type.NullableTypeOrThis();
|
||||
if (gentype != exp.Type.NullableTypeOrThis()) {
|
||||
switch (exp.Type.NullableTypeOrThis().ToString()) {
|
||||
case "System.Boolean": return $"({getExp(operandExp)} not in ('0','false'))";
|
||||
case "System.Byte": return $"cast({getExp(operandExp)} as int2)";
|
||||
case "System.Char": return $"substr(cast({getExp(operandExp)} as character), 1, 1)";
|
||||
case "System.DateTime": return $"datetime({getExp(operandExp)})";
|
||||
case "System.Decimal": return $"cast({getExp(operandExp)} as decimal(36,18))";
|
||||
case "System.Double": return $"cast({getExp(operandExp)} as double)";
|
||||
case "System.Int16":
|
||||
case "System.Int32":
|
||||
case "System.Int64":
|
||||
case "System.SByte": return $"cast({getExp(operandExp)} as smallint)";
|
||||
case "System.Single": return $"cast({getExp(operandExp)} as float)";
|
||||
case "System.String": return $"cast({getExp(operandExp)} as character)";
|
||||
case "System.UInt16": return $"cast({getExp(operandExp)} as unsigned)";
|
||||
case "System.UInt32": return $"cast({getExp(operandExp)} as decimal(10,0))";
|
||||
case "System.UInt64": return $"cast({getExp(operandExp)} as decimal(21,0))";
|
||||
case "System.Guid": return $"substr(cast({getExp(operandExp)} as character), 1, 36)";
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ExpressionType.Call:
|
||||
|
Reference in New Issue
Block a user