/[H9]/trunk/tntnet/dynamic/customerlist.ecpp
ViewVC logotype

Contents of /trunk/tntnet/dynamic/customerlist.ecpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 195 - (show annotations) (download)
Sat Dec 8 16:47:03 2007 UTC (16 years, 5 months ago) by torben
File size: 1918 byte(s)
Use persistant connections / connection pooling for faster db access

1 <%pre>
2 #include <tntdb/connect.h>
3 #include <tntdb/connection.h>
4 #include <tntdb/result.h>
5 #include <tntdb/row.h>
6
7 #include "common.h"
8
9 #include <sstream>
10 </%pre>
11
12 <%config>
13 dburl;
14 </%config>
15
16 <&header title="Customers and installations">
17 </&header>
18
19 <h2>Customers and installations</h2>
20
21 <{
22 tntdb::Connection conn;
23
24 conn = tntdb::connectCached(dburl); //letting exceptions flow up and to tntnet and let it display an error message
25
26 std::string customer_sql = "SELECT id,name,address,phonenr,contactperson FROM customer ORDER BY name ASC";
27
28 tntdb::Result res = conn.select(customer_sql);
29
30 std::ostream& out = reply.out();
31
32 if (res.size() != 0)
33 {
34 for (tntdb::Result::const_iterator it = res.begin(); it != res.end(); ++it)
35 {
36 tntdb::Row row = *it;
37 int customerid = row.getInt(0);
38 out << "<table border=1 width='80%' cellspacing=0 align=center><tr><td>";
39 out << "<b>" << row.getString(1) << "</b><br>\n\n";
40
41
42 out << nl2br(trim(row.getString(2))) << "<br>\n";
43
44 out << "<i>Phone:</i> " << row.getString(3) << "<br>\n";
45 out << "<i>Contact:</i> " << row.getString(4) << "<br>\n";
46
47 out << "<br>\n";
48
49
50 std::stringstream sqlstream;
51 sqlstream << "SELECT id, description FROM installation ";
52 sqlstream << "WHERE customerid = " << customerid;
53 sqlstream << " ORDER BY description ASC";
54
55 tntdb::Result instres = conn.select(sqlstream.str());
56
57 if (instres.size() > 0)
58 {
59 out << "Installations:\n";
60 out << "<ol>\n";
61 for (tntdb::Result::const_iterator instit = instres.begin(); instit != instres.end(); ++instit)
62 {
63 tntdb::Row instrow = *instit;
64 out << "<li><a href='installationdetails?id=" << instrow.getString(0) << "'>";
65 out << instrow.getString(1) << "</a></li>";
66 }
67 out << "</ol>\n";
68 }
69 else
70 {
71 out << "<i>No installations !</i>\n";
72 }
73
74
75
76
77
78 out << "</td></tr></table><br>\n";
79
80 }
81 }
82 else
83 {
84 out << "<i>No customer records found!</i>";
85 }
86
87 }>
88
89 <&footer>
90 </&footer>

  ViewVC Help
Powered by ViewVC 1.1.20