Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port Information Schema to Sql Server #1

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
81a8080
Port Information Schema to Sql Server
sudqijawabreh Apr 3, 2021
aeeb391
Use DustyTables and Throwaway instead of postgres packages
sudqijawabreh Apr 9, 2021
165f1a1
Replace bigserial and serial with int and bigint using identity keyword
sudqijawabreh Apr 10, 2021
cb75307
Use nvarchar instead of text and text[]
sudqijawabreh Apr 10, 2021
dfe6220
Remove sql client error in Test file
sudqijawabreh Apr 10, 2021
53ae2b0
Fixing some unit tests
sudqijawabreh Apr 10, 2021
753714e
Remove "@" character from paramater names to be compatabile with pars…
sudqijawabreh Apr 10, 2021
d9a8a38
Fix semanticAnalysis-missingParameter code because missing column tes…
sudqijawabreh Apr 10, 2021
f9093ca
Fix semanticAnalysis-typeMistmatch code because missing column test e…
sudqijawabreh Apr 10, 2021
4d1744e
Remove Returning from update statement because it is not needed and n…
sudqijawabreh Apr 10, 2021
e1be54f
order unbound vars in ReWriteSqlStatementToEnableMoreThanOneParameter…
sudqijawabreh Apr 11, 2021
62068d6
Fix test type mismatch with comparing against non-nullable column dur…
sudqijawabreh Apr 11, 2021
eb70eef
Fix column type name when extracting output columns
sudqijawabreh Apr 11, 2021
eb9dc7a
Bit is the same as as boolean in tsql when providing parameters
sudqijawabreh Apr 11, 2021
1ded3f4
Fix insert queries in tests
sudqijawabreh Apr 11, 2021
4411fd7
Use output instead of Return
sudqijawabreh Apr 11, 2021
c4356f0
Remove array tests
sudqijawabreh Apr 11, 2021
f246511
Port some tests to work on MS SQL
sudqijawabreh Aug 9, 2021
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
5 changes: 3 additions & 2 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ nuget Microsoft.NET.Test.Sdk 15.7.2
nuget altcover ~> 6
nuget FSharp.Analyzers.SDK 0.8.0
nuget Npgsql
nuget ThrowawayDb.Postgres
nuget Npgsql.FSharp ~> 4.0
nuget Npgsql.FSharp
nuget ThrowawayDb
nuget DustyTables
nuget F23.StringSimilarity

// [ FAKE GROUP ]
Expand Down
62 changes: 38 additions & 24 deletions paket.lock

Large diffs are not rendered by default.

611 changes: 333 additions & 278 deletions src/NpgsqlFSharpAnalyzer.Core/InformationSchema.fs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
<PackageReference Include="F23.StringSimilarity" Version="3.1.0" />
<PackageReference Include="FSharp.Compiler.Service" Version="39.0.0" />
<PackageReference Update="FSharp.Core" Version="5.0.1" />
<PackageReference Include="Microsoft.SqlServer.TransactSql.ScriptDom" Version="150.4897.1" />
<PackageReference Include="Npgsql" Version="4.1.3" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NpgsqlFSharpParser\NpgsqlFSharpParser.fsproj" />
Expand Down
19 changes: 7 additions & 12 deletions src/NpgsqlFSharpAnalyzer.Core/SqlAnalysis.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ open F23.StringSimilarity
open NpgsqlFSharpParser
open InformationSchema
open Npgsql
open System.Data.SqlClient

module SqlAnalysis =

Expand Down Expand Up @@ -419,6 +420,8 @@ module SqlAnalysis =
| :? PostgresException as databaseError ->
// errors such as syntax errors are reported here
Result.Error (sprintf "%s: %s" databaseError.Severity databaseError.MessageText)
| :? SqlException as sqlexcpetion ->
Result.Error (sprintf "%s" (sqlexcpetion.Message.Replace("The batch could not be analyzed because of compile errors.",String.Empty)))
| error ->
// any other generic error
Result.Error (sprintf "%s\n%s" error.Message error.StackTrace)
Expand Down Expand Up @@ -577,15 +580,7 @@ module SqlAnalysis =
()
else if not requiredParam.DataType.IsArray then
match requiredParam.DataType.Name with
| "bit" ->
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@falfaddaghi this the only part that needs some thought to make it work for both postgres and sql server.

