Am 23.02.2015 um 18:23 schrieb Tommi Mäkitalo:
...
>
> I prefer not to use getString nor tntdb::Result. I suggest to do
> something like:
>
> tntdb::Statement q = conn.prepare("SELECT foo, teams, bar FROM baz");
> // add bindings for where clause here
> std::string teams;
> for(tntdb::Statement::const_iterator it = q.begin(); it != q.end(); ++it)
> {
>     if (it->get(teams))
>       WHATEVR(teams);
> }
>
> The iterator over tntdb::Statement do not read the whole result into
> memory. It will use a cursor.
>
> The get method is just a matter of taste. I prefer to use the get
> method, so I do not need to remember whether to use getInt or getInteger
> or getLong or whatever for numbers but just define my variable as needed.
>
>
> Tommi
My example is wrong. Dereferencing an tntdb::Statement::const_iterator 
returns a tntdb::Row. But the get method is in tntdb::Value. So it 
should be:

tntdb::Statement q = conn.prepare("SELECT foo, teams, bar FROM baz");
// add bindings for where clause here
std::string teams;
for(tntdb::Statement::const_iterator it = q.begin(); it != q.end(); ++it)
{
   tntdb::Row row = *it;
   if (row[1].get(teams))
      WHATEVR(teams);
}

Tommi

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general

Reply via email to