From a2446187fa1ff61656820c032bf7bdbaea14ba5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Rombauts?= Date: Wed, 31 Oct 2012 10:10:49 +0100 Subject: [PATCH] Added comments on opening a database connection --- src/SQLiteC++/Database.cpp | 5 +++-- src/example1/main.cpp | 21 +++++++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/SQLiteC++/Database.cpp b/src/SQLiteC++/Database.cpp index bdcd4a9..b1baf3e 100644 --- a/src/SQLiteC++/Database.cpp +++ b/src/SQLiteC++/Database.cpp @@ -14,12 +14,13 @@ namespace SQLite { -// Open the provided database UTF-8 filename. +// Open the provided database UTF-8 filename with SQLITE_OPEN_xxx provided flags. Database::Database(const char* apFilename, const int aFlags /*= SQLITE_OPEN_READONLY*/) : // throw(SQLite::Exception) mpSQLite(NULL), mFilename(apFilename) { - // TODO SRombauts : add a :memory: mode, and a backup to/from :memory: + // TODO SRombauts : use the "zVfs" (last) parameter to give access to the ":memory:" VFS module + // TODO SRombauts : then add a backup mode to/from ":memory:" int ret = sqlite3_open_v2(apFilename, &mpSQLite, aFlags, NULL); if (SQLITE_OK != ret) { diff --git a/src/example1/main.cpp b/src/example1/main.cpp index 888bafb..5fd37f9 100644 --- a/src/example1/main.cpp +++ b/src/example1/main.cpp @@ -23,8 +23,9 @@ class Example { public: + // Constructor Example(void) : - mDb("example.db3"), // Open a database file + mDb("example.db3"), // Open a database file in readonly mode mQuery(mDb, "SELECT * FROM test WHERE size > :min_size")// Compile a SQL query, containing one parameter (index 1) { } @@ -32,7 +33,7 @@ public: { } - // List the rows where the "size" column is greater than the provided aParamValue + /// List the rows where the "size" column is greater than the provided aParamValue void ListGreaterThan (const int aParamValue) { std::cout << "ListGreaterThan (" << aParamValue << ")\n"; @@ -51,8 +52,8 @@ public: } private: - SQLite::Database mDb; - SQLite::Statement mQuery; + SQLite::Database mDb; ///< Database connection + SQLite::Statement mQuery; ///< Database prepared SQL query }; @@ -61,8 +62,8 @@ int main (void) // Basic example (1/5) : try { - // Open a database file - SQLite::Database db("example.db3"); + // Open a database file in readonly mode + SQLite::Database db("example.db3"); // SQLITE_OPEN_READONLY std::cout << "SQLite database file '" << db.getFilename().c_str() << "' opened successfully\n"; // Test if the 'test' table exists @@ -128,8 +129,8 @@ int main (void) // The execAndGet wrapper example (3/5) : try { - // Open a database file - SQLite::Database db("example.db3"); + // Open a database file in readonly mode + SQLite::Database db("example.db3"); // SQLITE_OPEN_READONLY std::cout << "SQLite database file '" << db.getFilename().c_str() << "' opened successfully\n"; // WARNING: Be very careful with this dangerous method: you have to @@ -147,7 +148,7 @@ int main (void) // Simple batch queries example (4/5) : try { - // Open a database file + // Open a database file in create/write mode SQLite::Database db("test.db3", SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE); std::cout << "SQLite database file '" << db.getFilename().c_str() << "' opened successfully\n"; @@ -170,7 +171,7 @@ int main (void) // RAII transaction example (5/5) : try { - // Open a database file + // Open a database file in create/write mode SQLite::Database db("transaction.db3", SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE); std::cout << "SQLite database file '" << db.getFilename().c_str() << "' opened successfully\n";