49 #include "cntsymbiansrvconnection.h" |
49 #include "cntsymbiansrvconnection.h" |
50 #include "cntsymbiantransformerror.h" |
50 #include "cntsymbiantransformerror.h" |
51 |
51 |
52 // Constants |
52 // Constants |
53 // To be removed. Should be defined in a header file |
53 // To be removed. Should be defined in a header file |
54 #define KCntSearchResultList 99 |
54 |
55 #define KCntOpenDataBase 100 // = KCapabilityReadUserData |
55 #define KCntOpenDataBase 100 // = KCapabilityReadUserData |
56 |
56 |
57 _LIT(KCntServerExe,"CNTSRV.EXE"); // Name of the exe for the Contacts server. |
57 _LIT(KCntServerExe,"CNTSRV.EXE"); // Name of the exe for the Contacts server. |
58 _LIT(KCntServerName,"CNTSRV"); // Name used to connect a session |
58 _LIT(KCntServerName,"CNTSRV"); // Name used to connect a session |
59 // to the Contacts server. |
59 // to the Contacts server. |
99 QList<QContactLocalId> CntSymbianSrvConnection::searchContacts(const QString& sqlQuery, |
99 QList<QContactLocalId> CntSymbianSrvConnection::searchContacts(const QString& sqlQuery, |
100 QContactManager::Error* error) |
100 QContactManager::Error* error) |
101 { |
101 { |
102 QList<QContactLocalId> list; |
102 QList<QContactLocalId> list; |
103 TPtrC queryPtr(reinterpret_cast<const TUint16*>(sqlQuery.utf16())); |
103 TPtrC queryPtr(reinterpret_cast<const TUint16*>(sqlQuery.utf16())); |
104 TRAPD(err, list = searchContactIdsL(queryPtr)); |
104 TRAPD(err, list = searchContactIdsL(queryPtr, CntSymbianSrvConnection::CntSearchResultList)); |
105 CntSymbianTransformError::transformError(err, error); |
105 CntSymbianTransformError::transformError(err, error); |
106 return list; |
106 return list; |
107 } |
107 } |
108 |
108 |
|
109 /*! |
|
110 * Query the SQL database |
|
111 * |
|
112 * \a sqlQuery An SQL query |
|
113 * a QueryType query type |
|
114 * \a error On return, contains the possible error. |
|
115 * \return the list of matched contact ids |
|
116 */ |
|
117 QList<QContactLocalId> CntSymbianSrvConnection::searchOnServer(const QString& sqlQuery, |
|
118 QueryType aQueryType, |
|
119 QContactManager::Error* error) |
|
120 { |
|
121 QList<QContactLocalId> list; |
|
122 TPtrC queryPtr(reinterpret_cast<const TUint16*>(sqlQuery.utf16())); |
|
123 TRAPD(err, list = searchContactIdsL(queryPtr, aQueryType)); |
|
124 CntSymbianTransformError::transformError(err, error); |
|
125 return list; |
|
126 } |
109 /*! |
127 /*! |
110 * Fetches all contact names from the database. If there are more than 3000 contacts, |
128 * Fetches all contact names from the database. If there are more than 3000 contacts, |
111 * only the first (by id) 3000 contacts will be fetched due to RAM restrictions. |
129 * only the first (by id) 3000 contacts will be fetched due to RAM restrictions. |
112 * |
130 * |
113 * \a error On return, contains the possible error. |
131 * \a error On return, contains the possible error. |
151 * The leaving function that queries the SQL database |
169 * The leaving function that queries the SQL database |
152 * |
170 * |
153 * \a aSqlQuery An SQL query |
171 * \a aSqlQuery An SQL query |
154 * \return the list of matched contact ids |
172 * \return the list of matched contact ids |
155 */ |
173 */ |
156 QList<QContactLocalId> CntSymbianSrvConnection::searchContactIdsL(const TDesC& aSqlQuery) |
174 QList<QContactLocalId> CntSymbianSrvConnection::searchContactIdsL(const TDesC& aSqlQuery, QueryType aQueryType) |
157 { |
175 { |
158 readContactsToBufferL(aSqlQuery); |
176 readContactsToBufferL(aSqlQuery, aQueryType); |
159 |
177 |
160 RBufReadStream readStream; |
178 RBufReadStream readStream; |
161 QList<QContactLocalId> list; |
179 QList<QContactLocalId> list; |
162 TInt item; |
180 TInt item; |
163 |
181 |
175 * \a aSqlQuery An SQL query |
193 * \a aSqlQuery An SQL query |
176 * \return the list of matched contact ids |
194 * \return the list of matched contact ids |
177 */ |
195 */ |
178 QList<QContact> CntSymbianSrvConnection::searchContactNamesL(const TDesC& aSqlQuery) |
196 QList<QContact> CntSymbianSrvConnection::searchContactNamesL(const TDesC& aSqlQuery) |
179 { |
197 { |
180 readContactsToBufferL(aSqlQuery); |
198 readContactsToBufferL(aSqlQuery, CntSymbianSrvConnection::CntSearchResultList); |
181 |
199 |
182 RBufReadStream readStream; |
200 RBufReadStream readStream; |
183 QList<QContact> contacts; |
201 QList<QContact> contacts; |
184 TInt id; |
202 TInt id; |
185 TBuf<256> firstName; |
203 TBuf<256> firstName; |
228 * The leaving function that queries the SQL database |
246 * The leaving function that queries the SQL database |
229 * |
247 * |
230 * \a id database id of the contact |
248 * \a id database id of the contact |
231 * \return the list of matched contact names |
249 * \return the list of matched contact names |
232 */ |
250 */ |
233 void CntSymbianSrvConnection::readContactsToBufferL(const TDesC& sqlQuery) |
251 void CntSymbianSrvConnection::readContactsToBufferL(const TDesC& sqlQuery, QueryType aQueryType) |
234 { |
252 { |
235 // Initialize connection if it is not initialized yet. |
253 // Initialize connection if it is not initialized yet. |
236 if (!m_isInitialized) { |
254 if (!m_isInitialized) { |
237 ConnectSrvL(); |
255 ConnectSrvL(); |
238 OpenDatabaseL(); |
256 OpenDatabaseL(); |
240 } |
258 } |
241 |
259 |
242 TIpcArgs args; |
260 TIpcArgs args; |
243 args.Set(0, &GetReceivingBufferL()); |
261 args.Set(0, &GetReceivingBufferL()); |
244 args.Set(1, &sqlQuery); |
262 args.Set(1, &sqlQuery); |
245 TInt newBuffSize = SendReceive(KCntSearchResultList, args); |
263 TInt newBuffSize = SendReceive(aQueryType, args); |
246 User::LeaveIfError(newBuffSize); |
264 User::LeaveIfError(newBuffSize); |
247 if (newBuffSize > 0) { |
265 if (newBuffSize > 0) { |
248 args.Set(0, &GetReceivingBufferL(newBuffSize)); |
266 args.Set(0, &GetReceivingBufferL(newBuffSize)); |
249 args.Set(1, &sqlQuery); |
267 args.Set(1, &sqlQuery); |
250 User::LeaveIfError(SendReceive(KCntSearchResultList, args)); |
268 User::LeaveIfError(SendReceive(aQueryType, args)); |
251 } |
269 } |
252 } |
270 } |
253 |
271 |
254 |
272 |
255 /*! |
273 /*! |