mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-23 06:43:04 +01:00
I want to be able to pass const input params.
This commit is contained in:
parent
dba50607bb
commit
d944111a47
@ -54,7 +54,7 @@ namespace Jrd {
|
||||
// Move data from result set message to user variables.
|
||||
void PreparedStatement::Builder::moveFromResultSet(thread_db* tdbb, ResultSet* rs) const
|
||||
{
|
||||
for (Array<Slot>::const_iterator i = outputSlots.begin(); i != outputSlots.end(); ++i)
|
||||
for (Array<OutputSlot>::const_iterator i = outputSlots.begin(); i != outputSlots.end(); ++i)
|
||||
{
|
||||
switch (i->type)
|
||||
{
|
||||
@ -98,7 +98,7 @@ void PreparedStatement::Builder::moveFromResultSet(thread_db* tdbb, ResultSet* r
|
||||
// Move data from user variables to the request input message.
|
||||
void PreparedStatement::Builder::moveToStatement(thread_db* tdbb, PreparedStatement* stmt) const
|
||||
{
|
||||
for (Array<Slot>::const_iterator i = inputSlots.begin(); i != inputSlots.end(); ++i)
|
||||
for (Array<InputSlot>::const_iterator i = inputSlots.begin(); i != inputSlots.end(); ++i)
|
||||
{
|
||||
if (i->specifiedAddress && !*i->specifiedAddress)
|
||||
{
|
||||
|
@ -76,7 +76,15 @@ public:
|
||||
size_t number;
|
||||
};
|
||||
|
||||
struct Slot
|
||||
struct InputSlot
|
||||
{
|
||||
Type type;
|
||||
unsigned number;
|
||||
const void* address;
|
||||
const bool* specifiedAddress;
|
||||
};
|
||||
|
||||
struct OutputSlot
|
||||
{
|
||||
Type type;
|
||||
unsigned number;
|
||||
@ -102,7 +110,7 @@ public:
|
||||
|
||||
template <typename T> OutputParam operator ()(const char* chunk, T& param)
|
||||
{
|
||||
add(getType(param), ¶m, outputSlots);
|
||||
addOutput(getType(param), ¶m, outputSlots);
|
||||
return OutputParam(chunk, outputSlots.getCount() - 1);
|
||||
}
|
||||
|
||||
@ -124,16 +132,16 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T> Builder& operator <<(TriStateType<T>& param)
|
||||
template <typename T> Builder& operator <<(const TriStateType<T>& param)
|
||||
{
|
||||
*this << param.value;
|
||||
inputSlots[inputSlots.getCount() - 1].specifiedAddress = ¶m.specified;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T> Builder& operator <<(T& param)
|
||||
template <typename T> Builder& operator <<(const T& param)
|
||||
{
|
||||
add(getType(param), ¶m, inputSlots);
|
||||
addInput(getType(param), ¶m, inputSlots);
|
||||
text += "?";
|
||||
return *this;
|
||||
}
|
||||
@ -149,16 +157,26 @@ public:
|
||||
|
||||
private:
|
||||
// Make the C++ template engine return the constant for each type.
|
||||
static Type getType(SSHORT&) { return TYPE_SSHORT; }
|
||||
static Type getType(SLONG&) { return TYPE_SLONG; }
|
||||
static Type getType(SINT64&) { return TYPE_SINT64; }
|
||||
static Type getType(double&) { return TYPE_DOUBLE; }
|
||||
static Type getType(Firebird::AbstractString&) { return TYPE_STRING; }
|
||||
static Type getType(Firebird::MetaName&) { return TYPE_METANAME; }
|
||||
static Type getType(SSHORT) { return TYPE_SSHORT; }
|
||||
static Type getType(SLONG) { return TYPE_SLONG; }
|
||||
static Type getType(SINT64) { return TYPE_SINT64; }
|
||||
static Type getType(double) { return TYPE_DOUBLE; }
|
||||
static Type getType(const Firebird::AbstractString&) { return TYPE_STRING; }
|
||||
static Type getType(const Firebird::MetaName&) { return TYPE_METANAME; }
|
||||
|
||||
void add(Type type, void* address, Firebird::Array<Slot>& slots)
|
||||
void addInput(Type type, const void* address, Firebird::Array<InputSlot>& slots)
|
||||
{
|
||||
Slot slot;
|
||||
InputSlot slot;
|
||||
slot.type = type;
|
||||
slot.number = (unsigned) slots.getCount() + 1;
|
||||
slot.address = address;
|
||||
slot.specifiedAddress = NULL;
|
||||
slots.add(slot);
|
||||
}
|
||||
|
||||
void addOutput(Type type, void* address, Firebird::Array<OutputSlot>& slots)
|
||||
{
|
||||
OutputSlot slot;
|
||||
slot.type = type;
|
||||
slot.number = (unsigned) slots.getCount() + 1;
|
||||
slot.address = address;
|
||||
@ -168,7 +186,8 @@ public:
|
||||
|
||||
private:
|
||||
Firebird::string text;
|
||||
Firebird::Array<Slot> inputSlots, outputSlots;
|
||||
Firebird::Array<InputSlot> inputSlots;
|
||||
Firebird::Array<OutputSlot> outputSlots;
|
||||
unsigned outputParams;
|
||||
};
|
||||
|
||||
@ -261,7 +280,7 @@ public:
|
||||
{
|
||||
fb_assert(param > 0);
|
||||
|
||||
const dsc* desc = &inValues[(param - 1) * 2 + 1];
|
||||
dsc* desc = &inValues[(param - 1) * 2 + 1];
|
||||
fb_assert(desc->dsc_dtype == dtype_short);
|
||||
*reinterpret_cast<SSHORT*>(desc->dsc_address) = -1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user