mirror of
https://github.com/cuberite/SQLiteCpp.git
synced 2025-08-04 09:46:02 -04:00
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:
parent
cfe042dd41
commit
37a760945c
5
TODO.txt
5
TODO.txt
@ -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)
|
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:
|
Missing features in v0.4.0:
|
||||||
- Database::tableExists
|
|
||||||
- Blob
|
- Blob
|
||||||
- getColumnByName ? std::map getRow() ?
|
- getColumnByName ? std::map getRow() ?
|
||||||
|
|
||||||
Missing documentation in v0.3.0:
|
Missing documentation in v0.4.0:
|
||||||
- Help for the new helper functions
|
- Help for the new helper functions
|
||||||
|
|
||||||
Advanced missing features:
|
Advanced missing features:
|
||||||
|
@ -53,6 +53,7 @@ int Database::exec(const char* apQueries) // throw(SQLite::Exception);
|
|||||||
// WARNING: Be very careful with this dangerous method: you have to
|
// 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
|
// 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)
|
// (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)
|
Column Database::execAndGet(const char* apQuery) // throw(SQLite::Exception)
|
||||||
{
|
{
|
||||||
Statement query(*this, apQuery);
|
Statement query(*this, apQuery);
|
||||||
@ -60,6 +61,15 @@ Column Database::execAndGet(const char* apQuery) // throw(SQLite::Exception)
|
|||||||
return query.getColumn(0);
|
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
|
// 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)
|
void Database::check(const int aRet) const // throw(SQLite::Exception)
|
||||||
|
@ -78,10 +78,19 @@ public:
|
|||||||
*
|
*
|
||||||
* @see also Statement class for handling queries with multiple results
|
* @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);
|
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.
|
* @brief Set a busy handler that sleeps for a specified amount of time when a table is locked.
|
||||||
*
|
*
|
||||||
|
@ -32,5 +32,5 @@
|
|||||||
* with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same
|
* with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same
|
||||||
* numbers used in [SQLITECPP_VERSION].
|
* numbers used in [SQLITECPP_VERSION].
|
||||||
*/
|
*/
|
||||||
#define SQLITECPP_VERSION "0.3.0"
|
#define SQLITECPP_VERSION "0.4.0"
|
||||||
#define SQLITECPP_VERSION_NUMBER 0003000
|
#define SQLITECPP_VERSION_NUMBER 0004000
|
||||||
|
@ -65,9 +65,11 @@ int main (void)
|
|||||||
SQLite::Database db("example.db3");
|
SQLite::Database db("example.db3");
|
||||||
std::cout << "SQLite database file '" << db.getFilename().c_str() << "' opened successfully\n";
|
std::cout << "SQLite database file '" << db.getFilename().c_str() << "' opened successfully\n";
|
||||||
|
|
||||||
// TODO SRombauts:
|
// Test if the 'test' table exists
|
||||||
//SQLite::Statement::Column col = db.execAndGet("SELECT value FROM test WHERE id=2");
|
bool bExists = db.tableExists("test");
|
||||||
//const char* pvalue = col;
|
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::string value = db.execAndGet("SELECT value FROM test WHERE id=2");
|
||||||
std::cout << "execAndGet=" << value << std::endl;
|
std::cout << "execAndGet=" << value << std::endl;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user