Skip to content

Add initial SQLite type support#338

Closed
jas88 wants to merge 39 commits into
HicServices:mainfrom
jas88:feature/sqlite
Closed

Add initial SQLite type support#338
jas88 wants to merge 39 commits into
HicServices:mainfrom
jas88:feature/sqlite

Conversation

@jas88

@jas88 jas88 commented Jul 23, 2025

Copy link
Copy Markdown
Contributor

Do what @tznind and @jas88 wanted to do back in 2022: #139

@jas88 jas88 marked this pull request as draft July 23, 2025 19:11

@github-advanced-security github-advanced-security AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

jas88 and others added 15 commits October 16, 2025 18:46
* Fix Oracle driver exception inconsistency in TestKeywords_Invalid

Oracle's ManagedDataAccess driver throws OracleException instead of
ArgumentException when encountering invalid connection string keywords,
while other database drivers throw ArgumentException.

Updated the test to accept either exception type using Assert.Catch<Exception>
and Assert.Multiple with an Or constraint, making the test resilient to
driver-specific exception behavior.

This resolves CI test failure:
- Expected: ArgumentException
- Actual: OracleException (ORA-50008: 'FLIBBLE' is an invalid connection string attribute)

The test now verifies:
1. Either ArgumentException OR OracleException is thrown
2. The exception message contains the invalid keyword "FLIBBLE"

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Fix resource namespace mismatch for embedded resources

Backport fix from PR #3: The auto-generated Designer files were looking
for resources with namespace "FAnsi.*" but the actual embedded resources
used namespace "FAnsi.Core.*", causing MissingManifestResourceException.

Fixed by updating ResourceManager initialization in both:
- FAnsiStrings.Designer.cs: "FAnsi.FAnsiStrings" → "FAnsi.Core.FAnsiStrings"
- SR.Designer.cs: "FAnsi.SR" → "FAnsi.Core.SR"

This resolves the OneTimeSetUp error:
"Could not find the resource 'FAnsi.FAnsiStrings.resources' among the
resources 'FAnsi.Core.FAnsiStrings.resources'"

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
This fork is not a HIC project. Removed "HIC." prefix.

Other build error/warning fixes.
Bumps [dotnet-sdk](https://github.com/dotnet/sdk) from 9.0.200 to 9.0.306.
- [Release notes](https://github.com/dotnet/sdk/releases)
- [Commits](dotnet/sdk@v9.0.200...v9.0.306)

---
updated-dependencies:
- dependency-name: dotnet-sdk
  dependency-version: 9.0.306
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 5.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@v4...v5)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
---
updated-dependencies:
- dependency-name: Microsoft.Data.SqlClient
  dependency-version: 6.1.2
  dependency-type: direct:production
  update-type: version-update:semver-minor
- dependency-name: Microsoft.Data.SqlClient
  dependency-version: 6.1.2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
---
updated-dependencies:
- dependency-name: Npgsql
  dependency-version: 9.0.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: Npgsql
  dependency-version: 9.0.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
---
updated-dependencies:
- dependency-name: NUnit
  dependency-version: 4.4.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
---
updated-dependencies:
- dependency-name: NUnit3TestAdapter
  dependency-version: 5.2.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
---
updated-dependencies:
- dependency-name: Oracle.ManagedDataAccess.Core
  dependency-version: 23.26.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
- dependency-name: Oracle.ManagedDataAccess.Core
  dependency-version: 23.26.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
---
updated-dependencies:
- dependency-name: System.Linq.Async
  dependency-version: 6.0.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: System.Linq.Async
  dependency-version: 6.0.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3 to 4.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](github/codeql-action@v3...v4)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: '4'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
