From bb68ecb2cbe09cee6de53ec2623f748699836525 Mon Sep 17 00:00:00 2001 From: Elie Zananiri Date: Thu, 29 Aug 2013 16:11:30 -0400 Subject: [PATCH 1/2] Using ofLog instead of cout. --- src/ofxSQLite.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ofxSQLite.cpp b/src/ofxSQLite.cpp index 6e3b4c5..e173d1b 100755 --- a/src/ofxSQLite.cpp +++ b/src/ofxSQLite.cpp @@ -5,6 +5,8 @@ #include "ofxSQLiteSelect.h" //#include "ofxSQLiteSimpler.h" +#include "ofLog.h" + ofxSQLite::ofxSQLite() :db_name("") { @@ -21,10 +23,11 @@ void ofxSQLite::setup(std::string sDB) { db_name = sDB; db_file = sDB; if (SQLITE_OK != sqlite3_open(db_file.c_str(), &db)) { - cout << sqlite3_errmsg(db); exit(1); + ofLogError("ofxSQLite") << sqlite3_errmsg(db); } - cout << "opened:" << db_file << endl; + + ofLogNotice("ofxSQLite") << "Opened:" << db_file << endl; } int ofxSQLite::simpleQuery(const char* pSQL) { @@ -40,6 +43,7 @@ ofxSQLiteInsert ofxSQLite::insert(std::string sTable) { ofxSQLiteInsert insert = ofxSQLiteInsert(db, sTable); return insert; } + ofxSQLiteUpdate ofxSQLite::update(std::string sTable) { return ofxSQLiteUpdate(db, sTable); } From 029e6917128ea9bcf2e980df560c9603806e057d Mon Sep 17 00:00:00 2001 From: Elie Zananiri Date: Thu, 29 Aug 2013 16:11:58 -0400 Subject: [PATCH 2/2] setup() now returns a success flag instead of exiting the app if there's an error. --- src/ofxSQLite.cpp | 5 +++-- src/ofxSQLite.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ofxSQLite.cpp b/src/ofxSQLite.cpp index e173d1b..278071e 100755 --- a/src/ofxSQLite.cpp +++ b/src/ofxSQLite.cpp @@ -19,15 +19,16 @@ ofxSQLite::ofxSQLite(std::string sDB):db_name(sDB) { setup(sDB); } -void ofxSQLite::setup(std::string sDB) { +bool ofxSQLite::setup(std::string sDB) { db_name = sDB; db_file = sDB; if (SQLITE_OK != sqlite3_open(db_file.c_str(), &db)) { - exit(1); ofLogError("ofxSQLite") << sqlite3_errmsg(db); + return false; } ofLogNotice("ofxSQLite") << "Opened:" << db_file << endl; + return true; } int ofxSQLite::simpleQuery(const char* pSQL) { diff --git a/src/ofxSQLite.h b/src/ofxSQLite.h index bbd65b5..7957cbc 100755 --- a/src/ofxSQLite.h +++ b/src/ofxSQLite.h @@ -39,7 +39,7 @@ class ofxSQLite { public: ofxSQLite(); ofxSQLite(std::string sDB); - void setup(std::string sDB); + bool setup(std::string sDB); ofxSQLiteInsert insert(std::string sTable); ofxSQLiteUpdate update(std::string sTable); ofxSQLiteDelete remove(std::string sTable);