Logo
  • Main Page
  • Related Pages
  • Modules
  • Classes
  • Files

mmsdbfreetds.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2007 Stefan Schwarzer, Jens Schneider,             *
00003  *                           Matthias Hardt, Guido Madaus                  *
00004  *                                                                         *
00005  *   Copyright (C) 2007-2008 BerLinux Solutions GbR                        *
00006  *                           Stefan Schwarzer & Guido Madaus               *
00007  *                                                                         *
00008  *   Copyright (C) 2009-2013 BerLinux Solutions GmbH                       *
00009  *                                                                         *
00010  *   Authors:                                                              *
00011  *      Stefan Schwarzer   <stefan.schwarzer@diskohq.org>,                 *
00012  *      Matthias Hardt     <matthias.hardt@diskohq.org>,                   *
00013  *      Jens Schneider     <jens.schneider@diskohq.org>,                   *
00014  *      Guido Madaus       <guido.madaus@diskohq.org>,                     *
00015  *      Patrick Helterhoff <patrick.helterhoff@diskohq.org>,               *
00016  *      René Bählkow       <rene.baehlkow@diskohq.org>                     *
00017  *                                                                         *
00018  *   This library is free software; you can redistribute it and/or         *
00019  *   modify it under the terms of the GNU Lesser General Public            *
00020  *   License version 2.1 as published by the Free Software Foundation.     *
00021  *                                                                         *
00022  *   This library is distributed in the hope that it will be useful,       *
00023  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00024  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00025  *   Lesser General Public License for more details.                       *
00026  *                                                                         *
00027  *   You should have received a copy of the GNU Lesser General Public      *
00028  *   License along with this library; if not, write to the                 *
00029  *   Free Software Foundation, Inc.,                                       *
00030  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
00031  **************************************************************************/
00032 
00033 #ifndef MMSDBFREETDS_H_
00034 #define MMSDBFREETDS_H_
00035 
00036 #ifdef __ENABLE_FREETDS__
00037 
00038 #include "mmstools/base.h"
00039 #include "mmstools/mmserror.h"
00040 #include "mmstools/mmsrecordset.h"
00041 #include "mmstools/datasource.h"
00042 #include "mmstools/interfaces/immsdb.h"
00043 
00044 #include <sql.h>
00045 #include <map>
00046 #include <sqlext.h>
00047 
00048 /**
00049  * @file  mmsdbfreetds.h
00050  *
00051  * @brief Header file for freetds database functions.
00052  *
00053  * @ingroup mmstools
00054  */
00055 
00056 #define DIAG_TYPE_ENV   1
00057 #define DIAG_TYPE_DBC   2
00058 #define DIAG_TYPE_STMT  3
00059 
00060 #define FREETDS_SP_EXEC_CMD     "CALL "
00061 
00062 /**
00063  * Implementation of database access using FreeTDS (http://www.freetds.org).
00064  *
00065  * This allows usage of Microsoft SQL Server and Sybase database backends.
00066  * MMSDBFreeTDS implementes the IMMSDB interface, which should be used in
00067  * your application to provide simple database backend exchange by only
00068  * changing the configuration in your XML-configuration file.
00069  *
00070  * @see MMSDBMySQL
00071  * @see MMSDBSQLite
00072  */
00073 class MMSDBFreeTDS : public IMMSDB {
00074     public:
00075         /**
00076          * Constructor which only saves a reference to the given DataSource object.
00077          *
00078          *  @param  datasource  Database configuration to use.
00079          *
00080          *  @throws MMSError    datasource was NULL
00081          *
00082          * @see ~MMSDBFreeTDS()
00083          */
00084         MMSDBFreeTDS(DataSource *datasource);
00085 
00086         /**
00087          * Destructor which disconnects from the database.
00088          *
00089          * @see MMSDBFreeTDS()
00090          * @see disconnect()
00091          */
00092         virtual ~MMSDBFreeTDS();
00093 
00094         /**
00095          * Opens connection to the database.
00096          *
00097          * The database settings have to be given to the constructor before.
00098          *
00099          * @throws MMSError     Connection to SQL database could not be established
00100          *                      (for detailed information use MMSError::getMessage())
00101          *
00102          * @see MMSDBFreeTDS()
00103          * @see disconnect()
00104          */
00105         void connect();
00106 
00107         /**
00108          * Close connection to database if a connection was established before.
00109          *
00110          * @see connect()
00111          */
00112         void disconnect();
00113 
00114         /**
00115          * Method not implemented since the FreeTDS implementation does not
00116          * support transactions.
00117          */
00118         void startTransaction() {};
00119 
00120         /**
00121          * Method not implemented since the FreeTDS implementation does not
00122          * support transactions.
00123          */
00124         void commitTransaction() {};
00125 
00126         /**
00127          * Method not implemented since the FreeTDS implementation does not
00128          * support transactions.
00129          */
00130         void rollbackTransaction() {};
00131 
00132 
00133         /**
00134          * This function executes the given database query and puts the results in MMSRecordSet.
00135          *
00136          * This method is used for select statements.
00137          *
00138          * @param   statement   buffer with database query
00139          * @param   rs          recordset containing result of query
00140          *
00141          * @return Returns the number of affected rows.
00142          *
00143          * @throws MMSError     SQL query could not be executed
00144          *                      (for detailed information use MMSError::getMessage())
00145          *
00146          * @see MMSRecordSet
00147          */
00148         int query(string statement, MMSRecordSet *rs);
00149 
00150         /**
00151          * This function executes given database query.
00152          *
00153          * This method is used for insert, update and delete statements.
00154          *
00155          * @param   statement   buffer with database query
00156          *
00157          * @throws MMSError     SQL query could not be executed
00158          *                      (for detailed information use MMSError::getMessage())
00159          *
00160          * @return Returns the number of affected rows
00161          */
00162         int query(string statement);
00163 
00164         /**
00165          * This function executes given stored procedure and puts the results in MMSRecordSet.
00166          *
00167          * This method is used for insert, update and delete statements
00168          *
00169          * @param spName    name of stored procedure
00170          * @param argList   arguments for stored procedure
00171          * @param rs        recordset containing result
00172          *
00173          * @return Returns the number of affected rows
00174          */
00175         int executeSP(string spName, MMSDB_SP_ARGLIST argList, MMSRecordSet *rs);
00176 
00177         /**
00178          * This function executes a stored procedure.
00179          *
00180          * This method is used for insert, update and delete statements
00181          *
00182          * @param spName    name of stored procedure
00183          * @param argList   arguments for stored procedure
00184          *
00185          * @return Returns the number of affected rows
00186          */
00187         int executeSP(string spName, MMSDB_SP_ARGLIST argList);
00188 
00189         /**
00190          * This method is not supported by the FreeTDS implementation.
00191          *
00192          * @return Returns always 0.
00193          */
00194         int getLastInsertedID() { return 0; }
00195 
00196     private:
00197         SQLHDBC     *dbhandle;      /**< Database handle retrieved in connect(). */
00198         SQLHENV     henv;           /**< Database environment handle retrieved in connect(). */
00199         DataSource  *datasource;    /**< Database configuration. */
00200 
00201         /**
00202          * Internal function to execute a given database query.
00203          *
00204          * This method is used by the public query() methods.
00205          *
00206          * @param   statement       buffer with database query
00207          * @param   hstmt           reference to SQL statement handle
00208          * @param   finishStatement if false query cursor stays open i.e. to call SqlFetch() afterwards
00209          *
00210          * @throws MMSError     SQL query could not be executed
00211          *                      (for detailed information use MMSError::getMessage())
00212          *
00213          * @return Returns the number of affected rows
00214          */
00215         int query(string statement, SQLHSTMT &hstmt, bool finishStatement = true);
00216 };
00217 
00218 #endif /* __ENABLE_FREETDS__ */
00219 
00220 #endif /*MMSDBFREETDS_H_*/

Generated by doxygen