Skip to content

Format SqlRational as a decimal ... #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Database/HDBC/PostgreSQL/Utils.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Foreign.Storable
import Foreign.Marshal.Array
import Foreign.Marshal.Alloc
import Foreign.Marshal.Utils
import Data.Fixed (Pico, showFixed)
import Data.Word
import qualified Data.ByteString.UTF8 as BUTF8
import qualified Data.ByteString as B
Expand Down Expand Up @@ -76,12 +77,19 @@ withCStringArr0 inp action = withAnyArr0 convfunc freefunc inp action
convfunc y@(SqlUTCTime _) = convfunc (SqlZonedTime (fromSql y))
convfunc y@(SqlEpochTime _) = convfunc (SqlZonedTime (fromSql y))
convfunc (SqlByteString x) = cstrUtf8BString (cleanUpBSNulls x)
convfunc (SqlRational rat) = cstrUtf8BString (showRational rat)
convfunc x = cstrUtf8BString (fromSql x)
freefunc x =
if x == nullPtr
then return ()
else free x


{- | Helper that formats a 'Rational' using decimal. -}
showRational :: Rational -> B.ByteString
showRational rat = BCHAR8.pack $ showFixed True (fromRational rat :: Pico)


cleanUpBSNulls :: B.ByteString -> B.ByteString
cleanUpBSNulls bs | 0 `B.notElem` bs = bs
| otherwise = B.concatMap convfunc bs
Expand Down