本文整理汇总了C++中TConfig::at方法的典型用法代码示例。如果您正苦于以下问题:C++ TConfig::at方法的具体用法?C++ TConfig::at怎么用?C++ TConfig::at使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TConfig
的用法示例。
在下文中一共展示了TConfig::at方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fieldSeek
bool MTable::fieldSeek( int row, TConfig &cfg )
{
vector< vector<string> > tbl;
if( tblStrct.empty() ) throw TError(TSYS::DBTableEmpty,nodePath().c_str(),_("Table is empty."));
mLstUse = time(NULL);
string sid;
//> Make WHERE
string req = "SELECT ";
string req_where = "WHERE ";
//>> Add use keys to list
bool first_sel = true, next = false, trPresent = false;
for( unsigned i_fld = 1; i_fld < tblStrct.size(); i_fld++ )
{
sid = tblStrct[i_fld][1];
TCfg *u_cfg = cfg.at(sid,true);
if( !cfg.noTransl() && !u_cfg && sid.size() > 3 && sid.substr(0,3) == (Mess->lang2Code()+"#") )
{
u_cfg = cfg.at(sid.substr(3),true);
if( u_cfg && !(u_cfg->fld().flg()&TCfg::TransltText) ) continue;
trPresent = true;
}
if( !u_cfg ) continue;
if( u_cfg->fld().flg()&TCfg::Key && u_cfg->keyUse() )
{
req_where = req_where + (next?" AND \"":"\"") + mod->sqlReqCode(sid,'"') + "\"='" + mod->sqlReqCode(getVal(*u_cfg)) + "' ";
next = true;
}
else if( u_cfg->fld().flg()&TCfg::Key || u_cfg->view() )
{
req = req + (first_sel?"\"":",\"")+mod->sqlReqCode(sid,'"')+"\"";
first_sel = false;
}
}
//> Request
if( first_sel ) return false;
req = req + " FROM '" + mod->sqlReqCode(name()) + "' " + ((next)?req_where:"") + " LIMIT " + TSYS::int2str(row) + ",1;";
owner().sqlReq(req, &tbl/*, false*/); // For seek to deletion into save context do not set to "false"
if( tbl.size() < 2 ) return false;
//> Processing of query
for( unsigned i_fld = 0; i_fld < tbl[0].size(); i_fld++ )
{
sid = tbl[0][i_fld];
TCfg *u_cfg = cfg.at(sid,true);
if( u_cfg ) setVal(*u_cfg,tbl[1][i_fld]);
else if( trPresent && sid.size() > 3 && sid.substr(0,3) == (Mess->lang2Code()+"#") && tbl[1][i_fld].size() )
{
u_cfg = cfg.at(sid.substr(3),true);
if( u_cfg ) setVal(*u_cfg,tbl[1][i_fld]);
}
}
return true;
}
示例2: fieldGet
void MTable::fieldGet( TConfig &cfg )
{
vector< vector<string> > tbl;
if( tblStrct.empty() ) throw TError(TSYS::DBTableEmpty,nodePath().c_str(),_("Table is empty."));
mLstUse = time(NULL);
string sid;
//> Prepare request
string req = "SELECT ";
string req_where, first_key;
//>> Add fields list to queue
bool first_sel = true, next_wr = false, trPresent = false;
for(unsigned i_fld = 1; i_fld < tblStrct.size(); i_fld++)
{
sid = tblStrct[i_fld][1];
TCfg *u_cfg = cfg.at(sid,true);
if(!cfg.noTransl() && !u_cfg && sid.size() > 3 && sid.substr(0,3) == (Mess->lang2Code()+"#"))
{
u_cfg = cfg.at(sid.substr(3),true);
if(u_cfg && !(u_cfg->fld().flg()&TCfg::TransltText)) continue;
trPresent = true;
}
if(!u_cfg) continue;
if(u_cfg->fld().flg()&TCfg::Key)
{
req_where = req_where + (next_wr?" AND \"":"\"") + mod->sqlReqCode(sid,'"') + "\"='" + mod->sqlReqCode(getVal(*u_cfg)) + "'";
if(first_key.empty()) first_key = mod->sqlReqCode(sid,'"');
next_wr = true;
}
else if(u_cfg->view())
{
req = req + (first_sel?"\"":",\"") + mod->sqlReqCode(sid,'"') + "\"";
first_sel = false;
}
}
if(first_sel) req += "\""+first_key+"\"";
req = req + " FROM '" + mod->sqlReqCode(name()) + "' WHERE " + req_where + ";";
//> Query
owner().sqlReq(req, &tbl, false);
if( tbl.size() < 2 ) throw TError(TSYS::DBRowNoPresent,nodePath().c_str(),_("Row is not present."));
//> Processing of query
for( unsigned i_fld = 0; i_fld < tbl[0].size(); i_fld++ )
{
sid = tbl[0][i_fld];
TCfg *u_cfg = cfg.at(sid,true);
if( u_cfg ) setVal(*u_cfg,tbl[1][i_fld]);
else if( trPresent && sid.compare(0,3,Mess->lang2Code()+"#") == 0 && tbl[1][i_fld].size() )
{
u_cfg = cfg.at(sid.substr(3),true);
if( u_cfg && u_cfg->fld().flg()&TCfg::TransltText && !u_cfg->noTransl() ) setVal(*u_cfg,tbl[1][i_fld]);
}
}
}
示例3: fieldGet
void MTable::fieldGet( TConfig &cfg )
{
vector< vector<string> > tbl;
if(tblStrct.empty()) throw TError(nodePath().c_str(), _("Table is empty."));
mLstUse = SYS->sysTm();
string sid;
//Prepare request
string req = "SELECT ";
string req_where, first_key;
// Add fields list to queue
bool first_sel = true, next_wr = false, trPresent = false;
for(unsigned i_fld = 1; i_fld < tblStrct.size(); i_fld++) {
sid = tblStrct[i_fld][1];
TCfg *u_cfg = cfg.at(sid,true);
if(!u_cfg && !Mess->translDyn() && sid.compare(0,3,Mess->lang2Code()+"#") == 0) {
u_cfg = cfg.at(sid.substr(3), true);
if(u_cfg && !(u_cfg->fld().flg()&TCfg::TransltText)) continue;
trPresent = true;
}
if(!u_cfg) continue;
if(u_cfg->isKey()) {
req_where += (next_wr?" AND \"":"\"") + mod->sqlReqCode(sid,'"') + "\"=" + getVal(*u_cfg);
if(first_key.empty()) first_key = mod->sqlReqCode(sid,'"');
next_wr = true;
}
else if(u_cfg->view()) {
req += (first_sel?"\"":",\"") + mod->sqlReqCode(sid,'"') + "\"";
first_sel = false;
}
}
if(first_sel) req += "\""+first_key+"\"";
req += " FROM '" + mod->sqlReqCode(name()) + "' WHERE " + req_where + ";";
//Query
owner().sqlReq(req, &tbl, false);
if(tbl.size() < 2) throw TError(nodePath().c_str(), _("Row \"%s\" is not present."), req_where.c_str());
//Processing of query
for(unsigned i_fld = 0; i_fld < tbl[0].size(); i_fld++) {
sid = tbl[0][i_fld];
TCfg *u_cfg = cfg.at(sid, true);
if(u_cfg) setVal(*u_cfg, tbl[1][i_fld]);
else if(trPresent && sid.compare(0,3,Mess->lang2Code()+"#") == 0 && tbl[1][i_fld].size() && (u_cfg=cfg.at(sid.substr(3),true)))
setVal(*u_cfg, tbl[1][i_fld], true);
}
}
示例4: fieldDel
void MTable::fieldDel( TConfig &cfg )
{
if(tblStrct.empty()) return;
mLstUse = SYS->sysTm();
//Where prepare
string req_where = "WHERE ";
bool next = false;
for(unsigned i_fld = 1; i_fld < tblStrct.size(); i_fld++) {
string sid = tblStrct[i_fld][1];
TCfg *u_cfg = cfg.at(sid, true);
if(u_cfg && u_cfg->isKey() && u_cfg->keyUse()) {
req_where += (next?" AND \"":"\"") + mod->sqlReqCode(sid,'"') + "\"=" + getVal(*u_cfg) + " ";
next = true;
}
}
//Main request
try { owner().sqlReq("DELETE FROM '"+mod->sqlReqCode(name())+"' "+req_where+";", NULL, true); }
catch(TError err) {
//Check for present
vector< vector<string> > tbl;
owner().sqlReq("SELECT 1 FROM '"+mod->sqlReqCode(name())+"' "+req_where+";", &tbl, true);
if(tbl.size() < 2) return;
}
}
示例5: fieldGet
void MTable::fieldGet( TConfig &cfg )
{
MtxAlloc resource(owner().connRes, true);
if(!owner().enableStat()) return;
mLstUse = SYS->sysTm();
vector<string> cf_el;
//Request preparing
cfg.cfgList(cf_el);
char *attrs[cf_el.size()+1];
string fltr; int fltrN = 0;
for(unsigned iC = 0, iA = 0; iC < cf_el.size(); iC++) {
TCfg &cf = cfg.cfg(cf_el[iC]);
if(cf.isKey()) { fltr += "("+cf_el[iC]+"="+getVal(cf)+")"; fltrN++; }
else if(cf.view()) {
attrs[iA++] = (char*)cf_el[iC].c_str(); attrs[iA] = NULL;
setVal(cf, ""); //Clear from previous value
}
}
if(fltrN > 1) fltr = "&"+fltr;
if(fltr.empty()) fltr = "(objectclass=*)";
//Request
int rez;
LDAPMessage *result = NULL, *entry;
try {
if((rez=ldap_search_s(owner().ldp,("ou="+name()+","+owner().bdn).c_str(),LDAP_SCOPE_ONE,fltr.c_str(),attrs,0,&result)) != LDAP_SUCCESS)
throw err_sys(_("SEARCH: %s"), ldap_err2string(rez));
if(!ldap_count_entries(owner().ldp,result) || !(entry=ldap_first_entry(owner().ldp,result)))
throw err_sys(_("Entry \"%s\" is not present."), fltr.c_str());
char *a, **vals;
BerElement *ber;
for(a = ldap_first_attribute(owner().ldp,entry,&ber); a != NULL; a = ldap_next_attribute(owner().ldp,entry,ber)) {
string attr = a;
ldap_memfree(a);
string val;
if((vals=ldap_get_values(owner().ldp,entry,attr.c_str())) != NULL) {
for(int iV = 0; vals[iV] != NULL; iV++) val += vals[iV];
ldap_value_free(vals);
}
TCfg *cf = NULL; //cfg.at(attr, true);
for(unsigned iC = 0; iC < cf_el.size() && !cf; iC++)
if(strcasecmp(attr.c_str(),cf_el[iC].c_str()) == 0) { cf = cfg.at(cf_el[iC], true); attr = cf_el[iC]; }
if(cf) setVal(*cf, val);
}
ldap_msgfree(result);
}
catch(TError&) {
if(result) ldap_msgfree(result);
throw;
}
}
示例6: fieldSet
void MTable::fieldSet( TConfig &cfg )
{
MtxAlloc resource(owner().connRes, true);
if(!owner().enableStat()) return;
mLstUse = SYS->sysTm();
vector<string> cf_el;
//Find for need entry
// Request preparing
cfg.cfgList(cf_el);
char *attrs[cf_el.size()+1];
LDAPMod mods[cf_el.size()];
LDAPMod *mods_[cf_el.size()+1]; mods_[0] = NULL;
string vals[cf_el.size()];
char *vals_[cf_el.size()][2];
string fltr; int fltrN = 0;
for(unsigned iC = 0, iA = 0; iC < cf_el.size(); iC++) {
TCfg &cf = cfg.cfg(cf_el[iC]);
if(cf.isKey()) { fltr += "("+cf_el[iC]+"="+getVal(cf)+")"; fltrN++; }
else if(cf.view()) { attrs[iA++] = (char*)cf_el[iC].c_str(); attrs[iA] = NULL; }
}
if(fltrN > 1) fltr = "&"+fltr;
if(fltr.empty()) fltr = "(objectclass=*)";
// Request
int rez;
LDAPMessage *result = NULL, *entry;
char *chDN = NULL;
try {
if((rez=ldap_search_s(owner().ldp,("ou="+name()+","+owner().bdn).c_str(),LDAP_SCOPE_ONE,fltr.c_str(),attrs,0,&result)) != LDAP_SUCCESS)
throw err_sys(_("SEARCH: %s"), ldap_err2string(rez));
if(!ldap_count_entries(owner().ldp,result) || !(entry=ldap_first_entry(owner().ldp,result))) {
ldap_msgfree(result);
throw err_sys(_("Entry \"%s\" is not present."), fltr.c_str());
}
//Get DN of the entry
chDN = ldap_get_dn(owner().ldp, entry);
if(!chDN) throw err_sys(_("Get DN of the entry \"%s\" error."), fltr.c_str());
//Check for changed attributes of the entry to replace their.
int iA = 0;
char *a, **tvals;
BerElement *ber;
for(a = ldap_first_attribute(owner().ldp,entry,&ber); a != NULL; a = ldap_next_attribute(owner().ldp,entry,ber)) {
string attr = a;
ldap_memfree(a);
string val;
if((tvals=ldap_get_values(owner().ldp,entry,attr.c_str())) != NULL) {
for(int iV = 0; tvals[iV] != NULL; iV++) val += tvals[iV];
ldap_value_free(tvals);
}
TCfg *cf = NULL; //cfg.at(attr, true);
unsigned iC = 0;
for( ; iC < cf_el.size(); iC++)
if(strcasecmp(attr.c_str(),cf_el[iC].c_str()) == 0) { cf = cfg.at(cf_el[iC], true); attr = cf_el[iC]; break; }
if(cf && (vals[iA]=getVal(*cf)) != val) {
vals_[iA][0] = (char*)vals[iA].c_str(); vals_[iA][1] = NULL;
mods[iA].mod_op = LDAP_MOD_REPLACE;
mods[iA].mod_type = (char*)cf_el[iC].c_str();
mods[iA].mod_values = vals_[iA];
mods_[iA] = &mods[iA]; mods_[++iA] = NULL;
}
}
//Call the generic modify request
if((rez=ldap_modify_s(owner().ldp,chDN,mods_)) != LDAP_SUCCESS)
throw err_sys(_("MODIFY: %s"), ldap_err2string(rez));
ldap_memfree(chDN);
ldap_msgfree(result);
}
catch(TError&) {
if(chDN) ldap_memfree(chDN);
if(result) ldap_msgfree(result);
throw;
}
}
示例7: fieldSeek
bool MTable::fieldSeek( int row, TConfig &cfg, vector< vector<string> > *full )
{
MtxAlloc resource(owner().connRes, true);
if(!owner().enableStat()) return false;
mLstUse = SYS->sysTm();
vector< vector<string> > inTbl,
&tbl = full ? *full : inTbl;
//Request
if(!full || !full->size() || row == 0) {
tbl.clear();
vector<string> row, cf_el;
// Request preparing
map<string,int> headers;
cfg.cfgList(cf_el);
char *attrs[cf_el.size()+1];
row.reserve(cf_el.size());
string fltr; int fltrN = 0;
for(unsigned iC = 0, iA = 0; iC < cf_el.size(); iC++) {
TCfg &cf = cfg.cfg(cf_el[iC]);
if(cf.isKey() && cf.keyUse()) { fltr += "("+cf_el[iC]+"="+getVal(cf)+")"; fltrN++; }
else if(cf.isKey() || cf.view()) {
headers[cf_el[iC]] = row.size();
row.push_back(cf_el[iC]);
attrs[iA++] = (char*)cf_el[iC].c_str(); attrs[iA] = NULL;
}
}
tbl.push_back(row);
if(fltrN > 1) fltr = "&"+fltr;
if(fltr.empty())fltr = "(objectclass=*)";
// Request
LDAPMessage *result, *entry;
if(ldap_search_s(owner().ldp,("ou="+name()+","+owner().bdn).c_str(),LDAP_SCOPE_ONE,fltr.c_str(),attrs,0,&result) != LDAP_SUCCESS) return false;
for(entry = ldap_first_entry(owner().ldp,result); entry; entry = ldap_next_entry(owner().ldp,entry)) {
row.clear(); row.resize(headers.size());
char *a, **vals;
BerElement *ber;
bool entrMatch = true;
for(a = ldap_first_attribute(owner().ldp,entry,&ber); a != NULL && entrMatch; a = ldap_next_attribute(owner().ldp,entry,ber)) {
string attr = a;
ldap_memfree(a);
string val;
if((vals=ldap_get_values(owner().ldp,entry,attr.c_str())) != NULL) {
for(int iV = 0; vals[iV] != NULL; iV++) val += vals[iV];
ldap_value_free(vals);
}
TCfg *cf = NULL; //cfg.at(attr, true);
for(unsigned iC = 0; iC < cf_el.size() && !cf; iC++)
if(strcasecmp(attr.c_str(),cf_el[iC].c_str()) == 0) { cf = cfg.at(cf_el[iC], true); attr = cf_el[iC]; }
if(cf) {
if(cf->isKey() && (val.empty() || (cf->keyUse() && getVal(*cf) != val))) entrMatch = false;
if(headers.find(attr) != headers.end()) row[headers[attr]] = val;
}
}
if(entrMatch) {
// Late checking for keys
for(unsigned iC = 0; iC < cf_el.size() && entrMatch; iC++) {
TCfg &cf = cfg.cfg(cf_el[iC]);
if(cf.isKey() && !cf.keyUse() && row[headers[cf_el[iC]]].empty()) entrMatch = false;
}
if(entrMatch) tbl.push_back(row);
}
}
ldap_msgfree(result);
}
if(tbl.size() < 2 || (full && (row+1) >= tbl.size())) return false;
//Processing of the query
row = full ? row+1 : 1;
for(unsigned iFld = 0; iFld < tbl[0].size(); iFld++) {
string sid = tbl[0][iFld];
TCfg *cf = cfg.at(sid, true);
if(cf) setVal(*cf, tbl[row][iFld]);
}
return true;
}
示例8: fieldSeek
bool MTable::fieldSeek( int row, TConfig &cfg )
{
vector< vector<string> > tbl;
if(tblStrct.empty()) throw TError(nodePath().c_str(), _("Table is empty."));
mLstUse = SYS->sysTm();
//Check for no present and no empty keys allow
if(row == 0) {
vector<string> cf_el;
cfg.cfgList(cf_el);
for(unsigned i_c = 0; i_c < cf_el.size(); i_c++) {
TCfg &cf = cfg.cfg(cf_el[i_c]);
if(!cf.isKey() || !cf.getS().size()) continue;
unsigned i_fld = 1;
for( ; i_fld < tblStrct.size(); i_fld++)
if(cf.name() == tblStrct[i_fld][1]) break;
if(i_fld >= tblStrct.size()) return false;
}
}
string sid;
//Make WHERE
string req = "SELECT ";
string req_where = "WHERE ";
// Add use keys to list
bool first_sel = true, next = false, trPresent = false;
for(unsigned i_fld = 1; i_fld < tblStrct.size(); i_fld++) {
sid = tblStrct[i_fld][1];
TCfg *u_cfg = cfg.at(sid,true);
if(!u_cfg && !Mess->translDyn() && sid.compare(0,3,Mess->lang2Code()+"#") == 0) {
u_cfg = cfg.at(sid.substr(3),true);
if(u_cfg && !(u_cfg->fld().flg()&TCfg::TransltText)) continue;
trPresent = true;
}
if(!u_cfg) continue;
if(u_cfg->isKey() && u_cfg->keyUse()) {
req_where += (next?" AND \"":"\"") + mod->sqlReqCode(sid,'"') + "\"=" + getVal(*u_cfg) + " ";
next = true;
}
else if(u_cfg->isKey() || u_cfg->view()) {
req += (first_sel?"\"":",\"")+mod->sqlReqCode(sid,'"')+"\"";
first_sel = false;
}
}
//Request
if(first_sel) return false;
req += " FROM '" + mod->sqlReqCode(name()) + "' " + ((next)?req_where:"") + " LIMIT " + i2s(row) + ",1;";
owner().sqlReq(req, &tbl/*, false*/); // For seek to deletion into save context do not set to "false"
if(tbl.size() < 2) return false;
//Processing of the query
for(unsigned i_fld = 0; i_fld < tbl[0].size(); i_fld++) {
sid = tbl[0][i_fld];
TCfg *u_cfg = cfg.at(sid, true);
if(u_cfg) setVal(*u_cfg, tbl[1][i_fld]);
else if(trPresent && sid.compare(0,3,Mess->lang2Code()+"#") == 0 && tbl[1][i_fld].size() && (u_cfg=cfg.at(sid.substr(3),true)))
setVal(*u_cfg, tbl[1][i_fld], true);
}
return true;
}
示例9: fieldSeek
bool MTable::fieldSeek( int row, TConfig &cfg, vector< vector<string> > *full )
{
vector< vector<string> > inTbl,
&tbl = full ? *full : inTbl;
if(tblStrct.empty()) throw err_sys(_("Table is empty."));
mLstUse = SYS->sysTm();
//Check for not present and not empty keys allow
if(row == 0) {
vector<string> cf_el;
cfg.cfgList(cf_el);
for(unsigned iC = 0; iC < cf_el.size(); iC++) {
TCfg &cf = cfg.cfg(cf_el[iC]);
if(!cf.isKey() || !cf.getS().size()) continue;
unsigned iFld = 1;
for( ; iFld < tblStrct.size(); iFld++)
if(cf.name() == tblStrct[iFld][1]) break;
if(iFld >= tblStrct.size()) return false;
}
}
string sid;
//Make WHERE
string req = "SELECT ";
string req_where = "WHERE ";
// Add use keys to list
bool first_sel = true, next = false, trPresent = false;
for(unsigned iFld = 1; iFld < tblStrct.size(); iFld++) {
sid = tblStrct[iFld][1];
TCfg *u_cfg = cfg.at(sid, true);
if(!u_cfg && !Mess->translDyn() && sid.compare(0,3,Mess->lang2Code()+"#") == 0) {
u_cfg = cfg.at(sid.substr(3),true);
if(u_cfg && !(u_cfg->fld().flg()&TFld::TransltText)) continue;
trPresent = true;
}
if(!u_cfg) continue;
if(u_cfg->isKey() && u_cfg->keyUse()) {
req_where += (next?" AND \"":"\"") + TSYS::strEncode(sid,TSYS::SQL,"\"") + "\"=" + getVal(*u_cfg) + " ";
next = true;
}
else if(u_cfg->isKey() || u_cfg->view()) {
req += (first_sel?"\"":",\"")+TSYS::strEncode(sid,TSYS::SQL,"\"")+"\"";
first_sel = false;
}
}
//Request
if(!full || !full->size() || (row%SEEK_PRELOAD_LIM) == 0) {
if(first_sel) return false;
req += " FROM '" + TSYS::strEncode(name(),TSYS::SQL,"'") + "' " + ((next)?req_where:"");
if(!full) req += " LIMIT " + i2s(row) + ",1";
else req += " LIMIT " + i2s((row/SEEK_PRELOAD_LIM)*SEEK_PRELOAD_LIM) + "," + i2s(SEEK_PRELOAD_LIM);
req += ";";
tbl.clear();
owner().sqlReq(req, &tbl/*, false*/); // For seek to deletion into save context do not set to "false"
}
row = full ? (row%SEEK_PRELOAD_LIM)+1 : 1;
if(tbl.size() < 2 || (full && row >= (int)tbl.size())) return false;
//Processing of the query
for(unsigned iFld = 0; iFld < tbl[0].size(); iFld++) {
sid = tbl[0][iFld];
TCfg *u_cfg = cfg.at(sid, true);
if(u_cfg) setVal(*u_cfg, tbl[row][iFld]);
else if(trPresent && sid.compare(0,3,Mess->lang2Code()+"#") == 0 && tbl[row][iFld].size() && (u_cfg=cfg.at(sid.substr(3),true)))
setVal(*u_cfg, tbl[row][iFld], true);
}
return true;
}