sprint 1-alpha
|
00001 /****************************************************************************** 00002 * sprint::ODBC wrapper 00003 * 00004 * Copyright (C) 2004-2011 Paolo Medici <www.pmx.it> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 * 00020 *******************************************************************************/ 00021 00022 00023 #ifndef _SPRINT_ODBC_H 00024 #define _SPRINT_ODBC_H 00025 00028 /* @TODO: implement for UNIX*/ 00029 00030 #ifdef WIN32 00031 #include <windows.h> 00032 #include <sql.h> 00033 #include <SQLEXT.H> 00034 #include <sprint/thread/mutex.h> 00035 #endif 00036 00037 namespace sprint { 00038 00039 #ifdef WIN32 00040 00041 class odbc { 00042 HENV henv; 00043 HDBC hdbc; 00044 HSTMT hstmt; 00045 bool valid; 00046 sprint::mutex mutex; 00047 00049 void dbError(LPCSTR lpszMsg); 00051 bool dbCheck(const char *fn, SQLRETURN err); 00052 00054 template<class T, SQLSMALLINT type> 00055 bool _get(unsigned int col, T * value); 00056 00057 public: 00058 odbc(); 00059 ~odbc(); 00060 00065 bool connect(const char *provider, const char *username, const char *password); 00066 00074 bool connect(const char *InConnectionString); 00075 00077 bool disconnect(); 00078 00084 bool begin_query(const char *query); 00085 00087 void end_query(); 00088 00091 bool next(); 00092 00098 template<class T> 00099 bool get(unsigned int col, T * value); 00100 00105 bool get(unsigned int col, char *buf, unsigned int buf_len); 00106 00108 inline bool good() const { return valid; } 00109 }; 00110 #endif 00111 00112 } 00113 00114 #endif