5 |
|
// $Id$ |
6 |
|
|
7 |
|
#include "Person.hpp" |
8 |
– |
#include "Matcher.hpp" // XXX use SQL |
8 |
|
|
9 |
|
Person::Person(const string& sn) : name("Unknown Person") |
10 |
|
{ |
11 |
< |
// SELECT name FROM people, peopleaimmap, aim |
12 |
< |
// WHERE people.id=pid |
13 |
< |
// AND aid=aim.id |
15 |
< |
// AND sn=LOWER($1) |
16 |
< |
|
17 |
< |
string sn_(sn); // XXX get rid of |
11 |
> |
if (driver.empty()) configure(); |
12 |
> |
if (!sn.empty()) query(sn); |
13 |
> |
} |
14 |
|
|
15 |
< |
for (string::size_type index(0); index < sn_.length(); ++index) |
20 |
< |
{ |
21 |
< |
if (isupper(sn_[index])) sn_[index] = tolower(sn_[index]); |
22 |
< |
} // XXX won't need |
15 |
> |
string Person::driver, Person::host, Person::user, Person::password, Person::db; |
16 |
|
|
17 |
< |
Matcher matcher; // XXX definitely won't need |
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 |
< |
if (sn_ == matcher("^douglaswth|dwtoliver|dwtstanley$")) |
23 |
< |
{ |
24 |
< |
name = "Douglas William Thrift"; |
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 |
< |
Person person; |
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 (sn_ == "dwtoliver") |
33 |
< |
{ |
34 |
< |
person.name = "Oliver Hardy"; |
35 |
< |
|
36 |
< |
multiple.push_back(person); |
37 |
< |
} |
38 |
< |
else if (sn_ == "dwtstanley") |
39 |
< |
{ |
40 |
< |
person.name = "Stanley Laurel"; |
42 |
> |
if (people->MoveNext()) name = people->GetString("name"); |
43 |
|
|
44 |
< |
multiple.push_back(person); |
43 |
< |
} |
44 |
< |
} |
45 |
< |
else if (sn_ == "aemoncannon") |
46 |
< |
{ |
47 |
< |
name = "Aemon Cannon"; |
48 |
< |
} |
49 |
< |
else if (sn_ == "alpineguycom") |
50 |
< |
{ |
51 |
< |
name = "Colin Curtin"; |
52 |
< |
} |
53 |
< |
else if (sn_ == "iamfayemous") |
54 |
< |
{ |
55 |
< |
name = "Courtney Faye Minteer"; |
56 |
< |
} |
57 |
< |
else if (sn_ == "shupappa") |
58 |
< |
{ |
59 |
< |
name = "David Salamon"; |
60 |
< |
} |
61 |
< |
else if (sn_ == "csreddaddy") |
62 |
< |
{ |
63 |
< |
name = "Hamid Tahsildoost"; |
64 |
< |
} |
65 |
< |
else if (sn_ == "hamlett17") |
44 |
> |
while (people->MoveNext()) |
45 |
|
{ |
46 |
< |
name = "Jackson Strobel"; |
47 |
< |
} |
48 |
< |
else if (sn_ == "saurik") |
49 |
< |
{ |
50 |
< |
name = "Jay Freeman"; |
72 |
< |
} |
73 |
< |
else if (sn_ == "crxscentfresh") |
74 |
< |
{ |
75 |
< |
name = "Jessica Landon"; |
76 |
< |
} |
77 |
< |
else if (sn_ == "sagath84") |
78 |
< |
{ |
79 |
< |
name = "Kian Wilcox"; |
80 |
< |
} |
81 |
< |
else if (sn_ == "tobasc0cat") |
82 |
< |
{ |
83 |
< |
name = "Mika McKinnon"; |
84 |
< |
} |
85 |
< |
else if (sn_ == "slurp007") |
86 |
< |
{ |
87 |
< |
name = "Rohit Gehani"; |
88 |
< |
} |
89 |
< |
else if (sn_ == "fishofgoat") |
90 |
< |
{ |
91 |
< |
name = "Seth King"; |
92 |
< |
} |
93 |
< |
else if (sn_ == "amarmoset") |
94 |
< |
{ |
95 |
< |
name = "Shawn Brenneman"; |
46 |
> |
Person person; |
47 |
> |
|
48 |
> |
person.name = people->GetString("name"); |
49 |
> |
|
50 |
> |
multiple.InsertLast(person); |
51 |
|
} |
52 |
|
} |