Added a second possibility to create the directory and removed the TODO.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 5 Sep 2012 19:30:08 +0000 (19:30 +0000)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 5 Sep 2012 19:30:08 +0000 (19:30 +0000)
src/sql/sqlengine.cpp

index a0771d7..62d27e3 100644 (file)
@@ -46,8 +46,18 @@ SqlEngine::~SqlEngine() {
 
 
 void SqlEngine::open() {
+    // we may have to create the directory of the database
     QFileInfo dbFilenameInfo(dbFilename);
-    dbFilenameInfo.absoluteDir().mkpath("."); // TODO: handle error
+
+    // First possibility (works with Linux, not tested on Windows:
+    // QDir cwd;
+    // cwd.mkpath(dbFilenameInfo.absolutePath());
+
+    // Second possibility (works on Windows)
+    dbFilenameInfo.absoluteDir().mkpath(".");
+
+    // We don't have to handle errors because in worst case, opening the database will fail
+    // and db.isOpen() returns false.
     db = QSqlDatabase::addDatabase("QSQLITE");
     db.setDatabaseName(dbFilename);
     db.open();