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  * As a special exception, you may use this file as part of a free
00010  * software library without restriction. Specifically, if other files
00011  * instantiate templates or use macros or inline functions from this
00012  * file, or you compile this file and link it with other files to
00013  * produce an executable, this file does not by itself cause the
00014  * resulting executable to be covered by the GNU General Public
00015  * License. This exception does not however invalidate any other
00016  * reasons why the executable file might be covered by the GNU Library
00017  * General Public License.
00018  * 
00019  * This library is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00022  * Lesser General Public License for more details.
00023  * 
00024  * You should have received a copy of the GNU Lesser General Public
00025  * License along with this library; if not, write to the Free Software
00026  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00027  */
00028 
00029 #ifndef TNTDB_BITS_STATEMENT_H
00030 #define TNTDB_BITS_STATEMENT_H
00031 
00032 #include <string>
00033 #include <cxxtools/smartptr.h>
00034 #include <tntdb/iface/istatement.h>
00035 #include <tntdb/date.h>
00036 #include <tntdb/time.h>
00037 #include <tntdb/datetime.h>
00038 
00039 namespace tntdb
00040 {
00041   class Connection;
00042   class Result;
00043   class Row;
00044   class Value;
00045   class Date;
00046   class Time;
00047   class Datetime;
00048 
00058   class Statement
00059   {
00060     public:
00061       class const_iterator;
00062       typedef IStatement::size_type size_type;
00063 
00064     private:
00065       cxxtools::SmartPtr<IStatement> stmt;
00066 
00067     public:
00068       Statement(IStatement* stmt_ = 0)
00069         : stmt(stmt_)
00070         { }
00071 
00075       Statement& clear()
00076         { stmt->clear(); return *this; }
00080       Statement& setNull(const std::string& col)
00081         { stmt->setNull(col); return *this; }
00085       Statement& setBool(const std::string& col, bool data)
00086         { stmt->setBool(col, data); return *this; }
00090       Statement& setInt(const std::string& col, int data)
00091         { stmt->setInt(col, data); return *this; }
00095       Statement& setUnsigned(const std::string& col, unsigned data)
00096         { stmt->setUnsigned(col, data); return *this; }
00100       Statement& setInt32(const std::string& col, int32_t data)
00101         { stmt->setInt32(col, data); return *this; }
00105       Statement& setUnsigned32(const std::string& col, uint32_t data)
00106         { stmt->setUnsigned32(col, data); return *this; }
00110       Statement& setInt64(const std::string& col, int64_t data)
00111         { stmt->setInt64(col, data); return *this; }
00115       Statement& setUnsigned64(const std::string& col, uint64_t data)
00116         { stmt->setUnsigned64(col, data); return *this; }
00120       Statement& setDecimal(const std::string& col, const Decimal& data)
00121         { stmt->setDecimal(col, data); return *this; }
00125       Statement& setFloat(const std::string& col, float data)
00126         { stmt->setFloat(col, data); return *this; }
00130       Statement& setDouble(const std::string& col, double data)
00131         { stmt->setDouble(col, data); return *this; }
00135       Statement& setChar(const std::string& col, char data)
00136         { stmt->setChar(col, data); return *this; }
00140       Statement& setString(const std::string& col, const std::string& data)
00141         { stmt->setString(col, data); return *this; }
00146       Statement& setString(const std::string& col, const char* data)
00147         { data == 0 ? stmt->setNull(col)
00148                     : stmt->setString(col, data); return *this; }
00149       Statement& setBlob(const std::string& col, const Blob& data)
00150         { stmt->setBlob(col, data); return *this; }
00154       Statement& setDate(const std::string& col, const Date& data)
00155         { data.isNull() ? stmt->setNull(col)
00156                         : stmt->setDate(col, data); return *this; }
00160       Statement& setTime(const std::string& col, const Time& data)
00161         { data.isNull() ? stmt->setNull(col)
00162                         : stmt->setTime(col, data); return *this; }
00166       Statement& setDatetime(const std::string& col, const Datetime& data)
00167         { data.isNull() ? stmt->setNull(col)
00168                         : stmt->setDatetime(col, data); return *this; }
00169 
00171 
00175       Statement& set(const std::string& col, bool data)
00176         { stmt->setBool(col, data); return *this; }
00177       Statement& set(const std::string& col, int data)
00178         { stmt->setInt(col, data); return *this; }
00179       Statement& set(const std::string& col, unsigned data)
00180         { stmt->setUnsigned(col, data); return *this; }
00181       Statement& set(const std::string& col, float data)
00182         { stmt->setFloat(col, data); return *this; }
00183       Statement& set(const std::string& col, double data)
00184         { stmt->setDouble(col, data); return *this; }
00185       Statement& set(const std::string& col, char data)
00186         { stmt->setChar(col, data); return *this; }
00187       Statement& set(const std::string& col, const char* data)
00188         { data == 0 ? stmt->setNull(col)
00189                     : stmt->setString(col, data); return *this; }
00190       Statement& set(const std::string& col, const std::string& data)
00191         { stmt->setString(col, data); return *this; }
00192       Statement& set(const std::string& col, const Date& data)
00193         { data.isNull() ? stmt->setNull(col)
00194                         : stmt->setDate(col, data); return *this; }
00195       Statement& set(const std::string& col, const Time& data)
00196         { data.isNull() ? stmt->setNull(col)
00197                         : stmt->setTime(col, data); return *this; }
00198       Statement& set(const std::string& col, const Datetime& data)
00199         { data.isNull() ? stmt->setNull(col)
00200                         : stmt->setDatetime(col, data); return *this; }
00201       Statement& set(const std::string& col, const Decimal& data)
00202         { stmt->setDecimal(col, data); return *this; }
00203       Statement& set(const std::string& col, const Blob& data)
00204         { stmt->setBlob(col, data); return *this; }
00206 
00208 
00213       size_type execute();
00218       Result select();
00225       Row selectRow();
00232       Value selectValue();
00233 
00237       const_iterator begin(unsigned fetchsize = 100) const;
00242       const_iterator end() const;
00243 
00247       bool operator!() const             { return !stmt; }
00251       const IStatement* getImpl() const  { return &*stmt; }
00252   };
00253 }
00254 
00255 #endif // TNTDB_BITS_STATEMENT_H
00256 
Copyright © 2008 The Tntnet Development Team
Tntnet 1.6