While still hoping for a developer to comment on this matter, I did
some more testing and discovered that it is not the entire
backslash-in-single-quotes construct that makes SqlBuilder fail, but
only the sequence '\ (single quote, backslash – each of course further
backslash-escaped in C++ source code).

So, again, in a case like the following SqlBuilder::replace does not do
its job:
######################
SqlBuilder query_string7 ("\'\\ (%subset)");
cout << "replace 7:\n" << query_string7.replace("subset", "1,2,3").str() 
          << '\n' << std::endl; //does not work
######################

And, again, this is relevant, because one may want to use backslashes
as escape characters for LIKE clauses, as in: 
select […]where index_term like :tagstring escape '\' […]

I am attaching an updated (and reordered) version of a short test
program.

I would really appreciate any comment on this, even if it is only
"no time for this right now, ask again next month", or a hint that I am
doing something completely wrong, should that be the case.
/*
 * test.cpp
 */

#include <iostream>

#include <tntdb/sqlbuilder.h>


int main(int argc, char *argv[])
{
    using std::cout;
    using tntdb::SqlBuilder;

    // Several test cases for SqlBuilder::replace

    SqlBuilder query_string1 ("select distinct entry_id"
                                     "       from index_terms"
                                     "       where entry_id in (%subset)");
    cout << "replace 1:\n" << query_string1.replace("subset", "1,2,3").str() 
              << '\n' << std::endl; //works

    SqlBuilder query_string2 ("select distinct entry_id"
                                     "       from index_terms"
                                     "       where index_term like :tagstring"
                                     "                        escape \'\\\'"
                                     "         and entry_id in (%subset)");
    cout << "replace 2:\n" << query_string2.replace("subset", "1,2,3").str() 
              << '\n' << std::endl; //does not work

    SqlBuilder query_string3 ("\'\\\' (%subset)");
    cout << "replace 3:\n" << query_string3.replace("subset", "1,2,3").str() 
              << '\n' << std::endl; //does not work

    SqlBuilder query_string4 ("(%subset) \'\\\'");
    cout << "replace 4:\n" << query_string4.replace("subset", "1,2,3").str() 
              << '\n' << std::endl; //works

    SqlBuilder query_string5 ("\'\' (%subset)");
    cout << "replace 5:\n" << query_string5.replace("subset", "1,2,3").str() 
              << '\n' << std::endl; //works

    SqlBuilder query_string6 ("\\ (%subset)");
    cout << "replace 6:\n" << query_string6.replace("subset", "1,2,3").str() 
              << '\n' << std::endl; //works

    SqlBuilder query_string7 ("\'\\ (%subset)");
    cout << "replace 7:\n" << query_string7.replace("subset", "1,2,3").str() 
              << '\n' << std::endl; //does not work

    return 0;
}

Attachment: signature.asc
Description: PGP signature

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general

Reply via email to