SQLSelect.hh

00001 //********************************************************************
00002 //*** ResourcePool/mysql/SQLSelect.hh
00003 //*** Copyright (c) 2003-2009 by Markus Winand <mws@fatalmind.com>
00004 //*** $Id: SQLSelect.hh,v 1.27 2009-03-21 18:54:42 mws Exp $
00005 //********************************************************************
00006 /*
00007 This file is part of ResourcePool.
00008 
00009 ResourcePool is free software; you can redistribute it
00010 and/or modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2 of
00012 the License, or (at your option) any later version.
00013 
00014 ResourcePool is distributed in the hope that it will be
00015 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
00016 of 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 ResourcePool; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00022 02111-1307  USA */
00023 
00024 #ifndef RESOURCEPOOL_MYSQL_RESOURCEPOOL_HH
00025 #include <ResourcePool.hh>
00026 #endif
00027 
00028 #ifndef RESOURCEPOOL_MYSQL_SQLSELECT_HH
00029 #define RESOURCEPOOL_MYSQL_SQLSELECT_HH
00030 
00031 #ifndef RESOURCEPOOL_COMMAND_HH
00032 #include "ResourcePool/Command.hh"
00033 #endif
00034 
00035 #ifndef RESOURCEPOOL_MYSQL_MYSQLFWD_HH
00036 #include "mysqlFwd.hh"
00037 #endif
00038 
00039 #ifndef RESOURCEPOOL_MYSQL_SQLTYPE_HH
00040 #include "SQLType.hh"
00041 #endif
00042 
00043 #ifndef INCLUDED_GC_PTR_HH
00044 #include "mm/gc_ptr.hh"
00045 #endif
00046 
00047 #ifndef RESOURCEPOOL_SQL_BIND_HH
00048 #include "ResourcePool/SQL/Bind.hh"
00049 #endif
00050 
00051 #ifndef RESOURCEPOOL_SQL_BINDOUT_HH
00052 #include "ResourcePool/SQL/BindOut.hh"
00053 #endif
00054 
00055 #ifndef RESOURCEPOOL_SQL_SQLSELECT_HH
00056 #include "ResourcePool/SQL/SQLSelect.hh"
00057 #endif
00058 
00059 #include "ResourcePool/SQL/SQLStatement.hh"
00060 
00061 #include <string>
00062 #include <vector>
00063 
00064 namespace fatalmind {
00065 namespace mysql {
00066 
00067 namespace internal {
00068 class registerFinish;
00069 }
00070 
00075 class SQLSelect
00076 : public Command<fatalmind::ResourceType::mysql> 
00077 , public SQL::Bind<SQLType, SQLTypeImpl>
00078 , public SQL::BindOut<SQLRefType, SQLRefTypeImpl>
00079 , public fatalmind::SQLSelect
00080 {
00081     protected:
00082         typedef SQL::Bind<SQLType, SQLTypeImpl> super_bind;
00083         typedef fatalmind::SQLSelect super;
00084     public:
00085         SQLSelect(const SQL::SQLStatement& SQL, SQL::SQLFetcher& fetcher);
00086         SQLSelect(const ResourcePool<ResourceType>& p, const SQL::SQLStatement& SQL, SQL::SQLFetcher& fetcher);
00087         virtual ~SQLSelect();
00088         virtual void execute(mysqlResource&);
00089 
00090         virtual void outputoperator(std::ostream&) const;
00091 
00092     protected:
00093         virtual Clone* DoClone() const {
00094             return new SQLSelect(*this);
00095         }
00096         bool ishighlimit(int, mysqlResource& rdbh) const;
00097         // islowlimit's only purpose is to throw or not throw
00098         void islowlimit(int,  mysqlResource& rdbh) const;
00099 
00100         SQL::SQLStatement _SQL;
00101         // the maximal number of records expected to be fetched.
00102         int         highlimit;
00103         // the minimum number of records expected to be fetched.
00104         int         lowlimit;
00105         // specifies the behaviour if the limit is reached. 
00106         // true - will cause an exception
00107         // false - will just stop fetching more records
00108         bool        hardhighlimit;
00109     private:
00110         virtual bool fetch();
00111         void finish();
00112         void close_rs();
00113     
00114         MYSQL_RES* _rs;
00115         unsigned int _num_fields;
00116     friend
00117         class internal::registerFinish;
00118 };
00119 
00120 namespace internal {
00121 class registerFinish {
00122     public:
00123         registerFinish(SQLSelect& select)
00124         : _select(select)
00125         {
00126         }
00127         ~registerFinish()
00128         {
00129             _select.finish();
00130         }
00131     private:
00132         SQLSelect& _select;
00133 };
00134 } // namespace internal
00135 
00136 
00137 } // namespace mysql
00138 } // namespace fatalmind
00139 #endif

Generated on Mon Nov 9 16:21:24 2009 for ResourcePool by  doxygen 1.5.3