Skip to content

Commit

Permalink
Expose query progress on DuckDBConnection
Browse files Browse the repository at this point in the history
  • Loading branch information
Giorgi committed Feb 24, 2025
1 parent 12dbc9c commit 547e801
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DuckDB.NET.Bindings/DuckDBNativeObjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public unsafe partial struct DuckDBStringInlined
}

[StructLayout(LayoutKind.Sequential)]
public struct DuckDBQueryProgressType
public struct DuckDBQueryProgress
{
public double Percentage { get; }
public ulong RowsProcessed { get; }
Expand Down
2 changes: 1 addition & 1 deletion DuckDB.NET.Bindings/NativeMethods/NativeMethods.Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static class Startup
public static extern void DuckDBInterrupt(DuckDBNativeConnection connection);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_query_progress")]
public static extern DuckDBQueryProgressType DuckDBQueryProgress(DuckDBNativeConnection connection);
public static extern DuckDBQueryProgress DuckDBQueryProgress(DuckDBNativeConnection connection);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_library_version")]
public static extern IntPtr DuckDBLibraryVersion();
Expand Down
10 changes: 9 additions & 1 deletion DuckDB.NET.Data/DuckDBConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ protected override void Dispose(bool disposing)
// this check is to ensure exact same behavior as previous version
// where Close() was calling Dispose(true) instead of the other way around.
if (connectionState == ConnectionState.Open)
{
Close();
}
}

base.Dispose(disposing);
Expand Down Expand Up @@ -235,4 +237,10 @@ public override DataTable GetSchema(string collectionName) =>

public override DataTable GetSchema(string collectionName, string?[]? restrictionValues) =>
DuckDBSchema.GetSchema(this, collectionName, restrictionValues);
}

public DuckDBQueryProgress GetQueryProgress()
{
EnsureConnectionOpen();
return NativeMethods.Startup.DuckDBQueryProgress(NativeConnection);
}
}
4 changes: 2 additions & 2 deletions DuckDB.NET.Test/DuckDBDataReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ where x < 300000
[Theory]
[InlineData(false)]
[InlineData(true)]
public void CancellingLongRunningSyncQuery_ByTokenRegistration_ThrowsOperationCanceledException(bool useStreamingMode)
public void CancellingLongRunningSyncQueryByTokenRegistrationThrowsOperationCanceledException(bool useStreamingMode)
{
Command.CommandText = @"create table cnt as WITH RECURSIVE
cnt(x) AS (
Expand All @@ -408,7 +408,7 @@ SELECT x+1 FROM cnt
where x < 300000
) select * from cnt;";

var source = new CancellationTokenSource(TimeSpan.FromMilliseconds(1000));
using var source = new CancellationTokenSource(TimeSpan.FromMilliseconds(1000));

Command.UseStreamingMode = useStreamingMode;
Command.Invoking(c =>
Expand Down

0 comments on commit 547e801

Please sign in to comment.