1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

Using prepare SQL statements everywhere it is needed.

This commit is contained in:
nowrep 2012-08-23 15:37:43 +02:00
parent 8d2391da6f
commit 5ca2e2d75f
7 changed files with 55 additions and 15 deletions

View File

@ -58,7 +58,10 @@ bool AutoFillModel::isStored(const QUrl &url)
}
QSqlQuery query;
query.exec("SELECT count(id) FROM autofill WHERE server='" + server + "'");
query.prepare("SELECT count(id) FROM autofill WHERE server=?");
query.addBindValue(server);
query.exec();
query.next();
if (query.value(0).toInt() > 0) {
return true;
@ -78,7 +81,10 @@ bool AutoFillModel::isStoringEnabled(const QUrl &url)
}
QSqlQuery query;
query.exec("SELECT count(id) FROM autofill_exceptions WHERE server='" + server + "'");
query.prepare("SELECT count(id) FROM autofill_exceptions WHERE server=?");
query.addBindValue(server);
query.exec();
query.next();
if (query.value(0).toInt() > 0) {
return false;
@ -107,7 +113,10 @@ QString AutoFillModel::getUsername(const QUrl &url)
}
QSqlQuery query;
query.exec("SELECT username FROM autofill WHERE server='" + server + "'");
query.prepare("SELECT username FROM autofill WHERE server=?");
query.addBindValue(server);
query.exec();
query.next();
return query.value(0).toString();
}
@ -120,7 +129,10 @@ QString AutoFillModel::getPassword(const QUrl &url)
}
QSqlQuery query;
query.exec("SELECT password FROM autofill WHERE server='" + server + "'");
query.prepare("SELECT password FROM autofill WHERE server=?");
query.addBindValue(server);
query.exec();
query.next();
return query.value(0).toString();
}
@ -129,7 +141,10 @@ QString AutoFillModel::getPassword(const QUrl &url)
void AutoFillModel::addEntry(const QUrl &url, const QString &name, const QString &pass)
{
QSqlQuery query;
query.exec("SELECT username FROM autofill WHERE server='" + url.host() + "'");
query.prepare("SELECT username FROM autofill WHERE server=?");
query.addBindValue(url.host());
query.exec();
if (query.next()) {
return;
}
@ -150,7 +165,10 @@ void AutoFillModel::addEntry(const QUrl &url, const QString &name, const QString
void AutoFillModel::addEntry(const QUrl &url, const QByteArray &data, const QString &user, const QString &pass)
{
QSqlQuery query;
query.exec("SELECT data FROM autofill WHERE server='" + url.host() + "'");
query.prepare("SELECT data FROM autofill WHERE server=?");
query.addBindValue(url.host());
query.exec();
if (query.next()) {
return;
}

View File

@ -238,7 +238,11 @@ void BookmarksModel::removeBookmark(const QList<int> list)
bookmark.image = QImage::fromData(query.value(3).toByteArray());
bookmark.inSubfolder = isSubfolder(bookmark.folder);
if (!query.exec("DELETE FROM bookmarks WHERE id = " + QString::number(id))) {
query.prepare("DELETE FROM bookmarks WHERE id=?");
query.addBindValue(id);
query.exec();
if (!query.exec()) {
continue;
}
@ -286,7 +290,10 @@ bool BookmarksModel::editBookmark(int id, const QString &title, const QUrl &url,
}
QSqlQuery query;
query.exec("SELECT title, url, folder, icon FROM bookmarks WHERE id = " + QString::number(id));
query.prepare("SELECT title, url, folder, icon FROM bookmarks WHERE id=?");
query.addBindValue(id);
query.exec();
if (!query.next()) {
return false;
}
@ -325,7 +332,10 @@ bool BookmarksModel::editBookmark(int id, const QString &title, const QUrl &url,
bool BookmarksModel::changeIcon(int id, const QIcon &icon)
{
QSqlQuery query;
query.exec("SELECT title, url, folder, icon FROM bookmarks WHERE id = " + QString::number(id));
query.prepare("SELECT title, url, folder, icon FROM bookmarks WWHERE id=?");
query.addBindValue(id);
query.exec();
if (!query.next()) {
return false;
}

View File

@ -27,7 +27,7 @@
#include <QToolTip>
#include <QSqlQuery>
BookmarksWidget::BookmarksWidget(QupZilla *mainClass, WebView* view, QWidget* parent)
BookmarksWidget::BookmarksWidget(QupZilla* mainClass, WebView* view, QWidget* parent)
: QMenu(parent)
, ui(new Ui::BookmarksWidget)
, p_QupZilla(mainClass)

View File

@ -125,7 +125,9 @@ void AutoFillManager::removePass()
}
QString id = curItem->data(0, Qt::UserRole + 10).toString();
QSqlQuery query;
query.exec("DELETE FROM autofill WHERE id=" + id);
query.prepare("DELETE FROM autofill WHERE id=?");
query.addBindValue(id);
query.exec();
delete curItem;
}
@ -186,7 +188,9 @@ void AutoFillManager::removeExcept()
}
QString id = curItem->data(0, Qt::UserRole + 10).toString();
QSqlQuery query;
query.exec("DELETE FROM autofill_exceptions WHERE id=" + id);
query.prepare("DELETE FROM autofill_exceptions WHERE id=?");
query.addBindValue(id);
query.exec();
delete curItem;
}

View File

@ -163,7 +163,9 @@ void RSSManager::deleteFeed()
return;
}
QSqlQuery query;
query.exec("DELETE FROM rss WHERE address='" + url + "'");
query.prepare("DELETE FROM rss WHERE address=?");
query.addBindValue(url);
query.exec();
ui->tabWidget->removeTab(ui->tabWidget->currentIndex());
if (ui->tabWidget->count() == 0) {

View File

@ -96,7 +96,10 @@ QImage IconProvider::iconForDomain(const QUrl &url)
}
QSqlQuery query;
query.exec("SELECT icon FROM icons WHERE url LIKE '%" + url.host() + "%'");
query.prepare("SELECT icon FROM icons WHERE url LIKE ?");
query.addBindValue(QString("%%1%").arg(url.host()));
query.exec();
if (query.next()) {
return QImage::fromData(query.value(0).toByteArray());
}

View File

@ -49,7 +49,10 @@ SiteInfoWidget::SiteInfoWidget(QupZilla* mainClass, QWidget* parent)
QSqlQuery query;
QString host = url.host();
query.exec("SELECT sum(count) FROM history WHERE url LIKE '" + scheme + "://" + host + "%' ");
query.prepare("SELECT sum(count) FROM history WHERE url LIKE ?");
query.addBindValue(QString("%1://%2%").arg(scheme, host));
query.exec();
if (query.next()) {
int count = query.value(0).toInt();
if (count > 3) {