bool ODBCTest::canConnect(const std::string& driver, std::string& dsn, std::string& uid, std::string& pwd, std::string& dbConnString, const std::string& db) { Utility::DriverMap::iterator itDrv = _drivers.begin(); for (; itDrv != _drivers.end(); ++itDrv) { if (((itDrv->first).find(driver) != std::string::npos)) { std::cout << "Driver found: " << itDrv->first << " (" << itDrv->second << ')' << std::endl; break; } } if (_drivers.end() == itDrv) { dsn = ""; uid = ""; pwd = ""; dbConnString = ""; std::cout << driver << " driver NOT found, tests not available." << std::endl; return false; } Utility::DSNMap dataSources; Utility::dataSources(dataSources); if (dataSources.size() > 0) { Utility::DSNMap::iterator itDSN = dataSources.begin(); std::cout << dataSources.size() << " DSNs found, enumerating ..." << std::endl; for (; itDSN != dataSources.end(); ++itDSN) { if (itDSN->first == dsn && itDSN->second == driver) { std::cout << "DSN found: " << itDSN->first << " (" << itDSN->second << ')' << std::endl; dbConnString = format("DSN=%s;UID=%s;PWD=%s;", dsn, uid, pwd); if (!db.empty()) format(dbConnString, "DATABASE=%s;", db); return true; } } } else std::cout << "No DSNs found, will attempt DSN-less connection ..." << std::endl; dsn = ""; return true; }
bool ODBCAccessTest::canConnect(const std::string& driver, const std::string& dsn) { Utility::DriverMap::iterator itDrv = _drivers.begin(); for (; itDrv != _drivers.end(); ++itDrv) { if (((itDrv->first).find(driver) != std::string::npos)) { std::cout << "Driver found: " << itDrv->first << " (" << itDrv->second << ')' << std::endl; break; } } if (_drivers.end() == itDrv) { std::cout << driver << " driver NOT found, tests not available." << std::endl; return false; } Utility::DSNMap dataSources; Utility::dataSources(dataSources); Utility::DSNMap::iterator itDSN = dataSources.begin(); for (; itDSN != dataSources.end(); ++itDSN) { if (itDSN->first == dsn && itDSN->second == driver) { std::cout << "DSN found: " << itDSN->first << " (" << itDSN->second << ')' << std::endl; format(_dbConnString, "DSN=%s", dsn); return true; } } // DSN not found, try connect without it format(_dbConnString, "DRIVER=%s;" "UID=admin;" "UserCommitSync=Yes;" "Threads=3;" "SafeTransactions=0;" "PageTimeout=5;" "MaxScanRows=8;" "MaxBufferSize=2048;" "FIL=MS Access;" "DriverId=25;" "DBQ=test.mdb;", driver); return true; }