355 qWarning() << "ServiceDatabase::registerService():-" |
356 qWarning() << "ServiceDatabase::registerService():-" |
356 << qPrintable(m_lastError.text()); |
357 << qPrintable(m_lastError.text()); |
357 #endif |
358 #endif |
358 return false; |
359 return false; |
359 } |
360 } |
|
361 |
|
362 #ifdef QT_SFW_SERVICEDATABASE_GENERATE |
|
363 statement = "INSERT INTO ServiceProperty(ServiceId,Key,Value) VALUES(?,?,?)"; |
|
364 bindValues.clear(); |
|
365 bindValues.append(serviceID); |
|
366 bindValues.append(SERVICE_INITIALIZED_KEY); |
|
367 bindValues.append(QString("NO")); |
|
368 if (!executeQuery(&query, statement, bindValues)) { |
|
369 rollbackTransaction(&query); |
|
370 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
|
371 qWarning() << "ServiceDatabase::registerService():-" |
|
372 << qPrintable(m_lastError.text()); |
|
373 #endif |
|
374 return false; |
|
375 } |
|
376 #endif |
360 |
377 |
361 #ifdef QT_SFW_SERVICEDATABASE_USE_SECURITY_TOKEN |
378 #ifdef QT_SFW_SERVICEDATABASE_USE_SECURITY_TOKEN |
362 // Insert a security token for the particular service |
379 // Insert a security token for the particular service |
363 statement = "INSERT INTO ServiceProperty(ServiceID,Key,Value) VALUES(?,?,?)"; |
380 statement = "INSERT INTO ServiceProperty(ServiceID,Key,Value) VALUES(?,?,?)"; |
364 bindValues.clear(); |
381 bindValues.clear(); |
1623 m_lastError.setError(DBError::NoError); |
1640 m_lastError.setError(DBError::NoError); |
1624 return true; |
1641 return true; |
1625 } |
1642 } |
1626 |
1643 |
1627 /* |
1644 /* |
|
1645 Registers the service initialization into the database. |
|
1646 */ |
|
1647 bool ServiceDatabase::serviceInitialized(const QString &serviceName, const QString &securityToken) |
|
1648 { |
|
1649 #ifndef QT_SFW_SERVICEDATABASE_USE_SECURITY_TOKEN |
|
1650 Q_UNUSED(securityToken); |
|
1651 #endif |
|
1652 |
|
1653 if (!checkConnection()) { |
|
1654 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
|
1655 qWarning() << "ServiceDatabase::unregisterService():-" |
|
1656 << "Problem:" << qPrintable(m_lastError.text()); |
|
1657 #endif |
|
1658 return false; |
|
1659 } |
|
1660 |
|
1661 QSqlDatabase database = QSqlDatabase::database(m_connectionName); |
|
1662 QSqlQuery query(database); |
|
1663 |
|
1664 if(!beginTransaction(&query, Write)) { |
|
1665 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
|
1666 qWarning() << "ServiceDatabase::serviceInitialized():-" |
|
1667 << "Problem: Unable to begin transaction" |
|
1668 << "\nReason:" << qPrintable(m_lastError.text()); |
|
1669 #endif |
|
1670 return false; |
|
1671 } |
|
1672 |
|
1673 QString statement("SELECT Service.ID from Service WHERE Service.Name = ? COLLATE NOCASE"); |
|
1674 QList<QVariant> bindValues; |
|
1675 bindValues.append(serviceName); |
|
1676 if(!executeQuery(&query, statement, bindValues)) { |
|
1677 rollbackTransaction(&query); |
|
1678 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
|
1679 qWarning() << "ServiceDatabase::serviceInitialized():-" |
|
1680 << qPrintable(m_lastError.text()); |
|
1681 #endif |
|
1682 return false; |
|
1683 } |
|
1684 |
|
1685 QStringList serviceIDs; |
|
1686 while(query.next()) { |
|
1687 serviceIDs << query.value(EBindIndex).toString(); |
|
1688 } |
|
1689 |
|
1690 |
|
1691 #ifdef QT_SFW_SERVICEDATABASE_USE_SECURITY_TOKEN |
|
1692 statement = "SELECT Value FROM ServiceProperty WHERE ServiceID = ? AND Key = ?"; |
|
1693 bindValues.clear(); |
|
1694 bindValues.append(serviceName); |
|
1695 bindValues.append(SECURITY_TOKEN_KEY); |
|
1696 if(!executeQuery(&query, statement, bindValues)) { |
|
1697 rollbackTransaction(&query); |
|
1698 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
|
1699 qWarning() << "ServiceDatabase::unregisterService():-" |
|
1700 << qPrintable(m_lastError.text()); |
|
1701 #endif |
|
1702 return false; |
|
1703 } |
|
1704 |
|
1705 QStringList securityTokens; |
|
1706 while(query.next()) { |
|
1707 securityTokens << query.value(EBindIndex).toString(); |
|
1708 } |
|
1709 |
|
1710 if (!securityTokens.isEmpty() && (securityTokens.first() != securityToken)) { |
|
1711 QString errorText("Access denied: \"%1\""); |
|
1712 m_lastError.setError(DBError::NoWritePermissions, errorText.arg(serviceName)); |
|
1713 rollbackTransaction(&query); |
|
1714 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
|
1715 qWarning() << "ServiceDatabase::serviceInitialized():-" |
|
1716 << "Problem: Unable to update service initialization" |
|
1717 << "\nReason:" << qPrintable(m_lastError.text()); |
|
1718 #endif |
|
1719 } |
|
1720 #endif |
|
1721 |
|
1722 statement = "DELETE FROM ServiceProperty WHERE ServiceID = ? AND Key = ?"; |
|
1723 foreach(const QString &serviceID, serviceIDs) { |
|
1724 bindValues.clear(); |
|
1725 bindValues.append(serviceID); |
|
1726 bindValues.append(SERVICE_INITIALIZED_KEY); |
|
1727 if (!executeQuery(&query, statement, bindValues)) { |
|
1728 rollbackTransaction(&query); |
|
1729 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
|
1730 qWarning() << "ServiceDatabase::serviceInitialized():-" |
|
1731 << qPrintable(m_lastError.text()); |
|
1732 #endif |
|
1733 return false; |
|
1734 } |
|
1735 } |
|
1736 |
|
1737 //databaseCommit |
|
1738 if (!commitTransaction(&query)) { |
|
1739 rollbackTransaction(&query); |
|
1740 return false; |
|
1741 } |
|
1742 m_lastError.setError(DBError::NoError); |
|
1743 return true; |
|
1744 } |
|
1745 |
|
1746 /* |
1628 Closes the database |
1747 Closes the database |
1629 |
1748 |
1630 May set the following error codes: |
1749 May set the following error codes: |
1631 DBError::NoError |
1750 DBError::NoError |
1632 DBError::InvalidDatabaseConnection |
1751 DBError::InvalidDatabaseConnection |
1667 */ |
1786 */ |
1668 QString ServiceDatabase::databasePath() const |
1787 QString ServiceDatabase::databasePath() const |
1669 { |
1788 { |
1670 QString path; |
1789 QString path; |
1671 if(m_databasePath.isEmpty()) { |
1790 if(m_databasePath.isEmpty()) { |
1672 #if (defined(Q_OS_SYMBIAN) && defined(__WINS__)) |
1791 #ifdef Q_OS_SYMBIAN |
1673 // On Symbian, database location never changes. On emulator it is fixed |
|
1674 // and on hardware it is relative to the db managers private directory. |
|
1675 path = QDir::toNativeSeparators("C:\\Data\\temp\\QtServiceFW"); |
|
1676 #elif defined(Q_OS_SYMBIAN) |
|
1677 QString qtVersion(qVersion()); |
1792 QString qtVersion(qVersion()); |
1678 qtVersion = qtVersion.left(qtVersion.size() -2); //strip off patch version |
1793 qtVersion = qtVersion.left(qtVersion.size() -2); //strip off patch version |
1679 path = QDir::toNativeSeparators(QCoreApplication::applicationDirPath() + "QtServiceFramework_" + |
1794 path = QDir::toNativeSeparators(QCoreApplication::applicationDirPath() + "/QtServiceFramework_" + |
1680 qtVersion + "_system" + QLatin1String(".db")); |
1795 qtVersion + "_system" + QLatin1String(".db")); |
1681 #else |
1796 #else |
1682 QSettings settings(QSettings::SystemScope, "Nokia", "Services"); |
1797 QSettings settings(QSettings::SystemScope, "Nokia", "Services"); |
1683 path = settings.value("ServicesDB/Path").toString(); |
1798 path = settings.value("ServicesDB/Path").toString(); |
1684 if (path.isEmpty()) { |
1799 if (path.isEmpty()) { |
1685 path = QDir::currentPath(); |
1800 path = QDir::currentPath(); |
2145 attribute = query.value(EBindIndex).toString(); |
2260 attribute = query.value(EBindIndex).toString(); |
2146 if (attribute == SERVICE_DESCRIPTION_KEY) { |
2261 if (attribute == SERVICE_DESCRIPTION_KEY) { |
2147 interface->d->attributes[QServiceInterfaceDescriptor::ServiceDescription] |
2262 interface->d->attributes[QServiceInterfaceDescriptor::ServiceDescription] |
2148 = query.value(EBindIndex1).toString(); |
2263 = query.value(EBindIndex1).toString(); |
2149 } |
2264 } |
|
2265 // fetch initialized and put it as a custom attribute |
|
2266 if (attribute == SERVICE_INITIALIZED_KEY) { |
|
2267 interface->d->customAttributes[attribute] = query.value(EBindIndex1).toString(); |
|
2268 } |
2150 } |
2269 } |
2151 |
2270 |
2152 if (!isFound) { |
2271 if (!isFound) { |
2153 QString errorText("Database integrity corrupted, Service Properties for ServiceID: \"%1\" does not exist in the ServiceProperty table for service \"%2\""); |
2272 QString errorText("Database integrity corrupted, Service Properties for ServiceID: \"%1\" does not exist in the ServiceProperty table for service \"%2\""); |
2154 m_lastError.setError(DBError::SqlError, errorText.arg(serviceID).arg(interface->serviceName())); |
2273 m_lastError.setError(DBError::SqlError, errorText.arg(serviceID).arg(interface->serviceName())); |