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
|
|
|
|
|
2014-09-29 13:03:47 +02:00
|
|
|
#include "firebird/Interface.h"
|
2013-02-17 13:08:53 +01:00
|
|
|
#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;
|
|
|
|
|
2015-01-12 01:21:38 +01:00
|
|
|
class MsgMetadata : public RefCntIface<IMessageMetadataImpl<MsgMetadata, CheckStatusWrapper> >
|
2013-02-17 13:08:53 +01:00
|
|
|
{
|
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
|
2014-09-29 13:03:47 +02:00
|
|
|
int release();
|
2013-02-17 13:08:53 +01:00
|
|
|
|
2015-01-12 01:21:38 +01:00
|
|
|
unsigned getCount(CheckStatusWrapper* /*status*/)
|
2013-02-17 13:08:53 +01:00
|
|
|
{
|
|
|
|
return (unsigned) items.getCount();
|
|
|
|
}
|
|
|
|
|
2015-01-12 01:21:38 +01:00
|
|
|
const char* getField(CheckStatusWrapper* 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;
|
|
|
|
}
|
|
|
|
|
2015-01-12 01:21:38 +01:00
|
|
|
const char* getRelation(CheckStatusWrapper* 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;
|
|
|
|
}
|
|
|
|
|
2015-01-12 01:21:38 +01:00
|
|
|
const char* getOwner(CheckStatusWrapper* 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;
|
|
|
|
}
|
|
|
|
|
2015-01-12 01:21:38 +01:00
|
|
|
const char* getAlias(CheckStatusWrapper* 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;
|
|
|
|
}
|
|
|
|
|
2015-01-12 01:21:38 +01:00
|
|
|
unsigned getType(CheckStatusWrapper* 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;
|
|
|
|
}
|
|
|
|
|
2015-01-12 01:21:38 +01:00
|
|
|
FB_BOOLEAN isNullable(CheckStatusWrapper* 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;
|
|
|
|
}
|
|
|
|
|
2015-01-12 01:21:38 +01:00
|
|
|
int getSubType(CheckStatusWrapper* 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;
|
|
|
|
}
|
|
|
|
|
2015-01-12 01:21:38 +01:00
|
|
|
unsigned getLength(CheckStatusWrapper* 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;
|
|
|
|
}
|
|
|
|
|
2015-01-12 01:21:38 +01:00
|
|
|
int getScale(CheckStatusWrapper* 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;
|
|
|
|
}
|
|
|
|
|
2015-01-12 01:21:38 +01:00
|
|
|
unsigned getCharSet(CheckStatusWrapper* 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;
|
|
|
|
}
|
|
|
|
|
2015-01-12 01:21:38 +01:00
|
|
|
unsigned getOffset(CheckStatusWrapper* 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;
|
|
|
|
}
|
|
|
|
|
2015-01-12 01:21:38 +01:00
|
|
|
unsigned getNullOffset(CheckStatusWrapper* 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;
|
|
|
|
}
|
|
|
|
|
2015-01-12 01:21:38 +01:00
|
|
|
IMetadataBuilder* getBuilder(CheckStatusWrapper* status);
|
2013-02-17 13:08:53 +01:00
|
|
|
|
2015-01-12 01:21:38 +01:00
|
|
|
unsigned getMessageLength(CheckStatusWrapper* /*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:
|
2015-01-12 01:21:38 +01:00
|
|
|
void raiseIndexError(CheckStatusWrapper* status, unsigned index, const char* method) const
|
2013-02-17 13:08:53 +01:00
|
|
|
{
|
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;
|
|
|
|
};
|
|
|
|
|
2015-01-12 01:21:38 +01:00
|
|
|
//class AttMetadata : public IMessageMetadataBaseImpl<AttMetadata, CheckStatusWrapper, MsgMetadata>
|
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)
|
2014-09-29 13:03:47 +02:00
|
|
|
: attachment(att)
|
2013-07-19 15:51:54 +02:00
|
|
|
{ }
|
|
|
|
|
|
|
|
// re-implement here release() present in MsgMetadata to call correct dtor
|
2014-09-29 13:03:47 +02:00
|
|
|
//virtual int 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
|
|
|
|
2015-01-12 01:21:38 +01:00
|
|
|
class MetadataBuilder FB_FINAL : public RefCntIface<IMetadataBuilderImpl<MetadataBuilder, CheckStatusWrapper> >
|
2014-04-04 17:57:18 +02:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
2014-09-29 13:03:47 +02:00
|
|
|
int release();
|
2014-04-04 17:57:18 +02:00
|
|
|
|
|
|
|
// IMetadataBuilder implementation
|
2015-01-12 01:21:38 +01:00
|
|
|
void setType(CheckStatusWrapper* status, unsigned index, unsigned type);
|
|
|
|
void setSubType(CheckStatusWrapper* status, unsigned index, int subType);
|
|
|
|
void setLength(CheckStatusWrapper* status, unsigned index, unsigned length);
|
|
|
|
void setCharSet(CheckStatusWrapper* status, unsigned index, unsigned charSet);
|
|
|
|
void setScale(CheckStatusWrapper* status, unsigned index, unsigned scale);
|
|
|
|
void truncate(CheckStatusWrapper* status, unsigned count);
|
|
|
|
void remove(CheckStatusWrapper* status, unsigned index);
|
|
|
|
void moveNameToIndex(CheckStatusWrapper* status, const char* name, unsigned index);
|
|
|
|
unsigned addField(CheckStatusWrapper* status);
|
|
|
|
IMessageMetadata* getMetadata(CheckStatusWrapper* status);
|
2014-04-04 17:57:18 +02:00
|
|
|
|
|
|
|
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
|