[fdo-internals] FdoParameterValue and FdoDataValue

Mateusz Loskot mateusz at loskot.net
Mon Feb 26 20:05:01 EST 2007


Hi,

I'd like to ask for some suggestion related to usage of
FdoParameterValue and FdoDataValue.

I call SQL command with PostreSQL-specific placeholders:

SELECT * FROM table WHERE id = $1 AND name = $2

I'd like to use the FdoParameterValueCollection to pass input
params that will be bound to placeholders.
I've rev-engineered how to play with this collection and how it works
in commands like FdoISQLCommand, besides one aspect.

The params binding is issued in textual mode, so I convert all params of
all types to their textual representation.

The first obvious soluton is to builda switch statement and manually
convert params from FdoDataValue to a string representation:

///////////////////////////////////////////////////////////
// Buffer stringified representation
std::string value;

// pointer got from  object of type of FdoParameterVale
FdoPtr<FdoDataValue> data = ...

FdoDataType type = data->GetDataType();
switch (type)
{
case FdoDataType_Boolean:
   FdoBooleanValue* pval = static_cast<FdoBooleanValue*>(data.p);
   value = (pval->GetBoolean() ? "TRUE" : "FALSE");
break;

... // and so on for every data type
}
///////////////////////////////////////////////////////////

It will work, but I'm wondering if there is a another possibility,
shorter. As I see, there is FdoDataValue::ToString() member function.

What is the purpose of this ToString() ?

I tested it a bit and it works well with simple types: integral,
real, string.

My question is what can I expect to get from ToString() for types like
FdoDataType_DateType, FdoDataType_BLOB and FdoDataType_CLOB ?

Generally, is it safe to use make the example above simpler by
calling just:

value = data->ToString();

?

Cheers
-- 
Mateusz Loskot
http://mateusz.loskot.net


More information about the fdo-internals mailing list