85
|
1 |
/*
|
|
2 |
* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <QList>
|
|
19 |
#include <QDebug>
|
|
20 |
#include <QString>
|
|
21 |
#include <QtSql>
|
|
22 |
#include <QMap>
|
|
23 |
#include <QMapIterator>
|
|
24 |
|
|
25 |
#include "caclientproxy.h"
|
|
26 |
#include "caobjectadapter.h"
|
|
27 |
|
|
28 |
#include "caentry.h"
|
|
29 |
#include "caquery.h"
|
|
30 |
#include "cadefs.h"
|
|
31 |
#include "canotifier.h"
|
|
32 |
#include "canotifier_p.h"
|
|
33 |
#include "canotifiers.h"
|
|
34 |
|
|
35 |
#include "hswidgetregistryservice.h"
|
|
36 |
|
87
|
37 |
const char *DATABASE_CONNECTION_NAME = "CaService";
|
|
38 |
const char *DATABASE_TYPE = "QSQLITE";
|
|
39 |
const char *DATABASE_NAME = "castoragedb";
|
85
|
40 |
|
|
41 |
static QSqlDatabase dbConnection()
|
|
42 |
{
|
|
43 |
return QSqlDatabase::database(DATABASE_CONNECTION_NAME, false);
|
|
44 |
}
|
|
45 |
|
|
46 |
//----------------------------------------------------------------------------
|
|
47 |
//
|
|
48 |
//----------------------------------------------------------------------------
|
|
49 |
CaClientProxy::CaClientProxy() :
|
|
50 |
mWidgetRegistryPath("hsresources/import/widgetregistry")
|
|
51 |
{
|
|
52 |
}
|
|
53 |
|
|
54 |
//----------------------------------------------------------------------------
|
|
55 |
//
|
|
56 |
//----------------------------------------------------------------------------
|
|
57 |
CaClientProxy::~CaClientProxy()
|
|
58 |
{
|
|
59 |
QSqlDatabase db = dbConnection();
|
|
60 |
if (db.isOpen()) {
|
|
61 |
db.close();
|
|
62 |
}
|
|
63 |
QSqlDatabase::removeDatabase(DATABASE_CONNECTION_NAME);
|
|
64 |
}
|
|
65 |
|
|
66 |
//----------------------------------------------------------------------------
|
|
67 |
//
|
|
68 |
//----------------------------------------------------------------------------
|
|
69 |
ErrorCode CaClientProxy::connect()
|
|
70 |
{
|
|
71 |
ErrorCode errorCode = NotFoundErrorCode;
|
|
72 |
QSqlDatabase db = QSqlDatabase::addDatabase(DATABASE_TYPE,
|
87
|
73 |
DATABASE_CONNECTION_NAME);
|
85
|
74 |
if (db.isValid()) {
|
|
75 |
db.setDatabaseName(DATABASE_NAME);
|
|
76 |
if (db.open()) {
|
|
77 |
errorCode = NoErrorCode;
|
|
78 |
updateWidgets();
|
|
79 |
}
|
|
80 |
}
|
|
81 |
if (errorCode) {
|
|
82 |
qDebug("CaClientProxy::CaClientProxy FAILED");
|
|
83 |
}
|
|
84 |
return errorCode;
|
|
85 |
}
|
|
86 |
|
|
87 |
/*!
|
|
88 |
Updates widgets.
|
|
89 |
*/
|
|
90 |
void CaClientProxy::updateWidgets()
|
|
91 |
{
|
|
92 |
qDebug("CaClientProxy::updateWidgets start");
|
87
|
93 |
|
85
|
94 |
HsWidgetRegistryService *rs =
|
|
95 |
new HsWidgetRegistryService(mWidgetRegistryPath);
|
|
96 |
QList<HsWidgetToken> widgets = rs->widgets();
|
87
|
97 |
|
85
|
98 |
// Read widgets in order to add synchronize the content of the widgets
|
|
99 |
// registry with Content Storage database.
|
87
|
100 |
foreach(const HsWidgetToken &widgetToken, widgets) {
|
85
|
101 |
int uid = widgetToken.mUid;
|
87
|
102 |
|
85
|
103 |
if (!hsWidgetExists(uid)) {
|
|
104 |
// The given widget does not have a corresonding entry
|
|
105 |
// in the databse, so such an entry needs do be created.
|
|
106 |
addWidgetEntry(widgetToken);
|
|
107 |
}
|
|
108 |
}
|
87
|
109 |
|
85
|
110 |
delete rs;
|
|
111 |
qDebug("CaClientProxy::updateWidgets end");
|
|
112 |
}
|
|
113 |
|
|
114 |
/*!
|
|
115 |
Returns true if a widget with the given uid exists in the database.
|
|
116 |
*/
|
|
117 |
void CaClientProxy::addWidgetEntry(const HsWidgetToken &widgetToken)
|
|
118 |
{
|
|
119 |
QString description = widgetToken.mDescription;
|
|
120 |
QString iconUri = widgetToken.mIconUri;
|
|
121 |
QString library = widgetToken.mLibrary;
|
|
122 |
QString title = widgetToken.mTitle;
|
|
123 |
int uid = widgetToken.mUid;
|
|
124 |
QString uri = widgetToken.mUri;
|
|
125 |
QSqlDatabase db = dbConnection();
|
|
126 |
QSqlQuery query(db);
|
|
127 |
QString hexUid;
|
|
128 |
hexUid.setNum(uid,16);
|
|
129 |
QDir currentDir = QDir::current();
|
87
|
130 |
|
85
|
131 |
// Add icon.
|
|
132 |
QString queryAddIcon =
|
|
133 |
"INSERT INTO CA_ICON " \
|
87
|
134 |
"(IC_FILENAME) " \
|
85
|
135 |
"VALUES " \
|
87
|
136 |
"(?)";
|
85
|
137 |
|
|
138 |
query.prepare(queryAddIcon);
|
|
139 |
query.addBindValue(iconUri);
|
|
140 |
query.exec();
|
|
141 |
qDebug() << query.executedQuery();
|
87
|
142 |
|
85
|
143 |
// Add entry.
|
|
144 |
QString queryAddEntry =
|
|
145 |
"INSERT INTO CA_ENTRY " \
|
87
|
146 |
"(EN_TEXT, EN_DESCRIPTION, EN_ROLE, EN_TYPE_NAME, EN_ICON_ID) " \
|
85
|
147 |
"VALUES " \
|
87
|
148 |
"(?, ?, 1, 'widget', last_insert_rowid())";
|
85
|
149 |
|
87
|
150 |
query.prepare(queryAddEntry);
|
85
|
151 |
query.addBindValue(title);
|
|
152 |
query.addBindValue(description);
|
|
153 |
query.exec();
|
|
154 |
qDebug() << query.executedQuery();
|
87
|
155 |
|
|
156 |
// Get last id
|
85
|
157 |
QString queryLastId = "SELECT last_insert_rowid() AS LAST_ID";
|
|
158 |
query.prepare(queryLastId);
|
|
159 |
query.exec();
|
|
160 |
query.next();
|
|
161 |
int lastId = query.value(query.record().indexOf("LAST_ID")).toInt();
|
87
|
162 |
|
85
|
163 |
// Add attribute packageuid
|
|
164 |
QString queryAddAttribute1 =
|
|
165 |
"INSERT INTO CA_ATTRIBUTE " \
|
87
|
166 |
"(AT_ENTRY_ID, AT_NAME, AT_VALUE) " \
|
85
|
167 |
"VALUES " \
|
87
|
168 |
"(?, 'packageuid', ?)";
|
85
|
169 |
|
|
170 |
query.prepare(queryAddAttribute1);
|
|
171 |
query.addBindValue(lastId);
|
|
172 |
query.addBindValue(hexUid);
|
|
173 |
query.exec();
|
|
174 |
qDebug() << query.executedQuery();
|
87
|
175 |
|
85
|
176 |
// Add attribute widget uri
|
|
177 |
QString queryAddAttribute2 =
|
|
178 |
"INSERT INTO CA_ATTRIBUTE " \
|
87
|
179 |
"(AT_ENTRY_ID, AT_NAME, AT_VALUE) " \
|
85
|
180 |
"VALUES " \
|
87
|
181 |
"(?, 'widget:uri', ?)";
|
85
|
182 |
|
|
183 |
query.prepare(queryAddAttribute2);
|
|
184 |
query.addBindValue(lastId);
|
|
185 |
query.addBindValue(uri);
|
|
186 |
query.exec();
|
|
187 |
qDebug() << query.executedQuery();
|
87
|
188 |
|
85
|
189 |
// Add attribute widget library
|
|
190 |
QString queryAddAttribute3 =
|
|
191 |
"INSERT INTO CA_ATTRIBUTE " \
|
87
|
192 |
"(AT_ENTRY_ID, AT_NAME, AT_VALUE) " \
|
85
|
193 |
"VALUES " \
|
87
|
194 |
"(?, 'widget:library', ?)";
|
85
|
195 |
|
|
196 |
query.prepare(queryAddAttribute3);
|
|
197 |
query.addBindValue(lastId);
|
|
198 |
query.addBindValue(library);
|
|
199 |
query.exec();
|
|
200 |
qDebug() << query.executedQuery();
|
|
201 |
}
|
|
202 |
|
|
203 |
/*!
|
|
204 |
Returns true if a widget with the given uid exists in the database.
|
|
205 |
*/
|
|
206 |
bool CaClientProxy::hsWidgetExists(int uid)
|
|
207 |
{
|
|
208 |
bool exists(false);
|
|
209 |
QSqlDatabase db = dbConnection();
|
|
210 |
QSqlQuery query(db);
|
87
|
211 |
QString hexUid;
|
85
|
212 |
hexUid.setNum(uid,16);
|
87
|
213 |
|
85
|
214 |
QString queryString =
|
|
215 |
"SELECT " \
|
87
|
216 |
"AT_ENTRY_ID " \
|
85
|
217 |
"FROM " \
|
87
|
218 |
"CA_ATTRIBUTE " \
|
85
|
219 |
"WHERE " \
|
87
|
220 |
"AT_VALUE LIKE ?";
|
|
221 |
|
85
|
222 |
query.prepare(queryString);
|
|
223 |
query.addBindValue(hexUid);
|
87
|
224 |
|
85
|
225 |
if (query.exec() && query.next()) {
|
|
226 |
// Query returned a non empty result.
|
|
227 |
exists = true;
|
|
228 |
} else {
|
|
229 |
// The widget with the given uid was not found.
|
|
230 |
exists = false;
|
|
231 |
}
|
87
|
232 |
|
85
|
233 |
qDebug() << query.executedQuery();
|
87
|
234 |
|
85
|
235 |
return exists;
|
|
236 |
}
|
|
237 |
|
|
238 |
//----------------------------------------------------------------------------
|
|
239 |
//
|
|
240 |
//----------------------------------------------------------------------------
|
|
241 |
ErrorCode CaClientProxy::addData(const CaEntry &entryToAdd,
|
87
|
242 |
CaEntry &targetEntry)
|
85
|
243 |
{
|
|
244 |
qDebug() << "CaClientProxy::addData" << "entry id: "
|
87
|
245 |
<< entryToAdd.id();
|
85
|
246 |
|
|
247 |
targetEntry = entryToAdd;
|
|
248 |
QSqlDatabase db = dbConnection();
|
|
249 |
QSqlQuery query(db);
|
|
250 |
if (entryToAdd.id() == 0) {
|
|
251 |
CaObjectAdapter::setId(targetEntry, 0);
|
|
252 |
}
|
|
253 |
query.exec("begin");
|
|
254 |
bool success = (setIconInDb(&targetEntry)
|
87
|
255 |
&& setEntryInDb(&targetEntry)
|
|
256 |
&& setAttributesInDb(&targetEntry));
|
85
|
257 |
if (success) {
|
|
258 |
query.exec("commit");
|
|
259 |
QList<int> parentIds;
|
|
260 |
GetParentsIds(QList<int>() << targetEntry.id(), parentIds);
|
|
261 |
if (entryToAdd.id() == 0) {
|
|
262 |
CaNotifiers::Notify(targetEntry, AddChangeType, parentIds);
|
|
263 |
} else {
|
|
264 |
CaNotifiers::Notify(targetEntry, UpdateChangeType, parentIds);
|
|
265 |
}
|
|
266 |
return NoErrorCode;
|
|
267 |
} else {
|
|
268 |
query.exec("rollback");
|
|
269 |
return UnknownErrorCode;
|
|
270 |
}
|
|
271 |
}
|
|
272 |
|
|
273 |
//----------------------------------------------------------------------------
|
|
274 |
//
|
|
275 |
//----------------------------------------------------------------------------
|
|
276 |
ErrorCode CaClientProxy::removeData(const QList<int> &entryIdList)
|
|
277 |
{
|
|
278 |
qDebug() << "CaClientProxy::removeData" << "entryIdList: "
|
87
|
279 |
<< entryIdList;
|
85
|
280 |
|
87
|
281 |
QList<CaEntry *> entryList;
|
85
|
282 |
getData(entryIdList, entryList);
|
|
283 |
QList<QList<int> > parentsIds;
|
87
|
284 |
foreach(CaEntry *entry, entryList) {
|
85
|
285 |
QList<int> parentIds;
|
|
286 |
GetParentsIds(QList<int>() << entry->id(), parentIds);
|
|
287 |
parentsIds.append(parentIds);
|
|
288 |
}
|
|
289 |
|
|
290 |
QSqlDatabase db = dbConnection();
|
|
291 |
QSqlQuery query(db);
|
|
292 |
//begin transaction
|
|
293 |
bool success(false);
|
|
294 |
query.exec("begin");
|
|
295 |
foreach(int entryId, entryIdList) {
|
|
296 |
query.prepare(
|
|
297 |
"SELECT ENTRY_ID FROM CA_ENTRY WHERE ENTRY_ID = ?");
|
|
298 |
query.addBindValue(entryId);
|
|
299 |
success = query.exec();
|
|
300 |
if (success && query.next()) {
|
|
301 |
success
|
87
|
302 |
= query.value(query.record().indexOf("ENTRY_ID")).toInt()
|
|
303 |
> 0;
|
85
|
304 |
}
|
|
305 |
if (!success) {
|
|
306 |
break;
|
|
307 |
}
|
|
308 |
|
|
309 |
query.prepare(
|
|
310 |
"SELECT EN_ICON_ID FROM CA_ENTRY WHERE ENTRY_ID = ?");
|
|
311 |
query.addBindValue(entryId);
|
|
312 |
int iconId(0);
|
|
313 |
success = query.exec();
|
87
|
314 |
if (success && query.next()) {
|
85
|
315 |
iconId
|
87
|
316 |
= query.value(query.record().indexOf("EN_ICON_ID")).toInt();
|
85
|
317 |
} else {
|
|
318 |
break;
|
|
319 |
}
|
|
320 |
|
|
321 |
query.prepare("DELETE FROM CA_LAUNCH WHERE LA_ENTRY_ID = ?");
|
|
322 |
query.addBindValue(entryId);
|
|
323 |
success = query.exec();
|
|
324 |
if (success) {
|
|
325 |
qDebug() << query.lastQuery() << " rows deleted: "
|
87
|
326 |
<< query.numRowsAffected();
|
85
|
327 |
} else {
|
|
328 |
break;
|
|
329 |
}
|
|
330 |
|
|
331 |
query.prepare(
|
|
332 |
"DELETE FROM CA_GROUP_ENTRY WHERE GE_ENTRY_ID = ?");
|
|
333 |
query.addBindValue(entryId);
|
|
334 |
success = query.exec();
|
|
335 |
if (success) {
|
|
336 |
qDebug() << query.lastQuery() << " rows deleted: "
|
87
|
337 |
<< query.numRowsAffected();
|
85
|
338 |
} else {
|
|
339 |
break;
|
|
340 |
}
|
|
341 |
|
|
342 |
query.prepare(
|
|
343 |
"DELETE FROM CA_GROUP_ENTRY WHERE GE_GROUP_ID = ?");
|
|
344 |
query.addBindValue(entryId);
|
|
345 |
success = query.exec();
|
|
346 |
if (success) {
|
|
347 |
qDebug() << query.lastQuery() << " rows deleted: "
|
87
|
348 |
<< query.numRowsAffected();
|
85
|
349 |
} else {
|
|
350 |
break;
|
|
351 |
}
|
|
352 |
|
|
353 |
query.prepare("DELETE FROM CA_ATTRIBUTE WHERE AT_ENTRY_ID = ?");
|
|
354 |
query.addBindValue(entryId);
|
|
355 |
success = query.exec();
|
|
356 |
if (success) {
|
|
357 |
qDebug() << query.lastQuery() << " rows deleted: "
|
87
|
358 |
<< query.numRowsAffected();
|
85
|
359 |
} else {
|
|
360 |
break;
|
|
361 |
}
|
|
362 |
|
|
363 |
query.prepare("DELETE FROM CA_ENTRY WHERE ENTRY_ID = ?");
|
|
364 |
query.addBindValue(entryId);
|
|
365 |
success = query.exec();
|
|
366 |
if (success) {
|
|
367 |
qDebug() << query.lastQuery() << " rows deleted: "
|
87
|
368 |
<< query.numRowsAffected();
|
85
|
369 |
} else {
|
|
370 |
break;
|
|
371 |
}
|
|
372 |
|
|
373 |
if (iconId != 0) {
|
|
374 |
query.prepare("DELETE FROM CA_ICON WHERE ICON_ID = ?");
|
|
375 |
query.addBindValue(iconId);
|
|
376 |
success = query.exec();
|
|
377 |
if (success) {
|
|
378 |
qDebug() << query.lastQuery() << " rows deleted: "
|
87
|
379 |
<< query.numRowsAffected();
|
85
|
380 |
} else {
|
|
381 |
// ignore, this means that the icon cannot be removed
|
|
382 |
// because some other entry has the same icon.
|
|
383 |
success = true;
|
|
384 |
}
|
|
385 |
}
|
|
386 |
}
|
|
387 |
|
|
388 |
ErrorCode error(NoErrorCode);
|
|
389 |
if (success) {
|
|
390 |
query.exec("commit");
|
|
391 |
if (parentsIds.count() == entryList.count()) {
|
|
392 |
for (int i = 0; i < entryList.count(); i++) {
|
|
393 |
GetParentsIds(QList<int>() << entryList[i]->id(), parentsIds[i]);
|
|
394 |
CaNotifiers::Notify(*entryList[i], RemoveChangeType, parentsIds[i]);
|
|
395 |
}
|
|
396 |
}
|
|
397 |
} else {
|
|
398 |
query.exec("rollback");
|
|
399 |
error = UnknownErrorCode;
|
|
400 |
}
|
|
401 |
|
|
402 |
return error;
|
|
403 |
}
|
|
404 |
|
|
405 |
//----------------------------------------------------------------------------
|
|
406 |
//
|
|
407 |
//----------------------------------------------------------------------------
|
|
408 |
ErrorCode CaClientProxy::insertEntriesIntoGroup(int groupId,
|
87
|
409 |
const QList<int> &entryIdList, int beforeEntryId)
|
85
|
410 |
{
|
|
411 |
qDebug() << "CaClientProxy::insertEntriesIntoGroup" << "groupId: "
|
87
|
412 |
<< groupId << "beforeEntryId: " << beforeEntryId << "entryIdList: "
|
|
413 |
<< entryIdList;
|
85
|
414 |
|
|
415 |
removeEntriesFromGroup(groupId, entryIdList, false);
|
|
416 |
QString queryText;
|
|
417 |
if (beforeEntryId == AfterTheLastEntry) {
|
|
418 |
queryText = QString("INSERT INTO CA_GROUP_ENTRY (GE_GROUP_ID,GE_ENTRY_ID,GE_POSITION) "
|
87
|
419 |
"VALUES ( ?, ?,(SELECT MAX(DATA) FROM ( SELECT MAX(GE_POSITION)+ 1 AS DATA FROM CA_GROUP_ENTRY "
|
|
420 |
"WHERE GE_GROUP_ID = %1 UNION SELECT 1 AS DATA FROM CA_GROUP_ENTRY ) ) )").arg(groupId);
|
85
|
421 |
} else if (beforeEntryId == BeforeTheFirstEntry) {
|
|
422 |
queryText = "INSERT INTO CA_GROUP_ENTRY (GE_GROUP_ID,GE_ENTRY_ID,GE_POSITION) VALUES ( ?, ?, 0 ) ";
|
|
423 |
} else {
|
|
424 |
queryText = QString("INSERT INTO CA_GROUP_ENTRY (GE_GROUP_ID,GE_ENTRY_ID,GE_POSITION) VALUES ( "
|
87
|
425 |
"?, ?, ( SELECT GE_POSITION FROM CA_GROUP_ENTRY WHERE GE_ENTRY_ID = %1 ) ) ").arg(beforeEntryId);
|
85
|
426 |
}
|
|
427 |
|
|
428 |
bool success = true;
|
|
429 |
QSqlDatabase db = dbConnection();
|
|
430 |
QSqlQuery query(db);
|
|
431 |
query.exec("begin");
|
|
432 |
for (int i = 0; i < entryIdList.count() && success; ++i) {
|
|
433 |
query.prepare(queryText);
|
|
434 |
query.addBindValue(groupId);
|
|
435 |
query.addBindValue(entryIdList.at(i));
|
|
436 |
success = query.exec();
|
|
437 |
}
|
|
438 |
|
|
439 |
ErrorCode error(NoErrorCode);
|
|
440 |
if (success) {
|
|
441 |
query.exec("commit");
|
|
442 |
CaNotifiers::Notify(groupId);
|
|
443 |
} else {
|
|
444 |
query.exec("rollback");
|
|
445 |
error = UnknownErrorCode;
|
|
446 |
}
|
|
447 |
return error;
|
|
448 |
}
|
|
449 |
|
|
450 |
//----------------------------------------------------------------------------
|
|
451 |
//
|
|
452 |
//----------------------------------------------------------------------------
|
|
453 |
ErrorCode CaClientProxy::removeEntriesFromGroup(int groupId,
|
87
|
454 |
const QList<int> &entryIdList,
|
|
455 |
bool calledDirectly)
|
85
|
456 |
{
|
|
457 |
qDebug() << "CaClientProxy::removeEntriesFromGroup" << "groupId: "
|
87
|
458 |
<< groupId << "entryIdList: " << entryIdList;
|
85
|
459 |
|
|
460 |
bool success = true;
|
|
461 |
QSqlDatabase db = dbConnection();
|
|
462 |
QSqlQuery query(db);
|
|
463 |
query.exec("begin");
|
|
464 |
for (int i = 0; i < entryIdList.count() && success; ++i) {
|
|
465 |
query.prepare(
|
|
466 |
"DELETE FROM CA_GROUP_ENTRY WHERE GE_ENTRY_ID = ? AND GE_GROUP_ID = ? ");
|
|
467 |
query.addBindValue(entryIdList.at(i));
|
|
468 |
query.addBindValue(groupId);
|
|
469 |
success = query.exec();
|
|
470 |
}
|
|
471 |
|
|
472 |
ErrorCode error(NoErrorCode);
|
|
473 |
if (success) {
|
|
474 |
query.exec("commit");
|
|
475 |
if (calledDirectly) {
|
|
476 |
CaNotifiers::Notify(groupId);
|
|
477 |
}
|
|
478 |
} else {
|
|
479 |
query.exec("rollback");
|
|
480 |
error = UnknownErrorCode;
|
|
481 |
}
|
|
482 |
return error;
|
|
483 |
}
|
|
484 |
|
|
485 |
//----------------------------------------------------------------------------
|
|
486 |
//
|
|
487 |
//----------------------------------------------------------------------------
|
|
488 |
ErrorCode CaClientProxy::getData(const QList<int> &entryIdList,
|
87
|
489 |
QList<CaEntry *> &sourceList)
|
85
|
490 |
{
|
|
491 |
qDebug() << "CaClientProxy::getData" << "entryIdList: "
|
87
|
492 |
<< entryIdList;
|
85
|
493 |
|
|
494 |
QSqlDatabase db = dbConnection();
|
|
495 |
|
|
496 |
bool success(true);
|
87
|
497 |
foreach(int i, entryIdList) {
|
85
|
498 |
QSqlQuery query(db);
|
|
499 |
query.prepare(
|
|
500 |
"SELECT ENTRY_ID, EN_TEXT, EN_DESCRIPTION, EN_TYPE_NAME, EN_FLAGS, EN_ROLE, EN_UID, \
|
88
|
501 |
ICON_ID, IC_FILENAME, IC_SKIN_ID, IC_APP_ID \
|
85
|
502 |
FROM CA_ENTRY LEFT JOIN CA_ICON ON EN_ICON_ID = ICON_ID WHERE ENTRY_ID = ?");
|
|
503 |
query.addBindValue(i);
|
|
504 |
|
|
505 |
success = query.exec();
|
|
506 |
if (success && query.next()) {
|
|
507 |
qDebug() << query.executedQuery();
|
|
508 |
int role =
|
|
509 |
query.value(query.record().indexOf("EN_ROLE")).toInt();
|
87
|
510 |
CaEntry *entry = new CaEntry((EntryRole) role);
|
85
|
511 |
CaObjectAdapter::setId(*entry,
|
87
|
512 |
query.value(query.record().indexOf("ENTRY_ID")).toInt());
|
85
|
513 |
entry->setText(query.value(
|
87
|
514 |
query.record().indexOf("EN_TEXT")).toString());
|
85
|
515 |
entry->setDescription(query.value(
|
87
|
516 |
query.record().indexOf("EN_DESCRIPTION")).toString());
|
85
|
517 |
entry->setEntryTypeName(query.value(query.record().indexOf(
|
87
|
518 |
"EN_TYPE_NAME")).toString());
|
|
519 |
entry->setFlags(static_cast<EntryFlag>(query.value(
|
|
520 |
query.record().indexOf("EN_FLAGS")).toUInt()));
|
85
|
521 |
|
|
522 |
CaIconDescription icon;
|
|
523 |
CaObjectAdapter::setId(icon,
|
87
|
524 |
query.value(query.record().indexOf("ICON_ID")).toInt());
|
88
|
525 |
|
85
|
526 |
icon.setFilename(query.value(query.record().indexOf(
|
87
|
527 |
"IC_FILENAME")).toString());
|
88
|
528 |
icon.setSkinId(query.value(query.record().indexOf(
|
|
529 |
"IC_SKIN_ID")).toString());
|
|
530 |
icon.setApplicationId(query.value(query.record().indexOf(
|
|
531 |
"IC_APP_ID")).toString());
|
85
|
532 |
entry->setIconDescription(icon);
|
|
533 |
|
|
534 |
// attributes
|
|
535 |
// UID as attribute
|
|
536 |
if (query.value(query.record().indexOf("EN_UID")).toString().length()
|
87
|
537 |
> 0) {
|
85
|
538 |
entry->setAttribute("application:uid", query.value(
|
87
|
539 |
query.record().indexOf("EN_UID")).toString());
|
85
|
540 |
}
|
|
541 |
|
|
542 |
// fetch from DB attributes
|
|
543 |
QSqlQuery attributesQuery(db);
|
|
544 |
attributesQuery.prepare(
|
|
545 |
"SELECT AT_NAME, AT_VALUE FROM CA_ATTRIBUTE WHERE AT_ENTRY_ID = ?");
|
|
546 |
attributesQuery.addBindValue(i);
|
|
547 |
success = attributesQuery.exec();
|
|
548 |
if (success) {
|
|
549 |
while (attributesQuery.next()) {
|
|
550 |
entry->setAttribute(
|
|
551 |
attributesQuery.value(0).toString(),
|
|
552 |
attributesQuery.value(1).toString());
|
|
553 |
}
|
|
554 |
sourceList << entry;
|
|
555 |
}
|
|
556 |
} else {
|
|
557 |
break;
|
|
558 |
}
|
|
559 |
}
|
|
560 |
|
|
561 |
ErrorCode error = NoErrorCode;
|
|
562 |
if (!success) {
|
|
563 |
error = UnknownErrorCode;
|
|
564 |
} else if ((entryIdList.count() != sourceList.count())) {
|
|
565 |
error = NotFoundErrorCode;
|
|
566 |
}
|
|
567 |
return error;
|
|
568 |
}
|
|
569 |
|
|
570 |
//----------------------------------------------------------------------------
|
|
571 |
//
|
|
572 |
//----------------------------------------------------------------------------
|
|
573 |
ErrorCode CaClientProxy::getData(const CaQuery &query,
|
87
|
574 |
QList<CaEntry *> &sourceList)
|
85
|
575 |
{
|
|
576 |
QList<int> entryIdList;
|
|
577 |
ErrorCode errorCode = getEntryIds(query, entryIdList);
|
|
578 |
if (errorCode == NoErrorCode) {
|
|
579 |
errorCode = getData(entryIdList, sourceList);
|
|
580 |
}
|
|
581 |
return errorCode;
|
|
582 |
}
|
|
583 |
|
|
584 |
//----------------------------------------------------------------------------
|
|
585 |
//
|
|
586 |
//----------------------------------------------------------------------------
|
|
587 |
ErrorCode CaClientProxy::getEntryIds(const CaQuery &query,
|
87
|
588 |
QList<int> &sourceIdList)
|
85
|
589 |
{
|
|
590 |
qDebug() << "CaClientProxy::getEntryIds";
|
|
591 |
|
|
592 |
QSqlDatabase db = dbConnection();
|
|
593 |
|
|
594 |
bool success(true);
|
|
595 |
QString whereStatement;
|
|
596 |
if (query.flagsOn() != 0)
|
|
597 |
whereStatement.append(" AND ").append(QString().setNum(
|
87
|
598 |
query.flagsOn())).append(" & EN_FLAGS == ").append(
|
|
599 |
QString().setNum(query.flagsOn()));
|
85
|
600 |
if (query.flagsOff() != 0)
|
|
601 |
whereStatement.append(" AND ").append(QString().setNum(
|
87
|
602 |
query.flagsOff())).append(" & (~EN_FLAGS) == ").append(
|
|
603 |
QString().setNum(query.flagsOff()));
|
85
|
604 |
if (query.entryRoles() != 0)
|
|
605 |
whereStatement.append(" AND ").append(QString().setNum(
|
87
|
606 |
query.entryRoles())) .append(" | EN_ROLE == ").append(
|
|
607 |
QString().setNum(query.entryRoles()));
|
85
|
608 |
//TODO: by uid???
|
|
609 |
|
|
610 |
if (query.entryTypeNames().count()) {
|
|
611 |
whereStatement.append(" AND EN_TYPE_NAME IN (");
|
|
612 |
for (int i = 0; i < query.entryTypeNames().count(); i++) {
|
|
613 |
whereStatement.append("\'" + query.entryTypeNames()[i] + "\'");
|
|
614 |
if (i < query.entryTypeNames().count() - 1)
|
|
615 |
whereStatement.append(",");
|
|
616 |
}
|
|
617 |
whereStatement.append(") ");
|
|
618 |
}
|
|
619 |
|
|
620 |
QSqlQuery sqlquery(db);
|
|
621 |
if (query.parentId() == 0) {
|
|
622 |
// sort
|
|
623 |
QString queryString("SELECT ENTRY_ID from CA_ENTRY where 1=1 ");
|
|
624 |
queryString.append(whereStatement);
|
|
625 |
modifyQueryForSortOrder(queryString, query, false);
|
|
626 |
if (query.count() > 0)
|
|
627 |
queryString.append(" LIMIT ").append(query.count());
|
|
628 |
qDebug() << "CaServicePrivate::getEntryIds query text: "
|
87
|
629 |
<< queryString;
|
85
|
630 |
success = sqlquery.prepare(queryString);
|
|
631 |
success = sqlquery.exec();
|
|
632 |
if (success) {
|
|
633 |
while (sqlquery.next()) {
|
|
634 |
sourceIdList << sqlquery.value(sqlquery.record().indexOf(
|
87
|
635 |
"ENTRY_ID")).toInt();
|
85
|
636 |
}
|
|
637 |
}
|
87
|
638 |
} else {
|
85
|
639 |
QString
|
87
|
640 |
queryString(
|
|
641 |
"SELECT ENTRY_ID FROM CA_ENTRY \
|
85
|
642 |
LEFT JOIN CA_GROUP_ENTRY ON GE_ENTRY_ID = ENTRY_ID WHERE GE_GROUP_ID = ? ");
|
|
643 |
queryString.append(whereStatement);
|
|
644 |
modifyQueryForSortOrder(queryString, query, true);
|
|
645 |
if (query.count() > 0)
|
|
646 |
queryString.append(" LIMIT ").append(query.count());
|
|
647 |
qDebug() << "CaServicePrivate::getEntryIds query text: "
|
87
|
648 |
<< queryString;
|
85
|
649 |
sqlquery.prepare(queryString);
|
|
650 |
sqlquery.addBindValue(query.parentId());
|
|
651 |
success = sqlquery.exec();
|
|
652 |
if (success) {
|
|
653 |
while (sqlquery.next()) {
|
|
654 |
sourceIdList << sqlquery.value(sqlquery.record().indexOf(
|
87
|
655 |
"ENTRY_ID")).toInt();
|
85
|
656 |
}
|
|
657 |
}
|
|
658 |
}
|
|
659 |
ErrorCode error = UnknownErrorCode;
|
|
660 |
if (success) {
|
87
|
661 |
error = NoErrorCode;
|
85
|
662 |
}
|
|
663 |
return error;
|
|
664 |
}
|
|
665 |
|
|
666 |
//----------------------------------------------------------------------------
|
|
667 |
//
|
|
668 |
//----------------------------------------------------------------------------
|
|
669 |
ErrorCode CaClientProxy::executeCommand(const CaEntry &entry,
|
87
|
670 |
const QString &command)
|
85
|
671 |
{
|
|
672 |
qDebug() << "CaClientProxy::executeCommand" << "entry id: "
|
87
|
673 |
<< entry.id() << "command: " << command;
|
|
674 |
return NoErrorCode;
|
85
|
675 |
}
|
|
676 |
|
|
677 |
//----------------------------------------------------------------------------
|
|
678 |
//
|
|
679 |
//----------------------------------------------------------------------------
|
|
680 |
ErrorCode CaClientProxy::touch(const CaEntry &entry)
|
|
681 |
{
|
|
682 |
const int id = entry.id();
|
|
683 |
|
|
684 |
qDebug() << "CaClientProxy::touch" << "id: " << id;
|
|
685 |
|
|
686 |
QSqlDatabase db = dbConnection();
|
|
687 |
QSqlQuery query(db);
|
|
688 |
query.exec("begin");
|
|
689 |
|
|
690 |
query.prepare(
|
|
691 |
"INSERT INTO CA_LAUNCH (LA_ENTRY_ID,LA_LAUNCH_TIME) VALUES ( ?,? )");
|
|
692 |
query.addBindValue(id);
|
|
693 |
query.addBindValue(QDateTime::currentDateTime().toTime_t());
|
|
694 |
bool success = query.exec();
|
|
695 |
|
|
696 |
if (success) {
|
|
697 |
query.prepare(
|
|
698 |
"UPDATE CA_ENTRY SET EN_FLAGS = EN_FLAGS | ? WHERE ENTRY_ID = ?");
|
|
699 |
query.addBindValue((int) UsedEntryFlag);
|
|
700 |
query.addBindValue(id);
|
|
701 |
success = query.exec();
|
|
702 |
}
|
|
703 |
|
|
704 |
ErrorCode error = NoErrorCode;
|
|
705 |
if (success) {
|
|
706 |
query.exec("commit");
|
|
707 |
QList<CaEntry *> entryList;
|
|
708 |
if (getData(QList<int>() << id, entryList) == NoErrorCode) {
|
|
709 |
QList<int> parentIds;
|
|
710 |
GetParentsIds(QList<int>() << id, parentIds);
|
|
711 |
CaNotifiers::Notify(*entryList[0], UpdateChangeType, parentIds);
|
|
712 |
}
|
|
713 |
} else {
|
|
714 |
query.exec("rollback");
|
|
715 |
error = UnknownErrorCode;
|
|
716 |
}
|
87
|
717 |
|
85
|
718 |
return error;
|
|
719 |
}
|
|
720 |
|
|
721 |
//----------------------------------------------------------------------------
|
|
722 |
//
|
|
723 |
//----------------------------------------------------------------------------
|
|
724 |
ErrorCode CaClientProxy::customSort(const QList<int> &entryIdList,
|
87
|
725 |
int groupId)
|
85
|
726 |
{
|
|
727 |
bool success = true;
|
|
728 |
QSqlDatabase db = dbConnection();
|
|
729 |
QSqlQuery query(db);
|
|
730 |
query.exec("begin");
|
|
731 |
for (int i = 0; i < entryIdList.count(); i++) {
|
|
732 |
int position = i+1;
|
|
733 |
query.prepare(
|
87
|
734 |
"UPDATE CA_GROUP_ENTRY SET GE_POSITION = ? WHERE GE_ENTRY_ID = ? AND GE_GROUP_ID = ?");
|
85
|
735 |
query.addBindValue(position);
|
|
736 |
query.addBindValue(entryIdList.at(i));
|
|
737 |
query.addBindValue(groupId);
|
|
738 |
success = query.exec();
|
|
739 |
if (!success) {
|
|
740 |
break;
|
|
741 |
}
|
|
742 |
}
|
|
743 |
|
|
744 |
ErrorCode error(NoErrorCode);
|
|
745 |
if (success) {
|
|
746 |
query.exec("commit");
|
|
747 |
CaNotifiers::Notify(groupId);
|
|
748 |
} else {
|
|
749 |
query.exec("rollback");
|
|
750 |
error = UnknownErrorCode;
|
|
751 |
}
|
|
752 |
return error;
|
|
753 |
}
|
|
754 |
|
|
755 |
/*!
|
|
756 |
//TODO:
|
|
757 |
*/
|
87
|
758 |
void CaClientProxy::modifyQueryForSortOrder(QString &queryString,
|
|
759 |
const CaQuery &query, bool parent) const
|
85
|
760 |
{
|
|
761 |
SortAttribute sortAttribute;
|
|
762 |
Qt::SortOrder sortOrder;
|
|
763 |
query.getSort(sortAttribute, sortOrder);
|
|
764 |
QString oldQueryString(queryString);
|
|
765 |
queryString.clear();
|
|
766 |
|
|
767 |
if (sortAttribute == NameSortAttribute) {
|
|
768 |
queryString.append(oldQueryString).append(" ORDER BY EN_TEXT ");
|
87
|
769 |
} else if (sortAttribute == CreatedTimestampSortAttribute) {
|
85
|
770 |
queryString.append(oldQueryString).append(
|
|
771 |
" ORDER BY EN_CREATION_TIME ");
|
87
|
772 |
} else if (sortAttribute == MostUsedSortAttribute) {
|
85
|
773 |
queryString.append("SELECT ENTRY_ID FROM (").append(oldQueryString).append(
|
|
774 |
" \
|
|
775 |
) LEFT JOIN \
|
|
776 |
(SELECT LA_ENTRY_ID, COUNT(*) AS USAGE_DATA FROM CA_LAUNCH GROUP BY LA_ENTRY_ID) \
|
|
777 |
ON ENTRY_ID = LA_ENTRY_ID ORDER BY USAGE_DATA ");
|
87
|
778 |
} else if (sortAttribute == LastUsedSortAttribute) {
|
85
|
779 |
queryString.append("SELECT ENTRY_ID FROM (").append(oldQueryString).append(
|
|
780 |
" \
|
|
781 |
) LEFT JOIN \
|
|
782 |
(SELECT LA_ENTRY_ID, MAX(LA_LAUNCH_TIME) AS USAGE_DATA FROM CA_LAUNCH GROUP BY LA_ENTRY_ID) \
|
|
783 |
ON ENTRY_ID = LA_ENTRY_ID ORDER BY USAGE_DATA ");
|
87
|
784 |
} else if (parent && sortAttribute == DefaultSortAttribute) {
|
85
|
785 |
queryString.append(oldQueryString).append(
|
|
786 |
" ORDER BY GE_GROUP_ID, GE_POSITION ");
|
87
|
787 |
} else if (!parent && sortAttribute == DefaultSortAttribute) {
|
85
|
788 |
queryString.append(oldQueryString).append(" ORDER BY ENTRY_ID ");
|
87
|
789 |
} else {
|
85
|
790 |
queryString.append(oldQueryString);
|
|
791 |
}
|
|
792 |
|
|
793 |
if (sortAttribute == NameSortAttribute || sortAttribute
|
87
|
794 |
== CreatedTimestampSortAttribute || sortAttribute
|
|
795 |
== MostUsedSortAttribute || sortAttribute == LastUsedSortAttribute
|
|
796 |
|| (sortAttribute == DefaultSortAttribute && parent)) {
|
85
|
797 |
if (sortOrder == Qt::AscendingOrder)
|
|
798 |
queryString.append(" ASC ");
|
|
799 |
else
|
|
800 |
queryString.append(" DESC ");
|
|
801 |
}
|
|
802 |
|
|
803 |
}
|
|
804 |
|
|
805 |
/*!
|
|
806 |
//TODO:
|
|
807 |
*/
|
|
808 |
bool CaClientProxy::setIconInDb(CaEntry *entryClone) const
|
|
809 |
{
|
|
810 |
//set icon information into db
|
|
811 |
QSqlQuery query(dbConnection());
|
|
812 |
query.prepare(
|
88
|
813 |
"SELECT ICON_ID FROM CA_ICON WHERE IC_FILENAME = :IC_FILENAME"
|
|
814 |
" AND IC_SKIN_ID = :IC_SKIN_ID"
|
|
815 |
" AND IC_APP_ID = :IC_APP_ID");
|
85
|
816 |
query.bindValue(":IC_FILENAME",
|
87
|
817 |
entryClone->iconDescription().filename());
|
88
|
818 |
query.bindValue(":IC_SKIN_ID",
|
|
819 |
entryClone->iconDescription().filename());
|
|
820 |
query.bindValue(":IC_APP_ID",
|
|
821 |
entryClone->iconDescription().filename());
|
|
822 |
|
85
|
823 |
|
|
824 |
bool success = query.exec();
|
|
825 |
if (success && query.next()) {
|
|
826 |
qDebug() << "query.executedQuery() : " << query.executedQuery();
|
|
827 |
int iconId = query.value(query.record().indexOf("ICON_ID")).toInt();
|
|
828 |
qDebug() << "iconId = " << iconId;
|
|
829 |
CaIconDescription iconDescription = entryClone->iconDescription();
|
88
|
830 |
if (iconId <= 0
|
|
831 |
&& (!iconDescription.filename().isEmpty()
|
|
832 |
|| !iconDescription.skinId().isEmpty()
|
|
833 |
|| !iconDescription.applicationId().isEmpty())) {
|
85
|
834 |
query.prepare(
|
88
|
835 |
"INSERT INTO CA_ICON"
|
|
836 |
" (IC_FILENAME, IC_SKIN_ID, IC_APP_ID)"
|
|
837 |
" VALUES ( ? , ? , ? , ? , ? )");
|
85
|
838 |
query.addBindValue(iconDescription.filename());
|
88
|
839 |
query.addBindValue(iconDescription.skinId());
|
|
840 |
query.addBindValue(iconDescription.applicationId());
|
85
|
841 |
success = query.exec();
|
|
842 |
qDebug() << query.executedQuery();
|
|
843 |
iconId = query.lastInsertId().toInt();
|
|
844 |
}
|
|
845 |
CaObjectAdapter::setId(iconDescription, iconId);
|
|
846 |
entryClone->setIconDescription(iconDescription);
|
|
847 |
}
|
|
848 |
return success;
|
|
849 |
}
|
|
850 |
|
|
851 |
/*!
|
|
852 |
//TODO:
|
|
853 |
*/
|
|
854 |
bool CaClientProxy::setEntryInDb(CaEntry *entryClone) const
|
|
855 |
{
|
|
856 |
QSqlQuery query(dbConnection());
|
|
857 |
bool isNewEntry(entryClone->id() <= 0);
|
|
858 |
QString
|
87
|
859 |
queryText(
|
|
860 |
"INSERT INTO CA_ENTRY \
|
85
|
861 |
(EN_TEXT,EN_ROLE,EN_TYPE_NAME,EN_FLAGS,EN_ICON_ID ) VALUES ( ?, ?, ?, ?, ");
|
|
862 |
if (!isNewEntry)
|
|
863 |
queryText
|
87
|
864 |
= "REPLACE INTO CA_ENTRY \
|
85
|
865 |
(ENTRY_ID,EN_TEXT,EN_ROLE,EN_TYPE_NAME,EN_FLAGS,EN_ICON_ID ) VALUES ( ?, ?, ?, ?, ?, ";
|
|
866 |
if (entryClone->iconDescription().id() > 0) {
|
|
867 |
queryText.append("?");
|
87
|
868 |
} else {
|
85
|
869 |
queryText.append("NULL");
|
|
870 |
}
|
|
871 |
queryText.append(")");
|
|
872 |
query.prepare(queryText);
|
|
873 |
if (!isNewEntry)
|
|
874 |
query.addBindValue(entryClone->id());
|
|
875 |
query.addBindValue(entryClone->text());
|
|
876 |
query.addBindValue((int) entryClone->role());
|
|
877 |
query.addBindValue(entryClone->entryTypeName());
|
|
878 |
query.addBindValue((int) entryClone->flags());
|
|
879 |
if (entryClone->iconDescription().id() > 0) {
|
|
880 |
query.addBindValue(entryClone->iconDescription().id());
|
|
881 |
}
|
|
882 |
|
|
883 |
bool success = query.exec();
|
|
884 |
if (success) {
|
|
885 |
qDebug() << query.executedQuery();
|
|
886 |
int newEntryId(0);
|
|
887 |
//set entry creation time if new entry
|
|
888 |
if (isNewEntry) {
|
|
889 |
newEntryId = query.lastInsertId().toInt();
|
|
890 |
|
|
891 |
CaObjectAdapter::setId(*entryClone, newEntryId);
|
|
892 |
uint timestamp = QDateTime::currentDateTime().toTime_t();
|
|
893 |
query.prepare(
|
|
894 |
"UPDATE CA_ENTRY SET EN_CREATION_TIME = ? WHERE ENTRY_ID = ?");
|
|
895 |
query.addBindValue(timestamp);
|
|
896 |
query.addBindValue(newEntryId);
|
|
897 |
success = query.exec();
|
|
898 |
qDebug() << "CaServicePrivate::setEntryInDb"
|
87
|
899 |
<< query.executedQuery();
|
85
|
900 |
}
|
|
901 |
}
|
|
902 |
return success;
|
|
903 |
}
|
|
904 |
|
|
905 |
/*!
|
|
906 |
//TODO:
|
|
907 |
*/
|
|
908 |
bool CaClientProxy::setAttributesInDb(CaEntry *entryClone) const
|
|
909 |
{
|
|
910 |
bool success = true;
|
|
911 |
QSqlQuery query(dbConnection());
|
|
912 |
if (entryClone->attributes().count() > 0) {
|
|
913 |
QMap<QString, QString> attributesMap = entryClone->attributes();
|
87
|
914 |
foreach(QString key, attributesMap.keys()) {
|
|
915 |
query.prepare(
|
|
916 |
"REPLACE INTO CA_ATTRIBUTE (AT_ENTRY_ID,AT_NAME,AT_VALUE) VALUES ( \
|
85
|
917 |
:AT_ENTRY_ID,\
|
|
918 |
:AT_NAME,\
|
|
919 |
:AT_VALUE )");
|
87
|
920 |
query.bindValue(":AT_ENTRY_ID", entryClone->id());
|
|
921 |
query.bindValue(":AT_NAME", key);
|
|
922 |
query.bindValue(":AT_VALUE", attributesMap.value(key));
|
|
923 |
success = query.exec();
|
|
924 |
if (!success) {
|
|
925 |
break;
|
85
|
926 |
}
|
87
|
927 |
qDebug() << "CaServicePrivate::setAttributesInDb"
|
|
928 |
<< query.boundValues();
|
|
929 |
}
|
85
|
930 |
}
|
87
|
931 |
return success;
|
85
|
932 |
}
|
|
933 |
|
|
934 |
|
|
935 |
void CaClientProxy::CreateGetParentsIdsQuery(
|
|
936 |
const QList<int> &entryIds,
|
|
937 |
const QList<int> &parentIds,
|
|
938 |
QString &query)
|
|
939 |
{
|
|
940 |
QString entryIdList;
|
|
941 |
int lastItemIndex = entryIds.count()-1;
|
|
942 |
for (int i = 0; i < lastItemIndex; i++) {
|
|
943 |
entryIdList.append(QString::number(entryIds[i]));
|
|
944 |
entryIdList.append(",");
|
|
945 |
}
|
|
946 |
if (lastItemIndex >= 0) {
|
|
947 |
entryIdList.append(QString::number(entryIds[lastItemIndex]));
|
|
948 |
}
|
|
949 |
query = QString("SELECT GE_GROUP_ID FROM CA_GROUP_ENTRY "
|
87
|
950 |
"WHERE GE_ENTRY_ID IN ( %1 )").arg(entryIdList);
|
85
|
951 |
|
|
952 |
int lastParentIndex = parentIds.count()-1;
|
|
953 |
if (lastParentIndex >= 0) {
|
|
954 |
QString parentIdList;
|
|
955 |
for (int i = 0; i < lastParentIndex; i++) {
|
|
956 |
parentIdList.append(QString::number(parentIds[i]));
|
|
957 |
parentIdList.append(",");
|
|
958 |
}
|
|
959 |
parentIdList.append(QString::number(parentIds[lastParentIndex]));
|
|
960 |
query.append(QString(" AND GE_GROUP_ID NOT IN( %1 )").arg(parentIdList));
|
|
961 |
}
|
|
962 |
}
|
|
963 |
|
|
964 |
|
87
|
965 |
bool CaClientProxy::GetParentsIds(const QList<int> &entryIds,
|
|
966 |
QList<int> &parentIds)
|
85
|
967 |
{
|
|
968 |
QString getParentIdsQuery;
|
|
969 |
CreateGetParentsIdsQuery(entryIds, parentIds, getParentIdsQuery);
|
|
970 |
QSqlQuery query(dbConnection());
|
|
971 |
bool success = query.exec(getParentIdsQuery);
|
|
972 |
|
|
973 |
if (success && query.next()) {
|
|
974 |
QList<int> newParentIds;
|
|
975 |
do {
|
|
976 |
newParentIds << query.value(query.record().indexOf("GE_GROUP_ID")).toInt();
|
|
977 |
} while (query.next());
|
|
978 |
parentIds.append(newParentIds);
|
|
979 |
GetParentsIds(newParentIds, parentIds);
|
|
980 |
}
|
|
981 |
return success;
|
|
982 |
}
|