Hi All,
i want to search in large libraries with sql
about 20000 books;
each book is in one table and all book names stored in table named books;
my code for search is :
void MyThread::run()
{
QStringList bookTables
=db
->getList
("Select booktable From books;");
QStringList bookNames
=db
->getList
("Select bookNames From books;");
int rowBook=0;
int totalResultBooks=0;
int totalResult=0;
int allBookCount=bookTables.size();
emit sendMaxProgress(allBookCount-1);
while(rowBook<allBookCount )
{
QString query
= QString("Select count(id) From b%1 Where text LIKE '%%2%' Limit 0,1 ; ").
arg(bookTables.
at(rowBook
)).
arg(searchPatterned
);
QString resultBook
=db
->getStr
(query
);
if(resultBook.toInt()>0)
{
totalResult+= resultBook.toInt();
totalResultBooks++;
item->setText(bookNames.at(rowBook)+" ("+resultBook+") ");
item->setData(12,bookTables.at(rowBook));
emit sendResult(item,str,rowBook);
}
msleep(40);
rowBook++;
}
}
void MyThread::run()
{
QStringList bookTables =db->getList("Select booktable From books;");
QStringList bookNames =db->getList("Select bookNames From books;");
int rowBook=0;
int totalResultBooks=0;
int totalResult=0;
int allBookCount=bookTables.size();
emit sendMaxProgress(allBookCount-1);
while(rowBook<allBookCount )
{
QString query = QString("Select count(id) From b%1 Where text LIKE '%%2%' Limit 0,1 ; ").arg(bookTables.at(rowBook)).arg(searchPatterned);
QString resultBook =db->getStr(query);
if(resultBook.toInt()>0)
{
totalResult+= resultBook.toInt();
totalResultBooks++;
QListWidgetItem *item = new QListWidgetItem;
item->setText(bookNames.at(rowBook)+" ("+resultBook+") ");
item->setData(12,bookTables.at(rowBook));
QString str = "found "+QString::number(totalResult)+"at"+QString::number(totalResultBooks)+"Books";
emit sendResult(item,str,rowBook);
}
msleep(40);
rowBook++;
}
}
To copy to clipboard, switch view to plain text mode
my question is :
i used :
msleep(40);
msleep(40);
To copy to clipboard, switch view to plain text mode
to free 20% of cpu ..
is this way right?
is there any better way ?
Bookmarks