Skip to content

Commit

Permalink
Get collection item type only once
Browse files Browse the repository at this point in the history
  • Loading branch information
Giorgi committed Nov 29, 2024
1 parent 1f1f024 commit 466c564
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions DuckDB.NET.Data/Internal/ClrToDuckDBConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ namespace DuckDB.NET.Data.Internal;

internal static class ClrToDuckDBConverter
{
public static DuckDBValue ToDuckDBValue(this object? item, DuckDBLogicalType logicalType)
public static DuckDBValue ToDuckDBValue(this object? item, DuckDBLogicalType logicalType, DuckDBType duckDBType)
{
if (item.IsNull())
{
return NativeMethods.Value.DuckDBCreateNullValue();
}

var duckDBType = NativeMethods.LogicalType.DuckDBGetTypeId(logicalType);

return (duckDBType, item) switch
{
(DuckDBType.Boolean, bool value) => NativeMethods.Value.DuckDBCreateBool(value),
Expand Down Expand Up @@ -76,12 +74,14 @@ private static DuckDBValue CreateCollectionValue(DuckDBLogicalType logicalType,
using var collectionItemType = isList ? NativeMethods.LogicalType.DuckDBListTypeChildType(logicalType) :
NativeMethods.LogicalType.DuckDBArrayTypeChildType(logicalType);

var duckDBType = NativeMethods.LogicalType.DuckDBGetTypeId(collectionItemType);

var values = new DuckDBValue[collection.Count];

var index = 0;
foreach (var item in collection)
{
var duckDBValue = item.ToDuckDBValue(collectionItemType);
var duckDBValue = item.ToDuckDBValue(collectionItemType, duckDBType);
values[index] = duckDBValue;
index++;
}
Expand Down
4 changes: 3 additions & 1 deletion DuckDB.NET.Data/Internal/PreparedStatement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ private static void BindParameters(DuckDBPreparedStatement preparedStatement, Du
private static void BindParameter(DuckDBPreparedStatement preparedStatement, long index, DuckDBParameter parameter)
{
using var parameterLogicalType = NativeMethods.PreparedStatements.DuckDBParamLogicalType(preparedStatement, index);
using var duckDBValue = parameter.Value.ToDuckDBValue(parameterLogicalType);
var duckDBType = NativeMethods.LogicalType.DuckDBGetTypeId(parameterLogicalType);

using var duckDBValue = parameter.Value.ToDuckDBValue(parameterLogicalType, duckDBType);

var result = NativeMethods.PreparedStatements.DuckDBBindValue(preparedStatement, index, duckDBValue);

Expand Down

0 comments on commit 466c564

Please sign in to comment.