@@ -11,21 +11,20 @@ import qualified Data.ByteString as B
11
11
12
12
import Database.PostgreSQL.Protocol.Types
13
13
14
- -- | Protocol Version 3.0, major version in the first word16
14
+ -- | Protocol Version 3.0, major version in the first word16.
15
15
currentVersion :: Int32
16
16
currentVersion = 3 * 256 * 256
17
17
18
18
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
22
21
where
23
22
len = fromIntegral $ BL. length $ toLazyByteString payload
24
23
payload = int32BE currentVersion <>
25
24
pgString " user" <> pgString uname <>
26
25
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.
29
28
30
29
encodeClientMessage :: ClientMessage -> Builder
31
30
encodeClientMessage (Bind (PortalName portalName) (StatementName stmtName)
@@ -53,12 +52,10 @@ encodeClientMessage (DescribeStatement (StatementName stmtName))
53
52
= prependHeader ' D' $ char8 ' S' <> pgString stmtName
54
53
encodeClientMess
8000
age (DescribePortal (PortalName portalName))
55
54
= prependHeader ' D' $ char8 ' P' <> pgString portalName
56
- encodeClientMessage (Execute (PortalName portalName))
55
+ encodeClientMessage (Execute (PortalName portalName) ( RowsToReceive rows) )
57
56
= prependHeader ' E' $
58
57
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
62
59
encodeClientMessage Flush
63
60
= prependHeader ' H' mempty
64
61
encodeClientMessage (Parse (StatementName stmtName) (StatementSQL stmt) oids)
@@ -67,8 +64,11 @@ encodeClientMessage (Parse (StatementName stmtName) (StatementSQL stmt) oids)
67
64
pgString stmt <>
68
65
int16BE (fromIntegral $ V. length oids) <>
69
66
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
72
72
encodeClientMessage (SimpleQuery (StatementSQL stmt))
73
73
= prependHeader ' Q' $ pgString stmt
74
74
encodeClientMessage Sync
0 commit comments