ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/Smersh/Person.cpp
(Generate patch)

Comparing Smersh/Person.cpp (file contents):
Revision 170 by Douglas Thrift, 2004-06-19T21:57:10-07:00 vs.
Revision 179 by Douglas Thrift, 2004-07-02T21:16:12-07:00

# Line 8 | Line 8
8  
9   Person::Person(const string& sn) : name("Unknown Person")
10   {
11 + #ifdef __FreeBSD__
12 +        if (db.empty()) configure();
13 + #else
14          if (file.empty()) configure();
15 + #endif
16          if (!sn.empty()) query(sn);
17   }
18  
19 + #ifdef __FreeBSD__
20 + string Person::user, Person::db;
21 + #else
22   string Person::file;
23   vector<string> Person::args(1, "smersh");
24   string Person::separator, Person::begin, Person::end;
25 + #endif
26  
27   void Person::configure()
28   {
29          ext::Handle<xml::Document> document(xml::Parse("smersh.xml"));
30          ext::Handle<xml::Node> smersh(*document/"smersh");
31  
32 + #ifdef __FreeBSD__
33 +        user = *smersh/"user";
34 +        db = *smersh/"db";
35 +
36 +        if (debug) cerr << "user = " << user << "\ndb = " << db << '\n';
37 + #else
38          file = *smersh/"command"/"file";
39  
40          xml::NodeSet nodes(*smersh/"command"/"arg");
# Line 47 | Line 61 | void Person::configure()
61                          << "begin = " << begin << '\n'
62                          << "end = " << end << '\n';
63          }
64 + #endif
65   }
66  
67   void Person::query(const string& sn)
68   {
69 + #ifdef __FreeBSD__
70 +        ext::Handle<dbi::Connection> db(dbi::Connect(user, this->db));
71 +        ext::Handle<dbi::ResultSet> people(db->Execute(string("SELECT name FROM pe")
72 +                + "ople, peopleaimmap, aim WHERE people.id=pid AND aid=aim.id AND sn=LO"
73 +                + "WER(\'" + sn + "\')"));
74 +
75 +        if (people->MoveNext()) name = people->GetString("name");
76 +
77 +        while (people->MoveNext())
78 +        {
79 +                Person person;
80 +
81 +                person.name = people->GetString("name");
82 +
83 +                multiple.push_back(person);
84 +        }
85 + #else
86          vector<string> args(Person::args);
87          
88          args.push_back(string("SELECT name FROM people, peopleaimmap, aim WHERE p")
89 <                + "eople.id=pid AND aid = aim.id AND sn = LOWER(\'" + sn + "\');");
89 >                + "eople.id=pid AND aid=aim.id AND sn=LOWER(\'" + sn + "\');");
90          
91          ipstream sql(file, args);
92          bool first(true);
# Line 90 | Line 122 | void Person::query(const string& sn)
122                  else break;
123          }
124          while (sql.good());
125 + #endif
126   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines