Skip to content

Commit da19ba1

Browse files
committed
fix(pg-protocol): specify number of result column format codes
Fixes a bug when binary format. We must specify both: - the number of result column format codes - the result column format codes The text format case was working by accident. When using text format, the intention was to set the format code to 0. Instead, we set the number of result column format codes was set to 0. This is valid because it indicates that all result columns should use the default format (text). When using binary format, the intention was to set the format code to 1. Instead, we set the number of result column format codes to 1. Importantly, we never set a result column format code. This caused an error: 'insufficient data left in message'. We now always set the number of result column format codes to '1'. The value of '1' has special meaning: > or one, in which case the specified format code is applied to all result columns (if any) We then set a single column format code based on whether the connection (or query) is set to binary. Fixes #3487
1 parent cd877a5 commit da19ba1

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

packages/pg-protocol/src/outbound-serializer.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ describe('serializer', () => {
9696
.addCString('')
9797
.addInt16(0)
9898
.addInt16(0)
99+
.addInt16(1)
99100
.addInt16(0)
100101
.join(true, 'B')
101102
assert.deepEqual(actual, expectedBuffer)
@@ -123,6 +124,7 @@ describe('serializer', () => {
123124
.addInt32(-1)
124125
.addInt32(4)
125126
.add(Buffer.from('zing'))
127+
.addInt16(1)
126128
.addInt16(0)
127129
.join(true, 'B')
128130
assert.deepEqual(actual, expectedBuffer)
@@ -149,6 +151,7 @@ describe('serializer', () => {
149151
.addInt32(-1)
150152
.addInt32(-1)
151153
.addInt32(-1)
154+
.addInt16(1)
152155
.addInt16(0)
153156
.join(true, 'B')
154157
assert.deepEqual(actual, expectedBuffer)
@@ -176,6 +179,7 @@ describe('serializer', () => {
176179
.addInt32(-1)
177180
.addInt32(4)
178181
.add(Buffer.from('zing', 'utf-8'))
182+
.addInt16(1)
179183
.addInt16(0)
180184
.join(true, 'B')
181185
assert.deepEqual(actual, expectedBuffer)

packages/pg-protocol/src/serializer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ const bind = (config: BindOpts = {}): Buffer => {
157157
writer.addInt16(len)
158158
writer.add(paramWriter.flush())
159159

160+
// all results use the same format code
161+
writer.addInt16(1)
160162
// format code
161163
writer.addInt16(binary ? ParamType.BINARY : ParamType.STRING)
162164
return writer.flush(code.bind)

0 commit comments

Comments
 (0)