Fixed the example failing to find the example files in the new directory structure

+ Fixed a GCC unused variable warning in example1
This commit is contained in:
Sébastien Rombauts 2013-03-13 17:58:49 +01:00
parent 017927741f
commit 3ee357900e

View File

@ -20,13 +20,17 @@
#include "../../src/Transaction.h" #include "../../src/Transaction.h"
static const char* filename_example_db3 = "examples/example1/example.db3";
static const char* filename_logo_png = "examples/example1/logo.png";
/// Object Oriented Basic example /// Object Oriented Basic example
class Example class Example
{ {
public: public:
// Constructor // Constructor
Example(void) : Example(void) :
mDb("example.db3"), // Open a database file in readonly mode mDb(filename_example_db3), // Open a database file in readonly mode
mQuery(mDb, "SELECT * FROM test WHERE weight > :min_weight")// Compile a SQL query, containing one parameter (index 1) mQuery(mDb, "SELECT * FROM test WHERE weight > :min_weight")// Compile a SQL query, containing one parameter (index 1)
{ {
} }
@ -64,7 +68,7 @@ int main (void)
try try
{ {
// Open a database file in readonly mode // Open a database file in readonly mode
SQLite::Database db("example.db3"); // SQLITE_OPEN_READONLY SQLite::Database db(filename_example_db3); // SQLITE_OPEN_READONLY
std::cout << "SQLite database file '" << db.getFilename().c_str() << "' opened successfully\n"; std::cout << "SQLite database file '" << db.getFilename().c_str() << "' opened successfully\n";
// Test if the 'test' table exists // Test if the 'test' table exists
@ -136,7 +140,7 @@ int main (void)
try try
{ {
// Open a database file in readonly mode // Open a database file in readonly mode
SQLite::Database db("example.db3"); // SQLITE_OPEN_READONLY SQLite::Database db(filename_example_db3); // SQLITE_OPEN_READONLY
std::cout << "SQLite database file '" << db.getFilename().c_str() << "' opened successfully\n"; std::cout << "SQLite database file '" << db.getFilename().c_str() << "' opened successfully\n";
// WARNING: Be very careful with this dangerous method: you have to // WARNING: Be very careful with this dangerous method: you have to
@ -271,7 +275,7 @@ int main (void)
db.exec("DROP TABLE IF EXISTS test"); db.exec("DROP TABLE IF EXISTS test");
db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value BLOB)"); db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value BLOB)");
FILE* fp = fopen("logo.png", "rb"); FILE* fp = fopen(filename_logo_png, "rb");
if (NULL != fp) if (NULL != fp)
{ {
char buffer[16*1024]; char buffer[16*1024];
@ -293,7 +297,7 @@ int main (void)
} }
else else
{ {
std::cout << "file logo.png not found !\n"; std::cout << "file " << filename_logo_png << " not found !\n";
abort(); // unexpected error : abort the example program abort(); // unexpected error : abort the example program
} }
@ -312,6 +316,7 @@ int main (void)
size = colBlob.getBytes (); size = colBlob.getBytes ();
std::cout << "row : (" << query.getColumn(0) << ", size=" << size << ")\n"; std::cout << "row : (" << query.getColumn(0) << ", size=" << size << ")\n";
size_t sizew = fwrite(blob, 1, size, fp); size_t sizew = fwrite(blob, 1, size, fp);
assert(sizew == size);
fclose (fp); fclose (fp);
} }
} }