1 |
Douglas Thrift |
164 |
// Smersh |
2 |
|
|
// |
3 |
|
|
// Douglas Thrift |
4 |
|
|
// |
5 |
|
|
// $Id$ |
6 |
|
|
|
7 |
|
|
#include "Person.hpp" |
8 |
|
|
|
9 |
Douglas Thrift |
167 |
Person::Person(const string& sn) : name("Unknown Person") |
10 |
Douglas Thrift |
164 |
{ |
11 |
Douglas Thrift |
183 |
if (driver.empty()) configure(); |
12 |
Douglas Thrift |
170 |
if (!sn.empty()) query(sn); |
13 |
|
|
} |
14 |
|
|
|
15 |
Douglas Thrift |
183 |
string Person::driver, Person::host, Person::user, Person::password, Person::db; |
16 |
Douglas Thrift |
170 |
|
17 |
|
|
void Person::configure() |
18 |
|
|
{ |
19 |
|
|
ext::Handle<xml::Document> document(xml::Parse("smersh.xml")); |
20 |
|
|
ext::Handle<xml::Node> smersh(*document/"smersh"); |
21 |
|
|
|
22 |
Douglas Thrift |
183 |
driver = *smersh/"driver"; |
23 |
|
|
host = *smersh/"host"; |
24 |
Douglas Thrift |
179 |
user = *smersh/"user"; |
25 |
Douglas Thrift |
183 |
password = *smersh/"password"; |
26 |
Douglas Thrift |
179 |
db = *smersh/"db"; |
27 |
|
|
|
28 |
Douglas Thrift |
183 |
if (debug) cerr << "driver = " << driver << "\nhost = " << host << '\n' |
29 |
|
|
<< "user = " << user << "\npassword = " << password << "\ndb = " << db |
30 |
|
|
<< '\n'; |
31 |
Douglas Thrift |
164 |
} |
32 |
Douglas Thrift |
170 |
|
33 |
|
|
void Person::query(const string& sn) |
34 |
|
|
{ |
35 |
Douglas Thrift |
183 |
ext::Handle<dbi::Connection> db(dbi::Connect(driver, host, user, password, |
36 |
|
|
this->db)); |
37 |
Douglas Thrift |
179 |
ext::Handle<dbi::ResultSet> people(db->Execute(string("SELECT name FROM pe") |
38 |
|
|
+ "ople, peopleaimmap, aim WHERE people.id=pid AND aid=aim.id AND sn=LO" |
39 |
|
|
+ "WER(\'" + sn + "\')")); |
40 |
|
|
|
41 |
|
|
if (people->MoveNext()) name = people->GetString("name"); |
42 |
|
|
|
43 |
|
|
while (people->MoveNext()) |
44 |
|
|
{ |
45 |
|
|
Person person; |
46 |
|
|
|
47 |
|
|
person.name = people->GetString("name"); |
48 |
|
|
|
49 |
|
|
multiple.push_back(person); |
50 |
|
|
} |
51 |
Douglas Thrift |
170 |
} |