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

/home/tommi/tntdb/include/tntdb/bits/connection.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_CONNECTION_H
00030 #define TNTDB_BITS_CONNECTION_H
00031 
00032 #include <string>
00033 #include <cxxtools/smartptr.h>
00034 #include <tntdb/iface/iconnection.h>
00035 #include <tntdb/bits/statement.h>
00036 
00037 namespace tntdb
00038 {
00039   class Result;
00040   class Row;
00041   class Value;
00042   class Statement;
00043 
00066   class Connection
00067   {
00068     public:
00069       typedef unsigned size_type;
00070 
00071     private:
00072       cxxtools::SmartPtr<IConnection> conn;
00073 
00074     public:
00078       Connection() { }
00082       Connection(IConnection* conn_)
00083         : conn(conn_)
00084         { }
00085 
00090       void close()
00091         { conn = 0; }
00092 
00097       void beginTransaction();
00101       void commitTransaction();
00105       void rollbackTransaction();
00106 
00114       size_type execute(const std::string& query);
00119       Result select(const std::string& query);
00125       Row selectRow(const std::string& query);
00131       Value selectValue(const std::string& query);
00135       Statement prepare(const std::string& query);
00136 
00144       Statement prepareCached(const std::string& query, const std::string& key);
00145 
00151       Statement prepareCached(const std::string& query)
00152       { return prepareCached(query, query); }
00153 
00157       void clearStatementCache()         { conn->clearStatementCache(); }
00158 
00162       bool ping()                        { return conn->ping(); }
00163 
00167       long lastInsertId(const std::string& name = std::string())
00168       { return conn->lastInsertId(name); }
00169 
00173       bool operator!() const             { return !conn; }
00177       const IConnection* getImpl() const { return &*conn; }
00178   };
00179 }
00180 
00181 #endif // TNTDB_BITS_CONNECTION_H
00182 
Copyright © 2008 The Tntnet Development Team
Tntnet 1.6