Skip to content

Commit

Permalink
Publish v3.12 with better analysis due to parameter nullability infer…
Browse files Browse the repository at this point in the history
…ence
  • Loading branch information
Zaid-Ajaj committed Aug 29, 2020
1 parent fdb4e9d commit b1592a8
Show file tree
Hide file tree
Showing 18 changed files with 298 additions and 101 deletions.
15 changes: 15 additions & 0 deletions NpgsqlFSharpAnalyzer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FParsecCS", "src\FParsecCS\
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FParsec", "src\FParsec\FParsec.fsproj", "{9C8E7641-9DC8-470C-8009-71A747C01DC5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ParserTestsWithNet48", "src\ParserTestsWithNet48\ParserTestsWithNet48.csproj", "{40067E09-6281-4DC2-905D-60F7C6E3B812}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -145,6 +147,18 @@ Global
{9C8E7641-9DC8-470C-8009-71A747C01DC5}.Release|x64.Build.0 = Release|Any CPU
{9C8E7641-9DC8-470C-8009-71A747C01DC5}.Release|x86.ActiveCfg = Release|Any CPU
{9C8E7641-9DC8-470C-8009-71A747C01DC5}.Release|x86.Build.0 = Release|Any CPU
{40067E09-6281-4DC2-905D-60F7C6E3B812}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{40067E09-6281-4DC2-905D-60F7C6E3B812}.Debug|Any CPU.Build.0 = Debug|Any CPU
{40067E09-6281-4DC2-905D-60F7C6E3B812}.Debug|x64.ActiveCfg = Debug|Any CPU
{40067E09-6281-4DC2-905D-60F7C6E3B812}.Debug|x64.Build.0 = Debug|Any CPU
{40067E09-6281-4DC2-905D-60F7C6E3B812}.Debug|x86.ActiveCfg = Debug|Any CPU
{40067E09-6281-4DC2-905D-60F7C6E3B812}.Debug|x86.Build.0 = Debug|Any CPU
{40067E09-6281-4DC2-905D-60F7C6E3B812}.Release|Any CPU.ActiveCfg = Release|Any CPU
{40067E09-6281-4DC2-905D-60F7C6E3B812}.Release|Any CPU.Build.0 = Release|Any CPU
{40067E09-6281-4DC2-905D-60F7C6E3B812}.Release|x64.ActiveCfg = Release|Any CPU
{40067E09-6281-4DC2-905D-60F7C6E3B812}.Release|x64.Build.0 = Release|Any CPU
{40067E09-6281-4DC2-905D-60F7C6E3B812}.Release|x86.ActiveCfg = Release|Any CPU
{40067E09-6281-4DC2-905D-60F7C6E3B812}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -159,6 +173,7 @@ Global
{BC524F8E-6282-4E31-9A0E-29FCE38832E7} = {C397A34C-84F1-49E7-AEBC-2F9F2B196216}
{C5EB813F-4278-4EE7-925B-6757BAD0FE9B} = {C397A34C-84F1-49E7-AEBC-2F9F2B196216}
{9C8E7641-9DC8-470C-8009-71A747C01DC5} = {C397A34C-84F1-49E7-AEBC-2F9F2B196216}
{40067E09-6281-4DC2-905D-60F7C6E3B812} = {ACBEE43C-7A88-4FB1-9B06-DB064D22B29F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BC821061-2FB3-4ABD-9FA1-044D4C59C475}
Expand Down
5 changes: 5 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### 3.12.0 - 2020-08-29
* Parameter nullability inference for parsable queries
* Detecting the missing columns which are required for INSERT queries
* Better error messages when reading from a result set which doesn't return any columns

### 3.11.0 - 2020-08-18
* Even better error messages that include whether types were arrays or not

Expand Down
6 changes: 3 additions & 3 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ let generateAssemblyInfo _ =
|> Seq.iter (fun (projFileName, _, folderName, attributes) ->
match projFileName with
| Fsproj -> AssemblyInfoFile.createFSharp (folderName @@ "AssemblyInfo.fs") attributes
| Csproj -> AssemblyInfoFile.createCSharp ((folderName @@ "Properties") @@ "AssemblyInfo.cs") attributes
| Vbproj -> AssemblyInfoFile.createVisualBasic ((folderName @@ "My Project") @@ "AssemblyInfo.vb") attributes
)
| Csproj -> ignore()
| Vbproj -> ignore()
)

