void DatabaseStorage::write(SerializableObject<T>& object) { std::stringstream ss; int nr, nc; nr = nc = 0; if (typeid(arma::mat) == typeid(object.variable_) || typeid(arma::umat) == typeid(object.variable_)) { nr = object.variable_.n_rows; nc = object.variable_.n_cols; } else { nr = nc = 1; } ss << object.variable_; if (!existTable()) return; mysqlpp::Connection con; if (!connectToDatabase(con)) return; try { mysqlpp::Query query = con.query(); query << "INSERT INTO Store (file, variable, data, nrows, ncols) VALUES(\"" << object.fileName_ << "\", \"" << object.variableName_ << "\", \"" << mysqlpp::escape << ss.str() << "\", " << nr << ", " << nc << ")"; mysqlpp::SimpleResult res = query.execute(); } catch (const mysqlpp::BadQuery& er) { std::cerr << "Query error: " << er.what() << std::endl; return; } catch(const std::exception& er) { // Catch-all for any other MySQL++ exceptions std::cerr << "Error: " << er.what() << std::endl; return; } }
/* * * init function creates database with specified name and makes a connection * which is stored in private variable mysqlpp::Connection connection_ * * Second phase is to parse given file and store found data: nodes, lines, surfaces and recorded data * into that database. * */ bool DatabaseStorage::init(const string& file) { if (file.empty()) { std::cerr << "DatabaseStorage::init --\n"; std::cerr << "File: is empty\n"; return false; } // TODO: repository? argument "file" is not needed. string repository = Oi::stripToFileName(file); if (repository.empty()) { std::cerr << "DatabaseStorage::init --\n"; std::cerr << "Bad file name: " << file << "\n"; return false; } mysqlpp::Connection con; // noexception is needed not to throw exception when such database exist. mysqlpp::NoExceptions ne(con); // try to create database and table if (!connectToDatabase(con)) { std::cout << "Database: " << DATABASE << " do not exist. Creating new one!\n"; if (!con.create_db(DATABASE)) { std::cerr << "Error creating database: " << con.error() << std::endl; return false; } if(!createTable()) { std::cerr << "Error creating table: Store.\n"; return false; } } if (!existTable()) createTable(); return true; }
void HQDeviceEnumD3D9::GetAllDisplayResolution(HQResolution *resolutionList , hq_uint32& numResolutions) { HQResolution res; HQHashTable<HQResolution , bool ,ResolutionHashFunc , ResolutonEqual> existTable(selectedAdapter->dModelist.GetSize() * 2 + 1); HQLinkedListNode<D3DDISPLAYMODE> *pRNode = selectedAdapter->dModelist.GetRoot(); if (resolutionList != NULL)//save resolutions array { hquint32 j = 0; for(hq_uint32 i = 0 ; i < selectedAdapter->dModelist.GetSize() && j < numResolutions ; ++i) { res.width = pRNode->m_element.Width; res.height = pRNode->m_element.Height; if (existTable.Add(res , true))//độ phân giải này chưa cho vào list { resolutionList[j++] = res; } pRNode = pRNode->m_pNext; } } else // count max number of resolutions { numResolutions = 0; for(hq_uint32 i = 0 ; i < selectedAdapter->dModelist.GetSize() ; ++i) { res.width = pRNode->m_element.Width; res.height = pRNode->m_element.Height; if (existTable.Add(res , true))//độ phân giải này chưa cho vào list { numResolutions ++; } pRNode = pRNode->m_pNext; } } }