writeErrorResponse sends an error to the client
(w io.Writer, severity, code, message string)
| 244 | } |
| 245 | |
| 246 | // writeBackendKeyData sends the backend key data (for cancel requests) |
| 247 | func WriteBackendKeyData(w io.Writer, pid, secretKey int32) error { |
| 248 | data := make([]byte, 8) |
| 249 | binary.BigEndian.PutUint32(data[:4], uint32(pid)) |
| 250 | binary.BigEndian.PutUint32(data[4:], uint32(secretKey)) |
| 251 | return WriteMessage(w, MsgBackendKeyData, data) |
| 252 | } |
| 253 | |
| 254 | // writeReadyForQuery indicates the server is ready for a new query |
| 255 | func WriteReadyForQuery(w io.Writer, txStatus byte) error { |
| 256 | return WriteMessage(w, MsgReadyForQuery, []byte{txStatus}) |
| 257 | } |
| 258 | |
| 259 | // writeErrorResponse sends an error to the client |
| 260 | func WriteErrorResponse(w io.Writer, severity, code, message string) error { |
| 261 | message = RedactSecrets(message) |
| 262 | |
| 263 | var data []byte |
| 264 | |
| 265 | // Severity |
| 266 | data = append(data, 'S') |
| 267 | data = append(data, []byte(severity)...) |
| 268 | data = append(data, 0) |
| 269 | |
| 270 | // SQLSTATE code |
| 271 | data = append(data, 'C') |
| 272 | data = append(data, []byte(code)...) |
| 273 | data = append(data, 0) |