Dear Tntdb developers and users,

I am using Tntdb for a simple, local SQLite-based application, and so far, I am very happy with it. Thank you for this nice library! However, after months of developing with it, I have run into a problem which I cannot seem to resolve by myself. I would be glad if someone could give me some advice on it.

It is about a certain select statement including an IN-clause. It only works with a constant query statement like this: tntdb::Statement statement_with_var = db.prepare("select distinct entry_id" " from index_terms" " where entry_id in (1,2,3,8)");
…while the parameterised version does not yield any result:
tntdb::Statement statement_with_var = db.prepare("select distinct entry_id" " from index_terms" " where entry_id in (:subset)"); //followed by statement_with_var.set("subset", "1,2,3,8").select(), of course

There is a full example programme attached to this mail. It cannot be run without a fitting database of course, but maybe someone can tell where I am wrong just by looking at it.

Thank you for your time!

Carlos Franke
/*
 * test.cpp
 */

#include <iostream>
#include <vector>

#include <tntdb/connect.h>
#include <tntdb/connection.h>
#include <tntdb/result.h>
#include <tntdb/statement.h>


int main(int argc, char *argv[])
{
    tntdb::Connection db = tntdb::connect("sqlite:/home/carlos/.local/share/savant/savant.sqlite");

    //With a variable ":subset", nothing is selected:
    tntdb::Statement statement_with_var = db.prepare("select distinct entry_id"
                                                     "       from index_terms"
                                                     "         where entry_id in (:subset)");
    tntdb::Result result_with_var = statement_with_var.set("subset", "1,2,3,8")
                                                      .select();
    std::cout << "\nResult from statement_with_var:" << std::endl;
    for (tntdb::Result::const_iterator i = result_with_var.begin(); i != result_with_var.end(); ++i)
        std::cout << (*i)[0].getInt() << std::endl; //never called

    //Without it, the expected entries are selected:
    tntdb::Statement statement_without_var = db.prepare("select distinct entry_id"
                                                        "       from index_terms"
                                                        "         where entry_id in (1,2,3,8)");
    tntdb::Result result_without_var = statement_without_var.select();
    std::cout << "\nResult from statement_without_var:" << std::endl;
    for (tntdb::Result::const_iterator i = result_without_var.begin(); i != result_without_var.end(); ++i)
        std::cout << (*i)[0].getInt() << std::endl;

    return 0;
}

Attachment: pgp7qUDdMDlgF.pgp
Description: PGP signature

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general

Reply via email to