---
updated-dependencies:
- dependency-name: NUnit.Analyzers
  dependency-version: 4.10.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [actions/setup-dotnet](https://github.com/actions/setup-dotnet) from 4 to 5.
- [Release notes](https://github.com/actions/setup-dotnet/releases)
- [Commits](actions/setup-dotnet@v4...v5)

---
updated-dependencies:
- dependency-name: actions/setup-dotnet
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
---
updated-dependencies:
- dependency-name: Microsoft.NET.Test.Sdk
  dependency-version: 18.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
dependabot Bot and others added 10 commits October 17, 2025 16:39
---
updated-dependencies:
- dependency-name: System.Linq.Async
  dependency-version: 6.0.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
---
updated-dependencies:
- dependency-name: Npgsql
  dependency-version: 9.0.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
---
updated-dependencies:
- dependency-name: Microsoft.Data.SqlClient
  dependency-version: 6.1.2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Addresses 8 CodeQL alerts for missing documentation summaries by adding
<summary> tags to methods that were using only <include> tags.

CodeQL requires explicit <summary> tags and doesn't recognize <include>
tags as documentation. This change adds brief summaries while preserving
the existing <include> tags for detailed documentation.

Files modified:
- FAnsi.Core/Discovery/IDiscoveredServerHelper.cs
- FAnsi.Core/Discovery/DiscoveredServerHelper.cs
- FAnsi.Core/Discovery/DiscoveredServer.cs
- FAnsi.Core/Discovery/DiscoveredTable.cs
- FAnsi.Core/Discovery/IDiscoveredTableHelper.cs

Resolves CodeQL alerts: #33-40

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Combined nested if statements in FAnsiExpressionVisitor.cs for cleaner logic flow
- Replaced if-else block with ternary operator in FAnsiQueryProvider.cs for more concise code

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
---
updated-dependencies:
- dependency-name: Oracle.ManagedDataAccess.Core
  dependency-version: 23.26.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
- MySQL: Replace legacy cross-join date generation with MySQL 8.0+ recursive CTEs
- MySQL: Optimize pivot implementation by combining GROUP_CONCAT calls
- MySQL: Remove 107 lines of dead commented code
- PostgreSQL: Implement BuildPivotOnlyAggregate and BuildPivotAndAxisAggregate using FILTER clause
- Oracle: Implement BuildPivotOnlyAggregate and BuildPivotAndAxisAggregate using CASE statements

This reduces MySQL complexity from 440 to 170 lines (61% reduction) and brings PostgreSQL and Oracle to feature parity with SQL Server for pivot operations.
jas88 and others added 12 commits October 20, 2025 16:33
#23)

* Fix MySQL SET SESSION conflicts in pivot with axis queries

Combine multiple SET SESSION statements into a single statement
at the top of queries that use both recursive CTEs and pivot.
Prevents 'You have an error in your SQL syntax' errors when
both cte_max_recursion_depth and group_concat_max_len need to be set.

Fixes Test_Calendar_WithPivot(MySql,True) failure.

* Complete fix: Add skipSessionSettings parameter to GetDateAxisTableDeclaration

* Complete MySQL aggregate fixes: recursion depth and SET SESSION

- Set cte_max_recursion_depth to 50000 (up from default 1000)
- Fix date generation termination to use <= instead of <
- Combine SET SESSION statements to avoid MySQL syntax errors
- Add skipSessionSettings parameter to avoid duplicate SET statements

Fixes Test_Calendar_Day, Test_Calendar_WithPivot and year overflow issues.

* Add null validation checks to fix nullable warnings

Replace implicit assumptions with explicit precondition checks that throw
InvalidOperationException when required properties are null. This provides
better error messages and fixes all nullable reference warnings in the file.

* Fix CTE syntax: SET SESSION must be separate statement

CTEs must be in the same statement as the SELECT that uses them.
Moved SET SESSION before the CTE+SELECT statement and removed
skipSessionSettings parameter since it's no longer needed.

* Fix NUnit analyzer warnings

- Make base test classes abstract (NUnit1034)
  - DatabaseTests
  - AggregationTests
- Fix Assert.That argument order (NUnit2007)
  - Swap actual and expected values in DatatypeComputerTests
  - Actual value should be first, expected value second

* Fix MySQL calendar aggregation and resolve all build warnings

- Fix SQL format string bug in BuildAxisAggregate causing syntax errors
  - Changed {4} AS "{4}" to dataset.{3} AS "{3}" to properly select count column
  - Fixes Test_Calendar_Day and Test_Calendar_Quarter failures
- Add null-forgiving operators to MySqlBulkCopy to fix CS8602/CS8604 warnings
- Suppress IL3050 AOT warnings in query providers with UnconditionalSuppressMessage
  - IQueryProvider inherently requires dynamic code for generic type creation

* Fix MySQL pivot with axis aggregation: combine CTEs correctly

MySQL doesn't allow multiple separate WITH statements. The dateAxis
and pivotValues CTEs must be combined into a single WITH clause with
comma-separated CTE definitions.

Fixes Test_Calendar_WithPivot failure.

* Fix CTE scope: put dateAxis CTE inside dynamic SQL

CTEs only exist within a single SQL statement. Moving dateAxis
CTE definition into the CONCAT'd dynamic SQL ensures it's in scope
when the SELECT references it in the PREPARE/EXECUTE statement.

Fixes: Table 'FAnsiTests.dateAxis' doesn't exist error

* Fix MySQL pivot column ordering with ROW_NUMBER

Pivot columns were appearing alphabetically instead of by aggregate
count descending. Added ROW_NUMBER() to preserve the count-based
ordering in GROUP_CONCAT operations.

Fixes: Test_Calendar_WithPivot(MySql,False) expecting T before E
Bumps [actions/setup-dotnet](https://github.com/actions/setup-dotnet) from 4 to 5.
- [Release notes](https://github.com/actions/setup-dotnet/releases)
- [Commits](actions/setup-dotnet@v4...v5)

---
updated-dependencies:
- dependency-name: actions/setup-dotnet
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 5.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@v4...v5)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
* Release v0.1.0: Modular packages and connection pooling

Breaking Changes:
- Rename packages from HIC.* to FAnsiSql.* (modular structure)
- Repository moved from HicServices/FAnsiSql to jas88/FAnsiSql
- Removed monolithic FAnsiSql package, replaced with modular packages

New Features:
- Thread-local connection pooling to eliminate connection churn
- Added FAnsiSql.Legacy meta-package for easy migration

Infrastructure:
- Migrated to modular package structure (FAnsiSql.Core + DBMS-specific packages)
- Updated to .NET 9.0
- AOT compatibility markers (with Oracle/MSSQL caveats)
- Updated all dependencies to latest versions

* Fix #26: Task disposal race condition in TestConnection()

- Remove 'using' statement for openTask to prevent premature disposal
- Only dispose Task in finally block when in completion state
- Prevents InvalidOperationException when LocalDB is busy or transitioning

* Fix infinite recursion in ManagedConnectionPool

- Create ManagedConnection directly instead of calling GetManagedConnection
- Prevents infinite loop when transaction is provided or creating pooled connections
- Addresses critical bug that would cause stack overflow

* Fix connection reuse error by properly disposing DataReaders

Resolves "MySqlConnection is already in use" errors in thread-local
connection pooling by ensuring all DataReaders are properly disposed.

When DataReaders are not disposed, they hold locks on the underlying
connection, preventing reuse even within the same thread. This caused
failures when the pooled connection was accessed by nested operations.

Changes:
- MySqlDatabaseHelper.cs:72 - Added using statement for ExecuteReader
- OracleDatabaseHelper.cs:53,68 - Added using statements for ExecuteReader
- MicrosoftSQLDatabaseHelper.cs:82 - Added using statement for ExecuteReader

All other ExecuteReader calls across the codebase already use proper
disposal patterns.

* Merge CodeQL and AOT checks into main workflow

Consolidates all CI/CD checks into a single workflow with three parallel jobs:
1. build - Main test and release pipeline (unchanged)
2. codeql - Security analysis with CodeQL
3. aot-compatibility - Native AOT compilation tests

Benefits:
- All checks run on every push
- Parallel execution for faster CI
- Single workflow to maintain
- Better visibility of all quality checks

Removed:
- .github/workflows/codeql.yml
- .github/workflows/aot-test.yml

* Integrate CodeQL into main build job

Optimizes CI by running CodeQL analysis on the same build used for tests:
1. Initialize CodeQL before tests
2. Run tests (builds the code)
3. Perform CodeQL analysis on that build
4. Pack and release

This eliminates duplicate builds and reduces CI time while maintaining
all security checks. AOT compatibility tests still run in parallel as
a separate job.

Benefits:
- Single build for both tests and security analysis
- Faster CI execution
- Same code coverage and security guarantees

* Fix AOT resource namespace mismatch

Resolves the runtime resource loading failure in Native AOT by aligning
embedded resource names with the FAnsi namespace:

Resource fixes:
- FAnsi.Core.csproj: Added LogicalName for FAnsiStrings and SR resources
- FAnsiStrings.Designer.cs: Changed from 'FAnsi.Core.FAnsiStrings' to 'FAnsi.FAnsiStrings'
- SR.Designer.cs: Changed from 'FAnsi.Core.SR' to 'FAnsi.SR'

This ensures resources are embedded as 'FAnsi.*.resources' matching the
namespace, fixing the MissingManifestResourceException in AOT scenarios.

Also fixed missing RequiresDynamicCodeAttribute messages:
- FAnsiQueryProvider.cs: Added message for Expression.Lambda call
- PostgreSql query providers: Added messages for MakeGenericType calls

AOT tests should now run successfully without resource loading errors.

* Fully integrate AOT tests into main build job

Eliminates ALL duplicate infrastructure by running AOT tests in the main
build job, reusing the same database services:

Changes:
- Moved AOT compilation and test steps after CodeQL analysis
- Removed separate aot-compatibility job entirely
- Reduced workflow from 421 to 205 lines (51% reduction)
- Updated workflow name to reflect all checks

Benefits:
- Single database infrastructure setup
- No duplicate service containers
- Faster CI execution with better resource usage
- All tests (unit, CodeQL, AOT) run sequentially on same databases
- Simpler workflow maintenance

The main job now runs:
1. Database setup (Oracle, PostgreSQL, MySQL, SQL Server)
2. CodeQL initialization
3. Unit tests (which builds the code)
4. CodeQL analysis
5. AOT compatibility tests (reuses databases)
6. Pack and release

* Fix transaction mismatch in pooled connections

Resolves 'transaction associated with this command is not the connection's
active transaction' errors by clearing transaction references when cloning
ManagedConnection for connection pooling.

Root cause:
- MemberwiseClone() creates shallow copy including Transaction references
- When connection is reused from pool, it has stale transaction from previous use
- MySQL connector validates transaction belongs to current connection

Solution:
- Made Transaction and ManagedTransaction properties settable (private set)
- Clone() now explicitly nulls transaction references after shallow copy
- Ensures pooled connections have clean state without transaction baggage

This complements the earlier DataReader disposal fix for full thread-local
connection pooling compatibility.

* Prevent pooling connections with active transactions

Further fixes transaction mismatch errors by ensuring we never reuse
connections that have active transactions.

Additional check in ManagedConnectionPool:
- Now verifies existingConnection.Transaction == null before reuse
- Connections with active transactions are removed from pool
- Forces new connection creation when transaction is active

This prevents the scenario where:
1. Connection has active DbTransaction
2. Clone() clears wrapper's Transaction reference
3. New command created without transaction
4. MySQL validates and finds mismatch

Combined with previous fixes (DataReader disposal and Clone transaction
clearing), this completes the thread-local connection pooling support.

* Add connection validation before reuse from pool

Fixes PostgreSQL 'terminating connection due to administrator command'
errors by validating pooled connections are actually usable before reuse.

New validation:
- Added IsConnectionAlive() method to test connections with SELECT 1
- Validates before returning pooled connection
- Dead connections are removed from pool and disposed
- Forces new connection creation when validation fails

This catches scenarios where:
- Database server terminated connection (idle timeout)
- Administrator killed the connection
- Network disconnection
- Connection appears Open but server has closed it

Combined with transaction checks and DataReader disposal, this completes
robust thread-local connection pooling.

* Fix Oracle connection validation query

Oracle requires 'SELECT 1 FROM DUAL' instead of standard 'SELECT 1'.
Updated IsConnectionAlive() to detect Oracle connections and use the
correct syntax.

This prevents Oracle connections from appearing dead during validation
and causing unnecessary connection churn or failures.
* Release v3.3.0: Modular packages and connection pooling

Breaking Changes:
- Rename packages from HIC.* to FAnsiSql.* (modular structure)
- Repository moved from HicServices/FAnsiSql to jas88/FAnsiSql
- Removed monolithic FAnsiSql package, replaced with modular packages

New Features:
- Thread-local connection pooling to eliminate connection churn
- Added FAnsiSql.Legacy meta-package for easy migration

Infrastructure:
- Migrated to modular package structure (FAnsiSql.Core + DBMS-specific packages)
- Updated to .NET 9.0
- AOT compatibility markers (with Oracle/MSSQL caveats)
- Updated all dependencies to latest versions

* Fix #26: Task disposal race condition in TestConnection()

- Remove 'using' statement for openTask to prevent premature disposal
- Only dispose Task in finally block when in completion state
- Prevents InvalidOperationException when LocalDB is busy or transitioning

* Fix infinite recursion in ManagedConnectionPool

- Create ManagedConnection directly instead of calling GetManagedConnection
- Prevents infinite loop when transaction is provided or creating pooled connections
- Addresses critical bug that would cause stack overflow

* Fix connection reuse error by properly disposing DataReaders

Resolves "MySqlConnection is already in use" errors in thread-local
connection pooling by ensuring all DataReaders are properly disposed.

When DataReaders are not disposed, they hold locks on the underlying
connection, preventing reuse even within the same thread. This caused
failures when the pooled connection was accessed by nested operations.

Changes:
- MySqlDatabaseHelper.cs:72 - Added using statement for ExecuteReader
- OracleDatabaseHelper.cs:53,68 - Added using statements for ExecuteReader
- MicrosoftSQLDatabaseHelper.cs:82 - Added using statement for ExecuteReader

All other ExecuteReader calls across the codebase already use proper
disposal patterns.

* Merge CodeQL and AOT checks into main workflow

Consolidates all CI/CD checks into a single workflow with three parallel jobs:
1. build - Main test and release pipeline (unchanged)
2. codeql - Security analysis with CodeQL
3. aot-compatibility - Native AOT compilation tests

Benefits:
- All checks run on every push
- Parallel execution for faster CI
- Single workflow to maintain
- Better visibility of all quality checks

Removed:
- .github/workflows/codeql.yml
- .github/workflows/aot-test.yml

* Integrate CodeQL into main build job

Optimizes CI by running CodeQL analysis on the same build used for tests:
1. Initialize CodeQL before tests
2. Run tests (builds the code)
3. Perform CodeQL analysis on that build
4. Pack and release

This eliminates duplicate builds and reduces CI time while maintaining
all security checks. AOT compatibility tests still run in parallel as
a separate job.

Benefits:
- Single build for both tests and security analysis
- Faster CI execution
- Same code coverage and security guarantees

* Fix AOT resource namespace mismatch

Resolves the runtime resource loading failure in Native AOT by aligning
embedded resource names with the FAnsi namespace:

Resource fixes:
- FAnsi.Core.csproj: Added LogicalName for FAnsiStrings and SR resources
- FAnsiStrings.Designer.cs: Changed from 'FAnsi.Core.FAnsiStrings' to 'FAnsi.FAnsiStrings'
- SR.Designer.cs: Changed from 'FAnsi.Core.SR' to 'FAnsi.SR'

This ensures resources are embedded as 'FAnsi.*.resources' matching the
namespace, fixing the MissingManifestResourceException in AOT scenarios.

Also fixed missing RequiresDynamicCodeAttribute messages:
- FAnsiQueryProvider.cs: Added message for Expression.Lambda call
- PostgreSql query providers: Added messages for MakeGenericType calls

AOT tests should now run successfully without resource loading errors.

* Fully integrate AOT tests into main build job

Eliminates ALL duplicate infrastructure by running AOT tests in the main
build job, reusing the same database services:

Changes:
- Moved AOT compilation and test steps after CodeQL analysis
- Removed separate aot-compatibility job entirely
- Reduced workflow from 421 to 205 lines (51% reduction)
- Updated workflow name to reflect all checks

Benefits:
- Single database infrastructure setup
- No duplicate service containers
- Faster CI execution with better resource usage
- All tests (unit, CodeQL, AOT) run sequentially on same databases
- Simpler workflow maintenance

The main job now runs:
1. Database setup (Oracle, PostgreSQL, MySQL, SQL Server)
2. CodeQL initialization
3. Unit tests (which builds the code)
4. CodeQL analysis
5. AOT compatibility tests (reuses databases)
6. Pack and release

* Fix transaction mismatch in pooled connections

Resolves 'transaction associated with this command is not the connection's
active transaction' errors by clearing transaction references when cloning
ManagedConnection for connection pooling.

Root cause:
- MemberwiseClone() creates shallow copy including Transaction references
- When connection is reused from pool, it has stale transaction from previous use
- MySQL connector validates transaction belongs to current connection

Solution:
- Made Transaction and ManagedTransaction properties settable (private set)
- Clone() now explicitly nulls transaction references after shallow copy
- Ensures pooled connections have clean state without transaction baggage

This complements the earlier DataReader disposal fix for full thread-local
connection pooling compatibility.

* Prevent pooling connections with active transactions

Further fixes transaction mismatch errors by ensuring we never reuse
connections that have active transactions.

Additional check in ManagedConnectionPool:
- Now verifies existingConnection.Transaction == null before reuse
- Connections with active transactions are removed from pool
- Forces new connection creation when transaction is active

This prevents the scenario where:
1. Connection has active DbTransaction
2. Clone() clears wrapper's Transaction reference
3. New command created without transaction
4. MySQL validates and finds mismatch

Combined with previous fixes (DataReader disposal and Clone transaction
clearing), this completes the thread-local connection pooling support.

* Add connection validation before reuse from pool

Fixes PostgreSQL 'terminating connection due to administrator command'
errors by validating pooled connections are actually usable before reuse.

New validation:
- Added IsConnectionAlive() method to test connections with SELECT 1
- Validates before returning pooled connection
- Dead connections are removed from pool and disposed
- Forces new connection creation when validation fails

This catches scenarios where:
- Database server terminated connection (idle timeout)
- Administrator killed the connection
- Network disconnection
- Connection appears Open but server has closed it

Combined with transaction checks and DataReader disposal, this completes
robust thread-local connection pooling.

* Fix Oracle connection validation query

Oracle requires 'SELECT 1 FROM DUAL' instead of standard 'SELECT 1'.
Updated IsConnectionAlive() to detect Oracle connections and use the
correct syntax.

This prevents Oracle connections from appearing dead during validation
and causing unnecessary connection churn or failures.

* Bump version to 3.3.0

Update from 0.1.0 to 3.3.0 to align with HIC versioning.
Last HIC release was 3.2.7, this adds thread-local connection pooling
as a new feature release.

* Fix NuGet API key secret name

Change from NUGET_KEY to NUGET_API_KEY to match the actual
GitHub secret name.
- Bump version to 3.3.1
- Add CHANGELOG entry for Oracle NOCACHE fix
- Fix CHANGELOG: correct version (0.1.0 → 3.3.0) and date (Jan → Oct)
- Add CHANGELOG entry for Oracle NOCACHE fix
- Fix CHANGELOG: correct version (0.1.0 → 3.3.0) and date (Jan → Oct)
- Fix connection pooling dangling transaction detection (#30)
- Added IsConnectionAlive() and HasDanglingTransaction() methods to IDiscoveredServerHelper interface
- Oracle connections set CloseOnDispose=false to rely on ADO.NET's pooling lifecycle
- HasDanglingTransaction() catch blocks return false to avoid false positives
- Updated ManagedConnection.Dispose() to warn when disposing pooled connections with dangling transactions
- Pool validation checks for dangling transactions when retrieving connections and rejects dirty ones
- Added DatabaseExists() to IDiscoveredServerHelper with implementations for all databases
- Updated DiscoveredDatabase.Exists() to use optimized helper method
- Performance improvement: 80-95% reduction for servers with many databases
- Added virtual Exists() method to DiscoveredTableHelper base class
- Default implementation lists all tables (to be optimized per-database in future)
- CRITICAL FIX: DatabaseExists must connect to system database, not target
- Add server-level connection key helpers for future pooling
- Add SQLite to TestDatabases-github.xml and TestDatabases.xml
- Implement enhanced error reporting in SqliteBulkCopy:
  - Line-by-line insert investigation on failure
  - Column-specific error identification
  - Detailed error messages matching SQL Server quality
- Add 10 explicit SQLite test cases to CrossPlatformTests.cs
Add ImplementationManager.Load<SqliteImplementation>() to enable SQLite tests.
Without this, tests fail with 'No implementation found for DatabaseType Sqlite'.

Verified: TestTableCreation_NullTableName(Sqlite) now passes.
Each DBMS package now auto-registers when its assembly loads:
- Added ModuleInitializer in each implementation (MicrosoftSQL, MySQL, Oracle, PostgreSQL, SQLite)
- Added AutoLoadAllImplementations in FAnsi.Legacy for convenience
- Marked ImplementationManager.Load<T>() as Obsolete (still works for backward compat)

Benefits:
- Users no longer need to manually call Load<T>()
- Just reference the DBMS package and it auto-registers
- Tests still use explicit loading for deterministic initialization
- Backward compatible - old code still works

Verified: SQLite test passes with auto-registration enabled.
@jas88 jas88 closed this Oct 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants