Skip to content

Commit

Permalink
Detect queries after calling print expressions; Fixes Zaid-Ajaj#16
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Francesconi committed Dec 8, 2020
1 parent 784bcf6 commit 21211a8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/NpgsqlFSharpAnalyzer.Core/SyntacticAnalysis.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
[ ]

Expand Down
2 changes: 1 addition & 1 deletion tests/NpgsqlFSharpAnalyzer.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
8 changes: 8 additions & 0 deletions tests/examples/hashing/syntacticAnalysis.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 21211a8

Please sign in to comment.