Fixed multiple database connections problem
authorPiotrek <ppilar11@gmail.com>
Wed, 18 Aug 2010 09:41:59 +0000 (11:41 +0200)
committerPiotrek <ppilar11@gmail.com>
Wed, 18 Aug 2010 09:41:59 +0000 (11:41 +0200)
trunk/src/plugins/xdxf/src/xdxfplugin.cpp
trunk/src/plugins/xdxf/tests/test.cpp

index 85379c6..1efd6eb 100644 (file)
@@ -102,6 +102,7 @@ QList<Translation*> XdxfPlugin::searchWordListCache(QString word, int limit) {
         while(cur.next())
             translations.insert(new TranslationXdxf(cur.value(0).toString(),
                                                     _infoNote, this));
+        db.close();
         return translations.toList();
 }
 
@@ -180,6 +181,7 @@ QString XdxfPlugin::searchCache(QString key) {
     cur.exec();
     if(cur.next())
         result = cur.value(0).toString();
+    db.close();
     return result;
 
 }
@@ -259,6 +261,7 @@ CommonDictInterface* XdxfPlugin::getNew(const Settings *settings) const {
 
         plugin->db_name = plugin->_settings->value("type")
                + plugin->_settings->value("path");
+        if(!plugin->db.connectionName().isEmpty())
         plugin->db = QSqlDatabase::addDatabase("QSQLITE", plugin->db_name);
 
         if(settings->value("cached").isEmpty() &&
@@ -482,10 +485,14 @@ bool XdxfPlugin::makeCache(QString dir) {
     cachingDialog->setVisible(false);
 
     if(!cur.next() || countWords() != cur.value(0).toInt())
+    {
+        db.close();
         return false;
+    }
     _settings->setValue("cache_path", cachePathN);
     _settings->setValue("cached", "true");
 
+    db.close();
     return true;
 }
 
index b06adf7..566d782 100644 (file)
@@ -42,7 +42,7 @@ void XdxfTest::search() {
     settings->setValue("path","../tests/dict.xdxf");
     CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
 
-    xdxfPlugin->search("wino");
+    //xdxfPlugin->search("wino");
     QCOMPARE(xdxfPlugin->search("."), QString("kropka\n"));
     QCOMPARE(xdxfPlugin->search("1"), QString("one\n"));
 }
@@ -87,7 +87,6 @@ void XdxfTest::searchWordList() {
     QList<Translation*> te11 = xdxfPlugin->searchWordList("h**?*?**e");
         QCOMPARE(te11.at(0)->key(), QString("house"));
 
-
 }
 
 void XdxfTest::stop() {