164 if (!database.isOpen()) { |
164 if (!database.isOpen()) { |
165 if(!database.open()) { |
165 if(!database.open()) { |
166 m_lastError.setError(DBError::SqlError, database.lastError().text()); |
166 m_lastError.setError(DBError::SqlError, database.lastError().text()); |
167 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
167 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
168 qWarning() << "ServiceDatabase::open():-" |
168 qWarning() << "ServiceDatabase::open():-" |
169 << "Problem:" << "Could not open database" |
169 << "Problem:" << "Could not open database. " |
170 << "\nReason:" << m_lastError.text(); |
170 << "Reason:" << m_lastError.text(); |
171 #endif |
171 #endif |
172 close(); |
172 close(); |
173 return false; |
173 return false; |
174 } |
174 } |
175 } |
175 } |
218 //bool ServiceDatabase::registerService(ServiceMetaData &service) |
218 //bool ServiceDatabase::registerService(ServiceMetaData &service) |
219 bool ServiceDatabase::registerService(const ServiceMetaDataResults &service, const QString &securityToken) |
219 bool ServiceDatabase::registerService(const ServiceMetaDataResults &service, const QString &securityToken) |
220 { |
220 { |
221 #ifndef QT_SFW_SERVICEDATABASE_USE_SECURITY_TOKEN |
221 #ifndef QT_SFW_SERVICEDATABASE_USE_SECURITY_TOKEN |
222 Q_UNUSED(securityToken); |
222 Q_UNUSED(securityToken); |
|
223 #else |
|
224 if (securityToken.isEmpty()) { |
|
225 QString errorText("Access denied, no security token provided (for registering service: \"%1\")"); |
|
226 m_lastError.setError(DBError::NoWritePermissions, errorText.arg(service.name)); |
|
227 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
|
228 qWarning() << "ServiceDatabase::registerService():-" |
|
229 << "Problem: Unable to register service," |
|
230 << "reason:" << qPrintable(m_lastError.text()); |
|
231 #endif |
|
232 return false; |
|
233 } |
223 #endif |
234 #endif |
224 |
235 |
225 if(!checkConnection()) { |
236 if(!checkConnection()) { |
226 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
237 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
227 qWarning() << "ServiceDatabase::registerService():-" |
238 qWarning() << "ServiceDatabase::registerService():-" |
234 QSqlQuery query(database); |
245 QSqlQuery query(database); |
235 |
246 |
236 if (!beginTransaction(&query, Write)) { |
247 if (!beginTransaction(&query, Write)) { |
237 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
248 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
238 qWarning() << "ServiceDatabase::registerService():-" |
249 qWarning() << "ServiceDatabase::registerService():-" |
239 << "Unable to begin transaction" |
250 << "Unable to begin transaction," |
240 << "\nReason:" << qPrintable(m_lastError.text()); |
251 << "reason:" << qPrintable(m_lastError.text()); |
241 #endif |
252 #endif |
242 return false; |
253 return false; |
243 } |
254 } |
244 //See if the service's location has already been previously registered |
255 //See if the service's location has already been previously registered |
245 QString statement("SELECT Name from Service WHERE Location=? COLLATE NOCASE"); |
256 QString statement("SELECT Name from Service WHERE Location=? COLLATE NOCASE"); |
272 #endif |
283 #endif |
273 return false; |
284 return false; |
274 } |
285 } |
275 |
286 |
276 #ifdef QT_SFW_SERVICEDATABASE_USE_SECURITY_TOKEN |
287 #ifdef QT_SFW_SERVICEDATABASE_USE_SECURITY_TOKEN |
277 statement = "SELECT Value FROM ServiceProperty WHERE ServiceID = ? AND Key = ?"; |
288 // If service(s) have already been registered with same name, they must all come from |
|
289 // same application. Fetch a service with given name and if such exists, check that its |
|
290 // security ID equals to the security ID of the current registrar. |
|
291 // One application may register multiple services with same name (different location), |
|
292 // hence the keyword DISTINCT. |
|
293 statement = "SELECT DISTINCT ServiceProperty.Value FROM Service, ServiceProperty " |
|
294 "WHERE Service.ID = ServiceProperty.ServiceID " |
|
295 "AND ServiceProperty.Key = ? " |
|
296 "AND Service.Name = ?"; |
278 bindValues.clear(); |
297 bindValues.clear(); |
|
298 bindValues.append(SECURITY_TOKEN_KEY); |
279 bindValues.append(service.name); |
299 bindValues.append(service.name); |
280 bindValues.append(SECURITY_TOKEN_KEY); |
300 if (!executeQuery(&query, statement, bindValues)) { |
281 |
|
282 if(!executeQuery(&query, statement, bindValues)) { |
|
283 rollbackTransaction(&query); |
301 rollbackTransaction(&query); |
284 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
302 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
285 qWarning() << "ServiceDatabase::registerService():-" |
303 qWarning() << "ServiceDatabase::registerService():-" |
286 << qPrintable(m_lastError.text()); |
304 << qPrintable(m_lastError.text()); |
287 #endif |
305 #endif |
288 return false; |
306 return false; |
289 } |
307 } |
290 |
308 QString existingSecurityToken; |
291 QStringList securityTokens; |
309 if (query.next()) { |
292 while(query.next()) { |
310 existingSecurityToken = query.value(EBindIndex).toString(); |
293 securityTokens << query.value(EBindIndex).toString(); |
311 } |
294 } |
312 if (!existingSecurityToken.isEmpty() && (existingSecurityToken != securityToken)) { |
295 |
|
296 if (!securityTokens.isEmpty() && securityTokens.first() != securityToken) { |
|
297 QString errorText("Access denied: \"%1\""); |
313 QString errorText("Access denied: \"%1\""); |
298 m_lastError.setError(DBError::NoWritePermissions, errorText.arg(service.name)); |
314 m_lastError.setError(DBError::NoWritePermissions, errorText.arg(service.name)); |
299 rollbackTransaction(&query); |
315 rollbackTransaction(&query); |
300 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
316 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
301 qWarning() << "ServiceDatabase::registerService():-" |
317 qWarning() << "ServiceDatabase::registerService():-" |
302 << "Problem: Unable to register service" |
318 << "Problem: Unable to register service," |
303 << "\nReason:" << qPrintable(m_lastError.text()); |
319 << "reason:" << qPrintable(m_lastError.text()); |
304 #endif |
320 #endif |
305 return false; |
321 return false; |
306 } |
322 } |
307 #endif |
323 #endif // QT_SFW_SERVICEDATABASE_USE_SECURITY_TOKEN |
308 |
324 |
|
325 // Checks done, create new rows into tables. |
309 statement = "INSERT INTO Service(ID,Name,Location) VALUES(?,?,?)"; |
326 statement = "INSERT INTO Service(ID,Name,Location) VALUES(?,?,?)"; |
310 QString serviceID = QUuid::createUuid().toString(); |
327 QString serviceID = QUuid::createUuid().toString(); |
311 |
328 |
312 bindValues.clear(); |
329 bindValues.clear(); |
313 bindValues.append(serviceID); |
330 bindValues.append(serviceID); |
340 #endif |
357 #endif |
341 return false; |
358 return false; |
342 } |
359 } |
343 |
360 |
344 #ifdef QT_SFW_SERVICEDATABASE_USE_SECURITY_TOKEN |
361 #ifdef QT_SFW_SERVICEDATABASE_USE_SECURITY_TOKEN |
345 if (securityTokens.isEmpty()) { |
362 // Insert a security token for the particular service |
346 statement = "INSERT INTO ServiceProperty(ServiceID,Key,Value) VALUES(?,?,?)"; |
363 statement = "INSERT INTO ServiceProperty(ServiceID,Key,Value) VALUES(?,?,?)"; |
347 bindValues.clear(); |
364 bindValues.clear(); |
348 bindValues.append(service.name); |
365 bindValues.append(serviceID); |
349 bindValues.append(SECURITY_TOKEN_KEY); |
366 bindValues.append(SECURITY_TOKEN_KEY); |
350 bindValues.append(securityToken); |
367 bindValues.append(securityToken); |
351 |
368 |
352 if (!executeQuery(&query, statement, bindValues)) { |
369 if (!executeQuery(&query, statement, bindValues)) { |
353 rollbackTransaction(&query); |
370 rollbackTransaction(&query); |
354 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
371 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
355 qWarning() << "ServiceDatabase::registerService():-" |
372 qWarning() << "ServiceDatabase::registerService():-" |
356 << qPrintable(m_lastError.text()); |
373 << qPrintable(m_lastError.text()); |
357 #endif |
374 #endif |
358 return false; |
375 return false; |
359 } |
376 } |
360 } |
377 #endif // QT_SFW_SERVICEDATABASE_USE_SECURITY_TOKEN |
361 #endif |
|
362 |
378 |
363 QList <QServiceInterfaceDescriptor> interfaces = service.interfaces; |
379 QList <QServiceInterfaceDescriptor> interfaces = service.interfaces; |
364 QString interfaceID;; |
380 QString interfaceID;; |
365 foreach (const QServiceInterfaceDescriptor &interface, interfaces) { |
381 foreach (const QServiceInterfaceDescriptor &interface, interfaces) { |
366 interfaceID = getInterfaceID(&query, interface); |
382 interfaceID = getInterfaceID(&query, interface); |
567 return QString(); |
583 return QString(); |
568 } |
584 } |
569 |
585 |
570 if (!query->next()) { |
586 if (!query->next()) { |
571 QString errorText("No Interface Descriptor found with " |
587 QString errorText("No Interface Descriptor found with " |
572 "\nService name: %1 " |
588 "Service name: %1 " |
573 "\nInterface name: %2 " |
589 "Interface name: %2 " |
574 "\nVersion: %3.%4"); |
590 "Version: %3.%4"); |
575 m_lastError.setError(DBError::NotFound, errorText.arg(interface.serviceName()) |
591 m_lastError.setError(DBError::NotFound, errorText.arg(interface.serviceName()) |
576 .arg(interface.interfaceName()) |
592 .arg(interface.interfaceName()) |
577 .arg(interface.majorVersion()) |
593 .arg(interface.majorVersion()) |
578 .arg(interface.minorVersion())); |
594 .arg(interface.minorVersion())); |
579 return QString(); |
595 return QString(); |
789 //multiple read queries are performed so wrap them |
805 //multiple read queries are performed so wrap them |
790 //in a read only transaction |
806 //in a read only transaction |
791 if (!beginTransaction(&query, Read)) { |
807 if (!beginTransaction(&query, Read)) { |
792 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
808 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
793 qWarning() << "ServiceDatabase::getInterfaces():-" |
809 qWarning() << "ServiceDatabase::getInterfaces():-" |
794 << "Unable to begin transaction:" |
810 << "Unable to begin transaction. " |
795 << "\nReason:" << qPrintable(m_lastError.text()); |
811 << "Reason:" << qPrintable(m_lastError.text()); |
796 #endif |
812 #endif |
797 return interfaces; |
813 return interfaces; |
798 } |
814 } |
799 |
815 |
800 //Prepare search query, bind criteria values |
816 //Prepare search query, bind criteria values |
943 QSqlQuery query(database); |
959 QSqlQuery query(database); |
944 |
960 |
945 if (!beginTransaction(&query, Read)) { |
961 if (!beginTransaction(&query, Read)) { |
946 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
962 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
947 qWarning() << "ServiceDatabase::getInterface():-" |
963 qWarning() << "ServiceDatabase::getInterface():-" |
948 << "Unable to begin transaction" |
964 << "Unable to begin transaction. " |
949 << "\nReason:" << qPrintable(m_lastError.text()); |
965 << "Reason:" << qPrintable(m_lastError.text()); |
950 #endif |
966 #endif |
951 return interface; |
967 return interface; |
952 } |
968 } |
953 |
969 |
954 QString selectComponent = "SELECT Interface.Name, " |
970 QString selectComponent = "SELECT Interface.Name, " |
1104 QSqlQuery query(database); |
1120 QSqlQuery query(database); |
1105 |
1121 |
1106 if (!inTransaction && !beginTransaction(&query, Read)) { |
1122 if (!inTransaction && !beginTransaction(&query, Read)) { |
1107 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
1123 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
1108 qWarning() << "ServiceDatabase::interfaceDefault(QString, QString):-" |
1124 qWarning() << "ServiceDatabase::interfaceDefault(QString, QString):-" |
1109 << "Unable to begin transaction" |
1125 << "Unable to begin transaction. " |
1110 << "\nReason:" << qPrintable(m_lastError.text()); |
1126 << "Reason:" << qPrintable(m_lastError.text()); |
1111 #endif |
1127 #endif |
1112 return interface; |
1128 return interface; |
1113 } |
1129 } |
1114 |
1130 |
1115 QString statement("SELECT InterfaceID FROM Defaults WHERE InterfaceName = ? COLLATE NOCASE"); |
1131 QString statement("SELECT InterfaceID FROM Defaults WHERE InterfaceName = ? COLLATE NOCASE"); |
1274 .arg(interface.serviceName())); |
1290 .arg(interface.serviceName())); |
1275 |
1291 |
1276 rollbackTransaction(&query); |
1292 rollbackTransaction(&query); |
1277 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
1293 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
1278 qWarning() << "ServiceDatbase::setInterfaceDefault(QServiceInterfaceDescriptor):-" |
1294 qWarning() << "ServiceDatbase::setInterfaceDefault(QServiceInterfaceDescriptor):-" |
1279 << "Problem: Unable to set default service" |
1295 << "Problem: Unable to set default service. " |
1280 << "\nReason:" << qPrintable(m_lastError.text()); |
1296 << "Reason:" << qPrintable(m_lastError.text()); |
1281 #endif |
1297 #endif |
1282 return false; |
1298 return false; |
1283 } |
1299 } |
1284 |
1300 |
1285 interfaceID = query.value(EBindIndex).toString(); |
1301 interfaceID = query.value(EBindIndex).toString(); |
1355 DBError::InvalidDatabaseConnection |
1371 DBError::InvalidDatabaseConnection |
1356 DBError::NoWritePermissions |
1372 DBError::NoWritePermissions |
1357 DBError::InvalidDatabaseFile |
1373 DBError::InvalidDatabaseFile |
1358 */ |
1374 */ |
1359 bool ServiceDatabase::unregisterService(const QString &serviceName, const QString &securityToken) |
1375 bool ServiceDatabase::unregisterService(const QString &serviceName, const QString &securityToken) |
1360 { |
1376 { |
1361 #ifndef QT_SFW_SERVICEDATABASE_USE_SECURITY_TOKEN |
1377 #ifndef QT_SFW_SERVICEDATABASE_USE_SECURITY_TOKEN |
1362 Q_UNUSED(securityToken); |
1378 Q_UNUSED(securityToken); |
1363 #endif |
1379 #else |
|
1380 if (securityToken.isEmpty()) { |
|
1381 QString errorText("Access denied, no security token provided (for unregistering service: \"%1\")"); |
|
1382 m_lastError.setError(DBError::NoWritePermissions, errorText.arg(serviceName)); |
|
1383 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
|
1384 qWarning() << "ServiceDatabase::unregisterService():-" |
|
1385 << "Problem: Unable to unregister service. " |
|
1386 << "Reason:" << qPrintable(m_lastError.text()); |
|
1387 #endif |
|
1388 return false; |
|
1389 } |
|
1390 #endif |
|
1391 |
1364 |
1392 |
1365 if (!checkConnection()) { |
1393 if (!checkConnection()) { |
1366 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
1394 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
1367 qWarning() << "ServiceDatabase::unregisterService():-" |
1395 qWarning() << "ServiceDatabase::unregisterService():-" |
1368 << "Problem:" << qPrintable(m_lastError.text()); |
1396 << "Problem:" << qPrintable(m_lastError.text()); |
1374 QSqlQuery query(database); |
1402 QSqlQuery query(database); |
1375 |
1403 |
1376 if(!beginTransaction(&query, Write)) { |
1404 if(!beginTransaction(&query, Write)) { |
1377 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
1405 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
1378 qWarning() << "ServiceDatabase::unregisterService():-" |
1406 qWarning() << "ServiceDatabase::unregisterService():-" |
1379 << "Problem: Unable to begin transaction" |
1407 << "Problem: Unable to begin transaction. " |
1380 << "\nReason:" << qPrintable(m_lastError.text()); |
1408 << "Reason:" << qPrintable(m_lastError.text()); |
1381 #endif |
1409 #endif |
1382 return false; |
1410 return false; |
1383 } |
1411 } |
1384 |
1412 |
1385 QString statement("SELECT Service.ID from Service WHERE Service.Name = ? COLLATE NOCASE"); |
1413 QString statement("SELECT Service.ID from Service WHERE Service.Name = ? COLLATE NOCASE"); |
1397 QStringList serviceIDs; |
1425 QStringList serviceIDs; |
1398 while(query.next()) { |
1426 while(query.next()) { |
1399 serviceIDs << query.value(EBindIndex).toString(); |
1427 serviceIDs << query.value(EBindIndex).toString(); |
1400 } |
1428 } |
1401 |
1429 |
1402 |
|
1403 #ifdef QT_SFW_SERVICEDATABASE_USE_SECURITY_TOKEN |
1430 #ifdef QT_SFW_SERVICEDATABASE_USE_SECURITY_TOKEN |
1404 statement = "SELECT Value FROM ServiceProperty WHERE ServiceID = ? AND Key = ?"; |
1431 // Only the application that registered the service is allowed to unregister that |
1405 bindValues.clear(); |
1432 // service. Fetch a security ID of a service (with given name) and verify that it matches |
1406 bindValues.append(serviceName); |
1433 // with current apps security id. Only one application is allowed to register services with |
1407 bindValues.append(SECURITY_TOKEN_KEY); |
1434 // same name, hence a distinct (just any of the) security token will do because they are identical. |
1408 if(!executeQuery(&query, statement, bindValues)) { |
1435 if (!serviceIDs.isEmpty()) { |
1409 rollbackTransaction(&query); |
1436 statement = "SELECT DISTINCT Value FROM ServiceProperty WHERE ServiceID = ? AND Key = ?"; |
1410 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
1437 bindValues.clear(); |
1411 qWarning() << "ServiceDatabase::unregisterService():-" |
1438 bindValues.append(serviceIDs.first()); |
1412 << qPrintable(m_lastError.text()); |
1439 bindValues.append(SECURITY_TOKEN_KEY); |
1413 #endif |
1440 |
1414 return false; |
1441 if (!executeQuery(&query, statement, bindValues)) { |
1415 } |
1442 rollbackTransaction(&query); |
1416 |
1443 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
1417 QStringList securityTokens; |
1444 qWarning() << "ServiceDatabase::unregisterService():-" |
1418 while(query.next()) { |
1445 << qPrintable(m_lastError.text()); |
1419 securityTokens << query.value(EBindIndex).toString(); |
1446 #endif |
1420 } |
1447 return false; |
1421 |
1448 } |
1422 if (!securityTokens.isEmpty() && (securityTokens.first() != securityToken)) { |
1449 QString existingSecurityToken; |
1423 QString errorText("Access denied: \"%1\""); |
1450 if (query.next()) { |
1424 m_lastError.setError(DBError::NoWritePermissions, errorText.arg(serviceName)); |
1451 existingSecurityToken = query.value(EBindIndex).toString(); |
1425 rollbackTransaction(&query); |
1452 } |
1426 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
1453 if (existingSecurityToken != securityToken) { |
1427 qWarning() << "ServiceDatabase::unregisterService():-" |
1454 QString errorText("Access denied: \"%1\""); |
1428 << "Problem: Unable to unregister service" |
1455 m_lastError.setError(DBError::NoWritePermissions, errorText.arg(serviceName)); |
1429 << "\nReason:" << qPrintable(m_lastError.text()); |
1456 rollbackTransaction(&query); |
1430 #endif |
1457 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
1431 } |
1458 qWarning() << "ServiceDatabase::unregisterService():-" |
1432 |
1459 << "Problem: Unable to unregister service" |
1433 #endif |
1460 << "Reason:" << qPrintable(m_lastError.text()); |
1434 |
1461 #endif |
|
1462 return false; |
|
1463 } |
|
1464 } |
|
1465 #endif // QT_SFW_SERVICEDATABASE_USE_SECURITY_TOKEN |
|
1466 |
1435 statement = "SELECT Interface.ID from Interface, Service " |
1467 statement = "SELECT Interface.ID from Interface, Service " |
1436 "WHERE Interface.ServiceID = Service.ID " |
1468 "WHERE Interface.ServiceID = Service.ID " |
1437 "AND Service.Name =? COLLATE NOCASE"; |
1469 "AND Service.Name =? COLLATE NOCASE"; |
1438 bindValues.clear(); |
1470 bindValues.clear(); |
1439 bindValues.append(serviceName); |
1471 bindValues.append(serviceName); |
1456 m_lastError.setError(DBError::NotFound, errorText.arg(serviceName)); |
1488 m_lastError.setError(DBError::NotFound, errorText.arg(serviceName)); |
1457 rollbackTransaction(&query); |
1489 rollbackTransaction(&query); |
1458 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
1490 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
1459 qWarning() << "ServiceDatabase::unregisterService():-" |
1491 qWarning() << "ServiceDatabase::unregisterService():-" |
1460 << "Problem: Unable to unregister service" |
1492 << "Problem: Unable to unregister service" |
1461 << "\nReason:" << qPrintable(m_lastError.text()); |
1493 << "Reason:" << qPrintable(m_lastError.text()); |
1462 #endif |
1494 #endif |
1463 return false; |
1495 return false; |
1464 } |
1496 } |
1465 |
1497 |
1466 statement = "SELECT Defaults.InterfaceName " |
1498 statement = "SELECT Defaults.InterfaceName " |
1509 #endif |
1541 #endif |
1510 return false; |
1542 return false; |
1511 } |
1543 } |
1512 } |
1544 } |
1513 |
1545 |
1514 #ifndef QT_SFW_SERVICEDATABASE_USE_SECURITY_TOKEN |
|
1515 statement = "DELETE FROM ServiceProperty WHERE ServiceID = ?"; |
1546 statement = "DELETE FROM ServiceProperty WHERE ServiceID = ?"; |
1516 #else |
|
1517 statement = "DELETE FROM ServiceProperty WHERE ServiceID = ? AND Key <> ?"; |
|
1518 #endif |
|
1519 |
|
1520 |
1547 |
1521 foreach(const QString &serviceID, serviceIDs) { |
1548 foreach(const QString &serviceID, serviceIDs) { |
1522 bindValues.clear(); |
1549 bindValues.clear(); |
1523 bindValues.append(serviceID); |
1550 bindValues.append(serviceID); |
1524 #ifdef QT_SFW_SERVICEDATABASE_USE_SECURITY_TOKEN |
|
1525 bindValues.append(SECURITY_TOKEN_KEY); |
|
1526 #endif |
|
1527 if (!executeQuery(&query, statement, bindValues)) { |
1551 if (!executeQuery(&query, statement, bindValues)) { |
1528 rollbackTransaction(&query); |
1552 rollbackTransaction(&query); |
1529 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
1553 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
1530 qWarning() << "ServiceDatabase::unregisterService():-" |
1554 qWarning() << "ServiceDatabase::unregisterService():-" |
1531 << qPrintable(m_lastError.text()); |
1555 << qPrintable(m_lastError.text()); |
1643 */ |
1667 */ |
1644 QString ServiceDatabase::databasePath() const |
1668 QString ServiceDatabase::databasePath() const |
1645 { |
1669 { |
1646 QString path; |
1670 QString path; |
1647 if(m_databasePath.isEmpty()) { |
1671 if(m_databasePath.isEmpty()) { |
|
1672 #if (defined(Q_OS_SYMBIAN) && defined(__WINS__)) |
|
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()); |
|
1678 qtVersion = qtVersion.left(qtVersion.size() -2); //strip off patch version |
|
1679 path = QDir::toNativeSeparators(QCoreApplication::applicationDirPath() + |
|
1680 "\\Nokia\\" + "QtServiceFramework_" + |
|
1681 qtVersion + "_system" + |
|
1682 QLatin1String(".db")); |
|
1683 #else |
1648 QSettings settings(QSettings::SystemScope, "Nokia", "Services"); |
1684 QSettings settings(QSettings::SystemScope, "Nokia", "Services"); |
1649 path = settings.value("ServicesDB/Path").toString(); |
1685 path = settings.value("ServicesDB/Path").toString(); |
1650 if (path.isEmpty()) { |
1686 if (path.isEmpty()) { |
1651 path = QDir::currentPath(); |
1687 path = QDir::currentPath(); |
1652 if (path.lastIndexOf(RESOLVERDATABASE_PATH_SEPARATOR) != path.length() -1) { |
1688 if (path.lastIndexOf(RESOLVERDATABASE_PATH_SEPARATOR) != path.length() -1) { |
1653 path.append(RESOLVERDATABASE_PATH_SEPARATOR); |
1689 path.append(RESOLVERDATABASE_PATH_SEPARATOR); |
1654 } |
1690 } |
1655 path.append(RESOLVERDATABASE); |
1691 path.append(RESOLVERDATABASE); |
1656 } |
1692 } |
1657 path = QDir::toNativeSeparators(path); |
1693 path = QDir::toNativeSeparators(path); |
|
1694 #endif |
1658 } else { |
1695 } else { |
1659 path = m_databasePath; |
1696 path = m_databasePath; |
1660 } |
1697 } |
1661 |
1698 |
1662 return path; |
1699 return path; |
1876 |
1913 |
1877 if (database.tables().count() > 0) { |
1914 if (database.tables().count() > 0) { |
1878 if (!beginTransaction(&query, Write)) { |
1915 if (!beginTransaction(&query, Write)) { |
1879 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
1916 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
1880 qWarning() << "ServiceDatabase::dropTables():-" |
1917 qWarning() << "ServiceDatabase::dropTables():-" |
1881 << "Unable to begin transaction" |
1918 << "Unable to begin transaction. " |
1882 << "\nReason:" << qPrintable(m_lastError.text()); |
1919 << "Reason:" << qPrintable(m_lastError.text()); |
1883 #endif |
1920 #endif |
1884 return false; |
1921 return false; |
1885 } |
1922 } |
1886 QStringList actualTables = database.tables(); |
1923 QStringList actualTables = database.tables(); |
1887 |
1924 |
1888 foreach(QString expectedTable, expectedTables) { |
1925 foreach(const QString expectedTable, expectedTables) { |
1889 if ((actualTables.contains(expectedTable)) |
1926 if ((actualTables.contains(expectedTable)) |
1890 && (!executeQuery(&query, QString("DROP TABLE ") + expectedTable))) { |
1927 && (!executeQuery(&query, QString("DROP TABLE ") + expectedTable))) { |
1891 rollbackTransaction(&query); |
1928 rollbackTransaction(&query); |
1892 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
1929 #ifdef QT_SFW_SERVICEDATABASE_DEBUG |
1893 qWarning() << "ServiceDatabase::dropTables():-" |
1930 qWarning() << "ServiceDatabase::dropTables():-" |