Q: Syntax error in SQLite (C bindings) I got this error recently, and couldn't get rid of it. It's puzzling me, because the exact same request (copy-paste) works from the CLI like a charm.
I am using the C bindings, from a Qt application (I only discovered later that there was a Qt wrapper class for SQL databases).
The request in question is the following : 
NSERT INTO classes(score,classe) VALUES((SELECT avg((julianday(arrivee)-julianday(debutCourse))/moyenne) FROM coureurs NATURAL JOIN resultats NATURAL JOIN courses NATURAL JOIN categories WHERE classe='4èmeB' AND moyenne IS NOT NULL),'4èmeB');

The error is : 

near "'4èmeB'": syntax error

I have three tables I use there, which are classes, coureurs (runners), resultats (results), courses (races), categories.
For each class, I want to compute the following : 
average of (runner's time/average time of its category).
Departure times are stored inside the courses (races) table, arrival times are stored inside the resultats (results) table and categories' average time are stored into categories.moyenne. If you have a more elegant way of performing such a request, I would be pleased to hear it. I would however like to have an explanation of what's going on here. Is this because of the UTF-8 characters ? It didn't seem to be a problem in other places.
In case it helps, here is the relevant C++ code : 
void database::voidQuery(QString query)
{
    sqlite3_stmt *res;
    int rc =sqlite3_prepare_v2(db,query.toStdString().c_str(),query.length(),&res,NULL);
    if(rc != SQLITE_OK){
        fprintf(stderr, "Error in voidquery : %s in the request %s\n", sqlite3_errmsg(db),query.toStdString().c_str());
        return;
    }
    sqlite3_step(res);
    sqlite3_finalize(res);
}

Together with The calling code :
for (QStringList::iterator it = classes.begin();it != classes.end(); ++it)
      {
          QString query("INSERT INTO classes(score,classe) "
                        "VALUES(("
                            "SELECT avg((julianday(arrivee)-julianday(debutCourse))/moyenne) "
                            "FROM coureurs NATURAL JOIN resultats NATURAL JOIN courses NATURAL JOIN categories "
                            "WHERE classe='%1' and moyenne is not null),'%2');");
          voidQuery(query.arg(*it).arg(*it));
      }

classes is a QStringList containing the different rows of a precedent query.
Thanks in advance ! (I hope it's not a trivial problem; it took me quite some time to debug it).

A: Use
INSERT INTO classes (score,classe) 
SELECT avg((julianday(arrivee)-julianday(debutCourse))/moyenne), '4èmeB'
FROM coureurs 
NATURAL JOIN resultats 
NATURAL JOIN courses 
NATURAL JOIN categories 
WHERE classe='4èmeB' 
AND moyenne IS NOT NULL

