c++/MQDB/MappedQuery.cpp
/******************************************* 
  fetch_single

  Description: General purpose template function for fetching a single instance
               of this class(subclass) using the create(row_map, database) method to convert
               a row of data into an object.
  Arg (1)    : $database (MQDB::Database)
  Arg (2)    : $sql (string of SQL statement with place holders)
  Arg (3...) : optional parameters to map to the placehodlers within the SQL
  Returntype : instance of this Class (subclass)
  Exceptions : none
  Caller     : subclasses (not public methods)
  Example    : 
                  sub fetch_by_id {
                      my $class = shift;
                      my $db = shift;
                      my $id = shift;
                      my $sql = "SELECT * FROM symbol WHERE symbol_id=?";
                      return $class->fetch_single($db, $sql, $id);
                  }


*******************************************/
fetch_single
Description: General purpose template function for fetching a single instance
of this class(subclass) using the create(row_map, database) method to convert
a row of data into an object.
fetch_single Description : General purpose template function for fetching a single instance of this class ( subclass ) using the create ( row_map database ) method to convert a row of data into an object .
DBObject* 
MQDB::fetch_single(DBObject* (*createFunc)(map<string, dynadata> &row_map, MQDB::Database* db), 
                   MQDB::Database *db, const char* sql, const char* fmt, ...)
{
  va_list                 ap;
  map<string, dynadata>   row_map;
  void                    *stmt;
  DBObject                *obj;
  if(db == NULL) { return NULL; }
  va_start(ap, fmt);
  stmt = db->prepare_fetch_sql(sql, fmt, ap);
  va_end(ap);
  db->fetch_next_row_map(stmt, row_map);
  if(row_map.empty()) { return NULL; }
  obj = createFunc(row_map, db);
  db->finalize_stmt(stmt);
  return obj;
}
DBObject * MQDB :: fetch_single ( DBObject * ( * createFunc ) ( map < string , dynadata > & row_map , MQDB :: Database * db ) , MQDB :: Database * db , const char * sql , const char * fmt , ... ) { va_list ap ; map < string , dynadata > row_map ; void * stmt ; DBObject * obj ; if ( db == NULL ) { return NULL ; } va_start ( ap , fmt ) ; stmt = db -> prepare_fetch_sql ( sql , fmt , ap ) ; va_end ( ap ) ; db -> fetch_next_row_map ( stmt , row_map ) ; if ( row_map . empty ( ) ) { return NULL ; } obj = createFunc ( row_map , db ) ; db -> finalize_stmt ( stmt ) ; return obj ; }
fetch_single
Description: General purpose template function for fetching a single instance
of this class(subclass) using the create(row_map, database) method to convert
a row of data into an object.
fetch_single Description : General purpose template function for fetching a single instance of this class ( subclass ) using the create ( row_map database ) method to convert a row of data into an object .
//if(!(db->get_connection)) { printf STDERR "error with connection on query %s", sql; return NULL; }