#include "cgilet.h"

using namespace cgid;

extern "C" {
extern void * create_cgi();
}

class PersonTest: public CGILet {
public:
   void process_request(tcp_stream & out, FormData & form_data, Connection * conn) {
      if(form_data["embed"] != "true") 
         out << "Content-type: text/html\r\n\r\n";

      if(conn) {
         Statement * p_statement = conn->get_statement();

         if(p_statement) {
            ResultSet * p_result = p_statement->execute("SELECT ID,NAME,AGE FROM PERSON");

            if(p_result) {
               out << "ID\tNAME\tAGE<BR>\n";

               while(p_result->has_more()) {
                  out << p_result->get_string(0) << "\t"
                      << p_result->get_string(1) << "\t"
                      << p_result->get_string(2) << "<BR>\n";

                  cout << p_result->get_string(0) << "\t"
                       << p_result->get_string(1) << "\t"
                       << p_result->get_string(2) << "\n";

                  p_result->next();
               }

               delete p_result;
            }

            delete p_statement;
         }
      }
   }
};

void * create_cgi() {
   return new PersonTest();
}
