Removed the Statement registration list, adding unnecessary extra complexity

This commit is contained in:
Sébastien Rombauts 2012-04-09 11:30:46 +02:00
parent 37f3bd506f
commit da95147cfa
9 changed files with 11 additions and 64 deletions

View File

@ -2,7 +2,7 @@
* @file Database.cpp * @file Database.cpp
* @brief Management of a SQLite Database Connection. * @brief Management of a SQLite Database Connection.
* *
* Copyright (c) 2012 Sebastien Rombauts (sebastien dot rombauts at gmail dot com) * Copyright (c) 2012 Sebastien Rombauts (sebastien.rombauts@gmail.com)
* *
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
* or copy at http://opensource.org/licenses/MIT) * or copy at http://opensource.org/licenses/MIT)
@ -31,16 +31,6 @@ Database::Database(const char* apFilename, const int aFlags /*= SQLITE_OPEN_READ
// Close the SQLite database connection. // Close the SQLite database connection.
Database::~Database(void) throw() // nothrow Database::~Database(void) throw() // nothrow
{ {
// check for undestroyed statements
std::vector<Statement*>::iterator iStatement;
for (iStatement = mStatementList.begin();
iStatement != mStatementList.end();
iStatement++)
{
// TODO (*iStatement)->Finalize(); ?
//std::cout << "Unregistered statement: " << (*iStatement)->getQuery().c_str() << " !\n";
}
int ret = sqlite3_close(mpSQLite); int ret = sqlite3_close(mpSQLite);
if (SQLITE_OK != ret) if (SQLITE_OK != ret)
{ {
@ -49,23 +39,6 @@ Database::~Database(void) throw() // nothrow
} }
} }
// Register a Statement object (a SQLite query)
void Database::registerStatement(Statement& aStatement) // throw(SQLite::Exception)
{
mStatementList.push_back(&aStatement);
}
// Unregister a Statement object
void Database::unregisterStatement(Statement& aStatement) // throw(SQLite::Exception)
{
TStatementList::iterator iStatement;
iStatement = std::find(mStatementList.begin(), mStatementList.end(), &aStatement);
if (mStatementList.end() != iStatement)
{
mStatementList.erase(iStatement);
}
}
// Shortcut to execute one or multiple SQL statements without results. // Shortcut to execute one or multiple SQL statements without results.
int Database::exec(const char* apQueries) // throw(SQLite::Exception); int Database::exec(const char* apQueries) // throw(SQLite::Exception);
{ {

View File

@ -2,7 +2,7 @@
* @file Database.h * @file Database.h
* @brief Management of a SQLite Database Connection. * @brief Management of a SQLite Database Connection.
* *
* Copyright (c) 2012 Sebastien Rombauts (sebastien dot rombauts at gmail dot com) * Copyright (c) 2012 Sebastien Rombauts (sebastien.rombauts@gmail.com)
* *
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
* or copy at http://opensource.org/licenses/MIT) * or copy at http://opensource.org/licenses/MIT)
@ -10,8 +10,6 @@
#pragma once #pragma once
#include <sqlite3.h> #include <sqlite3.h>
#include <vector>
#include <algorithm>
#include "Exception.h" #include "Exception.h"
namespace SQLite namespace SQLite
@ -35,9 +33,6 @@ class Database
{ {
friend class Statement; friend class Statement;
public:
typedef std::vector<Statement*> TStatementList; /// List of statements pointers
public: public:
/** /**
* @brief Open the provided database UTF-8 filename. * @brief Open the provided database UTF-8 filename.
@ -62,16 +57,6 @@ public:
*/ */
virtual ~Database(void) throw(); // nothrow virtual ~Database(void) throw(); // nothrow
/**
* @brief Register a Statement object (a SQLite query)
*/
void registerStatement(Statement& aStatement); // throw(SQLite::Exception);
/**
* @brief Unregister a Statement object
*/
void unregisterStatement(Statement& aStatement); // throw(SQLite::Exception);
/** /**
* @brief Shortcut to execute one or multiple statements without results. * @brief Shortcut to execute one or multiple statements without results.
* *
@ -91,14 +76,6 @@ public:
return mFilename; return mFilename;
} }
/**
* @brief List of registered statements
*/
inline const TStatementList& getStatementList(void) const
{
return mStatementList;
}
private: private:
// Database must not be copyable // Database must not be copyable
Database(void); Database(void);
@ -111,9 +88,8 @@ private:
void check(const int aRet) const; // throw(SQLite::Exception); void check(const int aRet) const; // throw(SQLite::Exception);
private: private:
sqlite3* mpSQLite; //!< Pointer to SQLite Database Connection Handle sqlite3* mpSQLite; //!< Pointer to SQLite Database Connection Handle
std::string mFilename; //!< UTF-8 filename used to open the database std::string mFilename; //!< UTF-8 filename used to open the database
TStatementList mStatementList; //!< List of SQL registered statements used with this database connexion
}; };

View File

