odbc++/preparedstatement.h

00001 /*
00002    This file is part of libodbc++.
00003 
00004    Copyright (C) 1999-2000 Manush Dodunekov <manush@stendahls.net>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 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    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.  If not, write to
00018    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019    Boston, MA 02111-1307, USA.
00020 */
00021 
00022 
00023 #ifndef __ODBCXX_PREPAREDSTATEMENT_H
00024 #define __ODBCXX_PREPAREDSTATEMENT_H
00025 
00026 #include <odbc++/setup.h>
00027 #include <odbc++/types.h>
00028 #include <odbc++/statement.h>
00029 
00030 #if defined(ODBCXX_HAVE_ISO_CXXLIB)
00031 # include <iosfwd>
00032 #else
00033 # include <iostream>
00034 #endif
00035 
00036 namespace odbc {
00037 
00038   class Rowset;
00039 
00062   class ODBCXX_EXPORT PreparedStatement : public Statement {
00063     friend class Connection;
00064 
00065   private:
00066     void _prepare();
00067     void _setupParams();
00068 
00069   protected:
00070     ODBCXX_STRING sql_;
00071     //here we store the parameters
00072     Rowset* rowset_;
00073     size_t numParams_;
00074     std::vector<int> directions_;
00075     int defaultDirection_;
00076     bool paramsBound_;
00077 
00078     PreparedStatement(Connection* con,
00079                       SQLHSTMT hstmt,
00080                       const ODBCXX_STRING& sql,
00081                       int resultSetType,
00082                       int resultSetConcurrency,
00083                       int defaultDirection =SQL_PARAM_INPUT);
00084 
00085     void _bindParams();
00086     void _unbindParams();
00087 
00088     void _checkParam(int idx,
00089                      int* allowed, int numAllowed,
00090                      int defPrec, int defScale);
00091 
00092   public:
00094     virtual ~PreparedStatement();
00095 
00102     void clearParameters();
00103 
00108     bool execute();
00109 
00117     ResultSet* executeQuery();
00118 
00120     int executeUpdate();
00121 
00126     void setDouble(int idx, double val);
00127 
00132     void setBoolean(int idx, bool val);
00133 
00138     void setByte(int idx, signed char val);
00139 
00140 
00145     void setBytes(int idx, const ODBCXX_BYTES& val);
00146 
00151     void setDate(int idx, const Date& val);
00152 
00157     void setFloat(int idx, float val);
00158 
00159 
00164     void setInt(int idx, int val);
00165 
00170     void setLong(int idx, Long val);
00171 
00176     void setShort(int idx, short val);
00177 
00182     void setString(int idx, const ODBCXX_STRING& val);
00183 
00188     void setTime(int idx, const Time& val);
00189 
00194     void setTimestamp(int idx, const Timestamp& val);
00195 
00201     void setAsciiStream(int idx, ODBCXX_STREAM* s, int len);
00202 
00208     void setBinaryStream(int idx, ODBCXX_STREAM* s, int len);
00209 
00210 
00216     void setNull(int idx, int sqlType);
00217   };
00218 
00219 
00220 } // namespace odbc
00221 
00222 #endif // __ODBCXX_PREPAREDSTATEMENT_H

Go back to the libodbc++ homepage