Added Statement::getColumnCount() and commented out the throw specifications (they are not usefull)

This commit is contained in:
Sebastien Rombauts 2012-03-31 17:45:40 +02:00
parent abc1f7bfa3
commit 0a1520ced0
5 changed files with 35 additions and 24 deletions

View File

@ -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<Statement*>::iterator iStatement;
iStatement = std::find(mStatementList.begin(), mStatementList.end(), &aStatement);

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -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);