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 Peshkov
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef COMMON_MSG_METADATA_H
|
|
|
|
#define COMMON_MSG_METADATA_H
|
|
|
|
|
|
|
|
#include "firebird/Provider.h"
|
|
|
|
#include "iberror.h"
|
|
|
|
#include "../common/classes/fb_string.h"
|
|
|
|
#include "../common/classes/objects_array.h"
|
|
|
|
#include "../common/classes/ImplementHelper.h"
|
2013-03-27 02:34:10 +01:00
|
|
|
#include "../common/dsc.h"
|
2013-02-17 13:08:53 +01:00
|
|
|
|
|
|
|
namespace Firebird {
|
|
|
|
|
2014-05-20 10:05:16 +02:00
|
|
|
class MetadataBuilder;
|
|
|
|
class StatementMetadata;
|
|
|
|
class MetadataFromBlr;
|
|
|
|
|
2013-02-17 13:08:53 +01:00
|
|
|
class MsgMetadata : public RefCntIface<IMessageMetadata, FB_MESSAGE_METADATA_VERSION>
|
|
|
|
{
|
2014-05-20 10:05:16 +02:00
|
|
|
friend class MetadataBuilder;
|
|
|
|
friend class StatementMetadata;
|
|
|
|
friend class MetadataFromBlr;
|
|
|
|
|
2013-02-17 13:08:53 +01:00
|
|
|
public:
|
|
|
|
struct Item
|
|
|
|
{
|
|
|
|
explicit Item(MemoryPool& pool)
|
|
|
|
: field(pool),
|
|
|
|
relation(pool),
|
|
|
|
owner(pool),
|
|
|
|
alias(pool),
|
|
|
|
type(0),
|
|
|
|
subType(0),
|
|
|
|
length(0),
|
|
|
|
scale(0),
|
2013-06-18 17:50:48 +02:00
|
|
|
charSet(0),
|
2013-02-17 13:08:53 +01:00
|
|
|
offset(0),
|
|
|
|
nullInd(0),
|
|
|
|
nullable(false),
|
|
|
|
finished(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Item(MemoryPool& pool, const Item& v)
|
|
|
|
: field(pool, v.field),
|
|
|
|
relation(pool, v.relation),
|
|
|
|
owner(pool, v.owner),
|
|
|
|
alias(pool, v.alias),
|
|
|
|
type(v.type),
|
|
|
|
subType(v.subType),
|
|
|
|
length(v.length),
|
|
|
|
scale(v.scale),
|
2013-06-18 17:50:48 +02:00
|
|
|
charSet(v.charSet),
|
2013-02-17 13:08:53 +01:00
|
|
|
offset(v.offset),
|
|
|
|
nullInd(v.nullInd),
|
|
|
|
nullable(v.nullable),
|
|
|
|
finished(v.finished)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
string field;
|
|
|
|
string relation;
|
|
|
|
string owner;
|
|
|
|
string alias;
|
|
|
|
unsigned type;
|
Implemented CORE-4317: Make ISQL use new object API with 32-bit length for object sizes (messages, SQL statements, etc.)
Implementation also includes changes in GPRE, but this utility is not complete - only commands, used in ISQL,
are working in code generator for new API.
New interface IUtl is added - it performs tasks, related with database objects (attachment, transaction, etc.),
but not requiring routing in YValve, i.e. client only tasks.
2014-01-15 14:02:08 +01:00
|
|
|
int subType;
|
2013-02-17 13:08:53 +01:00
|
|
|
unsigned length;
|
2013-11-22 08:44:22 +01:00
|
|
|
int scale;
|
2013-06-18 17:50:48 +02:00
|
|
|
unsigned charSet;
|
2013-02-17 13:08:53 +01:00
|
|
|
unsigned offset;
|
|
|
|
unsigned nullInd;
|
|
|
|
bool nullable;
|
|
|
|
bool finished;
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
MsgMetadata()
|
|
|
|
: items(getPool()),
|
|
|
|
length(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-12-29 01:35:50 +01:00
|
|
|
explicit MsgMetadata(IMessageMetadata* from)
|
2013-07-19 15:51:54 +02:00
|
|
|
: items(getPool()),
|
|
|
|
length(0)
|
|
|
|
{
|
|
|
|
assign(from);
|
|
|
|
}
|
|
|
|
|
2014-05-20 10:05:16 +02:00
|
|
|
void setItemsCount(unsigned n)
|
|
|
|
{
|
|
|
|
items.resize(n);
|
|
|
|
length = 0;
|
|
|
|
}
|
|
|
|
|
2014-05-23 04:12:56 +02:00
|
|
|
Item& getItem(unsigned n)
|
2014-05-20 10:05:16 +02:00
|
|
|
{
|
|
|
|
fb_assert(n < items.getCount());
|
|
|
|
return items[n];
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getMessageLength()
|
|
|
|
{
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getCount()
|
|
|
|
{
|
|
|
|
return items.getCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset()
|
|
|
|
{
|
|
|
|
setItemsCount(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// IMessageMetadata implementation
|
2013-11-18 13:20:23 +01:00
|
|
|
virtual int FB_CARG release();
|
2013-02-17 13:08:53 +01:00
|
|
|
|
2014-03-12 10:32:10 +01:00
|
|
|
virtual unsigned FB_CARG getCount(IStatus* /*status*/)
|
2013-02-17 13:08:53 +01:00
|
|
|
{
|
|
|
|
return (unsigned) items.getCount();
|
|
|
|
}
|
|
|
|
|
2014-03-12 10:32:10 +01:00
|
|
|
virtual const char* FB_CARG getField(IStatus* status, unsigned index)
|
2013-02-17 13:08:53 +01:00
|
|
|
{
|
|
|
|
if (index < items.getCount())
|
|
|
|
return items[index].field.c_str();
|
|
|
|
|
|
|
|
raiseIndexError(status, index, "getField");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-03-12 10:32:10 +01:00
|
|
|
virtual const char* FB_CARG getRelation(IStatus* status, unsigned index)
|
2013-02-17 13:08:53 +01:00
|
|
|
{
|
|
|
|
if (index < items.getCount())
|
|
|
|
return items[index].relation.c_str();
|
|
|
|
|
|
|
|
raiseIndexError(status, index, "getRelation");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-03-12 10:32:10 +01:00
|
|
|
virtual const char* FB_CARG getOwner(IStatus* status, unsigned index)
|
2013-02-17 13:08:53 +01:00
|
|
|
{
|
|
|
|
if (index < items.getCount())
|
|
|
|
return items[index].owner.c_str();
|
|
|
|
|
|
|
|
raiseIndexError(status, index, "getOwner");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-03-12 10:32:10 +01:00
|
|
|
virtual const char* FB_CARG getAlias(IStatus* status, unsigned index)
|
2013-02-17 13:08:53 +01:00
|
|
|
{
|
|
|
|
if (index < items.getCount())
|
|
|
|
return items[index].alias.c_str();
|
|
|
|
|
|
|
|
raiseIndexError(status, index, "getAlias");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-03-12 10:32:10 +01:00
|
|
|
virtual unsigned FB_CARG getType(IStatus* status, unsigned index)
|
2013-02-17 13:08:53 +01:00
|
|
|
{
|
|
|
|
if (index < items.getCount())
|
|
|
|
return items[index].type;
|
|
|
|
|
|
|
|
raiseIndexError(status, index, "getType");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-12 10:32:10 +01:00
|
|
|
virtual FB_BOOLEAN FB_CARG isNullable(IStatus* status, unsigned index)
|
2013-02-17 13:08:53 +01:00
|
|
|
{
|
|
|
|
if (index < items.getCount())
|
|
|
|
return items[index].nullable;
|
|
|
|
|
|
|
|
raiseIndexError(status, index, "isNullable");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-12 10:32:10 +01:00
|
|
|
virtual int FB_CARG getSubType(IStatus* status, unsigned index)
|
2013-02-17 13:08:53 +01:00
|
|
|
{
|
|
|
|
if (index < items.getCount())
|
|
|
|
return items[index].subType;
|
|
|
|
|
|
|
|
raiseIndexError(status, index, "getSubType");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-12 10:32:10 +01:00
|
|
|
virtual unsigned FB_CARG getLength(IStatus* status, unsigned index)
|
2013-02-17 13:08:53 +01:00
|
|
|
{
|
|
|
|
if (index < items.getCount())
|
|
|
|
return items[index].length;
|
|
|
|
|
|
|
|
raiseIndexError(status, index, "getLength");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-12 10:32:10 +01:00
|
|
|
virtual int FB_CARG getScale(IStatus* status, unsigned index)
|
2013-02-17 13:08:53 +01:00
|
|
|
{
|
|
|
|
if (index < items.getCount())
|
|
|
|
return items[index].scale;
|
|
|
|
|
|
|
|
raiseIndexError(status, index, "getScale");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-12 10:32:10 +01:00
|
|
|
virtual unsigned FB_CARG getCharSet(IStatus* status, unsigned index)
|
2013-02-17 13:08:53 +01:00
|
|
|
{
|
|
|
|
if (index < items.getCount())
|
2013-06-18 17:50:48 +02:00
|
|
|
return items[index].charSet;
|
2013-02-17 13:08:53 +01:00
|
|
|
|
2013-06-18 17:50:48 +02:00
|
|
|
raiseIndexError(status, index, "getCharSet");
|
2013-02-17 13:08:53 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-12 10:32:10 +01:00
|
|
|
virtual unsigned FB_CARG getOffset(IStatus* status, unsigned index)
|
2013-02-17 13:08:53 +01:00
|
|
|
{
|
|
|
|
if (index < items.getCount())
|
|
|
|
return items[index].offset;
|
|
|
|
|
|
|
|
raiseIndexError(status, index, "getOffset");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-12 10:32:10 +01:00
|
|
|
virtual unsigned FB_CARG getNullOffset(IStatus* status, unsigned index)
|
2013-02-17 13:08:53 +01:00
|
|
|
{
|
|
|
|
if (index < items.getCount())
|
|
|
|
return items[index].nullInd;
|
|
|
|
|
|
|
|
raiseIndexError(status, index, "getOffset");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-12 10:32:10 +01:00
|
|
|
virtual IMetadataBuilder* FB_CARG getBuilder(IStatus* status);
|
2013-02-17 13:08:53 +01:00
|
|
|
|
2014-03-12 10:32:10 +01:00
|
|
|
virtual unsigned FB_CARG getMessageLength(IStatus* /*status*/)
|
2013-02-17 13:08:53 +01:00
|
|
|
{
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2013-03-27 02:34:10 +01:00
|
|
|
void addItem(const MetaName& name, bool nullable, const dsc& desc);
|
2013-02-21 15:59:24 +01:00
|
|
|
unsigned makeOffsets();
|
2013-02-17 13:08:53 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
void raiseIndexError(IStatus* status, unsigned index, const char* method) const
|
|
|
|
{
|
2014-08-27 11:24:30 +02:00
|
|
|
(Arg::Gds(isc_invalid_index_val) <<
|
|
|
|
Arg::Num(index) << (string("IMessageMetadata::") + method)).copyTo(status);
|
2013-02-17 13:08:53 +01:00
|
|
|
}
|
|
|
|
|
2013-07-19 15:51:54 +02:00
|
|
|
void assign(IMessageMetadata* from);
|
|
|
|
|
2014-05-20 10:05:16 +02:00
|
|
|
private:
|
2013-02-17 13:08:53 +01:00
|
|
|
ObjectsArray<Item> items;
|
|
|
|
unsigned length;
|
|
|
|
};
|
|
|
|
|
2013-07-19 15:51:54 +02:00
|
|
|
class AttMetadata : public MsgMetadata
|
|
|
|
{
|
|
|
|
public:
|
2014-06-10 09:13:34 +02:00
|
|
|
explicit AttMetadata(RefCounted* att)
|
2013-07-19 15:51:54 +02:00
|
|
|
: MsgMetadata(),
|
|
|
|
attachment(att)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
// re-implement here release() present in MsgMetadata to call correct dtor
|
2013-11-18 13:20:23 +01:00
|
|
|
virtual int FB_CARG release();
|
2013-07-19 15:51:54 +02:00
|
|
|
|
2014-06-10 09:13:34 +02:00
|
|
|
RefPtr<RefCounted> attachment;
|
2013-07-19 15:51:54 +02:00
|
|
|
};
|
2013-02-17 13:08:53 +01:00
|
|
|
|
2014-04-04 17:57:18 +02:00
|
|
|
class MetadataBuilder FB_FINAL : public RefCntIface<IMetadataBuilder, FB_METADATA_BUILDER_VERSION>
|
|
|
|
{
|
|
|
|
public:
|
2014-04-05 03:44:32 +02:00
|
|
|
explicit MetadataBuilder(const MsgMetadata* from);
|
2014-04-04 17:57:18 +02:00
|
|
|
MetadataBuilder(unsigned fieldCount);
|
|
|
|
|
|
|
|
virtual int FB_CARG release();
|
|
|
|
|
|
|
|
// IMetadataBuilder implementation
|
|
|
|
virtual void FB_CARG setType(IStatus* status, unsigned index, unsigned type);
|
|
|
|
virtual void FB_CARG setSubType(IStatus* status, unsigned index, int subType);
|
|
|
|
virtual void FB_CARG setLength(IStatus* status, unsigned index, unsigned length);
|
|
|
|
virtual void FB_CARG setCharSet(IStatus* status, unsigned index, unsigned charSet);
|
|
|
|
virtual void FB_CARG setScale(IStatus* status, unsigned index, unsigned scale);
|
|
|
|
virtual void FB_CARG truncate(IStatus* status, unsigned count);
|
|
|
|
virtual void FB_CARG remove(IStatus* status, unsigned index);
|
|
|
|
virtual void FB_CARG moveNameToIndex(IStatus* status, const char* name, unsigned index);
|
|
|
|
virtual unsigned FB_CARG addField(IStatus* status);
|
|
|
|
virtual IMessageMetadata* FB_CARG getMetadata(IStatus* status);
|
|
|
|
|
|
|
|
private:
|
|
|
|
RefPtr<MsgMetadata> msgMetadata;
|
|
|
|
Mutex mtx;
|
|
|
|
|
|
|
|
void metadataError(const char* functionName);
|
|
|
|
void indexError(unsigned index, const char* functionName);
|
|
|
|
};
|
|
|
|
|
2013-02-17 13:08:53 +01:00
|
|
|
} // namespace Firebird
|
|
|
|
|
|
|
|
#endif // COMMON_MSG_METADATA_H
|