Webmaster  |  Imprint 
C++ Server Pages
Main  |  License  |  Documentation  |  Download 

/home/tommi/tntdb/include/tntdb/bits/statement.h

00001 /* 
00002  * Copyright (C) 2005 Tommi Maekitalo
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00017  */
00018 
00019 #ifndef TNTDB_BITS_STATEMENT_H
00020 #define TNTDB_BITS_STATEMENT_H
00021 
00022 #include <string>
00023 #include <cxxtools/smartptr.h>
00024 #include <tntdb/iface/istatement.h>
00025 #include <tntdb/date.h>
00026 #include <tntdb/time.h>
00027 #include <tntdb/datetime.h>
00028 
00029 namespace tntdb
00030 {
00031   class Connection;
00032   class Result;
00033   class Row;
00034   class Value;
00035   class Date;
00036   class Time;
00037   class Datetime;
00038 
00048   class Statement
00049   {
00050     public:
00051       class const_iterator;
00052       typedef IStatement::size_type size_type;
00053 
00054     private:
00055       cxxtools::SmartPtr<IStatement> stmt;
00056 
00057     public:
00058       Statement(IStatement* stmt_ = 0)
00059         : stmt(stmt_)
00060         { }
00061 
00065       Statement& clear()
00066         { stmt->clear(); return *this; }
00070       Statement& setNull(const std::string& col)
00071         { stmt->setNull(col); return *this; }
00075       Statement& setBool(const std::string& col, bool data)
00076         { stmt->setBool(col, data); return *this; }
00080       Statement& setInt(const std::string& col, int data)
00081         { stmt->setInt(col, data); return *this; }
00085       Statement& setUnsigned(const std::string& col, unsigned data)
00086         { stmt->setUnsigned(col, data); return *this; }
00090       Statement& setInt32(const std::string& col, int32_t data)
00091         { stmt->setInt32(col, data); return *this; }
00095       Statement& setUnsigned32(const std::string& col, uint32_t data)
00096         { stmt->setUnsigned32(col, data); return *this; }
00100       Statement& setInt64(const std::string& col, int64_t data)
00101         { stmt->setInt64(col, data); return *this; }
00105       Statement& setUnsigned64(const std::string& col, uint64_t data)
00106         { stmt->setUnsigned64(col, data); return *this; }
00110       Statement& setDecimal(const std::string& col, const Decimal& data)
00111         { stmt->setDecimal(col, data); return *this; }
00115       Statement& setFloat(const std::string& col, float data)
00116         { stmt->setFloat(col, data); return *this; }
00120       Statement& setDouble(const std::string& col, double data)
00121         { stmt->setDouble(col, data); return *this; }
00125       Statement& setChar(const std::string& col, char data)
00126         { stmt->setChar(col, data); return *this; }
00130       Statement& setString(const std::string& col, const std::string& data)
00131         { stmt->setString(col, data); return *this; }
00136       Statement& setString(const std::string& col, const char* data)
00137         { data == 0 ? stmt->setNull(col)
00138                     : stmt->setString(col, data); return *this; }
00139       Statement& setBlob(const std::string& col, const Blob& data)
00140         { stmt->setBlob(col, data); return *this; }
00144       Statement& setDate(const std::string& col, const Date& data)
00145         { data.isNull() ? stmt->setNull(col)
00146                         : stmt->setDate(col, data); return *this; }
00150       Statement& setTime(const std::string& col, const Time& data)
00151         { data.isNull() ? stmt->setNull(col)
00152                         : stmt->setTime(col, data); return *this; }
00156       Statement& setDatetime(const std::string& col, const Datetime& data)
00157         { data.isNull() ? stmt->setNull(col)
00158                         : stmt->setDatetime(col, data); return *this; }
00159 
00161 
00165       Statement& set(const std::string& col, bool data)
00166         { stmt->setBool(col, data); return *this; }
00167       Statement& set(const std::string& col, int data)
00168         { stmt->setInt(col, data); return *this; }
00169       Statement& set(const std::string& col, unsigned data)
00170         { stmt->setUnsigned(col, data); return *this; }
00171       Statement& set(const std::string& col, float data)
00172         { stmt->setFloat(col, data); return *this; }
00173       Statement& set(const std::string& col, double data)
00174         { stmt->setDouble(col, data); return *this; }
00175       Statement& set(const std::string& col, char data)
00176         { stmt->setChar(col, data); return *this; }
00177       Statement& set(const std::string& col, const char* data)
00178         { data == 0 ? stmt->setNull(col)
00179                     : stmt->setString(col, data); return *this; }
00180       Statement& set(const std::string& col, const std::string& data)
00181         { stmt->setString(col, data); return *this; }
00182       Statement& set(const std::string& col, const Date& data)
00183         { data.isNull() ? stmt->setNull(col)
00184                         : stmt->setDate(col, data); return *this; }
00185       Statement& set(const std::string& col, const Time& data)
00186         { data.isNull() ? stmt->setNull(col)
00187                         : stmt->setTime(col, data); return *this; }
00188       Statement& set(const std::string& col, const Datetime& data)
00189         { data.isNull() ? stmt->setNull(col)
00190                         : stmt->setDatetime(col, data); return *this; }
00191       Statement& set(const std::string& col, const Decimal& data)
00192         { stmt->setDecimal(col, data); return *this; }
00193       Statement& set(const std::string& col, const Blob& data)
00194         { stmt->setBlob(col, data); return *this; }
00196 
00198 
00203       size_type execute();
00208       Result select();
00215       Row selectRow();
00222       Value selectValue();
00223 
00227       const_iterator begin(unsigned fetchsize = 100) const;
00232       const_iterator end() const;
00233 
00237       bool operator!() const             { return !stmt; }
00241       const IStatement* getImpl() const  { return &*stmt; }
00242   };
00243 }
00244 
00245 #endif // TNTDB_BITS_STATEMENT_H
00246 
Copyright © 2008 The Tntnet Development Team
Tntnet 1.6