1 |
// Smersh |
2 |
// |
3 |
// Douglas Thrift |
4 |
// |
5 |
// $Id$ |
6 |
|
7 |
#include "Person.hpp" |
8 |
|
9 |
Person::Person(const string& sn) : name("Unknown Person") |
10 |
{ |
11 |
if (driver.empty()) configure(); |
12 |
if (!sn.empty()) query(sn); |
13 |
} |
14 |
|
15 |
string Person::driver, Person::host, Person::user, Person::password, Person::db; |
16 |
|
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 |
driver = ext::String(*smersh/"driver"); |
23 |
host = ext::String(*smersh/"host"); |
24 |
user = ext::String(*smersh/"user"); |
25 |
password = ext::String(*smersh/"password"); |
26 |
db = ext::String(*smersh/"db"); |
27 |
|
28 |
if (Smersh::debug) std::cerr << "driver = " << driver << "\nhost = " << host << '\n' |
29 |
<< "user = " << user << "\npassword = " << password << "\ndb = " << db |
30 |
<< '\n'; |
31 |
} |
32 |
|
33 |
void Person::query(const string& sn) |
34 |
{ |
35 |
ext::Handle<dbi::Driver> driver(dbi::GetDriver(this->driver)); |
36 |
ext::Handle<dbi::Connection> db(driver->Connect(host, user, password, |
37 |
this->db)); |
38 |
ext::Handle<dbi::ResultSet> people(db->Execute("SELECT name FROM people, " |
39 |
"peopleaimmap, aim WHERE people.id=pid AND aid=aim.id AND sn=LOWER(\'" |
40 |
+ sn + "\')")); |
41 |
|
42 |
if (people->MoveNext()) name = people->GetString("name"); |
43 |
|
44 |
while (people->MoveNext()) |
45 |
{ |
46 |
Person person; |
47 |
|
48 |
person.name = people->GetString("name"); |
49 |
|
50 |
multiple.InsertLast(person); |
51 |
} |
52 |
} |