mirror of
https://github.com/cuberite/SQLiteCpp.git
synced 2025-08-04 09:46:02 -04:00
Added an easy wrapper Column Database::execAndGet("query"), version number increased to 0.3.0
This commit is contained in:
parent
d516ea72c5
commit
fb1b17bfff
12
.cproject
12
.cproject
@ -467,7 +467,11 @@
|
|||||||
</storageModule>
|
</storageModule>
|
||||||
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
|
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
|
||||||
<storageModule moduleId="org.eclipse.cdt.core.language.mapping"/>
|
<storageModule moduleId="org.eclipse.cdt.core.language.mapping"/>
|
||||||
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
|
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings">
|
||||||
|
<doc-comment-owner id="org.eclipse.cdt.ui.doxygen">
|
||||||
|
<path value=""/>
|
||||||
|
</doc-comment-owner>
|
||||||
|
</storageModule>
|
||||||
</cconfiguration>
|
</cconfiguration>
|
||||||
<cconfiguration id="cdt.managedbuild.config.gnu.exe.release.326780594">
|
<cconfiguration id="cdt.managedbuild.config.gnu.exe.release.326780594">
|
||||||
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.release.326780594" moduleId="org.eclipse.cdt.core.settings" name="Release">
|
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.release.326780594" moduleId="org.eclipse.cdt.core.settings" name="Release">
|
||||||
@ -929,7 +933,11 @@
|
|||||||
</storageModule>
|
</storageModule>
|
||||||
<storageModule moduleId="org.eclipse.cdt.core.language.mapping"/>
|
<storageModule moduleId="org.eclipse.cdt.core.language.mapping"/>
|
||||||
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
|
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
|
||||||
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
|
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings">
|
||||||
|
<doc-comment-owner id="org.eclipse.cdt.ui.doxygen">
|
||||||
|
<path value=""/>
|
||||||
|
</doc-comment-owner>
|
||||||
|
</storageModule>
|
||||||
</cconfiguration>
|
</cconfiguration>
|
||||||
</storageModule>
|
</storageModule>
|
||||||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@ Release
|
|||||||
*.suo
|
*.suo
|
||||||
*.user
|
*.user
|
||||||
*~
|
*~
|
||||||
|
core
|
||||||
|
5
TODO.txt
5
TODO.txt
@ -1,9 +1,8 @@
|
|||||||
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.2.0:
|
Missing features in v0.3.0:
|
||||||
- Statement::execStepAndGetScalar() easy wrapper
|
|
||||||
- Database::execScalar() easy wrapper like CppSqlite
|
|
||||||
- Database::tableExists
|
- Database::tableExists
|
||||||
|
- Blob
|
||||||
- getColumnByName ? std::map getRow() ?
|
- getColumnByName ? std::map getRow() ?
|
||||||
|
|
||||||
Advanced missing features:
|
Advanced missing features:
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
#include "Database.h"
|
#include "Database.h"
|
||||||
|
|
||||||
#include "Statement.h"
|
#include "Statement.h"
|
||||||
#include "Column.h"
|
|
||||||
|
|
||||||
namespace SQLite
|
namespace SQLite
|
||||||
{
|
{
|
||||||
@ -50,6 +49,18 @@ int Database::exec(const char* apQueries) // throw(SQLite::Exception);
|
|||||||
return sqlite3_changes(mpSQLite);
|
return sqlite3_changes(mpSQLite);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Shortcut to execute a one step query and fetch the first column of the result.
|
||||||
|
// 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)
|
||||||
|
Column Database::execAndGet(const char* apQuery) // throw(SQLite::Exception)
|
||||||
|
{
|
||||||
|
Statement query(*this, apQuery);
|
||||||
|
query.executeStep();
|
||||||
|
return query.getColumn(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 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)
|
||||||
{
|
{
|
||||||
|
@ -11,14 +11,11 @@
|
|||||||
|
|
||||||
#include <sqlite3.h>
|
#include <sqlite3.h>
|
||||||
#include "Exception.h"
|
#include "Exception.h"
|
||||||
|
#include "Column.h"
|
||||||
|
|
||||||
namespace SQLite
|
namespace SQLite
|
||||||
{
|
{
|
||||||
|
|
||||||
// Forward declarations
|
|
||||||
class Statement;
|
|
||||||
class Exception;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief RAII management of a SQLite Database Connection.
|
* @brief RAII management of a SQLite Database Connection.
|
||||||
*
|
*
|
||||||
@ -68,6 +65,23 @@ public:
|
|||||||
*/
|
*/
|
||||||
int exec(const char* apQueries); // throw(SQLite::Exception);
|
int exec(const char* apQueries); // throw(SQLite::Exception);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Shortcut to execute a one step query and fetch the first column of the result.
|
||||||
|
*
|
||||||
|
* This is a shortcut to execute a simple statement with a single result.
|
||||||
|
* This should be used only for non reusable queries (else you should use a Statement with bind()).
|
||||||
|
* This should be used only for queries with expected results (else an exception is fired).
|
||||||
|
*
|
||||||
|
* @warning 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)
|
||||||
|
*
|
||||||
|
* @see also Statement class for handling queries with multiple results
|
||||||
|
*
|
||||||
|
* @param[in] apQuery a UTF-8 encoded SQL query
|
||||||
|
*/
|
||||||
|
Column execAndGet(const char* apQuery); // 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.
|
||||||
*
|
*
|
||||||
@ -80,7 +94,7 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the rowid of the most recent successful INSERT into the database from the current connection.
|
* @brief Get the rowid of the most recent successful INSERT into the database from the current connection.
|
||||||
*
|
*
|
||||||
* @return Rowid of the most recent successful INSERT into the database, or 0 if there was none.
|
* @return Rowid of the most recent successful INSERT into the database, or 0 if there was none.
|
||||||
*/
|
*/
|
||||||
inline sqlite3_int64 getLastInsertRowid(void) const // throw(); nothrow
|
inline sqlite3_int64 getLastInsertRowid(void) const // throw(); nothrow
|
||||||
|
@ -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.2.0"
|
#define SQLITECPP_VERSION "0.3.0"
|
||||||
#define SQLITECPP_VERSION_NUMBER 0002000
|
#define SQLITECPP_VERSION_NUMBER 0003000
|
||||||
|
@ -58,13 +58,19 @@ private:
|
|||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
// Basic example (1/4) :
|
// Basic example (1/5) :
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Open a database file
|
// Open a database file
|
||||||
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:
|
||||||
|
//SQLite::Statement::Column col = db.execAndGet("SELECT value FROM test WHERE id=2");
|
||||||
|
//const char* pvalue = col;
|
||||||
|
std::string value = db.execAndGet("SELECT value FROM test WHERE id=2");
|
||||||
|
std::cout << "execAndGet=" << value << std::endl;
|
||||||
|
|
||||||
// Compile a SQL query, containing one parameter (index 1)
|
// Compile a SQL query, containing one parameter (index 1)
|
||||||
SQLite::Statement query(db, "SELECT * FROM test WHERE size > ?");
|
SQLite::Statement query(db, "SELECT * FROM test WHERE size > ?");
|
||||||
std::cout << "SQLite statement '" << query.getQuery().c_str() << "' compiled (" << query.getColumnCount () << " columns in the result)\n";
|
std::cout << "SQLite statement '" << query.getQuery().c_str() << "' compiled (" << query.getColumnCount () << " columns in the result)\n";
|
||||||
@ -101,7 +107,7 @@ int main (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
// Object Oriented Basic example (2/4) :
|
// Object Oriented Basic example (2/5) :
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Open the database and compile the query
|
// Open the database and compile the query
|
||||||
@ -117,8 +123,26 @@ int main (void)
|
|||||||
std::cout << "SQLite exception: " << e.what() << std::endl;
|
std::cout << "SQLite exception: " << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The execAndGet wrapper example (3/5) :
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Open a database file
|
||||||
|
SQLite::Database db("example.db3");
|
||||||
|
std::cout << "SQLite database file '" << db.getFilename().c_str() << "' opened successfully\n";
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
std::string value = db.execAndGet("SELECT value FROM test WHERE id=2");
|
||||||
|
std::cout << "execAndGet=" << value << std::endl;
|
||||||
|
}
|
||||||
|
catch (std::exception& e)
|
||||||
|
{
|
||||||
|
std::cout << "SQLite exception: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
// Simple batch queries example (3/4) :
|
// Simple batch queries example (4/5) :
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Open a database file
|
// Open a database file
|
||||||
@ -141,7 +165,7 @@ int main (void)
|
|||||||
remove("test.db3");
|
remove("test.db3");
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
// RAII transaction example (4/4) :
|
// RAII transaction example (5/5) :
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Open a database file
|
// Open a database file
|
||||||
|
Loading…
x
Reference in New Issue
Block a user