00001 // 00002 // File: src/handle.cpp 00003 // Object: Implementation of the low level handle object 00004 // Project: http://www.m2osw.com/odbcpp 00005 // Author: alexis_wilke@sourceforge.net 00006 // 00007 // Copyright (C) 2008 Made to Order Software Corp. 00008 // 00009 // This program is free software: you can redistribute it and/or modify 00010 // it under the terms of the GNU General Public License as published by 00011 // the Free Software Foundation, either version 3 of the License, or 00012 // (at your option) any later version. 00013 // 00014 // This program is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 // GNU General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU General Public License 00020 // along with this program. If not, see <http://www.gnu.org/licenses/> 00021 // or <http://gpl3.m2osw.com/>. 00022 // 00023 00024 #include "odbcpp/handle.h" 00025 #include <iostream> 00026 00027 00028 00029 namespace odbcpp 00030 { 00031 00032 00033 00131 handle::handle(SQLSMALLINT handle_type) : 00132 f_handle(SQL_NULL_HANDLE), 00133 f_handle_type(handle_type) 00134 //f_diag -- auto-init 00135 { 00136 } 00137 00138 00150 handle::~handle() 00151 { 00152 // we cannot check for errors since we're in 00153 // a destructor and we cannot throw from here 00154 SQLFreeHandle(f_handle_type, f_handle); 00155 } 00156 00157 00184 SQLRETURN handle::check(SQLRETURN return_code, handle *parent) const 00185 { 00186 // no error and no info 00187 if(return_code == SQL_SUCCESS) { 00188 diagnostic d; 00189 f_diag = d; 00190 return return_code; 00191 } 00192 00193 // retrieve a copy of the diagnostic 00194 diagnostic d(f_handle_type, f_handle, parent); 00195 f_diag = d; 00196 00197 // an error or just success with info? 00198 if(return_code == SQL_SUCCESS_WITH_INFO) { 00199 return return_code; 00200 } 00201 00202 //std::cerr << "return code is " << return_code << "\n"; 00203 00204 throw odbcpp_error(f_diag); 00205 /*NOTREACHED*/ 00206 } 00207 00208 00209 00228 } // namespace odbcpp