|
| 1 | +module SprocParameterTests |
| 2 | + |
| 3 | +// Issue #877: stored procedures compiled against an offline ContextSchema |
| 4 | +// have result-set / return-value columns in their parameter list. |
| 5 | + |
| 6 | +open System.Data |
| 7 | +open FSharp.Data.Sql.Schema |
| 8 | +open FSharp.Data.Sql.Providers |
| 9 | +open NUnit.Framework |
| 10 | + |
| 11 | +let private intType = TypeMapping.Create(typeof<int>.ToString(), DbType.Int32) |
| 12 | +let private cursorType = TypeMapping.Create(typeof<obj>.ToString(), DbType.Object, "cursor") |
| 13 | + |
| 14 | +let private param name ordinal typeMapping direction = |
| 15 | + QueryParameter.Create(name, ordinal, typeMapping, direction) |
| 16 | + |
| 17 | +[<Test>] |
| 18 | +let ``MSSQL sproc call ignores result set columns from an offline schema``() = |
| 19 | + let resultSet = param "ResultSet" 0 cursorType ParameterDirection.Output |
| 20 | + // Offline the cached parameter list has the result set appended to the real parameters |
| 21 | + let inputParameters = |
| 22 | + [| param "@a" 1 intType ParameterDirection.Input |
| 23 | + param "@b" 2 intType ParameterDirection.InputOutput |
| 24 | + resultSet |] |
| 25 | + let values = [| box 1; box 2 |] |
| 26 | + |
| 27 | + let allParams, outps = MSSqlServer.executeSprocCommandCommon inputParameters [| resultSet |] values |
| 28 | + |
| 29 | + let names = allParams |> Array.map (fun (_,name,_) -> name) |
| 30 | + Assert.AreEqual([| "@a"; "@b" |], names) |
| 31 | + let values = allParams |> Array.map (fun (_,_,p) -> p.Value) |
| 32 | + Assert.AreEqual([| box 1; box 2 |], values) |
| 33 | + Assert.AreEqual(1, outps.Length) |
| 34 | + |
| 35 | +[<Test>] |
| 36 | +let ``MSSQL function call passes the return value parameter``() = |
| 37 | + let returnValue = param "ReturnValue" 0 intType ParameterDirection.ReturnValue |
| 38 | + let inputParameters = |
| 39 | + [| param "" 0 intType ParameterDirection.ReturnValue |
| 40 | + param "@a" 1 intType ParameterDirection.Input |
| 41 | + returnValue |] |
| 42 | + |
| 43 | + let allParams, _ = MSSqlServer.executeSprocCommandCommon inputParameters [| returnValue |] [| box 5 |] |
| 44 | + |
| 45 | + let names = allParams |> Array.map (fun (_,_,p) -> (p :?> IDataParameter).ParameterName) |
| 46 | + Assert.AreEqual([| "@RETURN_VALUE"; "@a" |], names) |
| 47 | + |
| 48 | +[<Test>] |
| 49 | +let ``distinctNamed drops repeated named parameters only``() = |
| 50 | + let parameters = |
| 51 | + [ param "" 0 intType ParameterDirection.ReturnValue |
| 52 | + param "@a" 1 intType ParameterDirection.Input |
| 53 | + param "@b" 2 intType ParameterDirection.InputOutput |
| 54 | + param "ResultSet" 0 cursorType ParameterDirection.Output |
| 55 | + param "ReturnValue" 0 intType ParameterDirection.ReturnValue |
| 56 | + param "@b" 2 intType ParameterDirection.InputOutput ] |
| 57 | + |
| 58 | + let result = SprocParameters.distinctNamed parameters |
| 59 | + |
| 60 | + Assert.AreEqual( |
| 61 | + [ "", ParameterDirection.ReturnValue |
| 62 | + "@a", ParameterDirection.Input |
| 63 | + "@b", ParameterDirection.InputOutput |
| 64 | + "ResultSet", ParameterDirection.Output |
| 65 | + "ReturnValue", ParameterDirection.ReturnValue ], |
| 66 | + result |> List.map (fun p -> p.Name, p.Direction)) |
0 commit comments