Commit Graph

58 Commits

Author SHA1 Message Date
Marc Gravell 79b2960a2f AddParameters(IDbCommand): dispatch via IDynamicParameters
A subclass that hides AddParameters and re-implements the interface - the
DynamicParameterWithIntTVP pattern from this very test suite - was skipped
by the direct call, which binds statically to the protected base method.
Routing through the interface uses the runtime type's interface map, so
the subclass version runs, matching what vanilla execution does.
2026-08-18 19:54:31 +01:00
Marc Gravell 3838f0ece5 DynamicParameters.AddParameters(IDbCommand): identity-free self-apply
The full bag protocol (per-parameter DbType/direction/size, templates,
literal replacement, RemoveUnused) already lives in AddParameters(command,
identity), but the identity requirement makes it uncallable from outside:
Identity's constructor is internal, and identity.Sql is consumed on the
first line. This overload builds the identity from the command's own text
and type, which is what identity.Sql is in practice - letting external
tooling (for example build-time code generators, aka Dapper.AOT) apply a
bag without reimplementing the protocol.

Test covers the bag+literal composition against a closed connection (no
database needed).
2026-08-18 17:11:09 +01:00
Marc Gravell 953f371805 keep deps up to date (#2204)
* keep deps up to date

* d'oh

* slnx
2026-05-16 21:08:13 +01:00
Andi 2a8faab235 Fix/prefer typehandlers for enums (#2200)
* Add Settings.PreferTypeHandlersForEnums opt-in flag

When enabled, Dapper checks for a registered TypeHandler for enum types
before falling back to the default integer boxing behavior. This allows
custom enum serialization (e.g. storing enums as strings via TypeHandlers)
to work on both reads and writes.

Patched locations:
- LookupDbType: return DbType.Object with handler when flag is on
- CreateParamInfoGenerator: skip integer boxing when handler exists
- GetSimpleValueDeserializer: route to TypeHandler before Enum.ToObject
- Parse<T>: route to TypeHandler before Enum.ToObject

Default is false — zero behavior change for existing users.

* Patch IL-emitted type deserializer and add tests

- Fix 6th enum-before-handler location in GetTypeDeserializer IL emit,
  preserving Nullable<T> wrapping for nullable enum properties
- Fix em-dash in comment (non-ASCII)
- Add two tests: round-trip write+read via StringEnumHandler, and
  nullable enum with null value

* Update SDK version from 10.0.102 to 8.0.100

* Update global.json

we have fixed the CI glitch separately

---------

Co-authored-by: Marc Gravell <marc.gravell@gmail.com>
2026-05-16 21:08:03 +01:00
Marc Gravell 464cb337ba Update dependencies (#2202)
* first snapshot, warnings

* intermediate

* more

* more fixings

* cleanup

* nuke NETCOREAPP3_1 ref
2026-04-29 08:38:12 +01:00
Andi b9bdd7c40b Fix segfault when ICustomQueryParameter is a value type (#2189) (#2198)
The IL emitted by CreateParamInfoGenerator used Callvirt to invoke
AddParameter on an unboxed struct sitting on the evaluation stack.
Callvirt expects a reference, so the CLR misinterpreted the raw struct
bytes as an object pointer, causing a fatal CLR error (0x80131506).
2026-04-29 07:29:21 +01:00
Marc Gravell 288730e69b TFM packaging for .NET 10 (#2195) 2026-03-06 07:10:01 +00:00
ri-rgb d994b6d932 OutputExpression wasn't working for methods that use QueryRowAsync (#2156)
Added command.OnCompleted() to QueryRowAsync

Co-authored-by: Rich <Rich@XPS-15>
2025-04-08 11:07:45 +01:00
Marc Gravell bd4f75b512 normalize async API surface over all TFMs (#2144)
* - normalize async API surface over all TFMs (fix #2143)
- target net8.0 instead of net5.0
- lib updates

* net9 SDK

* perf tests: clean up SqlClient warning

* CI fix: test concurrency

* rev snowflake
2025-02-06 12:11:30 +00:00
Andrea Latanza a3804ceb1d fix: properly handle value types when setting properties on dynamic objects returned by Dapper queries (#2122) 2024-10-13 09:31:25 +01:00
Marc Gravell b4f80b6b6b Improve performance of "queryunbuffered", and correctness of "first" APIs (#2121)
* see #2115

- correctness: do no use SingleRow by default; affects trailing errors
- performance: QueryUnbufferedAsync can mirror cmd?.Cancel() in finally (this is consistent with all other scenarios)

* remove settings tweak
2024-10-09 11:15:28 +01:00
Marc Gravell dddd102eef update package refs and fixup (#2120) 2024-10-08 13:23:00 +01:00
goerch 38df7bb89e Fix #2113 (#2118) 2024-10-07 13:00:15 +01:00
Cédric Luthi 9ed3525598 Do not close the inner reader when disposing wrapped data readers (#2100)
When disposing wrapped readers, only call Dispose() on the inner reader and let it catch exceptions if appropriate.

Note: this actually happened with `Microsoft.Data.SqlClient`.

```
Microsoft.Data.SqlClient.SqlException (0x80131904): Execution Timeout Expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
 ---> System.ComponentModel.Win32Exception (258): The wait operation timed out.
   at void Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, bool breakConnection, Action<Action> wrapCloseInAction)
   at void Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, bool callerHasConnectionLock, bool asyncClose)
   at bool Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, out bool dataReady)
   at bool Microsoft.Data.SqlClient.SqlDataReader.TryCloseInternal(bool closeReader)
   at void Microsoft.Data.SqlClient.SqlDataReader.Close()
   at void Dapper.DbWrappedReader.Dispose(bool disposing) in /_/Dapper/WrappedReader.cs:line 149
   at ValueTask System.Data.Common.DbDataReader.DisposeAsync()
```
2024-07-03 13:32:18 +01:00
Marc Gravell 907a4d9b35 disable DateOnly / TimeOnly support - see #2071 / #2072 2024-04-26 08:49:47 +01:00
Marc Gravell fa9c96aec0 revert #2050 - see #2049 for more details (#2070)
* revert #2050 - see #2049 for more details
2024-04-12 11:13:05 +01:00
Marc Gravell 402f20ce37 implement DateOnly/TimeOnly (#2051)
fix #1715
adds net6 TFM
2024-03-07 12:19:30 +00:00
Marc Gravell 87eb033118 string and byte[] : add UseGetFieldValue (#2050)
* string and byte[] : add UseGetFieldValue to prevent problems with npgsql using global deserializer
* switch to GetFieldValue<T> changes some messaging in invalid cast scenarios; if anything, new version is clearer, so: fine
* test fixes
2024-03-06 20:58:21 +00:00
Marc Gravell 360367ca54 add REVERT to CommandText checklist (#2048) 2024-03-06 14:59:19 +00:00
Ohorodniichuk Dmytro 8f369914ac Issue #1164 (#1795)
Fix unsigned types mapping arithmetic overflow
Add tests to reproduce issue #1164

Co-authored-by: Dmytro Ohorodniichuk <dmytro.ohorodniichuk@neogames.com>
2024-01-07 21:42:09 +00:00
Marc Gravell d7c16035d2 fix codegen error in value-type multimap #2005 (#2022)
in horizontal multi-map, don't "returnValueLocal = null" for value-types (invalid IL)
fix #2005
2024-01-02 15:32:04 +00:00
Marc Gravell c46c69a174 1. give clearer error messages when an ICustomQueryParameter is null (#2003)
2. provide a convenience .ctor on DbString
2023-11-23 08:58:18 +00:00
Marc Gravell 947b582c79 fix #1993 - when matching properties, prefer non-normalized property name (#1997) 2023-11-11 08:51:05 +00:00
Marc Gravell 6fdafc32e2 add commmit and rollback to "text" exclusion list (#1995) 2023-11-10 19:17:10 +00:00
Marc Gravell 2f56056a89 - expand auto-sproc detection to handle more scenarios and explicit exclusions (#1989)
- add net7 target
- use regex generator when available (net7+)
- fix #1984
2023-10-20 09:24:01 +01:00
Marc Gravell cdadfa6db6 whitespace for auto-SP detection: use unicode spec via regex (#1987)
* add fix and test for #1975

* wrong ticket number; is #1986
2023-10-19 12:25:11 +01:00
Giorgi Dalakishvili 19193b52bb Add a setting to turn off Ole Db "smell check" (#1974)
* Add a setting to turn off Ole Db "smell check"

* Rename setting, fix logic

* Test for SupportLegacyParameterTokens

* Fix exception type

* Add release note
2023-10-11 13:10:00 +01:00
Giorgi Dalakishvili 2837480903 Add DuckDB tests (#1970)
* Add DuckDB tests

* Update DuckDB.NET.Data.Full version
2023-10-11 12:41:06 +01:00
Marc Gravell a37b151bb7 auto-detect stored procedures as anything without whitespace (#1975)
* 1. auto-detect stored procedures as anything without whitespace
2. we have public fields? (hangs head in shame)

* release notes

* no need to use regex
2023-10-10 15:06:21 +01:00
Marc Gravell a4a55f5b79 assert that type handlers don't need object? (#1960)
* assert that type handlers don't need object? - include test to validate (plus: NRT check was happy)

fix #1959

* release notes
2023-09-13 21:43:13 +01:00
Marc Gravell 61ff85a2b8 add missing ReadUnbufferedAsync untyped API (#1958)
* - add missing ReadUnbufferedAsync untyped API
- remove an impossible branch

* release notes
2023-09-13 14:58:12 +01:00
Marc Gravell aecffecae1 attempt NRT makeover (#1928)
* attempt NRT makeover

- annotate NRTs on GridReader API
- add protected access to some of the GridReader internals
- switch GridReader callbacks to be more type-independent

docs

lib updates; deal with yellow warnings and test failures (SQL server certs and cancellation surfacing differently)

fix break

simplify proposed GridReader changes to protected OnBeforeGrid and OnAfterGrid[Async]

Builds: Bump library versions (#1935)

Tests: Upgrade dependencies for Dependabot (#1936)

I'll do a pass at all of these later, but getting CVE versions out of the pipe.

Resolving 4 alerts here: https://github.com/DapperLib/Dapper/security/dependabot

merge and lib updates

allow Identity to be constructed on-the-fly inside GridReader

fix build warnings

include readme

rev minor

- enable [SkipLocalsInit] everywhere
- use NET5_0_OR_GREATER
 for remoting check

# Conflicts:
#	Dapper/CommandDefinition.cs
#	Dapper/DefaultTypeMap.cs
#	Dapper/SqlMapper.Async.cs
#	Dapper/SqlMapper.IDataReader.cs
#	Dapper/SqlMapper.Link.cs
#	Dapper/SqlMapper.cs
#	Directory.Build.props

* shipped, not unshipped

* fixup SqlBuilder; use is null / is not null

* use central package management (#1949)

* Nullable test tweaks

* Nuget: let's just remove it!

* 2 test fixes from review

* fix FindExplicitConstructor

* add GetPropertySetterOrThrow

* fix NRT on FindConstructor

* DapperRow: value is object?

* use NotNullWhen

* make constructor problem more obvious

* test fixes

---------

Co-authored-by: Nick Craver <nrcraver@gmail.com>
2023-09-12 15:58:49 +01:00
Lehonti Ramos ff913be391 Removed block nesting levels in a few tests by using block-scoped using statements (#1939)
Co-authored-by: John Doe <john@doe>
2023-08-24 13:12:33 +01:00
Marc Gravell 33090c0218 Underscore handling (#1947)
* Adds MatchConstructorParametersWithUnderscores option

* generalize to single MatchNamesWithUnderscores (pre-existing)

* cite 2nd PR

---------

Co-authored-by: Jonas Goronczy <goronczy.jonas@gmail.com>
2023-08-17 17:30:34 +01:00
Nick Craver 136dc11f0c Tests: Upgrade dependencies for Dependabot (#1936)
I'll do a pass at all of these later, but getting CVE versions out of the pipe.

Resolving 4 alerts here: https://github.com/DapperLib/Dapper/security/dependabot
2023-07-08 11:43:58 -04:00
Marc Gravell 20d81380ca mark all structs as readonly; fix some compiler noise (no functional change) (#1925) 2023-06-20 13:33:43 +01:00
Marc Gravell d91d90465d reinstate support for IDataReader (#1913)
* if we stop supporting DbDataReader, someone is going to complain; I'd
rather wrap it for now (to make the lib work), and add an analyzer
in AOT that shouts at them for using IDbConnection

also: compiler nits

* release notes
2023-06-20 13:31:55 +01:00
Cédric Luthi 677fee27c6 Enable the Issue552_SignedUnsignedBooleans test (#1919)
It works fine with MySqlConnector 1.1.0
2023-06-13 17:11:13 +01:00
Cédric Luthi da6509a224 Document how to run docker for db tests (Firebird + MySQL + PostgreSQL) (#1918) 2023-06-13 17:06:30 +01:00
Marc Gravell d56340b885 add missing QueryUnbufferedAsync<T> API (#1912)
* impl QueryUnbufferedAsync<T>
* implement GridReader.ReadUnbufferedAsync<T>
2023-06-09 16:22:25 +01:00
Marc Gravell 01f03ef3e8 add support for fetching values via GetFieldValue<T> (#1910)
add support for fetching values via GetFieldValue<T>; this requires
DbDataReader, but in reality the reader is *always* DbDataReader;
acknowledge this, and stop pretending to use IDataReader internally
(no breaks to public API)
2023-06-09 14:02:06 +01:00
Olivier Spinelli 70be2bd5e2 Fixed case sensitivity issues. (#1801) 2022-08-21 13:27:09 -04:00
mgravell 3d405fea35 add type hint 2021-11-11 14:14:25 +00:00
mgravell 21ce60b523 move tests to npgsql 6 (GA); better datetime coverage 2021-11-11 14:05:48 +00:00
Marc Gravell b272cc664d Don't specify dbtype for DateTime et al; fixed npgsql 6 issue (#1723)
* context: #1716 https://github.com/DapperLib/Dapper/issues/1716

- change type-map to allow nullable
- change DateTime/TimeSpan to null
- do not specify DbType for null
- semi-breaking change: swap GetDbType to SetDbType, noting that it is marked [Obsolete] and internal-use-only
- semi-breaking change: make LookupDbType return nullable (same internal-use/[Obsolete])

* add test for Npgsql 6.0.0-rc.1

* try list parameters (like arrays)

* never assign -1 (sentinel) as the .DbType

* postgres tests
2021-11-03 14:01:15 +00:00
Marc Gravell 4aac41a2bc Enables "snowflake" connection (#1689)
* snowflake tests #1687

* actually add the tests!
2021-07-27 09:11:16 +01:00
Nick Craver 2b7b3fe4a9 Merge pull request #1575 from zqlovejyc/main 2021-05-10 08:58:31 -04:00
Nick Craver 600c1aca45 Add test cases and cleanup last call site.
This merges in the work in #1663 and cleans up the convert a bit further.
2021-05-09 23:10:31 -04:00
Nick Craver 566d169a26 Add DbString.ToString() overload
Fixes #1538 and #1545 by making DbString.ToString() much more descriptive.
2021-05-09 22:36:23 -04:00
Nick Craver fca49ebcce SplitOn: improve error message
Fixes #866. This provides a more informative error, saying _which_ splitOn column couldn't be found in the result set.
2021-05-09 21:51:20 -04:00