std::vector<Device *> ControllerDatabaseFactory::fetchDevices( const std::size_t id ) const { std::vector<Device *> devices; DatabaseStatement * statement; DatabaseResult * result; DatabaseResultRow * row; std::string query; std::size_t deviceId; query = "SELECT id " "FROM devices " "WHERE controller_id = "; query = query + std::to_string(id); statement = getDbConnection()->createStatement(query); if( statement != nullptr ) { result = statement->execute(); if( result != nullptr ) { while( result->hasNext() ) { row = result->next(); deviceId = static_cast<std::size_t>( atol(row->getColumn(0).c_str())); devices.push_back(mDeviceContainer->get(deviceId)); delete row; } delete result; } delete statement; } return ( devices ); }
std::vector<ValueType *> ValueTypeDatabaseFactory::fetchAll( void ) { DatabaseStatement * statement; DatabaseResult * result; DatabaseResultRow * row; std::vector<ValueType *> types; std::string strId; long bufferId; std::size_t id; std::string identifier; std::string name; std::string description; std::string regex; statement = getDbConnection()->createStatement( "SELECT *" "FROM value_types" ); if( statement != nullptr ) { result = statement->execute(); if( result != nullptr ) { while( result->hasNext() ) { row = result->next(); strId = row->getColumn(0); identifier = row->getColumn(1); regex = row->getColumn(2); name = row->getColumn(3); description = row->getColumn(4); bufferId = atol(strId.c_str()); id = static_cast<std::size_t>(bufferId); types.push_back( new ValueType(id,identifier,name,description,regex) ); delete row; } delete result; } delete statement; } return ( types ); }
std::vector<Controller *> ControllerDatabaseFactory::fetchAll( void ) { std::vector<Controller *> controllers; Controller * controller; DatabaseStatement * statement; DatabaseResult * result; DatabaseResultRow * row; std::string id; std::string identifier; std::string description; std::string name; std::string securityCode; statement = getDbConnection()->createStatement( "SELECT * " "FROM controllers;" ); if( statement != nullptr ) { result = statement->execute(); if( result != nullptr ) { while( result->hasNext() ) { row = result->next(); id = row->getColumn(0); identifier = row->getColumn(1); securityCode = row->getColumn(2); name = row->getColumn(3); description = row->getColumn(4); controller = allocateController(id,identifier,name, description,securityCode); controllers.push_back(controller); delete row; } delete result; } delete statement; } return ( controllers ); }