Poco::Data binding with std::array of arguments1

Please post support and help requests here.
throstur62
Posts: 16
Joined: 22 Nov 2012, 18:44

Poco::Data binding with std::array of arguments1

Postby throstur62 » 24 May 2016, 16:02

Hi,
I'm using Poco version 1.5.2. I have the below problem by example, using the Poco::Data stuff.

Statement select(mySession) // connect to SqLite session object.
std::vector<int> args;
args.push_back(1);
args.push_back(2);

// This does not work and throws this text to the standard output "Invalid access: Can not convert empty value."
select << "SELECT X,Y,Z FROM my_table WHERE a=? AND b=?", bind(args), into(myEntityContainer),now;

// However this works fine
select << "SELECT X,Y,Z FROM my_table WHERE a=? AND b=?", bind(arg[0]), bind(arg[1]) into(myEntityContainer),now;

Is this corrected in later releases?
How can I do a workaround in version 1.5.2?

alex
Posts: 1375
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: Poco::Data binding with std::array of arguments1

Postby alex » 24 May 2016, 20:14

throstur62 wrote:Is this corrected in later releases?

no
throstur62 wrote:How can I do a workaround in version 1.5.2?

you just did

throstur62
Posts: 16
Joined: 22 Nov 2012, 18:44

Re: Poco::Data binding with std::array of arguments1

Postby throstur62 » 24 May 2016, 20:27

Hi Alex, Like your answer :-) But I have not done the workaround. The thing is that I'm writing a genralized entity-model based on Poco. ... that I actually want to contribute to Poco if interest is for that.
In that case I do not know the number of retriev-arguments incoming in the bind-argument vector. So throwing the total vector into a ", bind(arguments)" is a very nice feature. And it works as long as the number of arguments in the std::vector<Poco::Dynamic::Var> arguments is only one. As soon as the number is more than one, the problem starts. So if you know of an easy workaround, I would appreciate....but remember it may not be a long code as this is template code, so I want as little as possible code in the header based template function(s).

guenter
Posts: 1268
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: Poco::Data binding with std::array of arguments1

Postby guenter » 30 May 2016, 10:15

You can do something like this (basically, explicitely creating a Statement object, then calling the comma operator repeatedly for each argument):

Code: Select all

Poco::Data::Statement stmt = (session << SELECT X,Y,Z FROM my_table WHERE a=? AND b=?", into(myEntityContainer);

for (auto arg: args)
{
    stmt , bind(arg);
}

stmt.execute();


@alex: Maybe we should have a bind() method in Statement to simplify this. I have similar code in the macchina.io JS Data bindings.


Return to “Support”

Who is online

Users browsing this forum: No registered users and 3 guests