From 21211a87896c98332806b5df0b8600d3995030c0 Mon Sep 17 00:00:00 2001 From: Daniel Francesconi <> Date: Tue, 8 Dec 2020 14:55:47 +0100 Subject: [PATCH] Detect queries after calling print expressions; Fixes #16 --- src/NpgsqlFSharpAnalyzer.Core/SyntacticAnalysis.fs | 6 ++++++ tests/NpgsqlFSharpAnalyzer.Tests/Tests.fs | 2 +- tests/examples/hashing/syntacticAnalysis.fs | 8 ++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/NpgsqlFSharpAnalyzer.Core/SyntacticAnalysis.fs b/src/NpgsqlFSharpAnalyzer.Core/SyntacticAnalysis.fs index dd014b9..cc02ef4 100644 --- a/src/NpgsqlFSharpAnalyzer.Core/SyntacticAnalysis.fs +++ b/src/NpgsqlFSharpAnalyzer.Core/SyntacticAnalysis.fs @@ -646,6 +646,12 @@ module SyntacticAnalysis = | SynExpr.Lambda (fromMethod, inSeq, args, body, range) -> visitSyntacticExpression body range + | SynExpr.Sequential (debugSeqPoint, isTrueSeq, expr1, expr2, range) -> + [ + yield! visitSyntacticExpression expr1 range + yield! visitSyntacticExpression expr2 range + ] + | otherwise -> [ ] diff --git a/tests/NpgsqlFSharpAnalyzer.Tests/Tests.fs b/tests/NpgsqlFSharpAnalyzer.Tests/Tests.fs index a3627b9..536e1b9 100644 --- a/tests/NpgsqlFSharpAnalyzer.Tests/Tests.fs +++ b/tests/NpgsqlFSharpAnalyzer.Tests/Tests.fs @@ -38,7 +38,7 @@ let tests = | None -> failwith "Could not crack project" | Some context -> let operationBlocks = SyntacticAnalysis.findSqlOperations context - Expect.equal 10 (List.length operationBlocks) "Found ten operation blocks" + Expect.equal 11 (List.length operationBlocks) "Found ten operation blocks" } test "Syntactic analysis: no SQL blocks should be found using sprintf" { diff --git a/tests/examples/hashing/syntacticAnalysis.fs b/tests/examples/hashing/syntacticAnalysis.fs index 68cf7e1..91de699 100644 --- a/tests/examples/hashing/syntacticAnalysis.fs +++ b/tests/examples/hashing/syntacticAnalysis.fs @@ -37,6 +37,14 @@ let findNumberOfUsers() = |> Sql.query "SELECT COUNT(*) as count FROM users" |> Sql.execute (fun read -> read.int64 "count") +let findNumberOfUsersAfterCallingPrintExpressions () = + printfn "Non blocking expression" + printf "Non blocking expression" + Sql.host "localhost" + |> Sql.connectFromConfig + |> Sql.query "SELECT COUNT(*) as count FROM users" + |> Sql.execute (fun read -> read.int64 "count") + let executeFunction() = Sql.host "localhost" |> Sql.connectFromConfig