@ -2,7 +2,7 @@
* @file Exception.h * @file Exception.h
* @brief Encapsulation of the error message from SQLite3 on a std::runtime_error. * @brief Encapsulation of the error message from SQLite3 on a std::runtime_error.
* *
* Copyright (c) 2012 Sebastien Rombauts (sebastien dot rombauts at gmail dot com) * Copyright (c) 2012 Sebastien Rombauts (sebastien.rombauts@gmail.com)
* *
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
* or copy at http://opensource.org/licenses/MIT) * or copy at http://opensource.org/licenses/MIT)

View File

@ -2,7 +2,7 @@
* @file SQLiteC++.h * @file SQLiteC++.h
* @brief SQLiteC++ is a smart and simple C++ SQLite3 wrapper. This file is only "easy include" for other files. * @brief SQLiteC++ is a smart and simple C++ SQLite3 wrapper. This file is only "easy include" for other files.
* *
* Copyright (c) 2012 Sebastien Rombauts (sebastien dot rombauts at gmail dot com) * Copyright (c) 2012 Sebastien Rombauts (sebastien.rombauts@gmail.com)
* *
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
* or copy at http://opensource.org/licenses/MIT) * or copy at http://opensource.org/licenses/MIT)

View File

@ -2,7 +2,7 @@
* @file Statement.cpp * @file Statement.cpp
* @brief A prepared SQLite Statement is a compiled SQL query ready to be executed. * @brief A prepared SQLite Statement is a compiled SQL query ready to be executed.
* *
* Copyright (c) 2012 Sebastien Rombauts (sebastien dot rombauts at gmail dot com) * Copyright (c) 2012 Sebastien Rombauts (sebastien.rombauts@gmail.com)
* *
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
* or copy at http://opensource.org/licenses/MIT) * or copy at http://opensource.org/licenses/MIT)
@ -26,7 +26,6 @@ Statement::Statement(Database &aDatabase, const char* apQuery) : // throw(SQLite
int ret = sqlite3_prepare_v2(mDatabase.mpSQLite, mQuery.c_str(), mQuery.size(), &mpStmt, NULL); int ret = sqlite3_prepare_v2(mDatabase.mpSQLite, mQuery.c_str(), mQuery.size(), &mpStmt, NULL);
check(ret); check(ret);
mColumnCount = sqlite3_column_count(mpStmt); mColumnCount = sqlite3_column_count(mpStmt);
mDatabase.registerStatement(*this);
} }
// Finalize and unregister the SQL query from the SQLite Database Connection. // Finalize and unregister the SQL query from the SQLite Database Connection.
@ -39,7 +38,6 @@ Statement::~Statement(void) throw() // nothrow
//std::cout << sqlite3_errmsg(mDatabase.mpSQLite); //std::cout << sqlite3_errmsg(mDatabase.mpSQLite);
} }
mpStmt = NULL; mpStmt = NULL;
mDatabase.unregisterStatement(*this);
} }
// Reset the statement to make it ready for a new execution // Reset the statement to make it ready for a new execution

View File

@ -2,7 +2,7 @@
* @file Statement.h * @file Statement.h
* @brief A prepared SQLite Statement is a compiled SQL query ready to be executed. * @brief A prepared SQLite Statement is a compiled SQL query ready to be executed.
* *
* Copyright (c) 2012 Sebastien Rombauts (sebastien dot rombauts at gmail dot com) * Copyright (c) 2012 Sebastien Rombauts (sebastien.rombauts@gmail.com)
* *
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
* or copy at http://opensource.org/licenses/MIT) * or copy at http://opensource.org/licenses/MIT)

View File

@ -2,7 +2,7 @@
* @file Transaction.cpp * @file Transaction.cpp
* @brief A prepared SQLite Transaction is a compiled SQL query ready to be executed. * @brief A prepared SQLite Transaction is a compiled SQL query ready to be executed.
* *
* Copyright (c) 2012 Sebastien Rombauts (sebastien dot rombauts at gmail dot com) * Copyright (c) 2012 Sebastien Rombauts (sebastien.rombauts@gmail.com)
* *
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
* or copy at http://opensource.org/licenses/MIT) * or copy at http://opensource.org/licenses/MIT)

View File

@ -2,7 +2,7 @@
* @file Transaction.h * @file Transaction.h
* @brief A Transaction is way to group multiple SQL statements into an atomic secured operation. * @brief A Transaction is way to group multiple SQL statements into an atomic secured operation.
* *
* Copyright (c) 2012 Sebastien Rombauts (sebastien dot rombauts at gmail dot com) * Copyright (c) 2012 Sebastien Rombauts (sebastien.rombauts@gmail.com)
* *
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
* or copy at http://opensource.org/licenses/MIT) * or copy at http://opensource.org/licenses/MIT)

View File

@ -4,7 +4,7 @@
* *
* Demonstrate how-to use the SQLite++ wrapper * Demonstrate how-to use the SQLite++ wrapper
* *
* Copyright (c) 2012 Sebastien Rombauts (sebastien dot rombauts at gmail dot com) * Copyright (c) 2012 Sebastien Rombauts (sebastien.rombauts@gmail.com)
* *
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
* or copy at http://opensource.org/licenses/MIT) * or copy at http://opensource.org/licenses/MIT)