Skip to content

Commit

Permalink
params removed from exception output
Browse files Browse the repository at this point in the history
  • Loading branch information
pimbrouwers committed Apr 2, 2024
1 parent a75073f commit a237f25
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 35 deletions.
24 changes: 2 additions & 22 deletions src/Donald/Core.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,15 @@ namespace Donald

open System
open System.Data
open System.Data.Common
open System.Threading

[<AutoOpen>]
module DbCommandExtensions =
type DbCommand with
member internal x.ToDetailString() =
let param =
[ for i in 0 .. x.Parameters.Count - 1 ->
let p = x.Parameters.[i]
let pName = p.ParameterName
let pValue = if isNull p.Value || p.Value = DBNull.Value then "NULL" else string p.Value
String.Concat("@", pName, " = ", pValue) ]
|> fun str -> String.Join(", ", str)
|> fun str -> if (String.IsNullOrWhiteSpace(str)) then "--" else str

String.Join("\n\n", param, x.CommandText)

type IDbCommand with
member internal x.ToDetailString() =
(x :?> DbCommand).ToDetailString()

/// Represents a configurable database command.
type DbUnit (cmd : IDbCommand) =
member _.Command = cmd
member val CommandBehavior = CommandBehavior.SequentialAccess with get, set
member val CancellationToken = CancellationToken.None with get,set

member x.ToDetailString() = x.Command.ToDetailString()
member x.ToDetailString() = x.Command.CommandText

interface IDisposable with
member x.Dispose () =
Expand Down Expand Up @@ -96,7 +76,7 @@ type DbExecutionException =
new() = { inherit Exception(); Statement = None }
new(message : string) = { inherit Exception(message); Statement = None }
new(message : string, inner : Exception) = { inherit Exception(message, inner); Statement = None }
new(cmd : IDbCommand, inner : Exception) = { inherit Exception($"Failed to process database command:\n{cmd.ToDetailString()}", inner); Statement = Some (cmd.ToDetailString()) }
new(cmd : IDbCommand, inner : Exception) = { inherit Exception($"Failed to process database command:\n{cmd.CommandText}", inner); Statement = Some (cmd.CommandText) }

/// Details of failure to process a database transaction.
type DbTransactionException =
Expand Down
13 changes: 0 additions & 13 deletions src/Donald/IDbCommand.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,6 @@ open System.Threading
[<AutoOpen>]
module IDbCommandExtensions =
type IDbCommand with
member internal x.ToDetailString() =
let cmd = x :?> DbCommand
let param =
[ for i in 0 .. cmd.Parameters.Count - 1 ->
let p = cmd.Parameters.[i]
let pName = p.ParameterName
let pValue = if isNull p.Value || p.Value = DBNull.Value then "NULL" else string p.Value
String.Concat("@", pName, " = ", pValue) ]
|> fun str -> String.Join(", ", str)
|> fun str -> if (String.IsNullOrWhiteSpace(str)) then "--" else str

String.Join("\n\n", param, cmd.CommandText)

member internal x.Exec() =
try
x.ExecuteNonQuery() |> ignore
Expand Down

0 comments on commit a237f25

Please sign in to comment.