Skip to content

Commit 9f98846

Browse files
fix docs
1 parent 5773dd0 commit 9f98846

File tree

11 files changed

+126
-88
lines changed

11 files changed

+126
-88
lines changed

RELEASE_NOTES.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
#### 1.8.2 - May 16, 2016
2+
* Issue #192 - Invert order of release notes so most recent is on top
3+
* Issue #195 - BREAKING CHANGE! Make connection parameter mandatory when literal connection string used at design time
4+
* Issue #196 - BREAKING CHANGE! API based run-time configuration
5+
* Issue #197
6+
* Issue #199 - Support for Stored procedure and Functions Synonyms
7+
* Issue #200 - Support for Table Synonyms
8+
* Issue #201 - Units of measure kind support in SqlEnumProvider
9+
* Issue #214 - BREAKING CHANGE! Add SqlCommand.Table type for ResultType.DataTable
10+
111
#### 1.8.1 - March 3, 2016
212
* Issue #185
313

docs/content/app.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<connectionStrings>
4-
<add name="AdventureWorks2014" connectionString="Data Source=.;Initial Catalog=AdventureWorks2014;Integrated Security=True" />
4+
<add name="AdventureWorks" connectionString="Data Source=.;Initial Catalog=AdventureWorks2012;Integrated Security=True" />
55
</connectionStrings>
66
</configuration>

docs/content/configuration and Input.fsx

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ CommandText
4646
open FSharp.Data
4747

4848
[<Literal>]
49-
let connectionString = @"Data Source=.;Initial Catalog=AdventureWorks2014;Integrated Security=True"
49+
let connStr = @"Data Source=.;Initial Catalog=AdventureWorks2012;Integrated Security=True"
5050

5151
//Inline T-SQL text convinient for short queries
52-
type GetDate = SqlCommandProvider<"SELECT GETDATE() AS Now", connectionString>
52+
type GetDate = SqlCommandProvider<"SELECT GETDATE() AS Now", connStr>
5353

5454
//More complex queries are better off extracted to stand-alone literals
5555

@@ -71,10 +71,12 @@ let fibonacci = "
7171
FROM Fibonacci
7272
"
7373

74-
type FibonacciQuery = SqlCommandProvider<fibonacci, connectionString>
74+
type FibonacciQuery = SqlCommandProvider<fibonacci, connStr>
7575

76-
(new FibonacciQuery())
77-
.Execute(10L)
76+
do
77+
let cmd = new FibonacciQuery(connStr)
78+
79+
cmd.Execute(10L)
7880
|> Seq.map Option.get
7981
|> Seq.toArray
8082
|> printfn "First 10 fibonacci numbers: %A"
@@ -103,7 +105,7 @@ For example, it can be handed over to DBA team for optimization. It's harder to
103105
are mixed together (LINQ).
104106
*)
105107

106-
let cmd = new SqlCommandProvider<"GetDate.sql", connectionString>()
108+
let cmd = new SqlCommandProvider<"GetDate.sql", connStr>(connStr)
107109
cmd.Execute() |> ignore
108110

109111
(**
@@ -118,7 +120,7 @@ Below is an example of SQL Table-Valued Function usage.
118120
*)
119121

120122
type GetContactInformation =
121-
SqlCommandProvider<"SELECT * FROM dbo.ufnGetContactInformation(@PersonId)", connectionString>
123+
SqlCommandProvider<"SELECT * FROM dbo.ufnGetContactInformation(@PersonId)", connStr>
122124