if requiredParam.IsNullable then
if providedParam.paramFunc <> "Sql.bit" && providedParam.paramFunc <> "Sql.bitOrNone" && providedParam.paramFunc <> "Sql.dbnull"
then yield typeMismatch [ "Sql.bit"; "Sql.bitOrNone";"Sql.dbnull"]
else
if providedParam.paramFunc <> "Sql.bit"
then yield typeMismatch [ "Sql.bit" ]

| ("bool" | "boolean") ->
| ("bool" | "boolean" | "bit") ->
if requiredParam.IsNullable then
if providedParam.paramFunc <> "Sql.bool" && providedParam.paramFunc <> "Sql.boolOrNone" && providedParam.paramFunc <> "Sql.dbnull"
then yield typeMismatch [ "Sql.bool"; "Sql.boolOrNone"; "Sql.dbnull" ]
Expand Down Expand Up @@ -681,7 +676,7 @@ module SqlAnalysis =
if providedParam.paramFunc <> "Sql.jsonb"
then yield typeMismatch [ "Sql.jsonb" ]

| ("text"|"json"|"xml") ->
| ("text"|"json"|"xml"|"nvarchar"|"varchar") ->
if requiredParam.IsNullable then
if providedParam.paramFunc <> "Sql.text" && providedParam.paramFunc <> "Sql.textOrNone" && providedParam.paramFunc <> "Sql.string" && providedParam.paramFunc <> "Sql.textOrNone" && providedParam.paramFunc <> "Sql.dbnull"
then yield typeMismatch [ "Sql.text"; "Sql.string"; "Sql.textOrNone"; "Sql.stringOrNone"; "Sql.dbnull" ]
Expand Down Expand Up @@ -808,7 +803,7 @@ module SqlAnalysis =
yield typeMismatch [ "Sql.readBool" ]
| ("text"|"json"|"xml"|"jsonb") when attempt.funcName <> "Sql.readString" ->
yield typeMismatch [ "Sql.readString" ]
| ("character varying"|"character"|"char"|"varchar"|"citext") when attempt.funcName <> "Sql.readString" ->
| ("character varying"|"character"|"char"|"nvarchar"|"varchar"|"citext") when attempt.funcName <> "Sql.readString" ->
yield typeMismatch [ "Sql.readString" ]
| ("int" | "int2" | "int4" | "smallint" | "integer") when attempt.funcName <> "Sql.readInt" ->
yield typeMismatch [ "Sql.readInt" ]
Expand Down Expand Up @@ -910,7 +905,7 @@ module SqlAnalysis =
else yield typeMismatch [ replace "double" ]
else ()

