Skip to content

Commit

Permalink
Merge branch 'develop' into nightly-builds
Browse files Browse the repository at this point in the history
  • Loading branch information
Giorgi committed Mar 10, 2024
2 parents 7ac8604 + b5552ce commit b090806
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 89 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/Sonar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
pull_request_target:
types: [opened, synchronize, reopened]
jobs:
authorize:
Authorize:
environment:
${{ github.event_name == 'pull_request_target' &&
github.event.pull_request.head.repo.full_name != github.repository &&
Expand All @@ -20,7 +20,7 @@ jobs:


build:
needs: authorize
needs: Authorize
name: Build and analyze
runs-on: ubuntu-latest
steps:
Expand All @@ -33,25 +33,34 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha || github.ref }}
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json

- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~/sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Cache SonarCloud scanner
id: cache-sonar-scanner
uses: actions/cache@v4
with:
path: ./.sonar/scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner

- name: Install SonarCloud scanner
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
shell: pwsh
run: |
New-Item -Path ./.sonar/scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path ./.sonar/scanner
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
Expand Down
18 changes: 13 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ on:
- '**.md'

schedule:
- cron: "0 */6 * * *"
- cron: "15 */12 * * *"

jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-14]
arch: ['amd64']
dotnet-version: ['8.0']
fail-fast: false

name: Build library (${{ matrix.os }})
Expand All @@ -46,10 +45,10 @@ jobs:
fetch-depth: 0
ref: ${{ env.BuildBranch }}

- name: Setup .NET Core SDK ${{ matrix.dotnet-version }}
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ matrix.dotnet-version }}
global-json-file: global.json

- name: Build
run: dotnet build --configuration Release /p:BuildType=Full
Expand All @@ -67,15 +66,23 @@ jobs:
CoverletOutputFormat: lcov
run: dotnet test --configuration Release --verbosity normal --logger GitHubActions /p:CollectCoverage=true /p:CoverletOutputFormat=lcov /p:BuildType=Full

- name: Coveralls Parallel
- name: Upload coverage reports to Coveralls Parallel
uses: coverallsapp/github-action@v2
if: github.event_name != 'schedule'
with:
github-token: ${{ secrets.github_token }}
flag-name: run-${{ matrix.os }}
path-to-lcov: DuckDB.NET.Test/coverage.net8.0.info
parallel: true
format: lcov

- name: Upload coverage reports to Codecov
if: matrix.os == 'ubuntu-latest' && github.event_name != 'schedule'
uses: codecov/codecov-action@v4.0.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: Giorgi/DuckDB.NET

- name: Upload Artifacts
if: matrix.os == 'ubuntu-latest' && github.event_name != 'pull_request' && github.actor == 'Giorgi'
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -109,6 +116,7 @@ jobs:
needs: build
name: Finish Coveralls Collection
runs-on: ubuntu-latest
if: github.event_name != 'schedule'
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@v2
Expand Down
7 changes: 0 additions & 7 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,4 @@
<PackagePath></PackagePath>
</None>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
5 changes: 1 addition & 4 deletions DuckDB.NET.Bindings/Bindings.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="GitVersion.MsBuild" Version="5.11.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="GitVersion.MsBuild" Version="5.11.1" PrivateAssets="all" />
</ItemGroup>
<!-- End native lib section -->
</Project>
13 changes: 2 additions & 11 deletions DuckDB.NET.Bindings/SafeUnmanagedMemoryHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,18 @@ namespace DuckDB.NET.Native;

