Esempio n. 1
0
string valueToString(IAttachment* attachment, ITransaction* transaction,
	MessageImpl& message, Offset<void*>& field)
{
	if (message.isNull(field))
		return "";

	void* p = message[field];

	switch (field.getType())
	{
		//// TODO: scale for SQL_SHORT, SQL_LONG and SQL_INT64

		case SQL_SHORT:
			return lexical_cast<string>(*static_cast<ISC_SHORT*>(p));

		case SQL_LONG:
			return lexical_cast<string>(*static_cast<ISC_LONG*>(p));

		case SQL_INT64:
			return lexical_cast<string>(*static_cast<ISC_INT64*>(p));

		case SQL_FLOAT:
			return lexical_cast<string>(*static_cast<float*>(p));

		case SQL_DOUBLE:
			return lexical_cast<string>(*static_cast<double*>(p));

		case SQL_BLOB:
		{
			IStatus* status = master->getStatus();

			IBlob* blob = attachment->openBlob(status, transaction,
				static_cast<ISC_QUAD*>(p), 0, NULL);
			BOOST_VERIFY(status->isSuccess());

			string str;
			char blobBuffer[1024];
			unsigned blobLen;

			while ((blobLen = blob->getSegment(status, sizeof(blobBuffer), blobBuffer)) != 0)
				str.append(blobBuffer, blobLen);

			blob->close(status);
			BOOST_VERIFY(status->isSuccess());

			status->dispose();

			return str;
		}

		case SQL_TEXT:
		case SQL_VARYING:
			return string(static_cast<char*>(p) + sizeof(ISC_USHORT),
				*static_cast<ISC_USHORT*>(p));

		default:
			BOOST_VERIFY(false);
			return "";
	}
}
Esempio n. 2
0
void getEngineVersion(Firebird::IAttachment* attachment, unsigned* major, unsigned* minor,
	unsigned* revision)
{
	static const UCHAR ITEMS[] = {isc_info_firebird_version};
	UCHAR buffer[512];
	IStatus* status = master->getStatus();

	attachment->getInfo(status, sizeof(ITEMS), ITEMS, sizeof(buffer), buffer);
	BOOST_VERIFY(status->isSuccess());

	if (buffer[0] == isc_info_firebird_version)
	{
		const UCHAR* p = buffer + 5;

		if (major)
			*major = p[4] - '0';

		if (minor)
			*minor = p[6] - '0';

		if (revision)
			*revision = p[8] - '0';
	}
	else
	{
		if (major)
			*major = 0;

		if (minor)
			*minor = 0;

		if (revision)
			*revision = 0;
	}

	status->dispose();
}