Fortune Fortune::create(const QString &message) { FortuneObject obj; obj.message = message; if (!obj.create()) { obj.clear(); } return Fortune(obj); }
int exec() { vf array; // query fortunes mysql_query(db.connection(), "SELECT id, message FROM Fortune;"); MYSQL_RES *sqlres = mysql_store_result(db.connection()); if (!sqlres) throw runtime_error(mysql_error(db.connection())); MYSQL_ROW row; while( (row=mysql_fetch_row(sqlres)) ){ array.push_back(Fortune(atoi(row[0]),row[1])); } mysql_free_result(sqlres); // add on the fly array.push_back(Fortune(0,"Additional fortune added at request time.")); // sort sort(array.begin(),array.end()); // output html res << "<!DOCTYPE html>" "<html>" "<head><title>Fortunes</title></head>" "<body>" "<table>" "<tr><th>id</th><th>message</th></tr>"; for(unsigned z=0;z<array.size();++z) { Fortune &az = array[z]; res << "<tr>" "<td>" << az.id << "</td>" "<td>" << xml::escape(az.message) << "</td>" "</tr>"; } res << "</table>" "</body>" "</html>"; return res.end(); }
UHTTP::mime_index = U_html; u_http_info.endHeader = 0; } (void) UClientImage_Base::wbuffer->append( U_CONSTANT_TO_PARAM("<!doctype html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>") ); Fortune* elem; unsigned char encoded[1024]; pstmt_fortune->execute(); pvfortune->push_back(U_NEW(Fortune(0, *pmessage))); do { pvfortune->push_back(U_NEW(Fortune(*pfortune))); } while (pstmt_fortune->nextRow()); pvfortune->sort(Fortune::cmp_obj); for (uint32_t i = 0, n = pvfortune->size(); i < n; ++i) { elem = (*pvfortune)[i]; (void) u_xml_encode((const unsigned char*)U_STRING_TO_PARAM(elem->message), encoded); USP_PRINTF_ADD( "<tr>"
Fortune Fortune::get(const uint &id) { TSqlORMapper<FortuneObject> mapper; return Fortune(mapper.findByPrimaryKey(id)); }