title: Syntax error in SQLite (C bindings)
body: <p>I got this error recently, and couldn't get rid of it. It's puzzling me, because <strong>the exact same request (copy-paste) works from the CLI like a charm</strong>.
  I am using the C bindings, from a Qt application (I only discovered later that there was a Qt wrapper class for SQL databases).</p>
  
  <p>The request in question is the following : </p>
  
  <pre><code>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');
  </code></pre>
  
  <p>The error is : </p>
  
  <blockquote>
    <p>near "'4èmeB'": syntax error</p>
  </blockquote>
  
  <p>I have three tables I use there, which are classes, coureurs (runners), resultats (results), courses (races), categories.</p>
  
  <p>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.</p>
  
  <p>In case it helps, here is the relevant C++ code : </p>
  
  <pre><code>void database::voidQuery(QString query)
  {
      sqlite3_stmt *res;
      int rc =sqlite3_prepare_v2(db,query.toStdString().c_str(),query.length(),&amp;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);
  }
  </code></pre>
  
  <p>Together with The calling code :</p>
  
  <pre><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));
        }
  </code></pre>
  
  <p>classes is a QStringList containing the different rows of a precedent query.</p>
  
  <p>Thanks in advance ! (I hope it's not a trivial problem; it took me quite some time to debug it).</p>