Skip to content

Commit

Permalink
Pass DuckDBResult as object instead of pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
Giorgi committed Sep 9, 2023
1 parent 612ec53 commit 10bd1b9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
33 changes: 33 additions & 0 deletions DuckDB.NET.Bindings/DuckDBNativeObjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,45 @@ public class DuckDBResult : IDisposable

private IntPtr internal_data;

public DuckDBResultStruct ToStruct()
{
return new DuckDBResultStruct()
{
ColumnCount = ColumnCount,

Check warning on line 81 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (ubuntu-20.04)

'DuckDBResultStruct.ColumnCount' is obsolete

Check warning on line 81 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (ubuntu-20.04)

'DuckDBResult.ColumnCount' is obsolete

Check warning on line 81 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (ubuntu-20.04)

'DuckDBResultStruct.ColumnCount' is obsolete

Check warning on line 81 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (ubuntu-20.04)

'DuckDBResult.ColumnCount' is obsolete

Check warning on line 81 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (windows-latest)

'DuckDBResultStruct.ColumnCount' is obsolete

Check warning on line 81 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (windows-latest)

'DuckDBResult.ColumnCount' is obsolete

Check warning on line 81 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (macos-12)

'DuckDBResultStruct.ColumnCount' is obsolete

Check warning on line 81 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (macos-12)

'DuckDBResult.ColumnCount' is obsolete
RowCount = RowCount,

Check warning on line 82 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (ubuntu-20.04)

'DuckDBResultStruct.RowCount' is obsolete

Check warning on line 82 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (ubuntu-20.04)

'DuckDBResult.RowCount' is obsolete

Check warning on line 82 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (ubuntu-20.04)

'DuckDBResultStruct.RowCount' is obsolete

Check warning on line 82 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (ubuntu-20.04)

'DuckDBResult.RowCount' is obsolete

Check warning on line 82 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (windows-latest)

'DuckDBResultStruct.RowCount' is obsolete

Check warning on line 82 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (windows-latest)

'DuckDBResult.RowCount' is obsolete

Check warning on line 82 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (macos-12)

'DuckDBResultStruct.RowCount' is obsolete

Check warning on line 82 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (macos-12)

'DuckDBResult.RowCount' is obsolete
RowsChanged = RowsChanged,

Check warning on line 83 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (ubuntu-20.04)

'DuckDBResultStruct.RowsChanged' is obsolete

Check warning on line 83 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (ubuntu-20.04)

'DuckDBResult.RowsChanged' is obsolete

Check warning on line 83 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (ubuntu-20.04)

'DuckDBResultStruct.RowsChanged' is obsolete

Check warning on line 83 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (ubuntu-20.04)

'DuckDBResult.RowsChanged' is obsolete

Check warning on line 83 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (windows-latest)

'DuckDBResultStruct.RowsChanged' is obsolete

Check warning on line 83 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (windows-latest)

'DuckDBResult.RowsChanged' is obsolete

Check warning on line 83 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (macos-12)

'DuckDBResultStruct.RowsChanged' is obsolete

Check warning on line 83 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (macos-12)

'DuckDBResult.RowsChanged' is obsolete
columns = columns,

Check warning on line 84 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (ubuntu-20.04)

'DuckDBResultStruct.columns' is obsolete

Check warning on line 84 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (ubuntu-20.04)

'DuckDBResult.columns' is obsolete

Check warning on line 84 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (ubuntu-20.04)

'DuckDBResultStruct.columns' is obsolete

Check warning on line 84 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (ubuntu-20.04)

'DuckDBResult.columns' is obsolete

Check warning on line 84 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (windows-latest)

'DuckDBResultStruct.columns' is obsolete

Check warning on line 84 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (windows-latest)

'DuckDBResult.columns' is obsolete

Check warning on line 84 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (macos-12)

'DuckDBResultStruct.columns' is obsolete

Check warning on line 84 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (macos-12)

'DuckDBResult.columns' is obsolete
ErrorMessage = ErrorMessage,

Check warning on line 85 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (ubuntu-20.04)

'DuckDBResultStruct.ErrorMessage' is obsolete

Check warning on line 85 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (ubuntu-20.04)

'DuckDBResult.ErrorMessage' is obsolete

Check warning on line 85 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (ubuntu-20.04)

'DuckDBResultStruct.ErrorMessage' is obsolete

Check warning on line 85 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (ubuntu-20.04)

'DuckDBResult.ErrorMessage' is obsolete

Check warning on line 85 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (windows-latest)

'DuckDBResultStruct.ErrorMessage' is obsolete

Check warning on line 85 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (windows-latest)

'DuckDBResult.ErrorMessage' is obsolete

Check warning on line 85 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (macos-12)

'DuckDBResultStruct.ErrorMessage' is obsolete

Check warning on line 85 in DuckDB.NET.Bindings/DuckDBNativeObjects.cs

View workflow job for this annotation

GitHub Actions / Build library (macos-12)

'DuckDBResult.ErrorMessage' is obsolete
internal_data = internal_data
};
}

public void Dispose()
{
NativeMethods.Query.DuckDBDestroyResult(this);
}
}

public struct DuckDBResultStruct
{
[Obsolete]
internal long ColumnCount;

[Obsolete]
internal long RowCount;

[Obsolete]
internal long RowsChanged;

[Obsolete]
internal IntPtr columns;

[Obsolete]
internal IntPtr ErrorMessage;

internal IntPtr internal_data;
}

[StructLayout(LayoutKind.Sequential)]
public struct DuckDBDate
{
Expand Down
4 changes: 2 additions & 2 deletions DuckDB.NET.Bindings/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@ public static class Types
public static extern DuckDBTimestampStruct DuckDBValueTimestamp([In, Out] DuckDBResult result, long col, long row);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_result_get_chunk")]
public static extern IntPtr DuckDBResultGetChunk([In, Out] DuckDBResult result, long chunkIndex);
public static extern IntPtr DuckDBResultGetChunk([In, Out] DuckDBResultStruct result, long chunkIndex);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_result_chunk_count")]
public static extern long DuckDBResultChunkCount([In, Out] DuckDBResult result);
public static extern long DuckDBResultChunkCount([In, Out] DuckDBResultStruct result);
}

public static class PreparedStatements
Expand Down
4 changes: 2 additions & 2 deletions DuckDB.NET.Data/DuckDBDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ internal DuckDBDataReader(DuckDbCommand command, List<DuckDBResult> queryResults

private void InitReaderData()
{
var chunkCount = NativeMethods.Types.DuckDBResultChunkCount(currentResult);
var chunk = NativeMethods.Types.DuckDBResultGetChunk(currentResult, 0);
var chunkCount = NativeMethods.Types.DuckDBResultChunkCount(currentResult.ToStruct());
var chunk = NativeMethods.Types.DuckDBResultGetChunk(currentResult.ToStruct(), 0);

var columnCount = NativeMethods.DataChunks.DuckDBDataChunkGetColumnCount(chunk);

Expand Down

0 comments on commit 10bd1b9

Please sign in to comment.