Skip to content

Commit

Permalink
Escape only single quotes in nvarchar fpco#32
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerjanssen committed Mar 16, 2021
1 parent 7c0cea4 commit 107435a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Database/ODBC/SQLServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,10 @@ escapeChar8 ch =

-- | A very conservative character escape.
escapeChar :: Char -> Text
escapeChar ch =
if allowedChar ch
then T.singleton ch
else "'+NCHAR(" <> Formatting.sformat Formatting.int (fromEnum ch) <> ")+'"
escapeChar =
\case
'\'' -> "''"
ch -> T.singleton ch

-- | Is the character allowed to be printed unescaped? We only print a
-- small subset of ASCII just for visually debugging later
Expand Down
1 change: 1 addition & 0 deletions test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ regressions = do
bigData :: Spec
bigData = do
roundtrip @Text "2MB text" "Text" "ntext" (T.replicate (1024*1024*2) "A")
roundtrip @Text "2MB text special characters" "Text" "ntext" (T.replicate (1024*1024*2) "<")
roundtrip @ByteString "2MB binary" "ByteString" "text" (S.replicate (1024*1024*2) 97)

conversionTo :: Spec
Expand Down

0 comments on commit 107435a

Please sign in to comment.