1
0
Fork 0

Merge pull request #1192 from rqlite/chat-gpt-fixes

Some improvements thanks to ChatGPT 4
master
Philip O'Toole 2 years ago committed by GitHub
commit 366cb0cc53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -216,8 +216,8 @@ func (s *Service) checkCommandPerm(c *Command, perm string) bool {
func (s *Service) handleConn(conn net.Conn) { func (s *Service) handleConn(conn net.Conn) {
defer conn.Close() defer conn.Close()
b := make([]byte, protoBufferLengthSize)
for { for {
b := make([]byte, protoBufferLengthSize)
_, err := io.ReadFull(conn, b) _, err := io.ReadFull(conn, b)
if err != nil { if err != nil {
return return

@ -65,7 +65,7 @@ func NewRequestMarshaler() *RequestMarshaler {
// Marshal marshals a Requester object, returning a byte slice, a bool // Marshal marshals a Requester object, returning a byte slice, a bool
// indicating whether the contents are compressed, or an error. // indicating whether the contents are compressed, or an error.
func (m *RequestMarshaler) Marshal(r Requester) ([]byte, bool, error) { func (m *RequestMarshaler) Marshal(r Requester) ([]byte, bool, error) {
stats.Add(numRequests, 0) stats.Add(numRequests, 1)
compress := false compress := false
stmts := r.GetRequest().GetStatements() stmts := r.GetRequest().GetStatements()

@ -909,6 +909,11 @@ func normalizeRowValues(row []interface{}, types []string) ([]*command.Parameter
for i, v := range row { for i, v := range row {
switch val := v.(type) { switch val := v.(type) {
case int: case int:
values[i] = &command.Parameter{
Value: &command.Parameter_I{
I: int64(val)},
Name: "",
}
case int64: case int64:
values[i] = &command.Parameter{ values[i] = &command.Parameter{
Value: &command.Parameter_I{ Value: &command.Parameter_I{
@ -985,7 +990,7 @@ func randomString() string {
for i := 0; i < 20; i++ { for i := 0; i < 20; i++ {
random := rand.Intn(len(chars)) random := rand.Intn(len(chars))
randomChar := chars[random] randomChar := chars[random]
output.WriteString(string(randomChar)) output.WriteByte(randomChar)
} }
return output.String() return output.String()
} }

@ -25,7 +25,7 @@ var (
// ParseRequest generates a set of Statements for a given byte slice. // ParseRequest generates a set of Statements for a given byte slice.
func ParseRequest(b []byte) ([]*command.Statement, error) { func ParseRequest(b []byte) ([]*command.Statement, error) {
if b == nil { if len(b) == 0 {
return nil, ErrNoStatements return nil, ErrNoStatements
} }
@ -115,6 +115,12 @@ func makeParameter(name string, i interface{}) (*command.Parameter, error) {
switch v := i.(type) { switch v := i.(type) {
case int: case int:
return &command.Parameter{
Value: &command.Parameter_I{
I: int64(v),
},
Name: name,
}, nil
case int64: case int64:
return &command.Parameter{ return &command.Parameter{
Value: &command.Parameter_I{ Value: &command.Parameter_I{

Loading…
Cancel
Save