-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* - fix DbConnection detection on VB - implement DbCommand detection * dap021 * DAP022, DAP023, DAP024 * nit * DAP029,DAP030,DAP031,DAP032 * tweaks * intermediate get args working again * fix output variable usage * DAP236 * DAP237, DAP238, DAP239 fix test setup (shared fixture) * more fixture tweaks * better param detection * DAP018 * clarify error ids
- Loading branch information
Showing
117 changed files
with
2,132 additions
and
797 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# DAP000 | ||
|
||
This message is mostly for debugging and monitoring. But hey, the generator is at least loading, so; yay, I guess? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# DAP018 | ||
|
||
It looks like you're passing parameters data to something that doesn't actually need | ||
parameters. If you *intended* to use the values from the parameters: fix that. Otherwise, | ||
consider not passing the parameters, to make the intent clear. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# DAP021 | ||
|
||
Database parameters need to have unique names within a single type (case-insensitive); when in doubt, `[DbValue]` allows the name of individual members | ||
to be specified explicitly. | ||
|
||
Bad: | ||
|
||
``` csharp | ||
public int x {get;set;} | ||
public string X {get;set;} | ||
``` | ||
|
||
Better: | ||
|
||
``` csharp | ||
public int x {get;set;} | ||
[DbValue(Name = "y")] | ||
public string X {get;set;} | ||
``` | ||
|
||
Best: | ||
|
||
``` csharp | ||
public int X {get;set;} | ||
public string Y {get;set;} | ||
``` | ||
|
||
The final option is preferred because avoiding ambiguity in the name solves a lot more problems than just Dapper! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# DAP022 | ||
|
||
Only one member on a type can capture the return value of a command; remove the duplicate. | ||
|
||
Bad: | ||
|
||
``` csharp | ||
[DbValue(Direction = ParameterDirection.ReturnVaue)] | ||
public int X {get;set;} | ||
|
||
[DbValue(Direction = ParameterDirection.ReturnVaue)] | ||
public int Y {get;set;} | ||
``` | ||
|
||
Good: | ||
|
||
``` csharp | ||
[DbValue(Direction = ParameterDirection.ReturnVaue)] | ||
public int X {get;set;} | ||
|
||
public int Y {get;set;} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# DAP023 | ||
|
||
Only one member on a type can capture the number of rows affected by a command; remove the duplicate. | ||
|
||
Bad: | ||
|
||
``` csharp | ||
[RowCount] | ||
public int X {get;set;} | ||
|
||
[RowCount] | ||
public int Y {get;set;} | ||
``` | ||
|
||
Good: | ||
|
||
``` csharp | ||
[RowCount] | ||
public int X {get;set;} | ||
|
||
public int Y {get;set;} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# DAP024 | ||
|
||
A single member cannot be marked with both `[DbValue]` and `[RowCount]`; split out the two purposes. | ||
|
||
Bad: | ||
|
||
``` csharp | ||
[RowCount, DbValue(...)] | ||
public int X {get;set;} | ||
``` | ||
|
||
Good: | ||
|
||
``` csharp | ||
[RowCount] | ||
public int X {get;set;} | ||
|
||
[DbValue(...)] | ||
public int Y {get;set;} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# DAP029 | ||
|
||
You can indicate an expected row-count via either a constant method-level `[RowCountHint(...)]` or a member-level `[RowCountHint]` on the parameter type (for variable hints), | ||
but you should not specify both. The member-level value will be preferred, so you should *probably* remove the method-level hint. | ||
|
||
Bad: | ||
|
||
``` csharp | ||
[RowCountHint(42)] | ||
public void SomeMethod() | ||
{ | ||
connection.Query("somesql", new SomeArgsType | ||
{ | ||
// | ||
SizeHint = 15, | ||
} | ||
} | ||
|
||
class SomeArgsType | ||
{ | ||
// ... | ||
[RowCountHint] | ||
public int SizeHint {get;set;} | ||
} | ||
``` | ||
|
||
Good: | ||
|
||
``` csharp | ||
public void SomeMethod() | ||
{ | ||
connection.Query("somesql", new SomeArgsType | ||
{ | ||
// | ||
SizeHint = 15, | ||
} | ||
} | ||
|
||
class SomeArgsType | ||
{ | ||
// ... | ||
[RowCountHint] | ||
public int SizeHint {get;set;} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# DAP030 | ||
|
||
When a constant method-level `[RowCountHint(...)]` is specified, it *must* include a positive integer to use as the estimated row count. | ||
|
||
Bad: | ||
|
||
``` csharp | ||
[RowCountHint] | ||
public void SomeMethod() | ||
{ ... } | ||
``` | ||
|
||
|
||
Also bad: | ||
|
||
``` csharp | ||
[RowCountHint(-15)] | ||
public void SomeMethod() | ||
{ ... } | ||
``` | ||
|
||
Good: | ||
|
||
``` csharp | ||
[RowCountHint(100)] | ||
public void SomeMethod() | ||
{ ... } | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# DAP031 | ||
|
||
When a member-level `[RowCountHint(...)]` is specified (to allow a per-call estimated row count hint), it *must not* include a value. | ||
|
||
Bad: | ||
|
||
``` csharp | ||
[RowCountHint(43)] | ||
public int RowCount {get;set;} | ||
``` | ||
|
||
Good: | ||
|
||
``` csharp | ||
[RowCountHint] | ||
public int RowCount {get;set;} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# DAP032 | ||
|
||
Only a single member-level `[RowCountHint(...)]` can be specified (to allow a per-call estimated row count hint); remove the duplicate. | ||
|
||
Bad: | ||
|
||
``` csharp | ||
[RowCountHint] | ||
public int X {get;set;} | ||
|
||
[RowCountHint] | ||
public int Y {get;set;} | ||
``` | ||
|
||
Good: | ||
|
||
``` csharp | ||
[RowCountHint] | ||
public int X {get;set;} | ||
|
||
public int Y {get;set;} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# DAP033 | ||
|
||
`[CommandProperty<T>]` allows additional properties to be specified against a particular command type, for example: | ||
|
||
``` csharp | ||
[CommandProperty<OracleCommand>(nameof(OracleCommand.FetchSize), 1024)] | ||
``` | ||
|
||
Unfortunately, the property you specified *doesn't seem to exist*. So... we can't do that, sorry. Check again? `nameof` is highly recommended. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# DAP034 | ||
|
||
`[CommandProperty<T>]` allows additional properties to be specified against a particular command type, but it is intended for things that Dapper.AOT | ||
*doesn't* handle internally. The option you've specified should is reserved for internal handling. If this presents a problem, [log an issue](https://github.com/DapperLib/DapperAOT/issues). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# DAP236 | ||
|
||
Dapper tries to only use parameters that are included in your query; it does this using basic | ||
pattern matching, but it looks like when analyzed properly: this parameter is not actually used. | ||
This might be because the parameter name is used in a comment or string literal. | ||
|
||
Try to restructure the query, or rename the parameter members, so that there is no confusion. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# DAP237 | ||
|
||
It looks like some calculation you are performing can be shown to produce a divide-by-zero. | ||
That's not something that mathematics can do in any meaningful ways, so: maybe try not to do | ||
that. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# DAP238 | ||
|
||
It looks like you're doing something the hard way... | ||
|
||
Bad: | ||
|
||
``` sql | ||
a + 0 | ||
b / 1 | ||
c * 0 | ||
d >> 0 | ||
e ^ -1 | ||
``` | ||
|
||
Good: | ||
|
||
``` sql | ||
a -- anything plus zero is itself | ||
b -- anything divided by one is itself | ||
0 -- anything multiplied by zero is zero | ||
d -- anything right-shifted by zero is zero | ||
~e -- anything xor'd with a full mask is the bitwise complement | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# DAP239 | ||
|
||
It is not *quite* true that any operation involving a `null` yields `null`. There *are exceptions*, in particular | ||
when a null literal (or something that is *very close* to a null literal) is involved. | ||
|
||
Examples: | ||
|
||
- `null >> 2` | ||
- `2 >> null` | ||
- `null & null` (needs at least one operand that is not hard null) | ||
|
||
Unusually this only applies to null literals; if you had a parameter/local that had a `null` *value*, | ||
the expression would evaluate to `null` as expected. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# DAP240 | ||
|
||
Dapper uses fairly simple parameter detection, and it looks like an available member on your | ||
parameters object is being detected as a parameter, but this conflicts with | ||
a variable declared in your SQL. Consider renaming the local, or renaming/removing the member | ||
on your type, to avoid this confusion. | ||
|
||
Bad: | ||
|
||
``` csharp | ||
conn.Execute(""" | ||
declare @id int = 42; | ||
-- etc using @id | ||
""", new Customer { Id = 14, ... }); | ||
``` | ||
|
||
Here `Customer.Id` will be interpreted as a parameter, because `@id` was | ||
seen in the command - however, this is actually the declaration of a local | ||
variable, which will cause a conflict at execution. | ||
|
||
Good: | ||
|
||
``` csharp | ||
conn.Execute(""" | ||
declare @newid int = 42; | ||
-- etc using @newid | ||
""", new Customer { Id = 14, ... }); | ||
``` | ||
|
||
After renaming the local, there is no longer an accidental conflict. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.