| ("text"|"json"|"xml"|"jsonb"|"varchar") ->
| ("text"|"json"|"xml"|"jsonb"|"varchar"|"nvarchar") ->
if column.Nullable && notUsing "textOrNone" && notUsing "stringOrNone"
then yield typeMismatch [ replace "textOrNone"; replace "stringOrNone" ]
else if notUsing "textOrNone" && notUsing "text" && notUsing "string" && notUsing "stringOrNone"
Expand Down
20 changes: 20 additions & 0 deletions src/NpgsqlFSharpVs/NpgsqlFSharpVs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,24 @@
<Choose>
<When Condition="($(TargetFrameworkIdentifier) == 'MonoAndroid' And ($(TargetFrameworkVersion) == 'v10.0' Or $(TargetFrameworkVersion) == 'v8.0' Or $(TargetFrameworkVersion) == 'v8.1' Or $(TargetFrameworkVersion) == 'v9.0')) Or ($(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.7.1' Or $(TargetFrameworkVersion) == 'v4.7.2' Or $(TargetFrameworkVersion) == 'v4.8')) Or ($(TargetFrameworkIdentifier) == '.NETCoreApp' And ($(TargetFrameworkVersion) == 'v2.0' Or $(TargetFrameworkVersion) == 'v2.1' Or $(TargetFrameworkVersion) == 'v2.2' Or $(TargetFrameworkVersion) == 'v3.0' Or $(TargetFrameworkVersion) == 'v3.1' Or $(TargetFrameworkVersion) == 'v5.0' Or ($(TargetFrameworkVersion) == 'v5.0' And '$(TargetPlatformIdentifier)' == 'Windows' And '$(TargetPlatformVersion)' == '10.0.17763.0') Or ($(TargetFrameworkVersion) == 'v5.0' And '$(TargetPlatformIdentifier)' == 'Windows' And '$(TargetPlatformVersion)' == '10.0.18362.0') Or ($(TargetFrameworkVersion) == 'v5.0' And '$(TargetPlatformIdentifier)' == 'Windows' And '$(TargetPlatformVersion)' == '10.0.19041.0') Or ($(TargetFrameworkVersion) == 'v5.0' And '$(TargetPlatformIdentifier)' == 'Windows' And '$(TargetPlatformVersion)' == '8.0') Or ($(TargetFrameworkVersion) == 'v5.0' And '$(TargetPlatformIdentifier)' == 'Windows') Or ($(TargetFrameworkVersion) == 'v5.0' And '$(TargetPlatformIdentifier)' == 'android') Or ($(TargetFrameworkVersion) == 'v5.0' And '$(TargetPlatformIdentifier)' == 'ios') Or ($(TargetFrameworkVersion) == 'v5.0' And '$(TargetPlatformIdentifier)' == 'macos') Or ($(TargetFrameworkVersion) == 'v5.0' And '$(TargetPlatformIdentifier)' == 'tvos') Or ($(TargetFrameworkVersion) == 'v5.0' And '$(TargetPlatformIdentifier)' == 'watchos'))) Or ($(TargetFrameworkIdentifier) == '.NETStandard' And ($(TargetFrameworkVersion) == 'v2.0' Or $(TargetFrameworkVersion) == 'v2.1')) Or ($(TargetFrameworkIdentifier) == '.NETCore' And $(TargetFrameworkVersion) == 'v5.0') Or ($(TargetFrameworkIdentifier) == 'Xamarin.iOS') Or ($(TargetFrameworkIdentifier) == 'Xamarin.Mac')" />
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5' Or $(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6' Or $(TargetFrameworkVersion) == 'v4.6.1' Or $(TargetFrameworkVersion) == 'v4.6.2' Or $(TargetFrameworkVersion) == 'v4.6.3' Or $(TargetFrameworkVersion) == 'v4.7' Or $(TargetFrameworkVersion) == 'v4.7.1' Or $(TargetFrameworkVersion) == 'v4.7.2' Or $(TargetFrameworkVersion) == 'v4.8')">
<ItemGroup>
<Reference Include="FSharp.Core">
<HintPath>..\..\..\..\.nuget\packages\fsharp.core\4.7.2\lib\net45\FSharp.Core.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
<When Condition="($(TargetFrameworkIdentifier) == 'MonoAndroid' And ($(TargetFrameworkVersion) == 'v10.0' Or $(TargetFrameworkVersion) == 'v8.0' Or $(TargetFrameworkVersion) == 'v8.1' Or $(TargetFrameworkVersion) == 'v9.0')) Or ($(TargetFrameworkIdentifier) == '.NETCoreApp' And ($(TargetFrameworkVersion) == 'v2.0' Or $(TargetFrameworkVersion) == 'v2.1' Or $(TargetFrameworkVersion) == 'v2.2' Or $(TargetFrameworkVersion) == 'v3.0' Or $(TargetFrameworkVersion) == 'v3.1' Or $(TargetFrameworkVersion) == 'v5.0')) Or ($(TargetFrameworkIdentifier) == '.NETStandard' And ($(TargetFrameworkVersion) == 'v2.0' Or $(TargetFrameworkVersion) == 'v2.1')) Or ($(TargetFrameworkIdentifier) == '.NETCore' And $(TargetFrameworkVersion) == 'v5.0') Or ($(TargetFrameworkIdentifier) == 'Xamarin.iOS') Or ($(TargetFrameworkIdentifier) == 'Xamarin.Mac')">
<ItemGroup>
<Reference Include="FSharp.Core">
<HintPath>..\..\..\..\.nuget\packages\fsharp.core\4.7.2\lib\netstandard2.0\FSharp.Core.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
<ProjectReference Include="..\..\src\NpgsqlFSharpParser\NpgsqlFSharpParser.fsproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="DustyTables" Version="3.0.0" />
<PackageReference Include="Expecto" Version="8.13.1" />
<PackageReference Include="Npgsql.FSharp" Version="3.6.0" />
<PackageReference Update="FSharp.Core" Version="5.0.1" />
<PackageReference Include="ThrowawayDb" Version="1.5.0" />
<PackageReference Include="ThrowawayDb.Postgres" Version="1.0.0" />
</ItemGroup>
</Project>
Loading