src/ResultSet.cpp
branchv_0
changeset 43 7f396cdb9628
parent 36 91cb012d779a
child 48 c83119110c7b
equal deleted inserted replaced
42:7f668a5a435b 43:7f396cdb9628
    12  * GNU General Public License for more details.
    12  * GNU General Public License for more details.
    13  *
    13  *
    14  * You should have received a copy of the GNU General Public License
    14  * You should have received a copy of the GNU General Public License
    15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
    15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
    16  */
    16  */
       
    17 
       
    18 #include <sstream>
       
    19 #include <algorithm>
    17 
    20 
    18 #include <sql.h>
    21 #include <sql.h>
    19 #include <sqlext.h>
    22 #include <sqlext.h>
    20 
    23 
    21 #include "ResultSet.h"
    24 #include "ResultSet.h"
   105 ResultSet::MetaData::ColumnDescriptor ResultSet::MetaData::describeColumn(unsigned short columnNumber) {
   108 ResultSet::MetaData::ColumnDescriptor ResultSet::MetaData::describeColumn(unsigned short columnNumber) {
   106 	if (columnNumber >= 1 && columnNumber <= columnCount) return columnDescriptors[columnNumber - 1];
   109 	if (columnNumber >= 1 && columnNumber <= columnCount) return columnDescriptors[columnNumber - 1];
   107 	else throw SqlException(L"Unable to describe column " + std::to_wstring(columnNumber) + L", out of bounds, column count is " + std::to_wstring(columnCount));
   110 	else throw SqlException(L"Unable to describe column " + std::to_wstring(columnNumber) + L", out of bounds, column count is " + std::to_wstring(columnCount));
   108 }
   111 }
   109 
   112 
       
   113 SQLUSMALLINT ResultSet::MetaData::getColumnNumber(relpipe::writer::string_t columnName) {
       
   114 	// TODO: also case insensitive mode
       
   115 	for (SQLUSMALLINT i = 0; i < columnDescriptors.size(); i++) {
       
   116 		if (columnDescriptors[i].name == columnName) return i + 1;
       
   117 	}
   110 
   118 
       
   119 	std::wstringstream errorMessage;
       
   120 	errorMessage << L"Unable to find column with name „" << columnName.c_str() << L"“ Availalable columns are: ";
       
   121 	for (MetaData::ColumnDescriptor cd : columnDescriptors) errorMessage << L"„" << cd.name.c_str() << L"“ ";
       
   122 	throw SqlException(errorMessage.str());
       
   123 }
   111 
   124 
   112 }
   125 }
   113 }
   126 }
   114 }
   127 }