Added a Database::tableExists() easy to use function, useful for unit testing.

- Adding a Doxyfile to generate documentation of the wrapper
This commit is contained in:
Sébastien Rombauts 2012-04-23 07:16:59 +02:00
parent cfe042dd41
commit 37a760945c
6 changed files with 1722 additions and 12 deletions

1690
Doxyfile Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,10 @@
Add a comparison of others C++ wrappers (code style, C++ design, in code documentation, tests, online documentation, examples, license, UTF-16)
Missing features in v0.3.0:
- Database::tableExists
Missing features in v0.4.0:
- Blob
- getColumnByName ? std::map getRow() ?
Missing documentation in v0.3.0:
Missing documentation in v0.4.0:
- Help for the new helper functions
Advanced missing features:

View File

@ -53,13 +53,23 @@ int Database::exec(const char* apQueries) // throw(SQLite::Exception);
// WARNING: Be very careful with this dangerous method: you have to
// make a COPY OF THE result, else it will be destroy before the next line
// (when the underlying temporary Statement and Column objects are destroyed)
// this is an issue only for pointer type result (ie. char* and blob)
Column Database::execAndGet(const char* apQuery) // throw(SQLite::Exception)
{
Statement query(*this, apQuery);
query.executeStep();
return query.getColumn(0);
Statement query(*this, apQuery);
query.executeStep();
return query.getColumn(0);
}
// Shortcut to test if a table exists.
bool Database::tableExists(const char* apTableName) // throw(SQLite::Exception)
{
Statement query(*this, "SELECT count(*) FROM sqlite_master WHERE type='table' AND name=?");
query.bind(1, apTableName);
query.executeStep();
int Nb = query.getColumn(0);
return (1 == Nb);
}
// Check if aRet equal SQLITE_OK, else throw a SQLite::Exception with the SQLite error message
void Database::check(const int aRet) const // throw(SQLite::Exception)

View File

@ -78,10 +78,19 @@ public:
*
* @see also Statement class for handling queries with multiple results
*
* @param[in] apQuery a UTF-8 encoded SQL query
* @param[in] apQuery an UTF-8 encoded SQL query
*/
Column execAndGet(const char* apQuery); // throw(SQLite::Exception);
/**
* @brief Shortcut to test if a table exists.
*
* Table names are case sensitive.
*
* @param[in] apTableName an UTF-8 encoded case sensitive Table name
*/
bool tableExists(const char* apTableName); // throw(SQLite::Exception);
/**
* @brief Set a busy handler that sleeps for a specified amount of time when a table is locked.
*

View File

@ -32,5 +32,5 @@
* with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same
* numbers used in [SQLITECPP_VERSION].
*/
#define SQLITECPP_VERSION "0.3.0"
#define SQLITECPP_VERSION_NUMBER 0003000
#define SQLITECPP_VERSION "0.4.0"
#define SQLITECPP_VERSION_NUMBER 0004000

View File

@ -65,9 +65,11 @@ int main (void)
SQLite::Database db("example.db3");
std::cout << "SQLite database file '" << db.getFilename().c_str() << "' opened successfully\n";
// TODO SRombauts:
//SQLite::Statement::Column col = db.execAndGet("SELECT value FROM test WHERE id=2");
//const char* pvalue = col;
// Test if the 'test' table exists
bool bExists = db.tableExists("test");
std::cout << "SQLite table 'test' exists=" << bExists << "\n";
// Get a single value result with an easy to use shortcut
std::string value = db.execAndGet("SELECT value FROM test WHERE id=2");
std::cout << "execAndGet=" << value << std::endl;