<%pre> #include #include #include #include #include "common.h" #include <%config> dburl; <&header title="Customers and installations">

Customers and installations

<{ tntdb::Connection conn; conn = tntdb::connectCached(dburl); //letting exceptions flow up and to tntnet and let it display an error message std::string customer_sql = "SELECT id,name,address,phonenr,contactperson FROM customer ORDER BY name ASC"; tntdb::Result res = conn.select(customer_sql); std::ostream& out = reply.out(); if (res.size() != 0) { for (tntdb::Result::const_iterator it = res.begin(); it != res.end(); ++it) { tntdb::Row row = *it; int customerid = row.getInt(0); out << "
"; out << "" << row.getString(1) << "
\n\n"; out << nl2br(trim(row.getString(2))) << "
\n"; out << "Phone: " << row.getString(3) << "
\n"; out << "Contact: " << row.getString(4) << "
\n"; out << "
\n"; std::stringstream sqlstream; sqlstream << "SELECT id, description FROM installation "; sqlstream << "WHERE customerid = " << customerid; sqlstream << " ORDER BY description ASC"; tntdb::Result instres = conn.select(sqlstream.str()); if (instres.size() > 0) { out << "Installations:\n"; out << "
    \n"; for (tntdb::Result::const_iterator instit = instres.begin(); instit != instres.end(); ++instit) { tntdb::Row instrow = *instit; out << "
  1. "; out << instrow.getString(1) << "
  2. "; } out << "
\n"; } else { out << "No installations !\n"; } out << "

\n"; } } else { out << "No customer records found!"; } }> <&footer>