本文整理汇总了C++中Statement::GetField方法的典型用法代码示例。如果您正苦于以下问题:C++ Statement::GetField方法的具体用法?C++ Statement::GetField怎么用?C++ Statement::GetField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Statement
的用法示例。
在下文中一共展示了Statement::GetField方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TableExists
bool Db::TableExists(const SQDB_CHAR* tableName)
{
QueryStr str;
Statement s =
Query(
str.Format(SQDB_MAKE_TEXT("select count(*) from sqlite_master where type='table' and name='%s';"), tableName));
s.Next();
const int count = s.GetField(0);
return count > 0;
}
示例2: read_SMC_sets_from_database
bool AbcSmc::read_SMC_sets_from_database (sqdb::Db &db, vector< vector<int> > &serials) {
// make sure database looks intact
if ( !db.TableExists("jobs") or !db.TableExists("parameters") or !db.TableExists("metrics") ) {
cerr << "ERROR: Failed to read SMC set from database because one or more tables are missing.\n";
return false;
}
// make sure set t is a completed set
QueryStr qstr;
Statement s = db.Query("select smcSet, count(*), COUNT(case status when 'D' then 1 else null end) from jobs group by smcSet order by smcSet;");
serials.clear();
_particle_parameters.clear();
_particle_metrics.clear();
while (s.Next()) {
int t = s.GetField(0);
int set_size = s.GetField(1);
int completed_set_size = s.GetField(2);
if (set_size != completed_set_size) {
cerr << "ERROR: Failed to read SMC set from database because not all particles are complete in set " << t << "\n";
return false;
}
_particle_parameters.push_back( Mat2D::Zero( completed_set_size, npar() ) );
_particle_metrics.push_back( Mat2D::Zero( completed_set_size, nmet() ) );
// join all three tables for rows with smcSet = t, slurp and store values
string select_str = "select J.serial, J.particleIdx, J.posterior, " + _build_sql_select_par_string("") + ", " + _build_sql_select_met_string()
+ "from jobs J, metrics M, parameters P where J.serial = M.serial and J.serial = P.serial "
+ "and J.smcSet = " + to_string((long long) t) + ";";
serials.push_back( vector<int>(completed_set_size) );
Statement s2 = db.Query( select_str.c_str() );
int particle_counter = 0;
vector<pair<int, int> > posterior_pairs;
while (s2.Next()) {
// not a header and #fields is correct
// first two columns are set num (t) and iteration
int offset = 3; // first values are J.serial, J.particleIdx, J.rank
const int serial = s2.GetField(0);
const int particle_idx = s2.GetField(1);
const int posterior_rank = s2.GetField(2);
if (particle_counter != particle_idx) cerr << "ERROR: particle_counter != particle_idx (" << particle_counter << " != " << particle_idx << ")\n";
assert(particle_counter == particle_idx);
serials[t][particle_counter] = serial;
if (posterior_rank > -1) posterior_pairs.push_back(make_pair( posterior_rank, particle_idx ) );
for(int i=offset; i < offset + npar(); i++) _particle_parameters[t](particle_counter,i-offset) = (double) s2.GetField(i);
offset += npar();
for(int i=offset; i < offset + nmet(); i++) _particle_metrics[t](particle_counter,i-offset) = (double) s2.GetField(i);
particle_counter++;
}
const int posterior_size = posterior_pairs.size() > 0 ? posterior_pairs.size() : _predictive_prior_size;
_predictive_prior.push_back( vector<int>(posterior_size) );
if (posterior_pairs.size() > 0) {
for (unsigned int i = 0; i < posterior_pairs.size(); i++) {
const int rank = posterior_pairs[i].first;
const int idx = posterior_pairs[i].second;
_predictive_prior.back()[rank] = idx;
}
} else {
cerr << double_bar << endl << "Set " << t << endl << double_bar << endl;
_filter_particles( t, _particle_metrics[t], _particle_parameters[t] );
vector<string> update_strings(_predictive_prior_size);
for (int i = 0; i < _predictive_prior_size; i++) { // best to worst performing particle in posterior?
const int particle_idx = _predictive_prior[t][i];
const int particle_serial = serials[t][particle_idx];
stringstream ss;
ss << "update jobs set posterior = " << i << " where serial = " << particle_serial << ";";
update_strings[i] = ss.str();
}
_db_execute_strings(db, update_strings);
}
calculate_predictive_prior_weights( t );
}
return true;
}