Skip to content

Commit 20191fe

Browse files
committed
Make StatementMetadata::parse() handle isc_info_error that could be returned by pre-v6 server.
1 parent 22b126f commit 20191fe

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/common/StatementMetadata.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ static const unsigned INFO_BUFFER_SIZE = MemoryPool::MAX_MEDIUM_BLOCK_SIZE;
5656
static USHORT getLen(const UCHAR** ptr, const UCHAR* bufferEnd);
5757
static int getNumericInfo(const UCHAR** ptr, const UCHAR* bufferEnd);
5858
static void getStringInfo(const UCHAR** ptr, const UCHAR* bufferEnd, string* str);
59+
static ISC_STATUS getErrorInfo(const UCHAR** ptr, const UCHAR* bufferEnd, UCHAR* item = nullptr);
5960

6061

6162
// Build a list of info codes based on a prepare flags bitmask.
@@ -359,6 +360,14 @@ void StatementMetadata::parse(unsigned bufferLength, const UCHAR* buffer)
359360
finishDescribe = true;
360361
break;
361362

363+
case isc_info_error:
364+
{
365+
const ISC_STATUS errorCode = getErrorInfo(&buffer, bufferEnd);
366+
if (errorCode != isc_infunk)
367+
Arg::Gds(errorCode).raise();
368+
break;
369+
}
370+
362371
default:
363372
--buffer;
364373
finishDescribe = true;
@@ -409,6 +418,14 @@ void StatementMetadata::parse(unsigned bufferLength, const UCHAR* buffer)
409418
break;
410419
}
411420

421+
case isc_info_error:
422+
{
423+
const ISC_STATUS errorCode = getErrorInfo(&buffer, bufferEnd);
424+
if (errorCode != isc_infunk)
425+
Arg::Gds(errorCode).raise();
426+
break;
427+
}
428+
412429
default:
413430
finish = true;
414431
break;
@@ -528,5 +545,27 @@ static void getStringInfo(const UCHAR** ptr, const UCHAR* bufferEnd, string* str
528545
*ptr += len;
529546
}
530547

548+
// Get error code and, optional, info item that caused the error.
549+
static ISC_STATUS getErrorInfo(const UCHAR** ptr, const UCHAR* bufferEnd, UCHAR* item)
550+
{
551+
// Expected error code in the buffer encoded as follows:
552+
// (short) clumplet lenght, (byte) item code, (long) error code
553+
554+
const USHORT len = getLen(ptr, bufferEnd);
555+
556+
if (len != 1 + sizeof(ULONG))
557+
fatal_exception::raiseFmt("Invalid info structure - expected error info length %d, actual %d",
558+
1 + sizeof(ULONG), len);
559+
560+
if (item)
561+
*item = **ptr;
562+
563+
(*ptr)++;
564+
565+
const ISC_STATUS err = gds__vax_integer(*ptr, sizeof(ULONG));
566+
*ptr += sizeof(ULONG);
567+
568+
return err;
569+
}
531570

532571
} // namespace Firebird

0 commit comments

Comments
 (0)