From 0a1520ced0010fa0662b5dcc1fd156ca8270d63f Mon Sep 17 00:00:00 2001 From: Sebastien Rombauts Date: Sat, 31 Mar 2012 17:45:40 +0200 Subject: [PATCH] Added Statement::getColumnCount() and commented out the throw specifications (they are not usefull) --- src/SQLiteC++/Database.cpp | 6 +++--- src/SQLiteC++/Database.h | 6 +++--- src/SQLiteC++/Statement.cpp | 23 ++++++++++++++--------- src/SQLiteC++/Statement.h | 23 ++++++++++++++--------- src/example1/main.cpp | 1 + 5 files changed, 35 insertions(+), 24 deletions(-) diff --git a/src/SQLiteC++/Database.cpp b/src/SQLiteC++/Database.cpp index 143701a..3176473 100644 --- a/src/SQLiteC++/Database.cpp +++ b/src/SQLiteC++/Database.cpp @@ -16,7 +16,7 @@ namespace SQLite { // Open the provided database UTF-8 filename. -Database::Database(const char* apFilename, const int aFlags /*= SQLITE_OPEN_READONLY*/) throw(SQLite::Exception) : +Database::Database(const char* apFilename, const int aFlags /*= SQLITE_OPEN_READONLY*/) : // throw(SQLite::Exception) mpSQLite(NULL), mFilename(apFilename) { @@ -50,13 +50,13 @@ Database::~Database(void) throw() // nothrow } // Register a Statement object (a SQLite query) -void Database::registerStatement(Statement& aStatement) throw(SQLite::Exception) +void Database::registerStatement(Statement& aStatement) // throw(SQLite::Exception) { mStatementList.push_back(&aStatement); } // Unregister a Statement object -void Database::unregisterStatement(Statement& aStatement) throw(SQLite::Exception) +void Database::unregisterStatement(Statement& aStatement) // throw(SQLite::Exception) { std::vector::iterator iStatement; iStatement = std::find(mStatementList.begin(), mStatementList.end(), &aStatement); diff --git a/src/SQLiteC++/Database.h b/src/SQLiteC++/Database.h index b930246..3b95c38 100644 --- a/src/SQLiteC++/Database.h +++ b/src/SQLiteC++/Database.h @@ -45,7 +45,7 @@ public: * @param[in] apFilename UTF-8 path/uri to the database file ("filename" sqlite3 parameter) * @param[in] aFlags SQLITE_OPEN_READONLY/SQLITE_OPEN_READWRITE/SQLITE_OPEN_CREATE... */ - explicit Database(const char* apFilename, const int aFlags = SQLITE_OPEN_READONLY) throw(SQLite::Exception); + explicit Database(const char* apFilename, const int aFlags = SQLITE_OPEN_READONLY); // throw(SQLite::Exception); /** * @brief Close the SQLite database connection. @@ -58,12 +58,12 @@ public: /** * @brief Register a Statement object (a SQLite query) */ - void registerStatement(Statement& aStatement) throw(SQLite::Exception); + void registerStatement(Statement& aStatement); // throw(SQLite::Exception); /** * @brief Unregister a Statement object */ - void unregisterStatement(Statement& aStatement) throw(SQLite::Exception); + void unregisterStatement(Statement& aStatement); // throw(SQLite::Exception); /** * @brief Filename used to open the database diff --git a/src/SQLiteC++/Statement.cpp b/src/SQLiteC++/Statement.cpp index 9ae6411..b9e33ca 100644 --- a/src/SQLiteC++/Statement.cpp +++ b/src/SQLiteC++/Statement.cpp @@ -16,7 +16,7 @@ namespace SQLite { // Compile and register the SQL query for the provided SQLite Database Connection -Statement::Statement(Database &aDatabase, const char* apQuery) throw(SQLite::Exception) : +Statement::Statement(Database &aDatabase, const char* apQuery) : // throw(SQLite::Exception) mpStmt(NULL), mDatabase(aDatabase), mQuery(apQuery), @@ -43,7 +43,7 @@ Statement::~Statement(void) throw() // nothrow } // Reset the statement to make it ready for a new execution -void Statement::reset(void) throw(SQLite::Exception) +void Statement::reset(void) // throw(SQLite::Exception) { mbDone = false; int ret = sqlite3_reset(mpStmt); @@ -54,7 +54,7 @@ void Statement::reset(void) throw(SQLite::Exception) } // Bind an int value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement -void Statement::bind(const int aIndex, const int& aValue) throw(SQLite::Exception) +void Statement::bind(const int aIndex, const int& aValue) // throw(SQLite::Exception) { int ret = sqlite3_bind_int(mpStmt, aIndex, aValue); if (SQLITE_OK != ret) @@ -64,7 +64,7 @@ void Statement::bind(const int aIndex, const int& aValue) throw(SQLite::Exceptio } // Bind a 64bits int value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement -void Statement::bind(const int aIndex, const sqlite3_int64& aValue) throw(SQLite::Exception) +void Statement::bind(const int aIndex, const sqlite3_int64& aValue) // throw(SQLite::Exception) { int ret = sqlite3_bind_int64(mpStmt, aIndex, aValue); @@ -75,7 +75,7 @@ void Statement::bind(const int aIndex, const sqlite3_int64& aValue) throw(SQLite } // Bind a double (64bits float) value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement -void Statement::bind(const int aIndex, const double& aValue) throw(SQLite::Exception) +void Statement::bind(const int aIndex, const double& aValue) // throw(SQLite::Exception) { int ret = sqlite3_bind_double(mpStmt, aIndex, aValue); if (SQLITE_OK != ret) @@ -85,7 +85,7 @@ void Statement::bind(const int aIndex, const double& aValue) throw(SQLite::Excep } // Bind a string value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement -void Statement::bind(const int aIndex, const std::string& aValue) throw(SQLite::Exception) +void Statement::bind(const int aIndex, const std::string& aValue) // throw(SQLite::Exception) { int ret = sqlite3_bind_text(mpStmt, aIndex, aValue.c_str(), aValue.size(), SQLITE_TRANSIENT); if (SQLITE_OK != ret) @@ -95,7 +95,7 @@ void Statement::bind(const int aIndex, const std::string& aValue) throw(SQLite:: } // Bind a text value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement -void Statement::bind(const int aIndex, const char* apValue) throw(SQLite::Exception) +void Statement::bind(const int aIndex, const char* apValue) // throw(SQLite::Exception) { int ret = sqlite3_bind_text(mpStmt, aIndex, apValue, -1, SQLITE_TRANSIENT); if (SQLITE_OK != ret) @@ -105,7 +105,7 @@ void Statement::bind(const int aIndex, const char* apValue) throw(SQLite::Except } // Bind a NULL value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement -void Statement::bind(const int aIndex) throw(SQLite::Exception) +void Statement::bind(const int aIndex) // throw(SQLite::Exception) { int ret = sqlite3_bind_null(mpStmt, aIndex); if (SQLITE_OK != ret) @@ -115,7 +115,7 @@ void Statement::bind(const int aIndex) throw(SQLite::Exception) } // Execute a step of the query to fetch one row of results -bool Statement::executeStep(void) throw(SQLite::Exception) +bool Statement::executeStep(void) // throw(SQLite::Exception) { bool bOk = false; @@ -140,5 +140,10 @@ bool Statement::executeStep(void) throw(SQLite::Exception) return bOk; } +// Return the number of columns in the result set returned by the prepared statement +int Statement::getColumnCount(void) const throw() // nothrow +{ + return sqlite3_column_count(mpStmt); +} }; // namespace SQLite diff --git a/src/SQLiteC++/Statement.h b/src/SQLiteC++/Statement.h index ca0437d..7561ba1 100644 --- a/src/SQLiteC++/Statement.h +++ b/src/SQLiteC++/Statement.h @@ -32,7 +32,7 @@ public: * * Exception is thrown in case of error, then the Statement object is NOT constructed. */ - explicit Statement(Database &aDatabase, const char* apQuery) throw(SQLite::Exception); + explicit Statement(Database &aDatabase, const char* apQuery); // throw(SQLite::Exception); /** * @brief Finalize and unregister the SQL query from the SQLite Database Connection. @@ -42,37 +42,42 @@ public: /** * @brief Reset the statement to make it ready for a new execution. */ - void reset(void) throw(SQLite::Exception); + void reset(void); // throw(SQLite::Exception); /** * @brief Bind an int value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement */ - void bind(const int aIndex, const int& aValue) throw(SQLite::Exception); + void bind(const int aIndex, const int& aValue) ; // throw(SQLite::Exception); /** * @brief Bind a 64bits int value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement */ - void bind(const int aIndex, const sqlite3_int64& aValue) throw(SQLite::Exception); + void bind(const int aIndex, const sqlite3_int64& aValue) ; // throw(SQLite::Exception); /** * @brief Bind a double (64bits float) value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement */ - void bind(const int aIndex, const double& aValue) throw(SQLite::Exception); + void bind(const int aIndex, const double& aValue) ; // throw(SQLite::Exception); /** * @brief Bind a string value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement */ - void bind(const int aIndex, const std::string& aValue) throw(SQLite::Exception); + void bind(const int aIndex, const std::string& aValue) ; // throw(SQLite::Exception); /** * @brief Bind a text value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement */ - void bind(const int aIndex, const char* apValue) throw(SQLite::Exception); + void bind(const int aIndex, const char* apValue) ; // throw(SQLite::Exception); /** * @brief Bind a NULL value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement */ - void bind(const int aIndex) throw(SQLite::Exception); // bind NULL value + void bind(const int aIndex); // throw(SQLite::Exception); // bind NULL value /** * @brief Execute a step of the query to fetch one row of results. */ - bool executeStep(void) throw(SQLite::Exception); + bool executeStep(void); // throw(SQLite::Exception); + + /** + * @brief Return the number of columns in the result set returned by the prepared statement + */ + int getColumnCount(void) const throw(); // nothrow /** * @brief UTF-8 SQL Query. diff --git a/src/example1/main.cpp b/src/example1/main.cpp index d7be5ba..3ebd7e4 100644 --- a/src/example1/main.cpp +++ b/src/example1/main.cpp @@ -11,6 +11,7 @@ int main (void) // Compile a SQL query, containing one parameter (index 1) SQLite::Statement query(db, "SELECT * FROM test WHERE size>?"); + std::cout << "SQLite statement compiled (" << query.getColumnCount () << " collumns in the result)\n"; // Bind an integer value "6" to the first parameter of the SQL query query.bind(1, 6);