let dotnetPack ctx =
let args =
Expand Down
31 changes: 20 additions & 11 deletions src/FParsec/AssemblyInfo.fs
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
namespace FParsec

// Auto-Generated by FAKE; do not edit
namespace System
open System.Reflection
open System.Runtime.CompilerServices
open System.Runtime.InteropServices

[<assembly: ComVisible(false)>]
[<assembly: AssemblyTitleAttribute("FParsec")>]
[<assembly: AssemblyProductAttribute("NpgsqlFSharpAnalyzer")>]
[<assembly: AssemblyVersionAttribute("3.12.0")>]
[<assembly: AssemblyMetadataAttribute("ReleaseDate","2020-08-29T00:00:00.0000000")>]
[<assembly: AssemblyFileVersionAttribute("3.12.0")>]
[<assembly: AssemblyInformationalVersionAttribute("3.12.0")>]
[<assembly: AssemblyMetadataAttribute("ReleaseChannel","release")>]
[<assembly: AssemblyMetadataAttribute("GitHash","fdb4e9da4d035afc38f1941a84adf621fd8c2574")>]
do ()

#if LOW_TRUST
[<assembly: System.Security.AllowPartiallyTrustedCallers>]
[<assembly: System.Security.SecurityTransparent>]
#endif
[<assembly: InternalsVisibleTo(FParsec.CommonAssemblyInfo.TestAssemblyName + FParsec.CommonAssemblyInfo.StrongNamePublicKey)>]
do ()
module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "FParsec"
let [<Literal>] AssemblyProduct = "NpgsqlFSharpAnalyzer"
let [<Literal>] AssemblyVersion = "3.12.0"
let [<Literal>] AssemblyMetadata_ReleaseDate = "2020-08-29T00:00:00.0000000"
let [<Literal>] AssemblyFileVersion = "3.12.0"
let [<Literal>] AssemblyInformationalVersion = "3.12.0"
let [<Literal>] AssemblyMetadata_ReleaseChannel = "release"
let [<Literal>] AssemblyMetadata_GitHash = "fdb4e9da4d035afc38f1941a84adf621fd8c2574"
31 changes: 2 additions & 29 deletions src/FParsecCS/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,5 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: ComVisible(false)]

#if LOW_TRUST
[assembly: System.Security.AllowPartiallyTrustedCallers]
[assembly: System.Security.SecurityTransparent]
#endif

[assembly: InternalsVisibleTo ("FParsec" + FParsec.CommonAssemblyInfo.StrongNamePublicKey)]
[assembly: InternalsVisibleTo (FParsec.CommonAssemblyInfo.TestAssemblyName + FParsec.CommonAssemblyInfo.StrongNamePublicKey)]

namespace FParsec {

internal static partial class CommonAssemblyInfo {
public const string TestAssemblyName = "Test";

#if STRONG_NAME
public const string StrongNamePublicKey =
", PublicKey=002400000480000094000000060200000024000052534131000400000100010077c6be48a40f5b" +
"194ec9f992e5b512bbbba33e211354d9ee50c3214decddad8356470a9a19a9ee84637cbd6ff690" +
"9527d3973741dbe0a69b1461eeae774af9a78de45618ffd6fe7c7d52e0441b92f3bc7e8fb5757f" +
"b8b1611a0b6b8c9f9ef64edcf51d44218ae040f3015373fd261d30f8e1f5a1f914fd9ebcde7d7e" +
"f42dbaa5";
#else
public const string StrongNamePublicKey = "";
#endif
};

}
[assembly: InternalsVisibleTo ("FParsec")]
20 changes: 10 additions & 10 deletions src/NpgsqlFSharpAnalyzer.Core/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ open System.Reflection

