Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static IFbClient Create(string dllName)
{
result = BuildFbClient(dllName);
cache.Add(dllName, result);
ShutdownHelper.RegisterFbClientShutdown(() => NativeHelpers.CallIfExists(() => result.fb_shutdown(0, 0)));
ShutdownHelper.RegisterFbClientShutdown(() => NativeHelpers.CallIfExists(nameof(IFbClient.fb_shutdown), () => result.fb_shutdown(0, 0)));
return result;
}
finally
Expand Down
24 changes: 14 additions & 10 deletions src/FirebirdSql.Data.FirebirdClient/Client/Native/FesStatement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,13 @@ public override void Execute(int timeout, IDescriptorFiller descriptorFiller)
descriptorFiller.Fill(_parameters, 0);

ClearStatusVector();
NativeHelpers.CallIfExists(() =>
{
_database.FbClient.fb_dsql_set_timeout(_statusVector, ref _handle, (uint)timeout);
_database.ProcessStatusVector(_statusVector);
});
NativeHelpers.CallIfExists(
nameof(IFbClient.fb_dsql_set_timeout),
() =>
{
_database.FbClient.fb_dsql_set_timeout(_statusVector, ref _handle, (uint)timeout);
_database.ProcessStatusVector(_statusVector);
});

ClearStatusVector();

Expand Down Expand Up @@ -441,11 +443,13 @@ public override async ValueTask ExecuteAsync(int timeout, IDescriptorFiller desc
await descriptorFiller.FillAsync(_parameters, 0, cancellationToken).ConfigureAwait(false);

ClearStatusVector();
NativeHelpers.CallIfExists(() =>
{
_database.FbClient.fb_dsql_set_timeout(_statusVector, ref _handle, (uint)timeout);
_database.ProcessStatusVector(_statusVector);
});
NativeHelpers.CallIfExists(
nameof(IFbClient.fb_dsql_set_timeout),
() =>
{
_database.FbClient.fb_dsql_set_timeout(_statusVector, ref _handle, (uint)timeout);
_database.ProcessStatusVector(_statusVector);
});

ClearStatusVector();

Expand Down
21 changes: 17 additions & 4 deletions src/FirebirdSql.Data.FirebirdClient/Common/NativeHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,31 @@
//$Authors = Jiri Cincura ([email protected])

using System;
using System.Collections.Concurrent;

namespace FirebirdSql.Data.Common;

internal static class NativeHelpers
{
public static void CallIfExists(Action action)
private static readonly ConcurrentDictionary<string, bool> _cache = new ConcurrentDictionary<string, bool>(StringComparer.Ordinal);

public static void CallIfExists(string actionId, Action action)
{
try
if (!_cache.TryGetValue(actionId, out var executionAllowed))
{
try
{
action();
_cache.TryAdd(actionId, true);
}
catch (EntryPointNotFoundException)
{
_cache.TryAdd(actionId, false);
}
}
else if (executionAllowed)
{
action();
}
catch (EntryPointNotFoundException)
{ }
}
}