title: how to store UTF-8 encoding data to sqlite3 using Visual C++
body: <p>I've created a sqlite database with encoding UTF-8(default).</p>
  
  <p>Then I use the following statement to insert data:</p>
  
  <pre><code>strcpy(sql,"insert into blog(title) values('呵呵')");
  sqlite3_exec(db,sql,0,0,0);
  </code></pre>
  
  <p>then I open the sqlite database with tool called SQLite Developer the value of <code>title</code> field shows <code>ºǺ�</code> garbage code under Data encoding:<strong>UNICODE</strong>.
  then I changed Data encoding to <strong>ANSI</strong>, value of <code>title</code> shows right.</p>
  
  <p>As I know the <code>sqlite3_exec</code> prototype is :</p>
  
  <pre><code>int sqlite3_exec(
    sqlite3*,                                  /* An open database */
    const char *sql,                           /* SQL to be evaluated */
    int (*callback)(void*,int,char**,char**),  /* Callback function */
    void *,                                    /* 1st argument to callback */
    char **errmsg                              /* Error msg written here */
  );
  </code></pre>
  
  <p>I still try to pass <code>wchar_t</code> type to <code>sql</code>,but still won't work it out.</p>
  
  <p>My Visual C++ project already defined <code>UNOCODE</code> &amp; <code>_UNICODE</code>, So my question is: <strong>how to store UTF-8 encoding data to sqlite3 using Visual C++?</strong></p>
  
  <hr>
  
  <p><strong>Update(question solved)</strong></p>
  
  <p>I use <strong>iconv</strong> to convert <strong>GBK</strong> encoding to <strong>UTF-8</strong> inspired by msandiford. Thanks msandiford so much.</p>
  
  <pre><code>char* pOut;
  char* pIn;
  size_t inLen,outLen=2000;
  strcpy(sql,"insert into blog(title) values('呵呵')");
  string strSQL = sql;
  char* sql2 = (char*)malloc(2000);
  memset(sql2,0,2000);
  pOut = &amp;sql2[0];
  inLen = strlen(strSQL.c_str());
  pIn = const_cast&lt;char*&gt;(strSQL.c_str());
  iconv_t g2u8 = iconv_open("UTF-8","GBK");
  iconv(g2u8,(const char**)&amp;pIn,&amp;inLen,&amp;pOut,&amp;outLen);
  sqlite3_exec(db,sql2,0,0,0);
  </code></pre>