67 */ |
67 */ |
68 QString DataStoreManager::getErrorText() const{ |
68 QString DataStoreManager::getErrorText() const{ |
69 return lastMsg; |
69 return lastMsg; |
70 } |
70 } |
71 |
71 |
72 SmfRelationId DataStoreManager::create(SmfProvider *aProvider, SmfContact *aContact){ |
72 SmfRelationId DataStoreManager::create(SmfProvider *aProvider, SmfContact *aContact) |
73 |
73 { |
|
74 if(NULL == aProvider || NULL == aContact) |
|
75 return QString::number(-1);//SmfUnknownError |
|
76 |
74 QString userId, contactUrl, localId, managerUri, presenceState, presenceText, statusText; |
77 QString userId, contactUrl, localId, managerUri, presenceState, presenceText, statusText; |
75 QDateTime dateTime; |
78 QDateTime dateTime; |
76 Int64 timeStampInSeconds; |
79 Int64 timeStampInSeconds; |
77 |
80 |
78 QContactGuid guid = aContact->value("Guid").value<QContactGuid>(); |
81 QContactGuid guid = aContact->value("Guid").value<QContactGuid>(); |
79 userId = guid.guid(); |
82 userId = guid.guid(); |
|
83 qDebug()<<"Inside DSM: userID "<<userId; |
80 |
84 |
81 QContactUrl url = aContact->value("Url").value<QContactUrl>(); |
85 QContactUrl url = aContact->value("Url").value<QContactUrl>(); |
82 contactUrl = url.url(); |
86 contactUrl = url.url(); |
|
87 |
|
88 qDebug()<<"Inside Test DSM: contactUrl "<<contactUrl; |
83 |
89 |
84 QContactId contactId = aContact->value("ContactId").value<QContactId>(); |
90 QContactId contactId = aContact->value("ContactId").value<QContactId>(); |
85 localId = contactId.localId() ; |
91 localId = contactId.localId() ; |
86 managerUri = contactId.managerUri(); |
92 managerUri = contactId.managerUri(); |
|
93 |
|
94 qDebug()<<"Inside Test DSM: localId"<<localId; |
|
95 qDebug()<<"Inside Test DSM: managerUri"<<managerUri; |
87 |
96 |
88 QContactTimestamp time = aContact->value("Timestamp").value<QContactTimestamp>(); |
97 QContactTimestamp time = aContact->value("Timestamp").value<QContactTimestamp>(); |
89 dateTime = time.created(); |
98 dateTime = time.created(); |
90 //Returns the datetime as the number of seconds that have passed since 1970-01-01T00:00:00, Coordinated Universal Time (Qt::UTC). |
99 //Returns the datetime as the number of seconds that have passed since 1970-01-01T00:00:00, Coordinated Universal Time (Qt::UTC). |
91 timeStampInSeconds = dateTime.toTime_t() ; |
100 timeStampInSeconds = dateTime.toTime_t() ; |
93 QContactPresence presence = aContact->value("Presence").value<QContactPresence>(); |
102 QContactPresence presence = aContact->value("Presence").value<QContactPresence>(); |
94 presenceState = QString::number( (int)presence.presenceState() ); |
103 presenceState = QString::number( (int)presence.presenceState() ); |
95 presenceText = presence.presenceStateText(); |
104 presenceText = presence.presenceStateText(); |
96 statusText = presence.customMessage(); |
105 statusText = presence.customMessage(); |
97 |
106 |
|
107 qDebug()<<"Inside Test DSM: presenceState"<<presenceState; |
|
108 qDebug()<<"Inside Test DSM: presenceText"<<presenceText; |
|
109 qDebug()<<"Inside Test DSM: statusText"<<statusText; |
|
110 |
98 QString snsName = aProvider->serviceName(); |
111 QString snsName = aProvider->serviceName(); |
99 QString snsUrl = (aProvider->serviceUrl()).toString(); |
112 QString snsUrl = (aProvider->serviceUrl()).toString(); |
100 QString snsDesc = aProvider->description(); |
113 QString snsDesc = aProvider->description(); |
101 |
114 |
102 |
115 qDebug()<<"Inside Test DSM Create: snsName"<<snsName; |
103 const int contactID = addContactToTable( userId, contactUrl, localId, managerUri, snsName, snsDesc, snsUrl, presenceState, presenceText , statusText, timeStampInSeconds); |
116 qDebug()<<"Inside Test DSM Create: snsUrl"<<snsUrl; |
|
117 qDebug()<<"Inside Test DSM Create: snsDesc"<<snsDesc; |
|
118 |
|
119 |
|
120 |
|
121 const int contactID = addContactToTable(userId, contactUrl, localId, managerUri, snsName, snsDesc, snsUrl, presenceState, presenceText , statusText, timeStampInSeconds); |
|
122 if(!(contactIfExist(contactID))) |
|
123 return QString::number(-1); |
104 return QString::number( addRelationToTable( contactID ) ); |
124 return QString::number( addRelationToTable( contactID ) ); |
105 } |
125 } |
106 |
126 |
107 SmfError DataStoreManager::associate( SmfRelationId aRelation, |
127 SmfError DataStoreManager::associate( SmfRelationId aPhoneId, |
108 const SmfContact* aContact, |
128 const SmfContact* aContact, |
109 SmfProvider* aProvider){ |
129 SmfProvider* aProvider){ |
110 |
130 if(NULL == aProvider || NULL == aContact) |
111 if( ! relationIfExist( aRelation.toInt()) ) |
131 return SmfError(-1);//SmfUnknownError |
|
132 |
|
133 if( ! relationIfExist( aPhoneId.toInt()) ) |
112 return SmfErrInvalidRelation; |
134 return SmfErrInvalidRelation; |
113 |
135 |
114 QString userId, contactUrl, localId, managerUri, presenceState, presenceText, statusText; |
136 QString userId, contactUrl, localId, managerUri, presenceState, presenceText, statusText, name; |
115 QDateTime dateTime; |
137 QDateTime dateTime; |
116 Int64 timeStampInSeconds; |
138 Int64 timeStampInSeconds; |
117 |
139 |
118 QContactGuid guid = aContact->value("Guid").value<QContactGuid>(); |
140 QContactGuid guid = aContact->value("Guid").value<QContactGuid>(); |
119 userId = guid.guid(); |
141 userId = guid.guid(); |
137 |
159 |
138 QString snsName = aProvider->serviceName(); |
160 QString snsName = aProvider->serviceName(); |
139 QString snsUrl = (aProvider->serviceUrl()).toString(); |
161 QString snsUrl = (aProvider->serviceUrl()).toString(); |
140 QString snsDesc = aProvider->description(); |
162 QString snsDesc = aProvider->description(); |
141 |
163 |
142 const int contactID = addContactToTable( userId, contactUrl, localId, managerUri, snsName, snsDesc, snsUrl, presenceState, presenceText , statusText, timeStampInSeconds); |
164 qDebug()<<"Inside Test DSM Associate: snsName"<<snsName; |
143 if( socialProfileBaseID <= addRelationToTable( contactID, aRelation.toInt() ) ) |
165 qDebug()<<"Inside Test DSM Associate: snsUrl"<<snsUrl; |
|
166 qDebug()<<"Inside Test DSM Associate: snsDesc"<<snsDesc; |
|
167 |
|
168 const int contactID = addContactToTable(userId, contactUrl, localId, managerUri, snsName, snsDesc, snsUrl, presenceState, presenceText , statusText, timeStampInSeconds); |
|
169 TInt Id = addRelationToTable( contactID, aPhoneId.toInt()); |
|
170 if(Id == aPhoneId.toInt()) |
144 return SmfNoError ; |
171 return SmfNoError ; |
145 else |
172 else |
146 return SmfDbOpeningError; |
173 return SmfDbOpeningError; |
147 } |
174 } |
148 |
175 |
150 SmfError DataStoreManager::remove(SmfRelationId aRelation, const SmfContact* aContact){ |
177 SmfError DataStoreManager::remove(SmfRelationId aRelation, const SmfContact* aContact){ |
151 |
178 |
152 int contactId, relationId; |
179 int contactId, relationId; |
153 QString userId, contactUrl, localId, managerUri; |
180 QString userId, contactUrl, localId, managerUri; |
154 |
181 |
|
182 //to check validity of relationId |
|
183 if(aRelation.size() == 0) |
|
184 return SmfErrInvalidRelation; |
155 relationId = aRelation.toInt(); |
185 relationId = aRelation.toInt(); |
156 |
186 |
|
187 //to check validity of SmfContact |
|
188 if(NULL == aContact) |
|
189 return SmfDbContactNotExist; |
|
190 |
157 if(SmfDbOpeningError == openDB()) |
191 if(SmfDbOpeningError == openDB()) |
158 return SmfDbOpeningError; |
192 return SmfDbOpeningError; |
159 |
193 |
160 QSqlQuery qry; |
194 QSqlQuery qry; |
161 |
195 |
162 QContactGuid guid = aContact->value("Guid").value<QContactGuid>(); |
196 QContactGuid guid = aContact->value("Guid").value<QContactGuid>(); |
163 userId = guid.guid(); |
197 userId = guid.guid(); |
164 |
198 |
165 if ( ! userId.isNull() ) |
199 if ( ! userId.isNull() ) |
166 { |
200 { |
167 QContactUrl url = aContact->value("Url").value<QContactUrl>(); |
201 QContactUrl url = aContact->value("Url").value<QContactUrl>(); |
168 contactUrl = url.url(); |
202 contactUrl = url.url(); |
169 |
203 qry.prepare("SELECT contactId FROM contact where userId=:userId AND contactUrl=:contactUrl"); |
170 qry.prepare("SELECT contactId FROM contact where userId=:userId AND contactUrl=:contactUrl"); |
204 qry.bindValue(":userId", userId); |
171 qry.bindValue(":userId", userId); |
205 qry.bindValue(":contactUrl", contactUrl); |
172 qry.bindValue(":contactUrl", contactUrl); |
206 } |
173 } |
|
174 else |
207 else |
175 { |
208 { |
176 QContactId contactId = aContact->value("ContactId").value<QContactId>(); |
209 //if userId is invalid then it shoudl return SmfError |
|
210 return SmfDbContactNotExist; |
|
211 |
|
212 /*QContactId contactId = aContact->value("ContactId").value<QContactId>(); |
177 localId = contactId.localId() ; |
213 localId = contactId.localId() ; |
178 managerUri = contactId.managerUri(); |
214 managerUri = contactId.managerUri(); |
179 |
215 |
180 qry.prepare("SELECT contactId FROM contact where localId=:localId AND managerUri=:managerUri"); |
216 qry.prepare("SELECT contactId FROM contact where localId=:localId AND managerUri=:managerUri"); |
181 qry.bindValue(":localId", localId); |
217 qry.bindValue(":localId", localId); |
182 qry.bindValue(":managerUri", managerUri); |
218 qry.bindValue(":managerUri", managerUri);*/ |
183 } |
219 } |
184 |
220 |
185 if(SmfDbQueryExecutonError == executeQuery(qry)) |
221 if(SmfDbQueryExecutonError == executeQuery(qry)) |
186 return SmfDbQueryExecutonError; |
222 return SmfDbQueryExecutonError; |
187 |
223 |
188 if(qry.next()) |
224 if(qry.next()) |
267 } |
306 } |
268 |
307 |
269 /** returns relation Id for a given contacts if exists, NULL otherwise */ |
308 /** returns relation Id for a given contacts if exists, NULL otherwise */ |
270 SmfRelationId DataStoreManager::searchByContact( SmfContact aContact){ |
309 SmfRelationId DataStoreManager::searchByContact( SmfContact aContact){ |
271 |
310 |
272 int contactId, relationId; |
311 int contId,relationId;/* */ |
273 QString userId, contactUrl, localId, managerUri; |
312 QString userId, contactUrl, localId, managerUri; |
274 |
313 |
275 if(SmfDbOpeningError == openDB()) |
314 if(SmfDbOpeningError == openDB()) |
276 return QString(); |
315 return QString(); |
277 |
316 |
278 QSqlQuery qry; |
317 QSqlQuery qry; |
279 |
318 |
280 QContactGuid guid = aContact.value("Guid").value<QContactGuid>(); |
319 QContactGuid guid = aContact.value("Guid").value<QContactGuid>(); |
281 userId = guid.guid(); |
320 userId = guid.guid(); |
282 |
321 |
283 if ( ! userId.isNull() ) |
322 |
284 { |
323 if (userId.isNull() ) |
285 QContactUrl url = aContact.value("Url").value<QContactUrl>(); |
324 { |
286 contactUrl = url.url(); |
325 |
287 |
|
288 qry.prepare("SELECT contactId FROM contact where userId=:userId AND contactUrl=:contactUrl"); |
|
289 qry.bindValue(":userId", userId); |
|
290 qry.bindValue(":contactUrl", contactUrl); |
|
291 } |
|
292 else |
|
293 { |
|
294 QContactId contactId = aContact.value("ContactId").value<QContactId>(); |
326 QContactId contactId = aContact.value("ContactId").value<QContactId>(); |
295 localId = contactId.localId() ; |
327 localId = contactId.localId() ; |
296 managerUri = contactId.managerUri(); |
328 managerUri = contactId.managerUri(); |
297 |
329 |
298 qry.prepare("SELECT contactId FROM contact where localId=:localId AND managerUri=:managerUri"); |
330 qry.prepare("SELECT contactId FROM contact where localId=:localId AND managerUri=:managerUri"); |
299 qry.bindValue(":localId", localId); |
331 qry.bindValue(":localId", localId); |
300 qry.bindValue(":managerUri", managerUri); |
332 qry.bindValue(":managerUri", managerUri); |
301 } |
333 } |
|
334 else |
|
335 { |
|
336 QContactUrl url = aContact.value("Url").value<QContactUrl>(); |
|
337 contactUrl = url.url(); |
|
338 |
|
339 qry.prepare("SELECT contactId FROM contact where userId=:userId "); /*AND contactUrl=:contactUrl*/ |
|
340 qry.bindValue(":userId", userId); |
|
341 //qry.bindValue(":contactUrl", contactUrl); |
|
342 |
|
343 } |
302 |
344 |
303 if(SmfDbQueryExecutonError == executeQuery(qry)) |
345 if(SmfDbQueryExecutonError == executeQuery(qry)) |
304 return QString(); |
346 return QString(); |
305 |
347 |
306 if(qry.next()) |
348 if(qry.next()){ |
307 contactId = qry.value(0).toInt(); |
349 contId = qry.value(0).toInt(); |
308 |
350 } |
|
351 |
309 qry.prepare("SELECT relationId FROM relation where contactId=:contactId"); |
352 qry.prepare("SELECT relationId FROM relation where contactId=:contactId"); |
310 qry.bindValue(":contactId", contactId); |
353 qry.bindValue(":contactId", contId); |
311 |
354 |
312 if(SmfDbQueryExecutonError == executeQuery(qry)) |
355 if(SmfDbQueryExecutonError == executeQuery(qry)) |
313 return QString(); |
356 return QString(); |
314 |
357 |
315 if(qry.next()){ |
358 if(qry.next()){ |
373 } |
416 } |
374 |
417 |
375 /** list of contacts and their provider */ |
418 /** list of contacts and their provider */ |
376 QList<SmfRelationItem> DataStoreManager::getAll(SmfRelationId aRelation){ |
419 QList<SmfRelationItem> DataStoreManager::getAll(SmfRelationId aRelation){ |
377 QList<SmfRelationItem> relationItemList; |
420 QList<SmfRelationItem> relationItemList; |
|
421 if(aRelation.size() == 0) |
|
422 return relationItemList; |
|
423 |
378 const int relationId = aRelation.toInt(); |
424 const int relationId = aRelation.toInt(); |
379 int contactId, contactIndex; |
425 int contactId, contactIndex; |
380 |
426 |
381 if(SmfDbOpeningError == openDB()) |
427 if(SmfDbOpeningError == openDB()) |
382 return relationItemList; |
428 return relationItemList; |
416 SmfContact * smfContact; |
462 SmfContact * smfContact; |
417 SmfProvider * smfProvider; |
463 SmfProvider * smfProvider; |
418 QString snsName, snsDesc; |
464 QString snsName, snsDesc; |
419 QUrl snsUrl; |
465 QUrl snsUrl; |
420 |
466 |
421 QVariant userId = QVariant::fromValue( aQry.value(0).toString() ); |
467 |
422 QVariant contactUrl = QVariant::fromValue(aQry.value(1).toString() ); |
468 QVariant userId = QVariant::fromValue( aQry.value(1).toString() ); |
423 |
469 QVariant contactUrl = QVariant::fromValue(aQry.value(2).toString() ); |
424 QString StrLocalId = aQry.value(2).toString() ; |
470 |
425 QString StrManagerUri = aQry.value(3).toString() ; |
471 QString StrLocalId = aQry.value(3).toString() ; |
|
472 QString StrManagerUri = aQry.value(4).toString() ; |
426 QContactId qContactId; |
473 QContactId qContactId; |
427 qContactId.setLocalId( StrLocalId.toInt() ); |
474 qContactId.setLocalId( StrLocalId.toInt() ); |
428 qContactId.setManagerUri( StrManagerUri ); |
475 qContactId.setManagerUri( StrManagerUri ); |
429 QVariant contactId = QVariant::fromValue(qContactId); |
476 QVariant contactId = QVariant::fromValue(qContactId); |
430 |
477 |
431 int presenceState = aQry.value(7).toInt() ; |
478 int presenceState = aQry.value(8).toInt() ; |
432 QString presenceStateText = aQry.value(8).toString() ; |
479 QString presenceStateText = aQry.value(9).toString() ; |
433 QString statusText = aQry.value(9).toString(); |
480 QString statusText = aQry.value(10).toString(); |
434 QContactPresence qContactPresence; |
481 QContactPresence qContactPresence; |
435 qContactPresence.setPresenceState(static_cast<QContactPresence::PresenceState>(presenceState)); |
482 qContactPresence.setPresenceState(static_cast<QContactPresence::PresenceState>(presenceState)); |
436 qContactPresence.setPresenceStateText(presenceStateText); |
483 qContactPresence.setPresenceStateText(presenceStateText); |
437 qContactPresence.setCustomMessage(statusText); |
484 qContactPresence.setCustomMessage(statusText); |
438 QVariant contactPresence = QVariant::fromValue(qContactPresence); |
485 QVariant contactPresence = QVariant::fromValue(qContactPresence); |
439 |
486 |
440 QDateTime dateTime; |
487 QDateTime dateTime; |
441 dateTime.setTime_t ( aQry.value(10).toLongLong() ) ; |
488 dateTime.setTime_t ( aQry.value(11).toLongLong() ) ; |
442 QContactTimestamp qContactTimestamp; |
489 QContactTimestamp qContactTimestamp; |
443 qContactTimestamp.setCreated(dateTime); |
490 qContactTimestamp.setCreated(dateTime); |
444 QVariant timeStamp = QVariant::fromValue( qContactTimestamp ); |
491 QVariant timeStamp = QVariant::fromValue( qContactTimestamp ); |
445 |
492 |
446 smfContact = new SmfContact; |
493 smfContact = new SmfContact; |
449 smfContact->setValue("ContactId", contactId); |
496 smfContact->setValue("ContactId", contactId); |
450 smfContact->setValue("Presence", contactPresence); |
497 smfContact->setValue("Presence", contactPresence); |
451 smfContact->setValue("Timestamp", timeStamp); |
498 smfContact->setValue("Timestamp", timeStamp); |
452 |
499 |
453 smfProvider = new SmfProvider; |
500 smfProvider = new SmfProvider; |
454 snsName = aQry.value(4).toString(); |
501 snsName = aQry.value(5).toString(); |
455 snsDesc = aQry.value(5).toString();; |
502 snsDesc = aQry.value(6).toString(); |
456 snsUrl = aQry.value(6).toUrl(); |
503 snsUrl = aQry.value(7).toUrl(); |
457 |
504 |
458 smfProvider->setServiceName( snsName ); |
505 smfProvider->setServiceName( snsName ); |
459 smfProvider->setDescription( snsDesc ); |
506 smfProvider->setDescription( snsDesc ); |
460 smfProvider->setServiceUrl( snsUrl ); |
507 smfProvider->setServiceUrl( snsUrl ); |
461 |
508 |
462 iSmsfRelationItem = new SmfRelationItem; |
509 iSmsfRelationItem = new SmfRelationItem(); |
463 iSmsfRelationItem->setIndex( aIndex ); |
510 iSmsfRelationItem->setIndex( aIndex ); |
464 iSmsfRelationItem->setProvider(*(smfProvider) ); |
511 iSmsfRelationItem->setProvider(*(smfProvider) ); |
465 iSmsfRelationItem->setContact(*( smfContact )); |
512 iSmsfRelationItem->setContact(*( smfContact )); |
466 } |
513 } |
467 uint DataStoreManager::count(SmfRelationId relation){ |
514 uint DataStoreManager::count(SmfRelationId relation){ |
534 state = READY; |
581 state = READY; |
535 |
582 |
536 const int tableCount = 2; |
583 const int tableCount = 2; |
537 |
584 |
538 QSqlQuery smfDsmTables[tableCount]; |
585 QSqlQuery smfDsmTables[tableCount]; |
539 |
586 |
540 smfDsmTables[0].prepare("CREATE TABLE IF NOT EXISTS contact (contactId INTEGER PRIMARY KEY AUTOINCREMENT," |
587 smfDsmTables[0].prepare("CREATE TABLE IF NOT EXISTS contact (contactId INTEGER PRIMARY KEY AUTOINCREMENT, userId TEXT, contactUrl TEXT, localId TEXT, managerUri TEXT, snsName TEXT, snsDesc TEXT, snsUrl TEXT, presenceState TEXT, presenceText TEXT, StatusText TEXT, timeStamp INTEGER )"); |
|
588 |
|
589 smfDsmTables[1].prepare("CREATE TABLE IF NOT EXISTS relation (relationId INTEGER, contactId INTEGER, contactIndex INTEGER)" ); |
|
590 |
|
591 |
|
592 |
|
593 /*smfDsmTables[0].prepare("CREATE TABLE IF NOT EXISTS contact (contactId INTEGER PRIMARY KEY AUTOINCREMENT," |
541 "contactGuid TEXT," |
594 "contactGuid TEXT," |
542 "contactUrl TEXT," |
595 "contactUrl TEXT," |
543 "localId TEXT," |
596 "localId TEXT," |
544 "managerUri TEXT," |
597 "managerUri TEXT," |
545 "snsName TEXT," |
598 "snsName TEXT," |
551 |
604 |
552 smfDsmTables[1].prepare("CREATE TABLE IF NOT EXISTS relation (relationId INTEGER," |
605 smfDsmTables[1].prepare("CREATE TABLE IF NOT EXISTS relation (relationId INTEGER," |
553 " contactId INTEGER," |
606 " contactId INTEGER," |
554 " contactIndex INTEGER)" ); |
607 " contactIndex INTEGER)" ); |
555 |
608 |
556 |
609 */ |
557 for(int i = 0; i < tableCount; i++){ |
610 for(int i = 0; i < tableCount; i++){ |
558 if(!smfDsmTables[i].exec()){ |
611 if(!smfDsmTables[i].exec()){ |
559 state = ERROR; |
612 state = ERROR; |
560 lastMsg = smfDsmTables[i].lastError().text(); |
613 lastMsg = smfDsmTables[i].lastError().text(); |
561 return FALSE; |
614 return FALSE; |
579 |
632 |
580 if(SmfDbOpeningError == openDB()) |
633 if(SmfDbOpeningError == openDB()) |
581 return SmfDbOpeningError; |
634 return SmfDbOpeningError; |
582 |
635 |
583 QSqlQuery qry; |
636 QSqlQuery qry; |
584 qry.prepare("INSERT INTO contact (userId, contactUrl, localId , managerUri, snsName," |
637 qry.prepare("INSERT INTO contact (userId, contactUrl, localId , managerUri, snsName, snsDesc, snsUrl, presenceState, presenceText, statusText, timeStamp ) VALUES (:userId, :contactUrl, :localId , :managerUri, :snsName, :snsDesc, :snsUrl, :presenceState, :presenceText, :statusText, :timeStamp )"); |
585 " snsDesc, snsUrl, presenceState, presenceText, statusText, timeStamp )" |
|
586 " VALUES (:userId, :contactUrl, :localId , :managerUri, :snsName," |
|
587 " :snsDesc, :snsUrl, :presenceState, :presenceText, :statusText, :timeStamp )"); |
|
588 qry.bindValue(":userId", NULL); |
638 qry.bindValue(":userId", NULL); |
589 qry.bindValue(":contactUrl", NULL); |
639 qry.bindValue(":contactUrl", NULL); |
590 qry.bindValue(":localId", aLocalId); |
640 qry.bindValue(":localId", aLocalId); |
591 qry.bindValue(":managerUri", aManagerUri); |
641 qry.bindValue(":managerUri", aManagerUri); |
592 qry.bindValue(":snsName", aSnsName); |
642 qry.bindValue(":snsName", aSnsName); |
615 db.close(); |
665 db.close(); |
616 return contactId; |
666 return contactId; |
617 |
667 |
618 } |
668 } |
619 |
669 |
620 int DataStoreManager::addContactToTable( const QString &aUserId, |
670 int DataStoreManager::addContactToTable(const QString &aUserId, |
621 const QString &aContactUrl, |
671 const QString &aContactUrl, |
622 const QString &aLocalId, |
672 const QString &aLocalId, |
623 const QString &aManagerUri, |
673 const QString &aManagerUri, |
624 const QString &aSnsName, |
674 const QString &aSnsName, |
625 const QString &aSnsDesc, |
675 const QString &aSnsDesc, |
633 |
683 |
634 if(SmfDbOpeningError == openDB()) |
684 if(SmfDbOpeningError == openDB()) |
635 return SmfDbOpeningError; |
685 return SmfDbOpeningError; |
636 |
686 |
637 QSqlQuery qry; |
687 QSqlQuery qry; |
638 qry.prepare("INSERT INTO contact (userId, contactUrl, localId , managerUri, snsName," |
688 qry.prepare("INSERT INTO contact (userId, contactUrl, localId , managerUri, snsName, snsDesc, snsUrl, PresenceState, PresenceText, statusText, timeStamp ) VALUES (:userId, :contactUrl, :localId , :managerUri, :snsName, :snsDesc, :snsUrl, :PresenceState, :PresenceText, :statusText, :timeStamp )"); |
|
689 |
|
690 qDebug()<<"DSM :: aUserId :"<<aUserId; |
|
691 qDebug()<<"DSM :: aContactUrl :"<<aContactUrl; |
|
692 |
|
693 |
|
694 /*qry.prepare("INSERT INTO contact (userId, contactUrl, localId , managerUri, snsName," |
639 " snsDesc, snsUrl, PresenceState, PresenceText, statusText, timeStamp )" |
695 " snsDesc, snsUrl, PresenceState, PresenceText, statusText, timeStamp )" |
640 " VALUES (:userId, :contactUrl, :localId , :managerUri, :snsName," |
696 " VALUES (:userId, :contactUrl, :localId , :managerUri, :snsName," |
641 " :snsDesc, :snsUrl, :PresenceState, :PresenceText, statusText, :timeStamp )"); |
697 " :snsDesc, :snsUrl, :PresenceState, :PresenceText, statusText, :timeStamp )");*/ |
642 |
698 |
643 qry.bindValue(":userId", aUserId); qry.bindValue(":contactUrl", aContactUrl); |
699 qry.bindValue(":userId", aUserId); qry.bindValue(":contactUrl", aContactUrl); |
644 qry.bindValue(":localId", aLocalId); qry.bindValue(":managerUri", aManagerUri); |
700 qry.bindValue(":localId", aLocalId); qry.bindValue(":managerUri", aManagerUri); |
645 qry.bindValue(":snsName", aSnsName); qry.bindValue(":snsDesc", aSnsDesc); |
701 qry.bindValue(":snsName", aSnsName); qry.bindValue(":snsDesc", aSnsDesc); |
646 qry.bindValue(":snsUrl", aSnsUrl); qry.bindValue(":PresenceState", aPresenceState); |
702 qry.bindValue(":snsUrl", aSnsUrl); qry.bindValue(":PresenceState", aPresenceState); |
648 qry.bindValue(":timeStamp", aTimeStamp); |
704 qry.bindValue(":timeStamp", aTimeStamp); |
649 |
705 |
650 if(SmfDbQueryExecutonError == executeQuery(qry)) |
706 if(SmfDbQueryExecutonError == executeQuery(qry)) |
651 return SmfDbQueryExecutonError; |
707 return SmfDbQueryExecutonError; |
652 |
708 |
653 qry.prepare("SELECT contactId FROM contact WHERE (localId=:localId AND managerUri=:managerUri) " |
709 qry.prepare("SELECT contactId FROM contact WHERE (localId=:localId AND managerUri=:managerUri) OR (userId=:userId AND contactUrl=:contactUrl)"); |
654 "OR (aContactGuid=:aContactGuid AND aContactUrl=:aContactUrl)"); |
710 |
655 qry.bindValue(":localId", aLocalId); qry.bindValue(":managerUri", aManagerUri); |
711 qry.bindValue(":localId", aLocalId); qry.bindValue(":managerUri", aManagerUri); |
656 qry.bindValue(":userId", aUserId); qry.bindValue(":aContactUrl", aContactUrl); |
712 qry.bindValue(":userId", aUserId); qry.bindValue(":aContactUrl", aContactUrl); |
657 |
713 |
658 if(SmfDbQueryExecutonError == executeQuery(qry)) |
714 if(SmfDbQueryExecutonError == executeQuery(qry)) |
659 return SmfDbQueryExecutonError; |
715 return SmfDbQueryExecutonError; |
730 |
789 |
731 return contactExist; |
790 return contactExist; |
732 } |
791 } |
733 |
792 |
734 |
793 |
735 const int DataStoreManager::findMaxIndexValue(const int aRelationId ){ |
794 int DataStoreManager::findMaxIndexValue(const int aRelationId ){ |
736 |
795 |
737 int contactIndex = 0; |
796 int contactIndex = 0; |
738 |
797 |
739 if(SmfDbOpeningError == openDB()) |
798 if(SmfDbOpeningError == openDB()) |
740 return SmfDbOpeningError; |
799 return SmfDbOpeningError; |
741 |
800 |
742 QSqlQuery qry; |
801 QSqlQuery qry; |
743 qry.prepare("SELECT MAX( contactIndex ) FROM (" |
802 qry.prepare("SELECT MAX( contactIndex ) FROM (SELECT contactIndex FROM relation WHERE (relationId=:relationId ))"); |
744 "SELECT contactIndex FROM relation WHERE (relationId=:relationId ))"); |
|
745 qry.bindValue(":relationId", aRelationId); |
803 qry.bindValue(":relationId", aRelationId); |
746 |
804 |
747 if(SmfDbQueryExecutonError == executeQuery(qry)) |
805 if(SmfDbQueryExecutonError == executeQuery(qry)) |
748 return SmfDbQueryExecutonError; |
806 return SmfDbQueryExecutonError; |
749 |
807 |
770 return SmfDbQueryExecutonError; |
828 return SmfDbQueryExecutonError; |
771 |
829 |
772 if(qry.next()){ |
830 if(qry.next()){ |
773 maxRelationId = qry.value(0).toInt(); |
831 maxRelationId = qry.value(0).toInt(); |
774 } |
832 } |
775 |
833 if(0==maxRelationId) |
|
834 maxRelationId = 1000;//socialProfileBaseID; |
|
835 |
776 qry.finish(); |
836 qry.finish(); |
777 db.close(); |
837 db.close(); |
778 return maxRelationId; |
838 return maxRelationId; |
779 } |
839 } |
780 |
840 |
781 const int DataStoreManager::addRelationToTable(const int aContactId, int aRelationId ){ |
841 int DataStoreManager::addRelationToTable(const int aContactId, int aRelationId ){ |
782 |
842 |
783 int relationId, contactIndex; |
843 int relationId=0; |
|
844 int contactIndex; |
|
845 |
|
846 //In case of invalid contactId |
|
847 if(aContactId <= 0) |
|
848 return relationId; |
784 |
849 |
785 if( aRelationId == ENewRelation ){ |
850 if( aRelationId == ENewRelation ){ |
786 relationId = findMaxRelationId() + 1; |
851 relationId = findMaxRelationId() + 1; |
787 contactIndex = 0; |
852 contactIndex = 0; |
788 } |
853 } |
789 else{ |
854 else{ |
790 relationId = aRelationId; |
855 relationId = aRelationId; |
791 contactIndex = 1 + ( findMaxIndexValue( aRelationId ) ) ; |
856 contactIndex = 1 + ( findMaxIndexValue( aRelationId ) ) ; |
|
857 //contactIndex = ( findMaxIndexValue( aRelationId ) ) ; |
792 } |
858 } |
793 |
859 |
794 if(SmfDbOpeningError == openDB()) |
860 if(SmfDbOpeningError == openDB()) |
795 return SmfDbOpeningError; |
861 return SmfDbOpeningError; |
796 |
862 |
797 QSqlQuery qry; |
863 QSqlQuery qry; |
798 qry.prepare("INSERT INTO relation (relationId, contactId, contactIndex )" |
864 qry.prepare("INSERT INTO relation (relationId, contactId, contactIndex ) VALUES (:relationId, :contactId, :contactIndex )"); |
799 " VALUES (:relationId, :contactId, :contactIndex )"); |
|
800 qry.bindValue(":relationId", relationId); |
865 qry.bindValue(":relationId", relationId); |
801 qry.bindValue(":contactId", aContactId); |
866 qry.bindValue(":contactId", aContactId); |
802 qry.bindValue(":contactIndex", contactIndex); |
867 qry.bindValue(":contactIndex", contactIndex); |
803 |
868 |
804 if(SmfDbQueryExecutonError == executeQuery(qry)) |
869 if(SmfDbQueryExecutonError == executeQuery(qry)) |
959 |
1031 |
960 |
1032 |
961 void DataStoreManager::manageContactIndex(const int aRelationId, const int aContactIndex ){ |
1033 void DataStoreManager::manageContactIndex(const int aRelationId, const int aContactIndex ){ |
962 |
1034 |
963 QSqlQuery qry; |
1035 QSqlQuery qry; |
964 qry.prepare("UPDATE relation SET contactIndex = contactIndex - 1 " |
1036 qry.prepare("UPDATE relation SET contactIndex = contactIndex - 1 WHERE ( relationId = :relationId AND contactIndex > :contactIndex )"); |
965 "WHERE ( relationId = :relationId AND contactIndex > :contactIndex )"); |
1037 if(aRelationId <=0 || aContactIndex <0) |
|
1038 { |
|
1039 qDebug()<<"ManageContactIndex: Invalid Argument"; |
|
1040 qry.finish(); |
|
1041 return; |
|
1042 } |
966 qry.bindValue(":relationId", aRelationId); |
1043 qry.bindValue(":relationId", aRelationId); |
967 qry.bindValue(":contactIndex", aContactIndex); |
1044 qry.bindValue(":contactIndex", aContactIndex); |
968 executeQuery(qry); |
1045 if(SmfDbQueryExecutonError == executeQuery(qry)) |
|
1046 qDebug()<<"ManageContactIndex: executeQuery() fails"; |
969 qry.finish(); |
1047 qry.finish(); |
970 } |
1048 } |
971 |
1049 |
972 uint DataStoreManager::count(const int aRelationId){ |
1050 uint DataStoreManager::count(const int aRelationId){ |
973 uint count = -1; |
1051 uint count = 0; |
974 |
1052 |
975 if(SmfDbOpeningError == openDB()) |
1053 if(SmfDbOpeningError == openDB()) |
976 return count; |
1054 return count; |
977 |
1055 |
978 QSqlQuery qry; |
1056 QSqlQuery qry; |