src/ResultSet.cpp
branchv_0
changeset 43 7f396cdb9628
parent 36 91cb012d779a
child 48 c83119110c7b
--- a/src/ResultSet.cpp	Tue Jun 02 18:40:20 2020 +0200
+++ b/src/ResultSet.cpp	Tue Jun 02 20:57:12 2020 +0200
@@ -15,6 +15,9 @@
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <sstream>
+#include <algorithm>
+
 #include <sql.h>
 #include <sqlext.h>
 
@@ -107,7 +110,17 @@
 	else throw SqlException(L"Unable to describe column " + std::to_wstring(columnNumber) + L", out of bounds, column count is " + std::to_wstring(columnCount));
 }
 
+SQLUSMALLINT ResultSet::MetaData::getColumnNumber(relpipe::writer::string_t columnName) {
+	// TODO: also case insensitive mode
+	for (SQLUSMALLINT i = 0; i < columnDescriptors.size(); i++) {
+		if (columnDescriptors[i].name == columnName) return i + 1;
+	}
 
+	std::wstringstream errorMessage;
+	errorMessage << L"Unable to find column with name „" << columnName.c_str() << L"“ Availalable columns are: ";
+	for (MetaData::ColumnDescriptor cd : columnDescriptors) errorMessage << L"„" << cd.name.c_str() << L"“ ";
+	throw SqlException(errorMessage.str());
+}
 
 }
 }