45 SQLCHAR description[255]; |
45 SQLCHAR description[255]; |
46 memset(name, 0, sizeof (name)); |
46 memset(name, 0, sizeof (name)); |
47 memset(description, 0, sizeof (description)); |
47 memset(description, 0, sizeof (description)); |
48 SQLSMALLINT nameLength; |
48 SQLSMALLINT nameLength; |
49 SQLSMALLINT descriptionLength; |
49 SQLSMALLINT descriptionLength; |
50 while (true) { |
50 for (int i = 0; true; i++) { |
51 SQLRETURN result = SQLDataSources(environment, SQL_FETCH_NEXT, name, sizeof (name), &nameLength, description, sizeof (description), &descriptionLength); |
51 SQLRETURN result = SQLDataSources(environment, i == 0 ? SQL_FETCH_FIRST : SQL_FETCH_NEXT, |
|
52 name, sizeof (name), &nameLength, |
|
53 description, sizeof (description), &descriptionLength); |
|
54 // TODO: description field actually contains the driver name – see comments in unixODBC file: DriverManager/SQLDataSources.c |
52 // TODO: check nameLength and descriptionLength whether values were truncated? |
55 // TODO: check nameLength and descriptionLength whether values were truncated? |
53 if (OdbcCommon::isSuccessful(result)) list.push_back({convertor.from_bytes((char*) name), convertor.from_bytes((char*) description)}); |
56 if (OdbcCommon::isSuccessful(result)) list.push_back({convertor.from_bytes((char*) name), convertor.from_bytes((char*) description)}); |
54 else if (result == SQL_NO_DATA_FOUND) break; |
57 else if (result == SQL_NO_DATA_FOUND) break; |
55 else throw SqlException(L"Unable to list data sources: " + std::to_wstring(result), result, SQL_HANDLE_ENV, environment); |
58 else throw SqlException(L"Unable to list data sources: " + std::to_wstring(result), result, SQL_HANDLE_ENV, environment); |
56 } |
59 } |