mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 02:32:50 +08:00
- 完善 DuckDB 测试;
This commit is contained in:
parent
a1013a39bf
commit
a576d157fb
@ -703,6 +703,7 @@ ManyToMany 级联删除中间表(注意不删除外部根)
|
|||||||
case DataType.CustomPostgreSQL:
|
case DataType.CustomPostgreSQL:
|
||||||
case DataType.KingbaseES:
|
case DataType.KingbaseES:
|
||||||
case DataType.ShenTong:
|
case DataType.ShenTong:
|
||||||
|
case DataType.DuckDB:
|
||||||
case DataType.Firebird: //firebird 只支持单条插入 returning
|
case DataType.Firebird: //firebird 只支持单条插入 returning
|
||||||
if (_tableIdentitys.Length == 1 && _tableReturnColumns.Length == 1)
|
if (_tableIdentitys.Length == 1 && _tableReturnColumns.Length == 1)
|
||||||
{
|
{
|
||||||
@ -758,6 +759,7 @@ ManyToMany 级联删除中间表(注意不删除外部根)
|
|||||||
case DataType.CustomPostgreSQL:
|
case DataType.CustomPostgreSQL:
|
||||||
case DataType.KingbaseES:
|
case DataType.KingbaseES:
|
||||||
case DataType.ShenTong:
|
case DataType.ShenTong:
|
||||||
|
case DataType.DuckDB:
|
||||||
var rets = OrmInsert(table).AppendData(data).ExecuteInserted();
|
var rets = OrmInsert(table).AppendData(data).ExecuteInserted();
|
||||||
_cascadeAffrows += rets.Count;
|
_cascadeAffrows += rets.Count;
|
||||||
if (rets.Count != data.Count()) throw new Exception($"特别错误:批量添加失败,{_orm.Ado.DataType} 的返回数据,与添加的数目不匹配");
|
if (rets.Count != data.Count()) throw new Exception($"特别错误:批量添加失败,{_orm.Ado.DataType} 的返回数据,与添加的数目不匹配");
|
||||||
@ -810,6 +812,7 @@ ManyToMany 级联删除中间表(注意不删除外部根)
|
|||||||
case DataType.CustomPostgreSQL:
|
case DataType.CustomPostgreSQL:
|
||||||
case DataType.KingbaseES:
|
case DataType.KingbaseES:
|
||||||
case DataType.ShenTong:
|
case DataType.ShenTong:
|
||||||
|
case DataType.DuckDB:
|
||||||
case DataType.ClickHouse:
|
case DataType.ClickHouse:
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
|
@ -344,6 +344,7 @@ namespace FreeSql
|
|||||||
case DataType.CustomPostgreSQL:
|
case DataType.CustomPostgreSQL:
|
||||||
case DataType.KingbaseES:
|
case DataType.KingbaseES:
|
||||||
case DataType.ShenTong:
|
case DataType.ShenTong:
|
||||||
|
case DataType.DuckDB:
|
||||||
case DataType.ClickHouse:
|
case DataType.ClickHouse:
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
|
@ -47,6 +47,7 @@ namespace FreeSql
|
|||||||
case DataType.CustomPostgreSQL:
|
case DataType.CustomPostgreSQL:
|
||||||
case DataType.KingbaseES:
|
case DataType.KingbaseES:
|
||||||
case DataType.ShenTong:
|
case DataType.ShenTong:
|
||||||
|
case DataType.DuckDB:
|
||||||
case DataType.Firebird: //firebird 只支持单条插入 returning
|
case DataType.Firebird: //firebird 只支持单条插入 returning
|
||||||
if (_tableIdentitys.Length == 1 && _tableReturnColumns.Length == 1)
|
if (_tableIdentitys.Length == 1 && _tableReturnColumns.Length == 1)
|
||||||
{
|
{
|
||||||
@ -115,6 +116,7 @@ namespace FreeSql
|
|||||||
case DataType.CustomPostgreSQL:
|
case DataType.CustomPostgreSQL:
|
||||||
case DataType.KingbaseES:
|
case DataType.KingbaseES:
|
||||||
case DataType.ShenTong:
|
case DataType.ShenTong:
|
||||||
|
case DataType.DuckDB:
|
||||||
await DbContextFlushCommandAsync(cancellationToken);
|
await DbContextFlushCommandAsync(cancellationToken);
|
||||||
var rets = await this.OrmInsert(data).ExecuteInsertedAsync(cancellationToken);
|
var rets = await this.OrmInsert(data).ExecuteInsertedAsync(cancellationToken);
|
||||||
if (rets.Count != data.Count()) throw new Exception(DbContextStrings.SpecialError_BatchAdditionFailed(_db.OrmOriginal.Ado.DataType));
|
if (rets.Count != data.Count()) throw new Exception(DbContextStrings.SpecialError_BatchAdditionFailed(_db.OrmOriginal.Ado.DataType));
|
||||||
|
@ -46,6 +46,7 @@ namespace FreeSql
|
|||||||
case DataType.CustomPostgreSQL:
|
case DataType.CustomPostgreSQL:
|
||||||
case DataType.KingbaseES:
|
case DataType.KingbaseES:
|
||||||
case DataType.ShenTong:
|
case DataType.ShenTong:
|
||||||
|
case DataType.DuckDB:
|
||||||
case DataType.Firebird: //firebird 只支持单条插入 returning
|
case DataType.Firebird: //firebird 只支持单条插入 returning
|
||||||
if (_tableIdentitys.Length == 1 && _tableReturnColumns.Length == 1)
|
if (_tableIdentitys.Length == 1 && _tableReturnColumns.Length == 1)
|
||||||
{
|
{
|
||||||
@ -118,6 +119,7 @@ namespace FreeSql
|
|||||||
case DataType.CustomPostgreSQL:
|
case DataType.CustomPostgreSQL:
|
||||||
case DataType.KingbaseES:
|
case DataType.KingbaseES:
|
||||||
case DataType.ShenTong:
|
case DataType.ShenTong:
|
||||||
|
case DataType.DuckDB:
|
||||||
DbContextFlushCommand();
|
DbContextFlushCommand();
|
||||||
var rets = this.OrmInsert(data).ExecuteInserted();
|
var rets = this.OrmInsert(data).ExecuteInserted();
|
||||||
if (rets.Count != data.Count()) throw new Exception(DbContextStrings.SpecialError_BatchAdditionFailed(_db.OrmOriginal.Ado.DataType));
|
if (rets.Count != data.Count()) throw new Exception(DbContextStrings.SpecialError_BatchAdditionFailed(_db.OrmOriginal.Ado.DataType));
|
||||||
|
@ -1117,14 +1117,14 @@ FROM ""tb_topic"" a", subquery);
|
|||||||
var subquery = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToSql();
|
var subquery = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToSql();
|
||||||
Assert.Equal(@"SELECT a.""id"", a.""clicks"", a.""typeguid"", a.""title"", a.""createtime""
|
Assert.Equal(@"SELECT a.""id"", a.""clicks"", a.""typeguid"", a.""title"", a.""createtime""
|
||||||
FROM ""tb_topic"" a
|
FROM ""tb_topic"" a
|
||||||
WHERE (((cast(a.""id"" as text)) in (SELECT b.""title""
|
WHERE ((((a.""id"")::text) in (SELECT b.""title""
|
||||||
FROM ""tb_topic"" b)))", subquery);
|
FROM ""tb_topic"" b)))", subquery);
|
||||||
var subqueryList = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToList();
|
var subqueryList = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToList();
|
||||||
|
|
||||||
subquery = select.Where(a => select.As("b").Limit(10).ToList(b => b.Title).Contains(a.Id.ToString())).ToSql();
|
subquery = select.Where(a => select.As("b").Limit(10).ToList(b => b.Title).Contains(a.Id.ToString())).ToSql();
|
||||||
Assert.Equal(@"SELECT a.""id"", a.""clicks"", a.""typeguid"", a.""title"", a.""createtime""
|
Assert.Equal(@"SELECT a.""id"", a.""clicks"", a.""typeguid"", a.""title"", a.""createtime""
|
||||||
FROM ""tb_topic"" a
|
FROM ""tb_topic"" a
|
||||||
WHERE (((cast(a.""id"" as text)) in (SELECT b.""title""
|
WHERE ((((a.""id"")::text) in (SELECT b.""title""
|
||||||
FROM ""tb_topic"" b
|
FROM ""tb_topic"" b
|
||||||
limit 10)))", subquery);
|
limit 10)))", subquery);
|
||||||
subqueryList = select.Where(a => select.As("b").Limit(10).ToList(b => b.Title).Contains(a.Id.ToString())).ToList();
|
subqueryList = select.Where(a => select.As("b").Limit(10).ToList(b => b.Title).Contains(a.Id.ToString())).ToList();
|
||||||
|
@ -8,6 +8,7 @@ using System.Collections.Generic;
|
|||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
@ -394,7 +395,7 @@ namespace FreeSql.Internal
|
|||||||
case DataType.CustomPostgreSQL:
|
case DataType.CustomPostgreSQL:
|
||||||
case DataType.KingbaseES:
|
case DataType.KingbaseES:
|
||||||
case DataType.ShenTong:
|
case DataType.ShenTong:
|
||||||
if (strlen < 0) colattr.DbType = $"TEXT{strNotNull}";
|
if (strlen < 0) colattr.DbType = $"TEXT{strNotNull}";
|
||||||
else colattr.DbType = Regex.Replace(colattr.DbType, charPattern, m =>
|
else colattr.DbType = Regex.Replace(colattr.DbType, charPattern, m =>
|
||||||
replaceCounter++ == 0 ? $"{m.Groups[1].Value}({strlen})" : m.Groups[0].Value);
|
replaceCounter++ == 0 ? $"{m.Groups[1].Value}({strlen})" : m.Groups[0].Value);
|
||||||
break;
|
break;
|
||||||
@ -416,7 +417,8 @@ namespace FreeSql.Internal
|
|||||||
replaceCounter++ == 0 ? $"{m.Groups[1].Value}({strlen})" : m.Groups[0].Value);
|
replaceCounter++ == 0 ? $"{m.Groups[1].Value}({strlen})" : m.Groups[0].Value);
|
||||||
break;
|
break;
|
||||||
case DataType.Sqlite:
|
case DataType.Sqlite:
|
||||||
if (strlen < 0) colattr.DbType = $"TEXT{strNotNull}";
|
case DataType.DuckDB:
|
||||||
|
if (strlen < 0) colattr.DbType = $"TEXT{strNotNull}";
|
||||||
else colattr.DbType = Regex.Replace(colattr.DbType, charPattern, m =>
|
else colattr.DbType = Regex.Replace(colattr.DbType, charPattern, m =>
|
||||||
replaceCounter++ == 0 ? $"{m.Groups[1].Value}({strlen})" : m.Groups[0].Value);
|
replaceCounter++ == 0 ? $"{m.Groups[1].Value}({strlen})" : m.Groups[0].Value);
|
||||||
break;
|
break;
|
||||||
@ -477,7 +479,8 @@ namespace FreeSql.Internal
|
|||||||
colattr.DbType = $"BLOB{strNotNull}";
|
colattr.DbType = $"BLOB{strNotNull}";
|
||||||
break;
|
break;
|
||||||
case DataType.Sqlite:
|
case DataType.Sqlite:
|
||||||
colattr.DbType = $"BLOB{strNotNull}";
|
case DataType.DuckDB:
|
||||||
|
colattr.DbType = $"BLOB{strNotNull}";
|
||||||
break;
|
break;
|
||||||
case DataType.MsAccess:
|
case DataType.MsAccess:
|
||||||
if (strlen < 0) colattr.DbType = $"BLOB{strNotNull}";
|
if (strlen < 0) colattr.DbType = $"BLOB{strNotNull}";
|
||||||
@ -2137,7 +2140,12 @@ namespace FreeSql.Internal
|
|||||||
{
|
{
|
||||||
if (obj == null) return null;
|
if (obj == null) return null;
|
||||||
if (obj is bool || obj is bool?) return (bool)obj == true ? "1" : "0";
|
if (obj is bool || obj is bool?) return (bool)obj == true ? "1" : "0";
|
||||||
return string.Concat(obj);
|
return string.Format(CultureInfo.InvariantCulture, "{0}", obj);
|
||||||
|
}
|
||||||
|
public static bool ValueIsEnumAndTargetIsNumber(object value, Type targetType)
|
||||||
|
{
|
||||||
|
if (value == null || targetType == null) return false;
|
||||||
|
return value.GetType().IsEnum && targetType.IsNumberType();
|
||||||
}
|
}
|
||||||
public static byte[] GuidToBytes(Guid guid)
|
public static byte[] GuidToBytes(Guid guid)
|
||||||
{
|
{
|
||||||
@ -2207,6 +2215,7 @@ namespace FreeSql.Internal
|
|||||||
static MethodInfo MethodDateTimeTryParse = typeof(DateTime).GetMethod("TryParse", new[] { typeof(string), typeof(DateTime).MakeByRefType() });
|
static MethodInfo MethodDateTimeTryParse = typeof(DateTime).GetMethod("TryParse", new[] { typeof(string), typeof(DateTime).MakeByRefType() });
|
||||||
static MethodInfo MethodDateTimeOffsetTryParse = typeof(DateTimeOffset).GetMethod("TryParse", new[] { typeof(string), typeof(DateTimeOffset).MakeByRefType() });
|
static MethodInfo MethodDateTimeOffsetTryParse = typeof(DateTimeOffset).GetMethod("TryParse", new[] { typeof(string), typeof(DateTimeOffset).MakeByRefType() });
|
||||||
static MethodInfo MethodToString = typeof(Utils).GetMethod("ToStringConcat", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(object) }, null);
|
static MethodInfo MethodToString = typeof(Utils).GetMethod("ToStringConcat", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(object) }, null);
|
||||||
|
static MethodInfo MethodValueIsEnumAndTargetIsNumber = typeof(Utils).GetMethod("ValueIsEnumAndTargetIsNumber", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(object), typeof(Type) }, null);
|
||||||
static MethodInfo MethodBigIntegerParse = typeof(Utils).GetMethod("ToBigInteger", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(string) }, null);
|
static MethodInfo MethodBigIntegerParse = typeof(Utils).GetMethod("ToBigInteger", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(string) }, null);
|
||||||
static PropertyInfo PropertyDateTimeOffsetDateTime = typeof(DateTimeOffset).GetProperty("DateTime", BindingFlags.Instance | BindingFlags.Public);
|
static PropertyInfo PropertyDateTimeOffsetDateTime = typeof(DateTimeOffset).GetProperty("DateTime", BindingFlags.Instance | BindingFlags.Public);
|
||||||
static PropertyInfo PropertyDateTimeTicks = typeof(DateTime).GetProperty("Ticks", BindingFlags.Instance | BindingFlags.Public);
|
static PropertyInfo PropertyDateTimeTicks = typeof(DateTime).GetProperty("Ticks", BindingFlags.Instance | BindingFlags.Public);
|
||||||
@ -2555,8 +2564,12 @@ namespace FreeSql.Internal
|
|||||||
Expression.Constant(typeof(DateTime)), Expression.Constant(typeof(DateTimeOffset))
|
Expression.Constant(typeof(DateTime)), Expression.Constant(typeof(DateTimeOffset))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
// BigInteger/bool -> int
|
//BigInteger/bool/Enum -> int
|
||||||
//defaultRetExp = Expression.Return(returnTarget, Expression.Call(MethodGetDataReaderValue, Expression.Constant(type), Expression.Convert(Expression.Call(MethodToString, valueExp), typeof(object))));
|
defaultRetExp = Expression.IfThenElse(
|
||||||
|
Expression.Call(MethodValueIsEnumAndTargetIsNumber, valueExp, Expression.Constant(type)),
|
||||||
|
defaultRetExp,
|
||||||
|
Expression.Return(returnTarget, Expression.Call(MethodGetDataReaderValue, Expression.Constant(type), Expression.Convert(Expression.Call(MethodToString, valueExp), typeof(object))))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
else if (tryparseBooleanExp != null)
|
else if (tryparseBooleanExp != null)
|
||||||
switchExp = Expression.Switch(
|
switchExp = Expression.Switch(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user