123125
(**
124126
### Syntax errors
@@ -147,9 +149,9 @@ type FizzOrBuzz = SqlCommandProvider<"
147149
WHEN @x % 3 = 0 THEN 'Fizz'
148150
WHEN @x % 5 = 0 THEN 'Buzz'
149151
ELSE CONCAT(@x, '') --use concat to avoid nullable column
150-
END", connectionString>
152+
END", connStr>
151153

152-
let fizzOrBuzz = new FizzOrBuzz()
154+
let fizzOrBuzz = new FizzOrBuzz(connStr)
153155
printfn "Answer on interview:\n%A" [ for i = 1 to 100 do yield! fizzOrBuzz.Execute(i) ]
154156

155157
(**
@@ -164,7 +166,7 @@ Connection string can be provided either via literal (all examples above) or inl
164166

165167
//Inline
166168
type Get42 =
167-
SqlCommandProvider<"SELECT 42", @"Data Source=.;Initial Catalog=AdventureWorks2014;Integrated Security=True">
169+
SqlCommandProvider<"SELECT 42", @"Data Source=.;Initial Catalog=AdventureWorks2012;Integrated Security=True">
168170

169171
(**
170172
@@ -176,10 +178,10 @@ The other option is to supply connection string name from config file.
176178
*)
177179

178180
//default config file name is app.config or web.config
179-
type Get43 = SqlCommandProvider<"SELECT 43", "name=AdventureWorks2014">
181+
type Get43 = SqlCommandProvider<"SELECT 43", "name=AdventureWorks">
180182

181183
//specify ANY other file name (including web.config) explicitly
182-
type Get44 = SqlCommandProvider<"SELECT 44", "name=AdventureWorks2014", ConfigFile = "user.config">
184+
type Get44 = SqlCommandProvider<"SELECT 44", "name=AdventureWorks", ConfigFile = "user.config">
183185

184186
(**
185187
I would like to emphasize that `ConfigFile` is about ***design time only*.
@@ -223,7 +225,7 @@ let get42 = new Get42(runTimeConnStr)
223225
//Factory or IOC of choice to avoid logic duplication. Use F# ctor static constraints.
224226
module DB =
225227
[<Literal>]
226-
let connStr = @"Data Source=.;Initial Catalog=AdventureWorks2014;Integrated Security=True"
228+
let connStr = @"Data Source=.;Initial Catalog=AdventureWorks2012;Integrated Security=True"
227229

228230
open System.Data.SqlClient
229231

@@ -245,7 +247,7 @@ let dbCmd2: DB.MyCmd2 = DB.createCommand()
245247
//Static type property ConnectionStringOrName that has exactly same value as passed into SqlCommandProvider helps.
246248
module DataAccess =
247249
[<Literal>]
248-
let adventureWorks = @"Data Source=.;Initial Catalog=AdventureWorks2014;Integrated Security=True"
250+
let adventureWorks = @"Data Source=.;Initial Catalog=AdventureWorks2012;Integrated Security=True"
249251
[<Literal>]
250252
let master = @"Data Source=.;Initial Catalog=master;Integrated Security=True"
251253

@@ -279,32 +281,34 @@ let bitCoinName = "Bitcoin"
279281

280282
type DeleteBitCoin =
281283
SqlCommandProvider<"DELETE FROM Sales.Currency WHERE CurrencyCode = @Code"
282-
, connectionString>
284+
, connStr>
283285
type InsertBitCoin =
284286
SqlCommandProvider<"INSERT INTO Sales.Currency VALUES(@Code, @Name, GETDATE())"
285-
, connectionString>
287+
, connStr>
286288
type GetBitCoin =
287289
SqlCommandProvider<"SELECT CurrencyCode, Name FROM Sales.Currency WHERE CurrencyCode = @code"
288-
, connectionString>
290+
, connStr>
289291

290292
do
291-
let cmd = new DeleteBitCoin() in cmd.Execute(bitCoinCode) |> ignore
292-
let conn = new System.Data.SqlClient.SqlConnection(connectionString)
293+
let cmd = new DeleteBitCoin(connStr) in cmd.Execute(bitCoinCode) |> ignore
294+
let conn = new System.Data.SqlClient.SqlConnection(connStr)
293295
conn.Open()
294296
let tran = conn.BeginTransaction()
295297

296-
let cmd = new SqlCommandProvider<"INSERT INTO Sales.Currency VALUES(@Code, @Name, GETDATE())"
297-
, connectionString>()
298+
let cmd =
299+
new SqlCommandProvider<"
300+
INSERT INTO Sales.Currency VALUES(@Code, @Name, GETDATE())
301+
", connStr>(connStr)
298302

299-
use insert = InsertBitCoin. Create(transaction = tran)
303+
use insert = InsertBitCoin.Create(conn, transaction = tran)
300304
assert(insert.Execute(bitCoinCode, bitCoinName) = 1)
301305

302-
use get = new GetBitCoin(transaction = tran)
306+
use get = new GetBitCoin(conn, transaction = tran)
303307
assert( get.Execute(bitCoinCode) |> Seq.length = 1)
304308

305309
tran.Rollback()
306310

307-
assert( GetBitCoin.Create().Execute(bitCoinCode) |> Seq.length = 0)
311+
assert( GetBitCoin.Create(connStr).Execute(bitCoinCode) |> Seq.length = 0)
308312

309313
(**
310314
@@ -316,7 +320,7 @@ to create command instances.
316320

317321
open System
318322

319-
type AdventureWorks2012 = SqlProgrammabilityProvider<connectionString>
323+
type AdventureWorks2012 = SqlProgrammabilityProvider<connStr>
320324

321325
(**
322326
@@ -328,10 +332,10 @@ But there are rare cases when you prefer to handle NULL input values inside T-SQ
328332
*)
329333

330334
type IncrBy = SqlCommandProvider<"SELECT @x + ISNULL(CAST(@y AS INT), 1) ",
331-
connectionString,
335+
connStr,
332336
AllParametersOptional = true,
333337
SingleRow = true>
334-
let incrBy = new IncrBy()
338+
let incrBy = new IncrBy(connStr)
335339
//pass both params passed
336340
incrBy.Execute(Some 10, Some 2) = Some( Some 12) //true
337341
//omit second parameter. default to 1
@@ -361,9 +365,9 @@ END
361365
</pre>
362366
*)
363367

364-
type TableValuedSample = SqlCommandProvider<"exec myProc @x", connectionString>
368+
type TableValuedSample = SqlCommandProvider<"exec myProc @x", connStr>
365369
type TVP = TableValuedSample.MyTableType
366-
let tvpSp = new TableValuedSample()
370+
let tvpSp = new TableValuedSample(connStr)
367371
//nullable columns mapped to optional ctor params
368372
tvpSp.Execute(x = [ TVP(myId = 1, myName = Some "monkey"); TVP(myId = 2) ])
369373

@@ -374,7 +378,7 @@ Same with `SqlProgrammabilityProvider<...>`
374378
type T = AdventureWorks2012.dbo.``User-Defined Table Types``.MyTableType
375379

376380
do
377-
use cmd = new AdventureWorks2012.dbo.MyProc()
381+
use cmd = new AdventureWorks2012.dbo.MyProc(connStr)
378382
cmd.Execute([ T(myId = 2); T(myId = 1) ]) |> printfn "%A"
379383

380384
(**
@@ -386,7 +390,7 @@ There is additional ExecuteSingle/ AsyncExecuteSingle to opt-in for singleton re
386390
*)
387391

388392
do
389-
use cmd = new AdventureWorks2012.dbo.uspGetWhereUsedProductID()
393+
use cmd = new AdventureWorks2012.dbo.uspGetWhereUsedProductID(connStr)
390394

391395
//sync
392396
cmd.Execute( StartProductID = 1, CheckDate = DateTime(2013,1,1)) |> printfn "%A"
@@ -404,19 +408,19 @@ do
404408
*)
405409

406410
do
407-
use cmd = new AdventureWorks2012.dbo.uspLogError()
411+
use cmd = new AdventureWorks2012.dbo.uspLogError(connStr)
408412
let errorLogId = ref -1
409413
let recordsAffected = cmd.Execute(errorLogId)
410414
printfn "errorLogId: %i" !errorLogId
411415

412416
do //tupled invocation syntax
413417
//works only in VS 2015 or later because of F# compiler bug
414-
use cmd = new AdventureWorks2012.dbo.uspLogError()
418+
use cmd = new AdventureWorks2012.dbo.uspLogError(connStr)
415419
let _, errorLogId = cmd.Execute()
416420
printfn "errorLogId: %i" errorLogId
417421

418422
do //mutable bindgings
419-
use cmd = new AdventureWorks2012.dbo.uspLogError()
423+
use cmd = new AdventureWorks2012.dbo.uspLogError(connStr)
420424
let mutable errorLogId = -1
421425
let recordsAffected = cmd.Execute(&errorLogId)
422426
printfn "errorLogId: %i" errorLogId
@@ -428,13 +432,14 @@ RETURN_VALUE will be the last byref parameter.
428432
*)
429433

430434
do
431-
use cmd = new SqlProgrammabilityProvider<connectionString, UseReturnValue = true>.dbo.uspLogError()
435+
use cmd =
436+
new SqlProgrammabilityProvider<connStr, UseReturnValue = true>.dbo.uspLogError(connStr)
432437
let recordsAffected, errorLogId, returnValue = cmd.Execute()
433438
printfn "recordsAffected: %i, errorLogId: %i, returnValue: %i" recordsAffected errorLogId returnValue
434439

435440
(**
436441
Things get interesting when stored procedure return both set of rows and output parameters.
437-
I won’t show any sample code because AdventureWorks database doesn’t have such procedure.
442+
I won't show any sample code because AdventureWorks database doesn't have such procedure.
438443
But the only change comparing to non-query stored procedure that instead of returning number
439444
of affected records it returns F# list of records.
440445
Notice that list is data structure as oppose to lazy evaluated seq<_> computation.

docs/content/data modification.fsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ open FSharp.Data
55
open System
66

77
[<Literal>]
8-
let connectionString = @"Data Source=.;Initial Catalog=AdventureWorks2014;Integrated Security=True"
8+
let connectionString = @"Data Source=.;Initial Catalog=AdventureWorks2012;Integrated Security=True"
99

1010
(**
1111
@@ -63,7 +63,7 @@ let businessEntityID, jobTitle, hireDate =
6363
HumanResources.Employee
6464
WHERE
6565
BusinessEntityID = @id
66-
", connectionString, ResultType.Tuples, SingleRow = true>(connectionString))
66+
", connectionString, ResultType.Tuples, SingleRow = true>(connectionString)
6767

6868
jamesKramerId |> cmd.Execute |> Option.get
6969

@@ -72,7 +72,7 @@ assert("Production Technician - WC60" = jobTitle)
7272
let newJobTitle = "Uber " + jobTitle
7373

7474
let recordsAffrected =
75-
use updatedJobTitle = new AdventureWorks.HumanResources.uspUpdateEmployeeHireInfo(connectionString))
75+
use updatedJobTitle = new AdventureWorks.HumanResources.uspUpdateEmployeeHireInfo(connectionString)
7676
updatedJobTitle.Execute(
7777
businessEntityID,
7878
newJobTitle,

docs/content/debugging.fsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ open FSharp.Data
55
open System
66

77
[<Literal>]
8-
let connectionString = @"Data Source=.;Initial Catalog=AdventureWorks2014;Integrated Security=True"
8+
let connectionString = @"Data Source=.;Initial Catalog=AdventureWorks2012;Integrated Security=True"
99

1010
(**
1111
@@ -25,7 +25,7 @@ let cmd = new SqlCommandProvider<"
2525
FROM Sales.vSalesPerson
2626
WHERE CountryRegionName = @regionName AND SalesYTD > @salesMoreThan
2727
ORDER BY SalesYTD
28-
" , connectionString>()
28+
" , connectionString>(connectionString)
2929

3030
cmd.ToTraceString(topN = 3L, regionName = "United States", salesMoreThan = 1000000M)
3131
|> printfn "Sql: %s"

docs/content/faq.fsx

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
open FSharp.Data
55

66
[<Literal>]
7-
let connectionString = @"Data Source=.;Initial Catalog=AdventureWorks2014;Integrated Security=True"
7+
let connectionString = @"Data Source=.;Initial Catalog=AdventureWorks2012;Integrated Security=True"
88

99
(**
1010
FAQ
@@ -25,7 +25,8 @@ consider wrapping it into stored procedure or function. Both accept default valu
2525
By default SqlCommandProvider treat all parameters as mandatory.
2626
*)
2727

28-
let echoOnly = new SqlCommandProvider<"SELECT ISNULL(@x, 42)", connectionString, SingleRow = true>()
28+
let echoOnly =
29+
new SqlCommandProvider<"SELECT ISNULL(@x, 42)", connectionString, SingleRow = true>(connectionString)
2930
echoOnly.Execute( x = (* must pass int value here *) 1)
3031

3132
(**
@@ -47,7 +48,7 @@ No generics, no F# specific types/annotations which includes optional parameters
4748
let echoOr42 =
4849
new SqlCommandProvider<"
4950
SELECT ISNULL(@x, 42)
50-
", connectionString, SingleRow = true, AllParametersOptional = true>()
51+
", connectionString, SingleRow = true, AllParametersOptional = true>(connectionString)
5152

5253
// Pass parameter value. Specifying Some constructor is mandatrory.
5354
echoOr42.Execute( Some 1)
@@ -77,13 +78,18 @@ To work around this limitation, you can declare another variable in your script:
7778
*)
7879

7980
// this one would fail with above mentionned error:
80-
// let echoFail = new SqlCommandProvider<"select 'hello' + @name, 'your name is :' @name", connectionString, SingleRow = true>()
81+
//let echoFail =
82+
// new SqlCommandProvider<"
83+
// select 'hello' + @name, 'your name is :' @name
84+
// ", connectionString, SingleRow = true>(connectionString)
8185

8286
// this one is ok as @name parameter is used only once in the statement:
83-
let echoOk = new SqlCommandProvider< @"
84-
declare @theName nvarchar(max)
85-
set @theName = @name
86-
select 'hello' + @theName, 'your name is :' + @theName", connectionString, ResultType.Tuples, SingleRow = true>()
87+
let echoOk =
88+
new SqlCommandProvider< @"
89+
declare @theName nvarchar(max)
90+
set @theName = @name
91+
select 'hello' + @theName, 'your name is :' + @theName
92+
", connectionString, ResultType.Tuples, SingleRow = true>(connectionString)
8793

8894

8995
(**
@@ -105,7 +111,12 @@ type SqlDataReader with
105111
member this.ToRecords<'T>() =
106112
seq {
107113
while this.Read() do
108-
let data = dict [ for i = 0 to this.VisibleFieldCount - 1 do yield this.GetName(i), this.GetValue(i)]
114+
let data =
115+
dict [
116+
for i = 0 to this.VisibleFieldCount - 1 do
117+
yield this.GetName(i), this.GetValue(i)
118+
]
119+
109120
yield FSharp.Data.SqlClient.DynamicRecord(data) |> box |> unbox<'T>
110121
}
111122

0 commit comments

Comments
 (0)