1

This is my first post in stack-overflow, so sorry in advance for possible "bad practices".

Context: the goal is to send SPARQL queries through http-requests to a GraphDB data base. Problem: to construct the queries on code in a safe way. Currently done by means of std::string dummyStr = "Hello"+" World" or dummyStr.append("bla") (I was told this was not safe due to XSS, but thats not the issue here)

Question: do you know any query builder library for doing this string concatenation? A search for C++ query builder on the web returned this answer. After implementing the approach with the suggested Qt QSqlQuery class, I'm able to ".prepare" the query, but not to ".bindValue".

QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.open();
QSqlQuery startQuery;
/*Prepare query*/
startQuery.prepare("INSERT INTO person (id, forename, surname) "
          "VALUES (:id, :forename, :surname)");
startQuery.bindValue(":id", 1001);
startQuery.bindValue(":forename", "Bart");
startQuery.bindValue(":surname", "Simpson");
/*convert query to std::string*/
QString startQueryString = startQuery.lastQuery();
std::string dummyQuery = startQueryString.toUtf8().constData();

Why can't I bind the values to the placeholders? Is it because I have no "actual" database, but rather a dummy-database just to construct the query?

My actual Query looks something like this: SELECT ?s WHERE { FILTER(STRSTARTS(STR(?s),":referenceIRI")). ?s rdf:type rdfs:Class.} And I would like to treat :referenceIRI as a placeholder.

I've searched overall to try to overcome this problem, as I just need the query-builder functionality.

Also: on my actual SPARQL query I have both ? and :myVal elements, which are the 2 types of placeholders in QSqlQuery for binding values. Any idea on how to by-pass the ? placeholder and just consider the :myVal-type?

2
  • BTW, INSERT INTO person (id, forename, surname) is impossible in SPARQL. Perhaps the VALUES keyword could help. Commented Apr 12, 2018 at 12:19
  • Thanks @stanislav, I tried that but still the same result, the values are not binded Commented Apr 13, 2018 at 11:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.