public class SafeUnmanagedMemoryHandle : SafeHandleZeroOrMinusOneIsInvalid
{
private readonly bool freeWithGlobal;
public SafeUnmanagedMemoryHandle() : base(true) { }

public SafeUnmanagedMemoryHandle(IntPtr preexistingHandle, bool ownsHandle, bool freeWithGlobal = true) : base(ownsHandle)
public SafeUnmanagedMemoryHandle(IntPtr preexistingHandle) : base(true)
{
this.freeWithGlobal = freeWithGlobal;
SetHandle(preexistingHandle);
}

protected override bool ReleaseHandle()
{
if (handle != IntPtr.Zero)
{
if (freeWithGlobal)
{
Marshal.FreeHGlobal(handle);
}
else
{
Marshal.FreeCoTaskMem(handle);
}
Marshal.FreeCoTaskMem(handle);

handle = IntPtr.Zero;

Expand Down
28 changes: 14 additions & 14 deletions DuckDB.NET.Bindings/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public static string ToManagedString(this IntPtr unmanagedString, bool freeWhenC
{
string result;
#if NET6_0_OR_GREATER
result = length.HasValue
? Marshal.PtrToStringUTF8(unmanagedString, length.Value)
result = length.HasValue
? Marshal.PtrToStringUTF8(unmanagedString, length.Value)
: Marshal.PtrToStringUTF8(unmanagedString) ?? string.Empty;
#else
if (unmanagedString == IntPtr.Zero)
Expand Down Expand Up @@ -59,23 +59,23 @@ public static SafeUnmanagedMemoryHandle ToUnmanagedString(this string? managedSt
{
#if NET6_0_OR_GREATER
var pointer = Marshal.StringToCoTaskMemUTF8(managedString);

return new SafeUnmanagedMemoryHandle(pointer, true, false);
return new SafeUnmanagedMemoryHandle(pointer);
#else
if (managedString == null)
{
return new SafeUnmanagedMemoryHandle(IntPtr.Zero, true);
}

if (managedString == null)
{
return new SafeUnmanagedMemoryHandle();
}

int len = Encoding.UTF8.GetByteCount(managedString);
int len = Encoding.UTF8.GetByteCount(managedString);

var buffer = new byte[len + 1];
Encoding.UTF8.GetBytes(managedString, 0, managedString.Length, buffer, 0);
var buffer = new byte[len + 1];
Encoding.UTF8.GetBytes(managedString, 0, managedString.Length, buffer, 0);

var nativeUtf8 = Marshal.AllocHGlobal(buffer.Length);
Marshal.Copy(buffer, 0, nativeUtf8, buffer.Length);
var nativeUtf8 = Marshal.AllocCoTaskMem(buffer.Length);
Marshal.Copy(buffer, 0, nativeUtf8, buffer.Length);

return new SafeUnmanagedMemoryHandle(nativeUtf8, true);
return new SafeUnmanagedMemoryHandle(nativeUtf8);
#endif
}

Expand Down
5 changes: 1 addition & 4 deletions DuckDB.NET.Data/Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GitVersion.MsBuild" Version="5.11.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="GitVersion.MsBuild" Version="5.11.1" PrivateAssets="all" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
Expand Down
16 changes: 4 additions & 12 deletions DuckDB.NET.Data/DuckDBConnectionStringBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using DuckDB.NET.Data.ConnectionString;
using System.Collections.Generic;
using DuckDB.NET.Native;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Diagnostics.CodeAnalysis;
using DuckDB.NET.Native;

namespace DuckDB.NET.Data;

Expand Down Expand Up @@ -50,14 +49,7 @@ internal static DuckDBConnectionString Parse(string connectionString)
continue;
}

if (ConfigurationOptions.Contains(pair.Key))
{
configurations.Add(pair.Key, pair.Value.ToString()!);
}
else
{
throw new InvalidOperationException($"Unrecognized connection string property '{pair.Key}'");
}
configurations.Add(pair.Key, pair.Value.ToString()!);
}

if (string.IsNullOrEmpty(dataSource))
Expand Down Expand Up @@ -90,7 +82,7 @@ internal static DuckDBConnectionString Parse(string connectionString)
}
else
{
throw new InvalidOperationException($"Unsupported property '{keyword}'");
throw new InvalidOperationException($"Unrecognized connection string property '{keyword}'");
}
}
}
Expand Down
18 changes: 8 additions & 10 deletions DuckDB.NET.Samples/Samples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
<TargetFrameworks>net6.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
<BuildType>Full</BuildType>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\DuckDB.NET.Test\Helpers\NativeLibraryHelper.cs" Link="Helpers\NativeLibraryHelper.cs" />
</ItemGroup>
<PropertyGroup>
<BuildType>Full</BuildType>
</PropertyGroup>

<ItemGroup>
<ItemGroup>
<Compile Include="..\DuckDB.NET.Test\Helpers\NativeLibraryHelper.cs" Link="Helpers\NativeLibraryHelper.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Dapper" Version="2.1.24" />
</ItemGroup>

Expand All @@ -25,6 +24,5 @@

<ItemGroup>
<Folder Include="Helpers\" />
</ItemGroup>

</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion DuckDB.NET.Test/Helpers/DisposableFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public DisposableFile(string filename)

public static DisposableFile GenerateInTemp(string extension = null, int? index = null, bool create = false)
{
var fileBuilder = new StringBuilder(Path.Combine(Path.GetTempPath(), "Temp File-" + Guid.NewGuid().ToString()));
var fileBuilder = new StringBuilder(Path.Combine(Directory.GetCurrentDirectory(), "Temp File-" + Guid.NewGuid().ToString()));

if (index != null)
{
Expand Down
43 changes: 40 additions & 3 deletions DuckDB.NET.Test/Parameters/HugeIntParameterTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Numerics;
using DuckDB.NET.Data;
using DuckDB.NET.Native;
using FluentAssertions;
using Xunit;

Expand Down Expand Up @@ -36,16 +37,52 @@ public void BindValueTest()
Command.ExecuteNonQuery();

Command.CommandText = "INSERT INTO HugeIntTests VALUES (9, ?);";

var value = BigInteger.Add(ulong.MaxValue, 125);
Command.Parameters.Add(new DuckDBParameter(value));
Command.ExecuteNonQuery();

Command.CommandText = "SELECT * from HugeIntTests;";


var reader = Command.ExecuteReader();
reader.Read();

var receivedValue = reader.GetFieldValue<BigInteger>(1);
receivedValue.Should().Be(value);
}

[Fact]
public void SimpleNegativeHugeIntTest()
{
Command.CommandText = $"SELECT {DuckDBHugeInt.HugeIntMinValue}::HUGEINT;";
Command.ExecuteNonQuery();

var scalar = Command.ExecuteScalar();
scalar.Should().Be(DuckDBHugeInt.HugeIntMinValue);

var reader = Command.ExecuteReader();
reader.Read();

var receivedValue = reader.GetFieldValue<BigInteger>(0);
receivedValue.Should().Be(DuckDBHugeInt.HugeIntMinValue);
}

[Fact]
public void BindNegativeHugeIntValueTest()
{
Command.CommandText = "CREATE TABLE NegativeHugeIntTests (key INTEGER, value HugeInt)";
Command.ExecuteNonQuery();

Command.CommandText = "INSERT INTO NegativeHugeIntTests VALUES (9, ?);";

var value = DuckDBHugeInt.HugeIntMinValue;
Command.Parameters.Add(new DuckDBParameter(value));
Command.ExecuteNonQuery();

Command.CommandText = "SELECT * from NegativeHugeIntTests;";

var reader = Command.ExecuteReader();
reader.Read();

var receivedValue = reader.GetFieldValue<BigInteger>(1);
receivedValue.Should().Be(value);
}
Expand Down
Loading

0 comments on commit b090806

Please sign in to comment.