8000 Fixed encoders · postgres-haskell/postgres-wire@4e2e57b · GitHub
[go: up one dir, main page]

Skip to content

Commit 4e2e57b

Browse files
Fixed encoders
1 parent bdf2751 commit 4e2e57b

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

src/Database/PostgreSQL/Protocol/Encoders.hs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,20 @@ import qualified Data.ByteString as B
1111

1212
import Database.PostgreSQL.Protocol.Types
1313

14-
-- | Protocol Version 3.0, major version in the first word16
14+
-- | Protocol Version 3.0, major version in the first word16.
1515
currentVersion :: Int32
1616
currentVersion = 3 * 256 * 256
1717

1818
encodeStartMessage :: StartMessage -> Builder
19-
-- Options except user and database are not supported
20-
encodeStartMessage (StartupMessage (Username uname) (DatabaseName dbname)) =
21-
int32BE (len + 4) <> payload
19+
encodeStartMessage (StartupMessage (Username uname) (DatabaseName dbname))
20+
= int32BE (len + 4) <> payload
2221
where
2322
len = fromIntegral $ BL.length $ toLazyByteString payload
2423
payload = int32BE currentVersion <>
2524
pgString "user" <> pgString uname <>
2625
pgString "database" <> pgString dbname <> word8 0
27-
-- TODO
28-
encodeStartMessage SSLRequest = undefined
26+
encodeStartMessage SSLRequest
27+
= int32BE 8 <> int32BE 80877103 -- value hardcoded by PostgreSQL docs.
2928

3029
encodeClientMessage :: ClientMessage -> Builder
3130
encodeClientMessage (Bind (PortalName portalName) (StatementName stmtName)
@@ -53,12 +52,10 @@ encodeClientMessage (DescribeStatement (StatementName stmtName))
5352
= prependHeader 'D' $ char8 'S' <> pgString stmtName
5453
encodeClientMess 8000 age (DescribePortal (PortalName portalName))
5554
= prependHeader 'D' $ char8 'P' <> pgString portalName
56-
encodeClientMessage (Execute (PortalName portalName))
55+
encodeClientMessage (Execute (PortalName portalName) (RowsToReceive rows))
5756
= prependHeader 'E' $
5857
pgString portalName <>
59-
--Maximum number of rows to return, if portal contains a query that
60-
--returns rows (ignored otherwise). Zero denotes "no limit".
61-
int32BE 0
58+
int32BE rows
6259
encodeClientMessage Flush
6360
= prependHeader 'H' mempty
6461
encodeClientMessage (Parse (StatementName stmtName) (StatementSQL stmt) oids)
@@ -67,8 +64,11 @@ encodeClientMessage (Parse (StatementName stmtName) (StatementSQL stmt) oids)
6764
pgString stmt <>
6865
int16BE (fromIntegral $ V.length oids) <>
6966
fold (int32BE . unOid <$> oids)
70-
encodeClientMessage (PasswordMessage (PasswordText passText))
71-
= prependHeader 'p' $ pgString passText
67+
encodeClientMessage (PasswordMessage passtext)
68+
= prependHeader 'p' $ pgString $ getPassword passtext
69+
where
70+
getPassword (PasswordPlain p) = p
71+
getPassword (PasswordMD5 p) = p
7272
encodeClientMessage (SimpleQuery (StatementSQL stmt))
7373
= prependHeader 'Q' $ pgString stmt
7474
encodeClientMessage Sync

src/Database/PostgreSQL/Protocol/Types.hs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ newtype ServerProcessId = ServerProcessId Int32 deriving (Show)
2727
newtype ServerSecretKey = ServerSecretKey Int32 deriving (Show)
2828

2929
newtype RowsCount = RowsCount Word deriving (Show)
30+
31+
-- | Maximum number of rows to return, if portal contains a query that
32+
-- returns rows (ignored otherwise). Zero denotes "no limit".
3033
newtype RowsToReceive = RowsToReceive Int32 deriving (Show)
3134

3235
-- | Information about completed command.
@@ -73,6 +76,11 @@ data Format = Text | Binary
7376

7477
-- All the commands have the same names as presented in the official
7578
-- postgres documentation except explicit exclusions.
79+
--
80+
data StartMessage
81+
= StartupMessage Username DatabaseName
82+
| SSLRequest
83+
deriving (Show)
7684

7785
data AuthResponse
7886
= AuthenticationOk
@@ -109,11 +117,6 @@ data ClientMessage
109117
data CancelRequest = CancelRequest ServerProcessId ServerSecretKey
110118
deriving (Show)
111119

112-
data StartMessage
113-
= StartupMessage Username DatabaseName
114-
| SSLRequest
115-
deriving (Show)
116-
117120
data ServerMessage
118121
= BackendKeyData ServerProcessId ServerSecretKey
119122
| BindComplete

0 commit comments

Comments
 (0)
0