getDataSources() can be called multiple-times, use SQL_FETCH_FIRST and SQL_FETCH_NEXT v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Tue, 02 Jun 2020 18:40:20 +0200
branchv_0
changeset 42 7f668a5a435b
parent 41 4b2d46989f44
child 43 7f396cdb9628
getDataSources() can be called multiple-times, use SQL_FETCH_FIRST and SQL_FETCH_NEXT
src/DriverManager.cpp
--- a/src/DriverManager.cpp	Mon Jun 01 17:23:27 2020 +0200
+++ b/src/DriverManager.cpp	Tue Jun 02 18:40:20 2020 +0200
@@ -47,8 +47,11 @@
 	memset(description, 0, sizeof (description));
 	SQLSMALLINT nameLength;
 	SQLSMALLINT descriptionLength;
-	while (true) {
-		SQLRETURN result = SQLDataSources(environment, SQL_FETCH_NEXT, name, sizeof (name), &nameLength, description, sizeof (description), &descriptionLength);
+	for (int i = 0; true; i++) {
+		SQLRETURN result = SQLDataSources(environment, i == 0 ? SQL_FETCH_FIRST : SQL_FETCH_NEXT,
+				name, sizeof (name), &nameLength,
+				description, sizeof (description), &descriptionLength);
+		// TODO: description field actually contains the driver name – see comments in unixODBC file: DriverManager/SQLDataSources.c
 		// TODO: check nameLength and descriptionLength whether values were truncated?
 		if (OdbcCommon::isSuccessful(result)) list.push_back({convertor.from_bytes((char*) name), convertor.from_bytes((char*) description)});
 		else if (result == SQL_NO_DATA_FOUND) break;