📄 aliasrecord.cxx
字号:
#include "AliasRecord.hxx"
#include "Record.hxx"
#include "DBResultset.hxx"
#include "DBConnection.hxx"
#include "PGSQLConnection.hxx"
#include "RecordTypes.h"
#include "DBTypes.h"
#include "VException.hxx"
#include "cpLog.h"
#include <ctime>
AliasRecord::AliasRecord() {
setRecordType(ALIAS_RECORD);
}
AliasRecord::~AliasRecord() {}
void AliasRecord::displayRecord() {
cout << "AliasRecord.cxx: Generic Data\n";
Record::displayRecord("AliasRecord.cxx");
cout << "AliasRecord.cxx: Specific Data\n";
cout << "AliasRecord.cxx: Username: " << username << "\n";
cout << "AliasRecord.cxx: E164 ?: " << (e164?"True":"False") << "\n";
}
bool AliasRecord::populateRecord(KeyType key, DBConnection* dbconn) {
DBResultset* results;
try {
results = dbconn->DBSQLSelect( (string) " " + // (string allows '+' op)
"SELECT l.e164, a.username FROM ALIASES l, ACCOUNTS a " +
" WHERE l.alias = '" + key + "' AND l.account_id = a.id " +
";"
);
}
catch ( VException &e ) {
cpLog(LOG_ERR, "DBSQLSelect failed due to %s",e.getDescription().c_str());
return false;
}
ResultTabletype recs = results->GetRecords();
delete results; // Delete the results object in case this fails
if (recs.begin() == recs.end()){
return false; // No records
}
ResultRecordtype oneRec = *(recs.begin());
if (oneRec.begin() == oneRec.end()){
return false; // No data in record
}
// Populate the record;
setKey(key);
ResultRecordtype::iterator i;
i = oneRec.begin();
e164 = (i[0] == (string) "t") ? true : false;
setUsername(i[1]);
return true;
}
bool AliasRecord::amendRecord(DBConnection* dbconn) {
return false;
}
bool AliasRecord::deleteRecord(DBConnection* dbconn) {
return false;
}
bool AliasRecord::insertRecord(DBConnection* dbconn) {
return false;
}
KeyList AliasRecord::getAllKeys(DBConnection* dbconn) {
KeyList keys;
DBResultset* results;
try {
results = dbconn->DBSQLSelect(
"SELECT alias FROM aliases;"
);
}
catch ( VException &e ) {
cpLog(LOG_ERR, "DBSQLSelect (for getAllKeys) failed due to %s",e.getDescription().c_str());
return keys;
}
ResultTabletype recs = results->GetRecords();
delete results; // Delete the results object in case this fails
for (ResultTabletype::iterator i = recs.begin();i < recs.end();i++) {
// i should point to a single string in a list, check this
if ((*i).begin() < (*i).end()) {
// Add the first string to the key list
keys.push_back(*((*i).begin()));
}
}
return keys;
}
Record* AliasRecord::clone() {
AliasRecord* rec = new AliasRecord();
Record::copyData(rec);
rec->setUsername(username);
rec->setE164(e164);
return rec;
}
string AliasRecord::whereCondition() {
return " WHERE username ='" + key + "'";
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -