Using ceegeye for the database retrieval

The Backend

Now to create a cgi program using the ceegeye library to return data from the database in json format. here is the json returned:
{
   "personnel": [
      { "id":"3", "first":"Endless", "last":"Charm" },
      { "id":"2", "first":"Hopeless", "last":"Dolt" },
      { "id":"6", "first":"Fete", "last":"Homeless" },
      { "id":"1", "first":"Reginald", "last":"Molehusband" },
      { "id":"5", "first":"Endless", "last":"Mutations" },
      { "id":"4", "first":"Nosebleed", "last":"Section" }
   ]
}
And here is the code that does this:
#include "personnel.h"
#include "person.h"
#include <algorithm>
#include "../ceegeye/ceegeye.h"
using namespace ceegeye;
using std::cout;

int main(int argc, char* argv[], char* envp[]) {
   CGI cgi;
   string json;
   try {
      // connect to the database
      personnel db("personnel", "personneluser", "secret");
      person people(db);
      std::vector all(people.rows());

      if(all.size()) {
         json = "{\n   \"personnel\": [\n";
         for(std::vector::const_iterator it = all.begin(); it != all.end(); ++it) {
            std::ostringstream VAL;
            VAL << it->id;
            if(it +1 != all.end()) {
               json += "      { \"id\":\"" + VAL.str() + "\",";
               json += " \"first\":\"" + it->first + "\",";
               json += " \"last\":\"" + it->last + "\" },\n";
            }
            else {
               json += "      { \"id\":\"" + VAL.str() + "\",";
               json += " \"first\":\"" + it->first + "\",";
               json += " \"last\":\"" + it->last + "\" }\n";
            }
         }
         json += "   ]\n}\n";
      }

      cout << "Content-Type: text/javascript\r\n";
      cout << "Content-Length: " << json.length() << "\r\n\r\n";
      cout << json;
   }
   catch (DBerror& dberr) {
      cout << dberr.what();
      return 1;
   }
   return 0;
}
This is reasonably self explanatory.
Create a CGI object
Create a string to hold the json object (text)
Connect to the database get all it's data and loop over the data adding the first and lastname and id to the string json.
Close the headers of the cgi object telling the browser we are sending json and the length of the data.
Send the string json, i.e the data