[<assembly: AssemblyTitleAttribute("NpgsqlFSharpAnalyzer.Core")>]
[<assembly: AssemblyProductAttribute("NpgsqlFSharpAnalyzer")>]
[<assembly: AssemblyVersionAttribute("3.11.0")>]
[<assembly: AssemblyMetadataAttribute("ReleaseDate","2020-08-18T00:00:00.0000000")>]
[<assembly: AssemblyFileVersionAttribute("3.11.0")>]
[<assembly: AssemblyInformationalVersionAttribute("3.11.0")>]
[<assembly: AssemblyVersionAttribute("3.12.0")>]
[<assembly: AssemblyMetadataAttribute("ReleaseDate","2020-08-29T00:00:00.0000000")>]
[<assembly: AssemblyFileVersionAttribute("3.12.0")>]
[<assembly: AssemblyInformationalVersionAttribute("3.12.0")>]
[<assembly: AssemblyMetadataAttribute("ReleaseChannel","release")>]
[<assembly: AssemblyMetadataAttribute("GitHash","dbe65f09faf4b6ddf40d5e84320acd761f6b4d81")>]
[<assembly: AssemblyMetadataAttribute("GitHash","fdb4e9da4d035afc38f1941a84adf621fd8c2574")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "NpgsqlFSharpAnalyzer.Core"
let [<Literal>] AssemblyProduct = "NpgsqlFSharpAnalyzer"
let [<Literal>] AssemblyVersion = "3.11.0"
let [<Literal>] AssemblyMetadata_ReleaseDate = "2020-08-18T00:00:00.0000000"
let [<Literal>] AssemblyFileVersion = "3.11.0"
let [<Literal>] AssemblyInformationalVersion = "3.11.0"
let [<Literal>] AssemblyVersion = "3.12.0"
let [<Literal>] AssemblyMetadata_ReleaseDate = "2020-08-29T00:00:00.0000000"
let [<Literal>] AssemblyFileVersion = "3.12.0"
let [<Literal>] AssemblyInformationalVersion = "3.12.0"
let [<Literal>] AssemblyMetadata_ReleaseChannel = "release"
let [<Literal>] AssemblyMetadata_GitHash = "dbe65f09faf4b6ddf40d5e84320acd761f6b4d81"
let [<Literal>] AssemblyMetadata_GitHash = "fdb4e9da4d035afc38f1941a84adf621fd8c2574"
63 changes: 58 additions & 5 deletions src/NpgsqlFSharpAnalyzer.Core/SqlAnalysis.fs
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,57 @@ module SqlAnalysis =
| Result.Ok expr ->
parameters

let missingInsertColumns (schema: DbSchemaLookups) (query:string) =
match Parser.parse query with
| Result.Error _ -> None
| Result.Ok expression ->
match expression with
| Expr.InsertQuery insertQuery ->
let missingInsertColumns =
schema.Columns.Values
|> Seq.filter (fun column -> column.BaseTableName = insertQuery.Table && not column.OptionalForInsert)
|> Seq.filter (fun column -> not (List.contains column.Name insertQuery.Columns))

if Seq.isEmpty missingInsertColumns then
None
else
let errorMessage =
missingInsertColumns
|> Seq.map (fun column -> sprintf "'%s'" column.Name)
|> Seq.toList
|> function
| [ ] -> "<empty>"
| [ first ] -> first
| [ first; second ] -> sprintf "%s and %s" first second
| columns ->
let lastColumn = List.last columns
let firstColumns =
columns
|> List.rev
|> List.skip 1
|> List.rev
|> String.concat ", "

sprintf "%s and %s" firstColumns lastColumn

|> fun columns -> sprintf "INSERT query is missing required columns %s when adding rows to the '%s' table" columns insertQuery.Table

Some errorMessage
| _ ->
None

let extractParametersAndOutputColumns(connectionString, commandText, dbSchemaLookups) =
try
let parameters, output, enums = InformationSchema.extractParametersAndOutputColumns(connectionString, commandText, false, dbSchemaLookups)
let parametersWithNullability = determineParameterNullability parameters dbSchemaLookups commandText
Result.Ok (parametersWithNullability, output)
let potentiallyMissingColumns = missingInsertColumns dbSchemaLookups commandText
Result.Ok (parametersWithNullability, output, potentiallyMissingColumns)
with
| :? PostgresException as databaseError ->
Result.Error databaseError.Message
// errors such as syntax errors are reported here
Result.Error (sprintf "%s: %s" databaseError.Severity databaseError.MessageText)
| error ->
// any other generic error
Result.Error (sprintf "%s\n%s" error.Message error.StackTrace)

let createWarning (message: string) (range: range) : Message =
Expand Down Expand Up @@ -409,6 +451,8 @@ module SqlAnalysis =
let warning =
if String.IsNullOrWhiteSpace(providedParam.name)
then createWarning (sprintf "Empty parameter name was provided. Please provide one of %s" expectedParameters) providedParam.range
else if List.length codeFixes = 1
then createWarning (sprintf "Unexpected parameter '%s' is provided. Did you mean '%s'?" providedParam.name closestAlternative) providedParam.range
else createWarning (sprintf "Unexpected parameter '%s' is provided. Did you mean '%s'? %s" providedParam.name closestAlternative expectedParameters) providedParam.range

yield { warning with Fixes = codeFixes }
Expand Down Expand Up @@ -453,7 +497,10 @@ module SqlAnalysis =

{ createWarning warning providedParam.paramFuncRange with Fixes = codeFixs }

if not requiredParam.DataType.IsArray then
if providedParam.paramFunc = "Sql.parameter" then
// do not do anything when the input is a generic param
()
else if not requiredParam.DataType.IsArray then
match requiredParam.DataType.Name with
| "bit" ->
if requiredParam.IsNullable then
Expand Down Expand Up @@ -617,7 +664,7 @@ module SqlAnalysis =
match findColumn attempt.columnName availableColumns with
| None ->
if List.isEmpty availableColumns then
let warningMsg = sprintf "Attempting to read column named '%s' from a result set which doesn't return any columns. In case you are executing DELETE, INSERT or UPDATE queries, you might want to use Sql.executeNonQuery or Sql.executeNonQueryAsync to obtain the number of affected rows." attempt.columnName
let warningMsg = sprintf "Attempting to read column named '%s' from a result set which doesn't return any columns. In case you are executing DELETE, INSERT or UPDATE queries, you might want to use Sql.executeNonQuery or Sql.executeNonQueryAsync to obtain the number of affected rows. You can also add a RETURNING clause in your query to make it return the rows which are updated, inserted or deleted from that query." attempt.columnName
yield createWarning warningMsg attempt.columnNameRange
else
let levenshtein = new NormalizedLevenshtein()
Expand Down Expand Up @@ -890,9 +937,15 @@ module SqlAnalysis =
match queryAnalysis with
| Result.Error queryError ->
[ createWarning queryError queryRange ]
| Result.Ok (parameters, outputColunms) ->
| Result.Ok (parameters, outputColunms, errorMessage) ->
let potentialInsertQueryError =
match errorMessage with
| None -> [ ]
| Some message -> [ createWarning message queryRange ]

let readingAttempts = defaultArg (findColumnReadAttempts operation) [ ]
[
yield! potentialInsertQueryError
yield! analyzeParameters operation parameters
yield! analyzeColumnReadingAttempts readingAttempts outputColunms
]
20 changes: 10 additions & 10 deletions src/NpgsqlFSharpAnalyzer/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ open System.Reflection

[<assembly: AssemblyTitleAttribute("NpgsqlFSharpAnalyzer")>]
[<assembly: AssemblyProductAttribute("NpgsqlFSharpAnalyzer")>]
[<assembly: AssemblyVersionAttribute("3.11.0")>]
[<assembly: AssemblyMetadataAttribute("ReleaseDate","2020-08-18T00:00:00.0000000")>]
[<assembly: AssemblyFileVersionAttribute("3.11.0")>]
[<assembly: AssemblyInformationalVersionAttribute("3.11.0")>]
[<assembly: AssemblyVersionAttribute("3.12.0")>]
[<assembly: AssemblyMetadataAttribute("ReleaseDate","2020-08-29T00:00:00.0000000")>]
[<assembly: AssemblyFileVersionAttribute("3.12.0")>]
[<assembly: AssemblyInformationalVersionAttribute("3.12.0")>]
[<assembly: AssemblyMetadataAttribute("ReleaseChannel","release")>]
[<assembly: AssemblyMetadataAttribute("GitHash","dbe65f09faf4b6ddf40d5e84320acd761f6b4d81")>]
[<assembly: AssemblyMetadataAttribute("GitHash","fdb4e9da4d035afc38f1941a84adf621fd8c2574")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "NpgsqlFSharpAnalyzer"
let [<Literal>] AssemblyProduct = "NpgsqlFSharpAnalyzer"
let [<Literal>] AssemblyVersion = "3.11.0"
let [<Literal>] AssemblyMetadata_ReleaseDate = "2020-08-18T00:00:00.0000000"
let [<Literal>] AssemblyFileVersion = "3.11.0"
let [<Literal>] AssemblyInformationalVersion = "3.11.0"
let [<Literal>] AssemblyVersion = "3.12.0"
let [<Literal>] AssemblyMetadata_ReleaseDate = "2020-08-29T00:00:00.0000000"
let [<Literal>] AssemblyFileVersion = "3.12.0"
let [<Literal>] AssemblyInformationalVersion = "3.12.0"
let [<Literal>] AssemblyMetadata_ReleaseChannel = "release"
let [<Literal>] AssemblyMetadata_GitHash = "dbe65f09faf4b6ddf40d5e84320acd761f6b4d81"
let [<Literal>] AssemblyMetadata_GitHash = "fdb4e9da4d035afc38f1941a84adf621fd8c2574"
23 changes: 23 additions & 0 deletions src/NpgsqlFSharpParser/AssemblyInfo.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Auto-Generated by FAKE; do not edit
namespace System
open System.Reflection

[<assembly: AssemblyTitleAttribute("NpgsqlFSharpParser")>]
[<assembly: AssemblyProductAttribute("NpgsqlFSharpAnalyzer")>]
[<assembly: AssemblyVersionAttribute("3.12.0")>]
[<assembly: AssemblyMetadataAttribute("ReleaseDate","2020-08-29T00:00:00.0000000")>]
[<assembly: AssemblyFileVersionAttribute("3.12.0")>]
[<assembly: AssemblyInformationalVersionAttribute("3.12.0")>]
[<assembly: AssemblyMetadataAttribute("ReleaseChannel","release")>]
[<assembly: AssemblyMetadataAttribute("GitHash","fdb4e9da4d035afc38f1941a84adf621fd8c2574")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "NpgsqlFSharpParser"
let [<Literal>] AssemblyProduct = "NpgsqlFSharpAnalyzer"
let [<Literal>] AssemblyVersion = "3.12.0"
let [<Literal>] AssemblyMetadata_ReleaseDate = "2020-08-29T00:00:00.0000000"
let [<Literal>] AssemblyFileVersion = "3.12.0"
let [<Literal>] AssemblyInformationalVersion = "3.12.0"
let [<Literal>] AssemblyMetadata_ReleaseChannel = "release"
let [<Literal>] AssemblyMetadata_GitHash = "fdb4e9da4d035afc38f1941a84adf621fd8c2574"
20 changes: 10 additions & 10 deletions src/NpgsqlFSharpVs/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@

[assembly: AssemblyTitle("NpgsqlFSharpVs")]
[assembly: AssemblyProduct("NpgsqlFSharpAnalyzer")]
[assembly: AssemblyVersion("3.11.0")]
[assembly: AssemblyMetadata("ReleaseDate","2020-08-18T00:00:00.0000000")]
[assembly: AssemblyFileVersion("3.11.0")]
[assembly: AssemblyInformationalVersion("3.11.0")]
[assembly: AssemblyVersion("3.12.0")]
[assembly: AssemblyMetadata("ReleaseDate","2020-08-29T00:00:00.0000000")]
[assembly: AssemblyFileVersion("3.12.0")]
[assembly: AssemblyInformationalVersion("3.12.0")]
[assembly: AssemblyMetadata("ReleaseChannel","release")]
[assembly: AssemblyMetadata("GitHash","dbe65f09faf4b6ddf40d5e84320acd761f6b4d81")]
[assembly: AssemblyMetadata("GitHash","fdb4e9da4d035afc38f1941a84adf621fd8c2574")]
namespace System {
internal static class AssemblyVersionInformation {
internal const System.String AssemblyTitle = "NpgsqlFSharpVs";
internal const System.String AssemblyProduct = "NpgsqlFSharpAnalyzer";
internal const System.String AssemblyVersion = "3.11.0";
internal const System.String AssemblyMetadata_ReleaseDate = "2020-08-18T00:00:00.0000000";
internal const System.String AssemblyFileVersion = "3.11.0";
internal const System.String AssemblyInformationalVersion = "3.11.0";
internal const System.String AssemblyVersion = "3.12.0";
internal const System.String AssemblyMetadata_ReleaseDate = "2020-08-29T00:00:00.0000000";
internal const System.String AssemblyFileVersion = "3.12.0";
internal const System.String AssemblyInformationalVersion = "3.12.0";
internal const System.String AssemblyMetadata_ReleaseChannel = "release";
internal const System.String AssemblyMetadata_GitHash = "dbe65f09faf4b6ddf40d5e84320acd761f6b4d81";
internal const System.String AssemblyMetadata_GitHash = "fdb4e9da4d035afc38f1941a84adf621fd8c2574";
}
}
Loading

0 comments on commit b1592a8

Please sign in to comment.