}
}
+int CookiesDatabase::cookieCount()
+{
+ // Get a handle for the cookies database.
+ QSqlDatabase cookiesDatabase = QSqlDatabase::database(CONNECTION_NAME);
+
+ // Instantiate a count cookies query.
+ QSqlQuery countCookiesQuery(cookiesDatabase);
+
+ // Set the query to be forward only.
+ countCookiesQuery.setForwardOnly(true);
+
+ // Prepare the query.
+ countCookiesQuery.prepare("SELECT " + _ID + " FROM " + COOKIES_TABLE);
+
+ // Execute the query.
+ countCookiesQuery.exec();
+
+ // Move to the last row.
+ countCookiesQuery.last();
+
+ // Initialize a number of cookies variable.
+ int numberOfCookies = 0;
+
+ // Check to see if the query is valid (there is at least one cookie).
+ if (countCookiesQuery.isValid())
+ {
+ // Get the number of rows (which is zero based) and add one to calculate the number of cookies.
+ numberOfCookies = countCookiesQuery.at() + 1;
+ }
+
+ // Return the number of cookies.
+ return numberOfCookies;
+}
+
void CookiesDatabase::deleteAllCookies()
{
// Get a handle for the cookies database.
return cookieListPointer;
}
+QNetworkCookie* CookiesDatabase::getCookieById(const int &id)
+{
+ // Get a handle for the cookies database.
+ QSqlDatabase cookiesDatabase = QSqlDatabase::database(CONNECTION_NAME);
+
+ // Instantiate a cookie query.
+ QSqlQuery cookieQuery(cookiesDatabase);
+
+ // Set the query to be forward only.
+ cookieQuery.setForwardOnly(true);
+
+ // Prepare the cookies query.
+ cookieQuery.prepare("SELECT * FROM " + COOKIES_TABLE + " WHERE " + _ID + " = :id");
+
+ // Bind the values.
+ cookieQuery.bindValue(":id", id);
+
+ // Execute the query.
+ cookieQuery.exec();
+
+ // Move to the first entry.
+ cookieQuery.first();
+
+ // Create a cookie.
+ QNetworkCookie *cookiePointer = new QNetworkCookie();
+
+ // Populate the cookie.
+ cookiePointer->setDomain(cookieQuery.value(DOMAIN).toString());
+ cookiePointer->setName(cookieQuery.value(NAME).toString().toUtf8());
+ cookiePointer->setPath(cookieQuery.value(PATH).toString());
+ cookiePointer->setExpirationDate(QDateTime::fromString(cookieQuery.value(EXPIRATION_DATE).toString(), Qt::ISODate));
+ cookiePointer->setHttpOnly(cookieQuery.value(HTTP_ONLY).toBool());
+ cookiePointer->setSecure(cookieQuery.value(SECURE).toBool());
+ cookiePointer->setValue(cookieQuery.value(VALUE).toString().toUtf8());
+
+ // Return the cookie.
+ return cookiePointer;
+}
+
bool CookiesDatabase::isDurable(const QNetworkCookie &cookie)
{
// Get a handle for the cookies database.
(isUpdateQuery.value(2).toBool() != cookie.isSecure()) ||
(isUpdateQuery.value(3).toString().toUtf8() != cookie.value())) // The cookies data has changed.
{
- qDebug() << "The durable cookie data has changed.";
+ //qDebug() << "The durable cookie data has changed.";
// Return true.
return true;
}
else // The cookie data has not changed.
{
- qDebug() << "The durable cookie data is unchanged.";
+ //qDebug() << "The durable cookie data is unchanged.";
// Return false.
return false;