template <typename T, typename X> void static_matrix<T, X>::forget_last_columns(unsigned how_many_to_forget) { lean_assert(m_columns.size() >= how_many_to_forget); unsigned j = column_count() - 1; for (; how_many_to_forget > 0; how_many_to_forget--) { remove_last_column(j --); } }
string Sql::query(string query) { if(dbSQLite==false) { // throw(QString("SqlJson::query: database not connected: "+query.toString())); } int rc; sqlite3_stmt *stmt=NULL; rc=prepare(dbSQLite,query,&stmt); if(rc!=SQLITE_OK) { // throw(errmsg(dbSQLite)+": "+query.toString()); } rc=step(stmt); if(rc!=SQLITE_DONE) if(rc!=SQLITE_OK) if(rc!=SQLITE_ROW) { // throw(errmsg(dbSQLite)+": "+query.toString()); } int numCols=column_count(stmt); while(rc==SQLITE_ROW) { for(int i=0;i<numCols;i++) { column_text(stmt,i); } rc=step(stmt); } finalize(stmt); return(""); }
void ResultResponse::decode_first_row() { if (row_count_ > 0 && metadata_ && // Valid metadata required for column count first_row_.values.empty()) { // Only decode the first row once first_row_.values.reserve(column_count()); rows_ = decode_row(rows_, this, first_row_.values); } }
template <typename T, typename X> T static_matrix<T, X>::dot_product_with_column(const std::vector<T> & y, unsigned j) const { lean_assert(j < column_count()); T ret = numeric_traits<T>::zero(); for (auto & it : m_columns[j]) { ret += y[it.m_i] * it.m_value; // get_value_of_column_cell(it); } return ret; }
int statement::column_index(string_t const& name) const { for (int c = 0, cc = column_count(); c < cc; ++c) { if ( name == column_name(c) ) return c; } throw no_such_column(name); }
std::string get_text(int column) { if (column >= column_count()) { throw Sqlite::Exception("Column larger than max columns", ""); } const char* textptr = reinterpret_cast<const char*>(sqlite3_column_text(m_statement, column)); if (!textptr) { throw Sqlite::Exception("Error reading text column", m_db.errmsg()); } return std::string(textptr); }
void write_header(std::ostream &out, char column_delimiter = '|', char end_line_delimiter = '\n') const { if(column_count()) { Table_header_t const& header(meta_data_.header()); Table_header_t::const_iterator it(header.begin()); Table_header_t::const_iterator end(--header.end()); for(; it != end; ++it) { out << *it << column_delimiter; } out << *it << end_line_delimiter; } }
template <typename T, typename X> unsigned static_matrix<T, X>::lowest_row_in_column(unsigned col) { lean_assert(col < column_count()); column_strip & colstrip = m_columns[col]; lean_assert(colstrip.size() > 0); unsigned ret = 0; for (auto & t : colstrip) { if (t.m_i > ret) { ret = t.m_i; } } return ret; }
bool matrix<T, X>::is_equal(const matrix<T, X>& other) { if (other.row_count() != row_count() || other.column_count() != column_count()) return false; for (unsigned i = 0; i < row_count(); i++) { for (unsigned j = 0; j < column_count(); j++) { auto a = get_elem(i, j); auto b = other.get_elem(i, j); if (numeric_traits<T>::precise()) { if (a != b) return false; } else if (fabs(numeric_traits<T>::get_double(a - b)) > 0.000001) { // cout << "returning false from operator== of matrix comparison" << endl; // cout << "this matrix is " << endl; // print_matrix(*this); // cout << "other matrix is " << endl; // print_matrix(other); return false; } } } return true; }
/** * initializes and loads world map * @*path: path to map text file * RETURNS: returns 0 if all goes well, 1 if there was an error */ int initialize_world_map(char *path) { int nrows, ncolumns, i; nrows = row_count(path); ncolumns = column_count(path); worldMap.map = malloc( (nrows+1) * sizeof(int *)); for (i=0; i<nrows; i++) { worldMap.map[i] = malloc(ncolumns * sizeof(int)); } worldMap.map[nrows] = NULL; load_map_from_file(path, ncolumns); return 0; }
template <typename T, typename X> void static_matrix<T, X>::set(unsigned row, unsigned col, T const & val) { if (numeric_traits<T>::is_zero(val)) return; lean_assert(row < row_count() && col < column_count()); #ifdef LEAN_DEBUG pair<unsigned, unsigned> p(row, col); lean_assert(m_domain.find(p) == m_domain.end()); m_domain.insert(p); #endif auto & r = m_rows[row]; unsigned offs_in_cols = m_columns[col].size(); m_columns[col].push_back(make_column_cell(row, r.size(), val)); r.push_back(make_row_cell(col, offs_in_cols, val)); }
/// Finds a column by name. /// /// \param name The name of the column to search for. /// /// \return The column identifier. /// /// \throw value_error If the name cannot be found. int sqlite::statement::column_id(const char* name) { std::map< std::string, int >& cache = _pimpl->column_cache; if (cache.empty()) { for (int i = 0; i < column_count(); i++) { const std::string aux_name = column_name(i); INV(cache.find(aux_name) == cache.end()); cache[aux_name] = i; } } const std::map< std::string, int >::const_iterator iter = cache.find(name); if (iter == cache.end()) throw invalid_column_error(_pimpl->db.db_filename(), name); else return (*iter).second; }
int get_int(int column) { if (column >= column_count()) { throw Sqlite::Exception("Column larger than max columns", m_db.errmsg()); } return sqlite3_column_int(m_statement, column); }
void ResultResponse::decode_first_row() { if (row_count_ > 0) { first_row_.values.reserve(column_count()); rows_ = decode_row(rows_, this, first_row_.values); } }
bool row::has_column (int column) { return column >= 0 && column < column_count (); }
bool row::is_valid_index(const std::size_t &index) const { return index < column_count(); }
//添加记录, 当记录为空时,int,float型置为-65535,string型为 "#" int add_record(string & table_name, string col_record[]) { if(isExit_table(table_name)) { int i; int count = 0; // 记录表中属性的个数 int col_int; float col_float; string col_str; int int_count = 0; int float_count = 0; int str_count = 0; struct record new_record = { {0}, {0}, {""} }; list<table>::iterator iter = find_table(table_name); // 指向表的指示器 count = column_count(iter); for(i=0; i<count; i++) { if("" == col_record[i]) { } switch( (*iter).col_type[i] ) { case 0: break; case 1: if("" == col_record[i]) { new_record.int_x[int_count] = -65535; int_count++; } else { col_int = atoi(col_record[i].c_str() ); new_record.int_x[int_count] = col_int; int_count++; } break; case 2: if("" == col_record[i]) { new_record.float_x[float_count] = -65535; float_count++; } else { col_float = atof(col_record[i].c_str()); new_record.float_x[float_count] = col_float; float_count++; } break; case 3: if("" == col_record[i]) { new_record.string_x[str_count] = ""; str_count++; } else { col_str = col_record[i]; new_record.string_x[str_count] = col_str; str_count++; } break; default: break; } } (*iter).table_c.push_back(new_record); //将新的记录添加到表中 return 1; } else { cout << "error" << endl; return -1; } }