title: C++ SQLite3 query issue unsolved
body: <p>I'm somewhat new to SQL and C++. I do believe the question I have yields a simple solution.</p>
  
  <p>I have to create a sql query to insert some values into an existing table (const char *sql_query), with mixed strings and float values. My issue is getting the string assembly operation nailed down, without getting compiler errors.</p>
  
  <p>Here is my attempt:</p>
  
  <pre><code>int main(int argc, char* argv[])
  {
      create_entry("mahut", "topa", "suma", 5.55, 6.66, 7.77);
  
      return 0;
  }
  
  void create_entry(char col1[], char col2[], char col3[], float col4, float col5, float col6)
  {
      cout &lt;&lt; ("create_entry") &lt;&lt; endl;
  
      sqlite3 *db;
      char *zErrMsg = 0;
      int rc;
      char *sql;
      char db_name[] = "db_test.db";
      stringstream sql_query;
  
      // assemble string
      sql_query &lt;&lt; "INSERT INTO Department1 (Date,Time,Accept,Factor1,Factor2,Factor3) VALUES ('" &lt;&lt; col1 &lt;&lt; "','" &lt;&lt; col2 &lt;&lt; "','" &lt;&lt; col3 &lt;&lt; "','" &lt;&lt; col4 &lt;&lt; "','" &lt;&lt; col5 &lt;&lt; "','" &lt;&lt; col6 &lt;&lt; "')";
      string str = sql_query.str();
  
      rc = sqlite3_open(db_name, &amp;db);
  
      if( rc )
      {
          fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
      }
      else
      {
          fprintf(stderr, "Opened database successfully\n");
      }
  
      // execute SQL statement
      rc = sqlite3_exec(db, str, callback, 0, &amp;zErrMsg);
  
      if( rc != SQLITE_OK )
      {
          fprintf(stderr, "SQL error: %s\n", zErrMsg);
          sqlite3_free(zErrMsg);
      }
      else
      {
          fprintf(stdout, "Records created successfully\n");
      }
      sqlite3_close(db);
  }
  
  static int callback(void *db, int argc, char **argv, char **azColName)
  {
      cout &lt;&lt; "Debug &lt;in callback&gt;" &lt;&lt; endl;
      for(int i=0; i&lt;argc; ++i)
      {
          //printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
          cout &lt;&lt; ("%s", argv[i] ? argv[i] : "NULL") &lt;&lt; endl;
      }
      tbl_exists = true;
  
      return 0;
  }
  </code></pre>
  
  <p>Particularly this is my problem:</p>
  
  <pre><code>sql_query &lt;&lt; "INSERT INTO Department1 (Date,Time,Accept,Factor1,Factor2,Factor3) VALUES ('" &lt;&lt; col1 &lt;&lt; "','" &lt;&lt; col2 &lt;&lt; "','" &lt;&lt; col3 &lt;&lt; "','" &lt;&lt; col4 &lt;&lt; "','" &lt;&lt; col5 &lt;&lt; "','" &lt;&lt; col6 &lt;&lt; "')";
  </code></pre>
  
  <p>As I don't understand if there is a proper way to mix in float, integer and string into const char *
  I'm not sure what's wrong, but like I said I have tried it for quite some time to properly assemble that string but have failed, as I just don't grasp pointers and strings in C++. Compiling fails due to following error</p>
  
  <pre class="lang-none prettyprint-override"><code>error: cannot convert ‘std::__cxx11::string {aka std::__cxx11::basic_string&lt;char&gt;}’ to ‘const char*’ for argument ‘2’ to ‘int sqlite3_exec(sqlite3*, const char*, int (*)(void*, int, char**, char**), void*, char**)’   rc = sqlite3_exec(db, str, callback, 0, &amp;zErrMsg);
  </code></pre>
  
  <p>I also get the following warning</p>
  
  <pre class="lang-none prettyprint-override"><code>warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
  </code></pre>