Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
zachmu committed Nov 21, 2023
1 parent 766c1d1 commit 2c2fbe8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
16 changes: 8 additions & 8 deletions postgres/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ func Receive(conn net.Conn) (Message, error) {
if n < headerSize {
return nil, errors.New("received message header is too short")
}

// TODO: there is one non-startup frontend message that doesn't have a header byte, which is the CancelRequest.
// We need to figure out how to handle it here.
// We need to figure out how to handle it here.
message, ok := allMessageHeaders[header[0]]
if !ok {
return nil, fmt.Errorf("received message header is not recognized: %v", header[0])
}

messageLen := int(binary.BigEndian.Uint32(header[1:])) - 4

var msgBuffer []byte
if messageLen > 0 {
read := 0
Expand All @@ -88,20 +88,20 @@ func Receive(conn net.Conn) (Message, error) {
if err != nil {
return nil, err
}

n, err = conn.Read(msgBuffer[headerSize+read:])
if err != nil {
return nil, err
}

read += n
}

copy(msgBuffer[:headerSize], header)
} else {
msgBuffer = header
msgBuffer = header
}

db := newDecodeBuffer(msgBuffer)
return receiveFromBuffer(db, message)
}
Expand Down
6 changes: 3 additions & 3 deletions postgres/connection/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestReceive(t *testing.T) {
require.NoError(t, err)

wg.Wait()

receivedQuery, ok := receivedMessage.(messages.Query)
require.True(t, ok, "Received message is not a Query type")

Expand Down Expand Up @@ -126,7 +126,7 @@ func TestReceive(t *testing.T) {
require.True(t, ok, "Received message is not a Query type")
assert.Equal(t, message.String, receivedQuery.String)
}

assert.Equal(t, len(queries), messageCount)
})

Expand Down Expand Up @@ -156,4 +156,4 @@ func getLocalHostConnection(t *testing.T) (net.Conn, net.Conn) {

wg.Wait()
return serverConn, clientConn
}
}
6 changes: 3 additions & 3 deletions postgres/connection/message_initialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func InitializeDefaultMessage(message Message) {

allFieldNames := make(map[string]struct{}) // Verify that all field names are unique
headerFound := false // Only one header may exist in the message
lastWasHeader := false // We enforce that messages with headers always have a length field next
lastWasHeader := false // We enforce that messages with headers always have a length field next
messageLengthFound := false // Only one message length may exist in the message
endingByteNFound := false // If a ByteN has been found that does not have a preceding ByteCount
repeatedFoundHeight := 0 // The depth that a Repeated type has been found
Expand Down Expand Up @@ -111,7 +111,7 @@ func InitializeDefaultMessage(message Message) {
headerFound = true
lastWasHeader = true
}

if field.Flags&(MessageLengthInclusive|MessageLengthExclusive) != 0 {
if messageLengthFound {
panic(fmt.Errorf("Multiple message lengths in message.\nMessageFormat:\n\n%s", messageFormat.String()))
Expand Down Expand Up @@ -223,7 +223,7 @@ func InitializeDefaultMessage(message Message) {
ftStack.Push(FieldTraversal{0, field.Children[0]})
}
}

if lastWasHeader {
panic(fmt.Errorf("Header was not followed by a message length.\nMessageFormat:\n\n%s", messageFormat.String()))
}
Expand Down
2 changes: 1 addition & 1 deletion server/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ func (l *Listener) handledPSQLCommands(conn net.Conn, mysqlConn *mysql.Conn, sta
}
// Command: \l on psql 16
if statement == "select\n d.datname as \"name\",\n pg_catalog.pg_get_userbyid(d.datdba) as \"owner\",\n pg_catalog.pg_encoding_to_char(d.encoding) as \"encoding\",\n case d.datlocprovider when 'c' then 'libc' when 'i' then 'icu' end as \"locale provider\",\n d.datcollate as \"collate\",\n d.datctype as \"ctype\",\n d.daticulocale as \"icu locale\",\n null as \"icu rules\",\n pg_catalog.array_to_string(d.datacl, e'\\n') as \"access privileges\"\nfrom pg_catalog.pg_database d\norder by 1;" {
return true, l.execute(conn, mysqlConn, ConvertedQuery{`SELECT SCHEMA_NAME AS 'Name', 'postgres' AS 'Owner', 'UTF8' AS 'Encoding', 'English_United States.1252' AS 'Collate', 'English_United States.1252' AS 'Ctype', '' AS 'ICU Locale', 'libc' AS 'Locale Provider', '' AS 'Access privileges' FROM INFORMATION_SCHEMA.SCHEMATA ORDER BY 1;`, nil})
return true, l.execute(conn, mysqlConn, ConvertedQuery{`SELECT SCHEMA_NAME AS 'Name', 'postgres' AS 'Owner', 'UTF8' AS 'Encoding', 'English_United States.1252' AS 'Collate', 'English_United States.1252' AS 'Ctype', '' AS 'ICU Locale', 'libc' AS 'Locale Provider', '' AS 'Access privileges' FROM INFORMATION_SCHEMA.SCHEMATA ORDER BY 1;`, nil})
}
// Command: \dt
if statement == "select n.nspname as \"schema\",\n c.relname as \"name\",\n case c.relkind when 'r' then 'table' when 'v' then 'view' when 'm' then 'materialized view' when 'i' then 'index' when 's' then 'sequence' when 't' then 'toast table' when 'f' then 'foreign table' when 'p' then 'partitioned table' when 'i' then 'partitioned index' end as \"type\",\n pg_catalog.pg_get_userbyid(c.relowner) as \"owner\"\nfrom pg_catalog.pg_class c\n left join pg_catalog.pg_namespace n on n.oid = c.relnamespace\n left join pg_catalog.pg_am am on am.oid = c.relam\nwhere c.relkind in ('r','p','')\n and n.nspname <> 'pg_catalog'\n and n.nspname !~ '^pg_toast'\n and n.nspname <> 'information_schema'\n and pg_catalog.pg_table_is_visible(c.oid)\norder by 1,2;" {
Expand Down

0 comments on commit 2c2fbe8

Please sign in to comment.