Skip to content

Commit 4867085

Browse files
committed
revert the binary columns fix, closed as a duplicate of brianc#3496
1 parent 8357f83 commit 4867085

3 files changed

Lines changed: 3 additions & 56 deletions

File tree

‎packages/pg-protocol/src/inbound-parser.test.ts‎

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -577,24 +577,6 @@ describe('PgPacketStream', function () {
577577
})
578578
})
579579

580-
// the row description says which columns are binary, and their values are bytes rather than
581-
// text: decoding them as utf8 would lose every byte it cannot carry
582-
it('keeps the bytes of a binary column', async function () {
583-
const description = buffers.rowDescription([
584-
{ name: 'n', dataTypeID: 23, formatCode: 1 },
585-
{ name: 't', dataTypeID: 25, formatCode: 0 },
586-
])
587-
const row = new BufferList()
588-
.addInt16(2)
589-
.addInt32(4)
590-
.add(Buffer.from([0, 0, 0x03, 0xe8]))
591-
.addInt32(2)
592-
.add(Buffer.from('é', 'utf8'))
593-
.join(true, 'D')
594-
const messages = await parseBuffers([description, row])
595-
assert.deepStrictEqual((messages[1] as any).fields, [Buffer.from([0, 0, 0x03, 0xe8]), 'é'])
596-
})
597-
598580
// the parser moves what is left of a chunk to the front of its buffer before reading the next
599581
// one, so a message that kept a view into that buffer would change after being delivered
600582
it('keeps a copyData chunk intact after the parser reuses its buffer', async function () {

‎packages/pg-protocol/src/parser.ts‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,6 @@ export class Parser {
8383
private bufferOffset: number = 0
8484
private reader = new BufferReader()
8585
private mode: Mode
86-
// which columns of the rows to come are in the binary format, from the last row description:
87-
// a binary value is bytes, and decoding it as text would lose every byte utf8 cannot carry
88-
private binaryColumns: boolean[] | null = null
8986

9087
constructor(opts?: StreamOptions) {
9188
if (opts?.mode === 'binary') {
@@ -191,7 +188,7 @@ export class Parser {
191188
message = emptyQuery
192189
break
193190
case MessageCodes.DataRow:
194-
message = parseDataRowMessage(reader, this.binaryColumns)
191+
message = parseDataRowMessage(reader)
195192
break
196193
case MessageCodes.CommandComplete:
197194
message = parseCommandCompleteMessage(reader)
@@ -219,7 +216,6 @@ export class Parser {
219216
break
220217
case MessageCodes.RowDescriptionMessage:
221218
message = parseRowDescriptionMessage(reader)
222-
this.binaryColumns = binaryColumnsOf(message as RowDescriptionMessage)
223219
break
224220
case MessageCodes.ParameterDescriptionMessage:
225221
message = parseParameterDescriptionMessage(reader)
@@ -280,12 +276,6 @@ const parseNotificationMessage = (reader: BufferReader) => {
280276
return new NotificationResponseMessage(LATEINIT_LENGTH, processId, channel, payload)
281277
}
282278

283-
// null when every column is text, which is nearly always, so the row parser has one check to make
284-
const binaryColumnsOf = (message: RowDescriptionMessage): boolean[] | null => {
285-
const formats = message.fields.map((field) => field.format === 'binary')
286-
return formats.includes(true) ? formats : null
287-
}
288-
289279
const parseRowDescriptionMessage = (reader: BufferReader) => {
290280
const fieldCount = reader.int16()
291281
const message = new RowDescriptionMessage(LATEINIT_LENGTH, fieldCount)
@@ -316,13 +306,13 @@ const parseParameterDescriptionMessage = (reader: BufferReader) => {
316306
return message
317307
}
318308

319-
const parseDataRowMessage = (reader: BufferReader, binaryColumns: boolean[] | null) => {
309+
const parseDataRowMessage = (reader: BufferReader) => {
320310
const fieldCount = reader.int16()
321311
const fields: any[] = new Array(fieldCount)
322312
for (let i = 0; i < fieldCount; i++) {
323313
const len = reader.int32()
324314
// a -1 for length means the value of the field is null
325-
fields[i] = len === -1 ? null : binaryColumns && binaryColumns[i] ? reader.bytes(len) : reader.string(len)
315+
fields[i] = len === -1 ? null : reader.string(len)
326316
}
327317
return new DataRowMessage(LATEINIT_LENGTH, fields)
328318
}

‎packages/pg/test/integration/client/binary-results-tests.js‎

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)