title: Inserting into SQLITE in cocos2d-x
body: <p>I am using cocos2d-x to create an app in android which needs to use a database.</p>
  
  <p>I have used the following method, which I found whilst searching forums, to use SQLITE in cocos2d-x :</p>
  
  <ol>
  <li>use CCFileUtils::getFileData() to read the sqlite file into a char*</li>
  <li>use standard ofstrem to write the char* into a file in CCFileUtils::getWriteablePath() (in android is /data/data/xxx/xx)</li>
  <li>than you can use sqlite3_open() to open the file in step 2</li>
  </ol>
  
  <p>The problem I am having is that when I insert into the database, the original file is not being updated, i.e. the sqlite file in step 1 is not being updated and the file in step 2 is. Now when the app restarts, the data within the file in step 2 is overwritten therefore losing any insert data.</p>
  
  <p>Here is my code :</p>
  
  <pre><code>string dbPath = CCFileUtils::sharedFileUtils()-&gt;getWritablePath();
  dbPath.append("DischargedNew.mp3");
  unsigned long tmpSize;
  unsigned char *xmlData = CCFileUtils::sharedFileUtils()-&gt;getFileData("Discharged.mp3", "rb", &amp;tmpSize);
  FILE *fp = fopen(dbPath.c_str(), "wb");
  fwrite(xmlData, tmpSize, 1, fp);
  fclose(fp);
  
  if(result = db-&gt;open((char*) dbPath.c_str()))
  {
      CCLog("DB Opened");
      db-&gt;query("INSERT INTO USERS (Name, Username, Email) VALUES ('Test Test', 'T', 'test@test.com');");
  }
  else
  {
      CCLog("OPENING WRONG, %d, MSG:%s", result, db-&gt;getError().c_str());
  }
  
  
  db-&gt;close();
  </code></pre>