-
Notifications
You must be signed in to change notification settings - Fork 29
Add connectdbParams
and other connection key-value functions
#67
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
bens
wants to merge
1
commit into
haskellari:master
Choose a base branch
from
bens:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE RecordWildCards #-} | ||
|
||
module Database.PostgreSQL.LibPQ.Connect where | ||
|
||
#include "hs-libpq.h" | ||
|
||
import Foreign (Storable (..), nullPtr) | ||
import Foreign.C (CInt) | ||
|
||
import qualified Data.ByteString as B | ||
|
||
------------------------------------------------------------------------------- | ||
-- ConninfoOption | ||
------------------------------------------------------------------------------- | ||
|
||
-- typedef struct | ||
-- { | ||
-- char *keyword; /* The keyword of the option */ | ||
-- char *envvar; /* Fallback environment variable name */ | ||
-- char *compiled; /* Fallback compiled in default value */ | ||
-- char *val; /* Option's current value, or NULL */ | ||
-- char *label; /* Label for field in connect dialog */ | ||
-- char *dispchar; /* Indicates how to display this field | ||
-- in a connect dialog. Values are: | ||
-- "" Display entered value as is | ||
-- "*" Password field - hide value | ||
-- "D" Debug option - don't show by default */ | ||
-- int dispsize; /* Field size in characters for dialog */ | ||
-- } PQconninfoOption; | ||
data ConninfoOption = ConninfoOption { | ||
conninfoKeyword :: B.ByteString -- ^ The keyword of the option | ||
, conninfoEnvVar :: Maybe B.ByteString -- ^ Fallback environment variable name | ||
, conninfoCompiled :: Maybe B.ByteString -- ^ Fallback compiled in default value | ||
, conninfoValue :: Maybe B.ByteString -- ^ Option's current value, or NULL | ||
, conninfoLabel :: B.ByteString -- ^ Label for field in connect dialog | ||
-- | Indicates how to display this field in a connect dialog. Values are: | ||
-- "" Display entered value as is | ||
-- "*" Password field - hide value | ||
-- "D" Debug option - don't show by default | ||
, conninfoDispChar :: B.ByteString | ||
, conninfoDispSize :: CInt -- ^ Field size in characters for dialog | ||
} | ||
deriving Show | ||
|
||
instance Storable ConninfoOption where | ||
sizeOf _ = #{size PQconninfoOption} | ||
|
||
alignment _ = #{alignment PQconninfoOption} | ||
|
||
peek ptr = do | ||
conninfoKeyword <- B.packCString =<< #{peek PQconninfoOption, keyword} ptr | ||
conninfoEnvVar <- do | ||
p <- #{peek PQconninfoOption, envvar} ptr | ||
if p == nullPtr then pure Nothing else Just <$> B.packCString p | ||
conninfoCompiled <- do | ||
p <- #{peek PQconninfoOption, compiled} ptr | ||
if p == nullPtr then pure Nothing else Just <$> B.packCString p | ||
conninfoValue <- do | ||
p <- #{peek PQconninfoOption, val} ptr | ||
if p == nullPtr then pure Nothing else Just <$> B.packCString p | ||
conninfoLabel <- B.packCString =<< #{peek PQconninfoOption, label} ptr | ||
conninfoDispChar <- B.packCString =<< #{peek PQconninfoOption, dispchar} ptr | ||
conninfoDispSize <- #{peek PQconninfoOption, dispsize} ptr | ||
return $! ConninfoOption{..} | ||
|
||
poke ptr ConninfoOption{..} = do | ||
B.useAsCString conninfoKeyword $ \keyword -> | ||
maybe ($ nullPtr) B.useAsCString conninfoEnvVar $ \envvar -> | ||
maybe ($ nullPtr) B.useAsCString conninfoCompiled $ \compiled -> | ||
maybe ($ nullPtr) B.useAsCString conninfoValue $ \value -> | ||
B.useAsCString conninfoLabel $ \label -> | ||
B.useAsCString conninfoDispChar $ \dispchar -> do | ||
#{poke PQconninfoOption, keyword} ptr keyword | ||
#{poke PQconninfoOption, envvar} ptr envvar | ||
#{poke PQconninfoOption, compiled} ptr compiled | ||
#{poke PQconninfoOption, val} ptr value | ||
#{poke PQconninfoOption, label} ptr label | ||
#{poke PQconninfoOption, dispchar} ptr dispchar | ||
#{poke PQconninfoOption, dispsize} ptr conninfoDispSize | ||
|
||
------------------------------------------------------------------------------- | ||
-- PQconninfoOption | ||
------------------------------------------------------------------------------- | ||
|
||
data PQconninfoOption | ||
|
||
pqConninfoOptionKeyword :: Int | ||
pqConninfoOptionKeyword = #{offset PQconninfoOption, keyword} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why
mask_
. That looks suspicious. But it seems existing stuff is usingmask
as well, but only when creating something in C-land and wrapping it ForeignPtr. i.e. to avoid memory leaks.I think here
bracket
is sufficient. No need to explicitlymask
.