2013-02-17 13:08:53 +01:00
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Initial
|
|
|
|
* Developer's Public License Version 1.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
* http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed AS IS,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing rights
|
|
|
|
* and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code was created by Adriano dos Santos Fernandes
|
|
|
|
* for the Firebird Open Source RDBMS project.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2011 Adriano dos Santos Fernandes <adrianosf at gmail.com>
|
|
|
|
* and all contributors signed below.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
* Contributor(s): ______________________________________.
|
|
|
|
* Alex Peshkoff
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "firebird.h"
|
|
|
|
#include "../common/MsgMetadata.h"
|
|
|
|
#include "../common/utils_proto.h"
|
|
|
|
|
|
|
|
using namespace Firebird;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2013-02-20 20:41:01 +01:00
|
|
|
class MetadataBuilder : public RefCntIface<IMetadataBuilder, FB_METADATA_BUILDER_VERSION>
|
2013-02-17 13:08:53 +01:00
|
|
|
{
|
|
|
|
public:
|
2013-02-20 20:41:01 +01:00
|
|
|
MetadataBuilder(const MsgMetadata* from)
|
2013-02-17 13:08:53 +01:00
|
|
|
: msgMetadata(new MsgMetadata)
|
|
|
|
{
|
|
|
|
msgMetadata->items = from->items;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int FB_CARG release()
|
|
|
|
{
|
|
|
|
if (--refCounter != 0)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete this;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-02-20 20:41:01 +01:00
|
|
|
// IMetadataBuilder implementation
|
2013-02-17 13:08:53 +01:00
|
|
|
virtual void FB_CARG setType(IStatus* status, unsigned index, unsigned type)
|
|
|
|
{
|
|
|
|
MutexLockGuard g(mtx, FB_FUNCTION);
|
|
|
|
|
|
|
|
if (!indexError(status, index, "setType"))
|
|
|
|
msgMetadata->items[index].type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void FB_CARG setSubType(IStatus* status, unsigned index, unsigned subType)
|
|
|
|
{
|
|
|
|
MutexLockGuard g(mtx, FB_FUNCTION);
|
|
|
|
|
|
|
|
if (!indexError(status, index, "setSubType"))
|
|
|
|
msgMetadata->items[index].subType = subType;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void FB_CARG setLength(IStatus* status, unsigned index, unsigned length)
|
|
|
|
{
|
|
|
|
MutexLockGuard g(mtx, FB_FUNCTION);
|
|
|
|
|
|
|
|
if (!indexError(status, index, "setLength"))
|
|
|
|
msgMetadata->items[index].length = length;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void FB_CARG setScale(IStatus* status, unsigned index, unsigned scale)
|
|
|
|
{
|
|
|
|
MutexLockGuard g(mtx, FB_FUNCTION);
|
|
|
|
|
|
|
|
if (!indexError(status, index, "setScale"))
|
|
|
|
msgMetadata->items[index].scale = scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual IMessageMetadata* FB_CARG getMetadata(IStatus* status)
|
|
|
|
{
|
|
|
|
MutexLockGuard g(mtx, FB_FUNCTION);
|
|
|
|
|
2013-02-18 12:06:52 +01:00
|
|
|
if (metadataError(status, "getMetadata"))
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-02-17 13:08:53 +01:00
|
|
|
msgMetadata->makeOffsets();
|
|
|
|
IMessageMetadata* rc = msgMetadata;
|
|
|
|
rc->addRef();
|
|
|
|
msgMetadata = NULL;
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
RefPtr<MsgMetadata> msgMetadata;
|
|
|
|
Mutex mtx;
|
|
|
|
|
2013-02-18 12:06:52 +01:00
|
|
|
bool metadataError(IStatus* status, const char* functionName)
|
2013-02-17 13:08:53 +01:00
|
|
|
{
|
|
|
|
if (!msgMetadata)
|
|
|
|
{
|
|
|
|
status->set((Arg::Gds(isc_random) <<
|
2013-02-20 20:41:01 +01:00
|
|
|
(string("MetadataBuilder interface is already inactive: IMetadataBuilder::") + functionName)).value());
|
2013-02-17 13:08:53 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-18 12:06:52 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool indexError(IStatus* status, unsigned index, const char* functionName)
|
|
|
|
{
|
|
|
|
if (metadataError(status, functionName))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index >= msgMetadata->items.getCount())
|
2013-02-17 13:08:53 +01:00
|
|
|
{
|
|
|
|
status->set((Arg::Gds(isc_invalid_index_val) <<
|
2013-02-20 20:41:01 +01:00
|
|
|
Arg::Num(index) << (string("IMetadataBuilder::") + functionName)).value());
|
2013-02-17 13:08:53 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace anonymous
|
|
|
|
|
|
|
|
|
|
|
|
namespace Firebird {
|
|
|
|
|
|
|
|
|
|
|
|
void MsgMetadata::makeOffsets()
|
|
|
|
{
|
|
|
|
length = 0;
|
|
|
|
|
|
|
|
for (unsigned n = 0; n < items.getCount(); ++n)
|
|
|
|
{
|
|
|
|
Item* param = &items[n];
|
|
|
|
if (!param->finished)
|
|
|
|
{
|
|
|
|
length = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
length = fb_utils::sqlTypeToDsc(length, param->type, param->length,
|
|
|
|
NULL /*dtype*/, NULL /*length*/, ¶m->offset, ¶m->nullInd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-20 20:41:01 +01:00
|
|
|
IMetadataBuilder* MsgMetadata::getBuilder(IStatus* status) const
|
2013-02-17 13:08:53 +01:00
|
|
|
{
|
2013-02-20 20:41:01 +01:00
|
|
|
IMetadataBuilder* rc = new MetadataBuilder(this);
|
2013-02-17 13:08:53 +01:00
|
|
|
rc->addRef();
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace Firebird
|