8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-30 20:03:03 +01:00
firebird-mirror/src/common/StatementMetadata.h

220 lines
5.5 KiB
C
Raw Normal View History

2011-04-14 03:03:43 +02: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): ______________________________________.
*
*/
#ifndef COMMON_STATEMENT_METADATA_H
#define COMMON_STATEMENT_METADATA_H
#include "firebird/Provider.h"
2011-04-14 03:03:43 +02:00
#include "iberror.h"
#include "../common/classes/Nullable.h"
#include "../common/classes/array.h"
#include "../common/classes/fb_string.h"
#include "../common/classes/objects_array.h"
#include "../common/classes/ImplementHelper.h"
2011-04-14 03:03:43 +02:00
namespace Firebird {
// Make new metadata support work together with old info-based buffers.
class StatementMetadata : public PermanentStorage
{
public:
class Parameters : public VersionedIface<IParametersMetadata, FB_PARAMETERS_METADATA_VERSION>,
public PermanentStorage
2011-04-14 03:03:43 +02:00
{
public:
struct Item : public PermanentStorage
{
2011-04-17 07:02:26 +02:00
explicit Item(MemoryPool& pool)
2011-04-14 03:03:43 +02:00
: PermanentStorage(pool),
field(pool),
relation(pool),
owner(pool),
alias(pool),
type(0),
subType(0),
length(0),
scale(0),
nullable(false),
finished(false)
{
}
string field;
string relation;
string owner;
string alias;
unsigned type;
unsigned subType;
unsigned length;
unsigned scale;
bool nullable;
bool finished;
};
public:
2011-04-17 07:02:26 +02:00
explicit Parameters(MemoryPool& pool)
2011-04-14 03:03:43 +02:00
: PermanentStorage(pool),
items(pool),
fetched(false)
{
}
virtual unsigned FB_CARG getCount(IStatus* /*status*/) const
{
return (unsigned) items.getCount();
}
virtual const char* FB_CARG getField(IStatus* status, unsigned index) const
{
if (index < items.getCount())
return items[index].field.c_str();
2011-04-17 07:02:26 +02:00
raiseIndexError(status, index, "getField");
return NULL;
2011-04-14 03:03:43 +02:00
}
virtual const char* FB_CARG getRelation(IStatus* status, unsigned index) const
{
if (index < items.getCount())
return items[index].relation.c_str();
2011-04-17 07:02:26 +02:00
raiseIndexError(status, index, "getRelation");
return NULL;
2011-04-14 03:03:43 +02:00
}
virtual const char* FB_CARG getOwner(IStatus* status, unsigned index) const
{
if (index < items.getCount())
return items[index].owner.c_str();
2011-04-17 07:02:26 +02:00
raiseIndexError(status, index, "getOwner");
return NULL;
2011-04-14 03:03:43 +02:00
}
virtual const char* FB_CARG getAlias(IStatus* status, unsigned index) const
{
if (index < items.getCount())
return items[index].alias.c_str();
2011-04-17 07:02:26 +02:00
raiseIndexError(status, index, "getAlias");
return NULL;
2011-04-14 03:03:43 +02:00
}
virtual unsigned FB_CARG getType(IStatus* status, unsigned index) const
{
if (index < items.getCount())
return items[index].type;
2011-04-17 07:02:26 +02:00
raiseIndexError(status, index, "getType");
return 0;
2011-04-14 03:03:43 +02:00
}
virtual bool FB_CARG isNullable(IStatus* status, unsigned index) const
{
if (index < items.getCount())
return items[index].nullable;
2011-04-17 07:02:26 +02:00
raiseIndexError(status, index, "isNullable");
return false;
2011-04-14 03:03:43 +02:00
}
virtual unsigned FB_CARG getSubType(IStatus* status, unsigned index) const
{
if (index < items.getCount())
return items[index].subType;
2011-04-17 07:02:26 +02:00
raiseIndexError(status, index, "getSubType");
return 0;
2011-04-14 03:03:43 +02:00
}
virtual unsigned FB_CARG getLength(IStatus* status, unsigned index) const
{
if (index < items.getCount())
return items[index].length;
2011-04-17 07:02:26 +02:00
raiseIndexError(status, index, "getLength");
return 0;
2011-04-14 03:03:43 +02:00
}
virtual unsigned FB_CARG getScale(IStatus* status, unsigned index) const
{
if (index < items.getCount())
return items[index].scale;
2011-04-17 07:02:26 +02:00
raiseIndexError(status, index, "getScale");
return 0;
2011-04-14 03:03:43 +02:00
}
private:
void raiseIndexError(IStatus* status, unsigned index, const char* method) const
{
status->set((Arg::Gds(isc_invalid_index_val) <<
Arg::Num(index) << (string("IParametersMetadata::") + method)).value());
}
public:
ObjectsArray<Item> items;
bool fetched;
};
public:
StatementMetadata(MemoryPool& pool, IStatement* aStatement)
: PermanentStorage(pool),
statement(aStatement),
legacyPlan(pool),
detailedPlan(pool),
inputParameters(pool),
outputParameters(pool)
{
}
static unsigned buildInfoItems(Array<UCHAR>& items, unsigned flags);
static unsigned buildInfoFlags(unsigned itemsLength, const UCHAR* items);
unsigned getType();
const char* getPlan(bool detailed);
const IParametersMetadata* getInputParameters();
const IParametersMetadata* getOutputParameters();
ISC_UINT64 getAffectedRecords();
void clear();
void parse(unsigned bufferLength, const UCHAR* buffer);
void getAndParse(unsigned itemsLength, const UCHAR* items, unsigned bufferLength, UCHAR* buffer);
bool fillFromCache(unsigned itemsLength, const UCHAR* items, unsigned bufferLength, UCHAR* buffer);
private:
void fetchParameters(UCHAR code, Parameters* parameters);
private:
IStatement* statement;
Nullable<unsigned> type;
string legacyPlan, detailedPlan;
Parameters inputParameters, outputParameters;
};
} // namespace Firebird
#endif // COMMON_STATEMENT_METADATA_H