return false;
}
QSqlQuery cur(db);
- cur.exec("create table bookmarks(word text ,translation text)");
+ cur.exec("create table bookmarks(key text ,translation text)");
return true;
}
QList<Translation*> Bookmarks::searchWordList(QString word) {
- if(word.indexOf("*")==-1 && word.indexOf("?")== 0)
+
+ if(word.indexOf("*")==-1 && word.indexOf("?")== -1)
word+="%";
word = word.replace("*", "%");
word = word.replace("?", "_");
word = removeAccents(word);
QSqlQuery cur(db);
- cur.prepare("select key from bookmarks where key=?");
+ cur.prepare("select key from bookmarks where key like ?");
cur.addBindValue(word);
cur.exec();
- QList<Translation*> res;
+ QSet<QString> res;
while(cur.next())
- res.append(new BookmarkTranslation(cur.value(0).toString(), this));
- return res;
+ res.insert(cur.value(0).toString());
+ qDebug() << "searchWordList " << res.size();
+ QList<Translation*> tr;
+ foreach(QString str, res.toList())
+ tr.append(new BookmarkTranslation(str, this));
+ return tr;
}
QStringList Bookmarks::search(QString word) {
+ qDebug() << "bookmarks::search";
QSqlQuery cur(db);
QStringList result;
- cur.prepare("select translation from bookmarks where word=?");
+ cur.prepare("select translation from bookmarks where key=?");
cur.addBindValue(word);
cur.exec();
while(cur.next())
result << cur.value(0).toString();
+
+ qDebug() << result.size() << " " << result;
return result;
}
bool Bookmarks::inBookmarks(QString word) {
QSqlQuery cur(db);
- cur.prepare("select translation from bookmarks where word=? limit 1");
+ cur.prepare("select translation from bookmarks where key like ? limit 1");
cur.addBindValue(word);
cur.exec();
if(cur.next())