title: Convert a custom flat database to a SQL based database like SQLite
body: <p>Our company has used some flat files as a database for many years, it has a fix structure snd unfortunately with no extra space. now they wanted to add some new fields and even make it more flexible to add new filed easily. It is a while I am working here and they gave this task to me.</p>
  
  <p>I have two questions:</p>
  
  <ol>
  <li>Firstly, I decided to convert it to a SQL based database like SQLite, I wrote a small program and used APIs sqlite3_prepare_v2 and sqlite_bind_* (for 18 fileds) to convert our legacy database to SQLite but it take forever. It’s four days and it just convert about 37,000 record from 500,000 records. </li>
  </ol>
  
  <p>How can I improve this process, is there any better way? Because typically there are about 30 to 90 separated flat files with about 500,000 to 10,000,000 records in each one.
  So by considering the maximum, we should deal with sbout 90 * 10,000,000 records</p>
  
  <ol start="2">
  <li>My second question is, whether it is reasonable to keep this fixed flat files with just some modification(a smart sulotion)? What you will do if you where in my situation? (I hope this question not be inappropriate to ask here, because I really need some advice in this case, but if it is not OK to ask these questions I am verry sorry about that)</li>
  </ol>
  
  <p>And it may worth to say that the information in these database are very sensitive and our approach should be immune to unexpected incidents like power failure and anything like that (being able to recover from that). And also, Losing to save even one record is very critical for our company and their customers.</p>
  
  <p>UPDATE 1: (some snipped code included)</p>
  
  <pre><code>const char sql = "INSERT INTO MetaData ("
   "Field_1,"
   "Field_2,"
   /* 16 other fields */
   ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
  
   for (unsigned record = 0; record &lt;= header.endpos; record++) {
     rc = sqlite3_precpare_v2(db, sql, strlen(sql), &amp;stmt, &amp;pzTail);
     if (rc) {
       fprintf(stderr, "cannot prepare database,\n");
       goto failed1;
     }
  
     dwReadCount = 0;
     ReadFile(hIndex, &amp;index, sizeof(index), &amp;dwReadCount, NULL);
  
     sqlite3_bind_int(stmt, 1, index.field1);
     sqlite3_bind_int(stmt, 2, index.field2);  
     /* 16 same other binding
     */
     ..
     ..
     ...
  
     sqlite3_step(stmt);
     sqlite3_finalize(stmt);
   }
  </code></pre>
  
  <p>I appreciate any help or hint.</p>
  
  <p>Thanks</p>