|
1 /* |
|
2 * Copyright (c) 2009 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 * Description: |
|
13 * |
|
14 */ |
|
15 |
|
16 #include <QSqlQuery> |
|
17 #include <QVariant> |
|
18 #include "favoriteswrapper.h" |
|
19 #include "irdb.h" |
|
20 |
|
21 favoritesWrapper::favoritesWrapper() |
|
22 { |
|
23 } |
|
24 |
|
25 favoritesWrapper::~favoritesWrapper() |
|
26 { |
|
27 } |
|
28 |
|
29 bool favoritesWrapper::putFavorites(columnMap* const RowData, |
|
30 bool& bNewRow) |
|
31 { |
|
32 uint uCid = 0; |
|
33 QString insSqlStr; |
|
34 QString updSqlStr; |
|
35 |
|
36 |
|
37 if( NULL == RowData ) |
|
38 { |
|
39 return false; |
|
40 } |
|
41 |
|
42 if(RowData->isEmpty()) |
|
43 { |
|
44 return false; |
|
45 } |
|
46 |
|
47 uCid = (RowData->value(channelId)).toUInt(); |
|
48 |
|
49 |
|
50 if(!uCid) |
|
51 { |
|
52 return false; |
|
53 } |
|
54 |
|
55 insSqlStr = "insert into favorites "; |
|
56 updSqlStr = "update favorites set "; |
|
57 |
|
58 //create insSqlstr and updSqlStr in advance; |
|
59 combinePutStr(RowData, colNameView, insSqlStr, updSqlStr); |
|
60 |
|
61 return m_pIRDB->chgRowFavorites(insSqlStr, updSqlStr, uCid, bNewRow)? false:true; |
|
62 } |
|
63 |
|
64 bool favoritesWrapper::deleteFavorites(const columnMap* const condAND, |
|
65 const columnMap* const condOR) |
|
66 { |
|
67 QString deleteSqlStr = "delete from Favorites "; |
|
68 |
|
69 if( (NULL != condAND)&&(NULL != condOR) ) |
|
70 { |
|
71 return false; |
|
72 } |
|
73 |
|
74 if(condAND) |
|
75 { |
|
76 if(condAND->isEmpty()) |
|
77 { |
|
78 return false; |
|
79 } |
|
80 } |
|
81 |
|
82 if(condOR) |
|
83 { |
|
84 if(condOR->isEmpty()) |
|
85 { |
|
86 return false; |
|
87 } |
|
88 } |
|
89 |
|
90 combineDeleteStr(condAND, condOR, colNameView, deleteSqlStr); |
|
91 |
|
92 return m_pIRDB->deleteRow(deleteSqlStr)? false:true; |
|
93 } |
|
94 |
|
95 QList<QVariant*>* favoritesWrapper::getFavorites(const columnMap* const condAND, |
|
96 const columnMap* const condOR) |
|
97 { |
|
98 QString sltSqlStr = "select * from IRVIEW_favorites "; |
|
99 QList<QVariant*>* pDataSet = NULL; |
|
100 |
|
101 if( (NULL != condAND)&&(NULL != condOR) ) |
|
102 { |
|
103 return NULL; |
|
104 } |
|
105 |
|
106 if(condAND) |
|
107 { |
|
108 if(condAND->isEmpty()) |
|
109 { |
|
110 return NULL; |
|
111 } |
|
112 } |
|
113 |
|
114 if(condOR) |
|
115 { |
|
116 if(condOR->isEmpty()) |
|
117 { |
|
118 return NULL; |
|
119 } |
|
120 } |
|
121 |
|
122 combineGetStr(condAND, condOR, colNameView, sltSqlStr); |
|
123 sltSqlStr = sltSqlStr + " order by FavSeq desc "; |
|
124 pDataSet = new QList<QVariant*>(); |
|
125 if( m_pIRDB->selectRow(this, sltSqlStr, pDataSet) ) |
|
126 { |
|
127 delete pDataSet; |
|
128 pDataSet = NULL; |
|
129 } |
|
130 |
|
131 return pDataSet; |
|
132 } |
|
133 |
|
134 bool favoritesWrapper::getIRTableCB(QSqlQuery& aIRDataSet, QList<QVariant*>* pDataSet) |
|
135 { |
|
136 while (aIRDataSet.next()) |
|
137 { |
|
138 QVariant* const p = new QVariant[IRDB_FAVORITES_COLUMN]; |
|
139 *pDataSet<<p; |
|
140 |
|
141 for(int i = 0; i < IRDB_FAVORITES_COLUMN; i++) |
|
142 { |
|
143 *(p+i) = aIRDataSet.value(i); |
|
144 } |
|
145 } |
|
146 |
|
147 return true; |
|
148 } |
|
149 |
|
150 |