|
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 "channelhistorywrapper.h" |
|
19 #include "irdb.h" |
|
20 |
|
21 |
|
22 channelHistoryWrapper::channelHistoryWrapper() |
|
23 { |
|
24 } |
|
25 |
|
26 channelHistoryWrapper::~channelHistoryWrapper() |
|
27 { |
|
28 } |
|
29 |
|
30 bool channelHistoryWrapper::deleteChannelHistory(const columnMap* const condAND, |
|
31 const columnMap* const condOR) |
|
32 { |
|
33 QString deleteSqlStr; |
|
34 |
|
35 if( (NULL != condAND)&&(NULL != condOR) ) |
|
36 { |
|
37 return false; |
|
38 } |
|
39 |
|
40 if(condAND) |
|
41 { |
|
42 if(condAND->isEmpty()) |
|
43 { |
|
44 return false; |
|
45 } |
|
46 } |
|
47 |
|
48 if(condOR) |
|
49 { |
|
50 if(condOR->isEmpty()) |
|
51 { |
|
52 return false; |
|
53 } |
|
54 } |
|
55 |
|
56 deleteSqlStr = "delete from channelHistory "; |
|
57 combineDeleteStr(condAND, condOR, colNameView, deleteSqlStr); |
|
58 |
|
59 return m_pIRDB->deleteRow(deleteSqlStr)?false:true; |
|
60 } |
|
61 |
|
62 bool channelHistoryWrapper::getIRTableCB(QSqlQuery& aIRDataSet, QList<QVariant*>* pQListDataSet) |
|
63 { |
|
64 while (aIRDataSet.next()) |
|
65 { |
|
66 QVariant* const p = new QVariant[IRDB_CHANNELHISTORY_COLUMN]; |
|
67 *pQListDataSet<<p; |
|
68 |
|
69 for(int i = 0; i < IRDB_CHANNELHISTORY_COLUMN; i++) |
|
70 { |
|
71 *(p+i) = aIRDataSet.value(i); |
|
72 } |
|
73 } |
|
74 |
|
75 return true; |
|
76 } |
|
77 |
|
78 uint channelHistoryWrapper::srhChannelId(QString& condUserCidStr, |
|
79 const columnMap* const condAND, |
|
80 const columnMap* const condOR) |
|
81 { |
|
82 uint srhCID = 0; |
|
83 |
|
84 //if condAND or condOR has channeld, |
|
85 if(condAND != NULL) |
|
86 { |
|
87 srhCID = (condAND->value(channelId)).toUInt(); |
|
88 } |
|
89 else if(condOR != NULL) |
|
90 { |
|
91 srhCID = (condOR->value(channelId)).toUInt(); |
|
92 } |
|
93 |
|
94 if(srhCID) |
|
95 { |
|
96 return srhCID ; |
|
97 } |
|
98 |
|
99 //channelId column is false |
|
100 //only one case, go to station view, channelUrl and channelNickName |
|
101 //search channelId according to urlinof and channelNickName; |
|
102 QString srhStr; |
|
103 if(condAND != NULL) |
|
104 { |
|
105 if( ( !(condAND->value(channelUrl).isEmpty()) )&&( !(condAND->value(channelNickName).isEmpty()) ) ) |
|
106 { |
|
107 srhStr = "where "+ colNameView[channelUrl] + " = "; |
|
108 srhStr = srhStr + "'" + condAND->value(channelUrl) + "' AND " ; |
|
109 srhStr = srhStr + colNameView[channelNickName] + " = "; |
|
110 srhStr = srhStr + "'" + condAND->value(channelNickName) + "'"; |
|
111 } |
|
112 condUserCidStr = srhStr; |
|
113 } |
|
114 |
|
115 return srhCID; |
|
116 } |
|
117 |
|
118 /* |
|
119 * this fuction don't suport "update" operation for mutliple records ; |
|
120 * if condAND != NULL AND condOR != NULL, illegal operation; |
|
121 * if condAND != NULL or condOR != NULL, it must be "update" operation. |
|
122 * if condAND == NULL AND condOR == NULL, it is "insert" or "update" operation; |
|
123 * |
|
124 */ |
|
125 bool channelHistoryWrapper::putChannelHistory(const columnMap* const RowData, |
|
126 uint* const cidUserDefined, |
|
127 const logoMap* const logoData, |
|
128 const columnMap* const condAND, |
|
129 const columnMap* const condOR) |
|
130 { |
|
131 uint uCid = 0; |
|
132 QString insSqlStr; |
|
133 QString updSqlStr; |
|
134 QString condSqlStr; |
|
135 QString condUserCidStr; |
|
136 columnMap* const RowDataAppend = const_cast<columnMap*>(RowData); |
|
137 QList<QByteArray>* pImgList = NULL; |
|
138 bool ret = true; |
|
139 |
|
140 |
|
141 if( NULL == RowData ) |
|
142 { |
|
143 return false; |
|
144 } |
|
145 |
|
146 if(RowData->isEmpty()) |
|
147 { |
|
148 return false; |
|
149 } |
|
150 |
|
151 |
|
152 if( (NULL != condAND)&&(NULL != condOR) ) |
|
153 { |
|
154 return false; |
|
155 } |
|
156 |
|
157 if(condAND) |
|
158 { |
|
159 if(condAND->isEmpty()) |
|
160 { |
|
161 return false; |
|
162 } |
|
163 } |
|
164 |
|
165 if(condOR) |
|
166 { |
|
167 if(condOR->isEmpty()) |
|
168 { |
|
169 return false; |
|
170 } |
|
171 } |
|
172 |
|
173 if(cidUserDefined) |
|
174 { |
|
175 *cidUserDefined = 0; |
|
176 } |
|
177 |
|
178 insSqlStr = "insert into IRBuff "; |
|
179 updSqlStr = "update IRBuff set "; |
|
180 RowDataAppend->insert(opt, QString::number(IRDB_OPT_INSERT)); |
|
181 RowDataAppend->insert(dataSource, QString::number(DATA_OF_CHANNELHISTORY)); |
|
182 |
|
183 if(NULL != logoData) |
|
184 { |
|
185 pImgList = new QList<QByteArray>(); |
|
186 combinePutStr(RowDataAppend, colNameView, insSqlStr, updSqlStr, logoData, pImgList); |
|
187 *pImgList=logoData->values(); |
|
188 |
|
189 } |
|
190 else |
|
191 { |
|
192 combinePutStr(RowDataAppend, colNameView, insSqlStr, updSqlStr); |
|
193 } |
|
194 |
|
195 if( (NULL == condAND)&&(NULL == condOR) ) |
|
196 { |
|
197 uCid = srhChannelId(condUserCidStr,RowData); |
|
198 } |
|
199 else //here it must be "update" operation; condition string |
|
200 { |
|
201 uCid = srhChannelId(condUserCidStr,condAND, condOR); |
|
202 combineCondStr(condAND, condOR, colNameView, condSqlStr); |
|
203 } |
|
204 |
|
205 if(uCid) |
|
206 { |
|
207 //updSqlStr += condSqlStr; |
|
208 m_pIRDB->chgRowIRDB(insSqlStr, updSqlStr, uCid, condSqlStr, pImgList)? ret = false:true; |
|
209 } |
|
210 else //here deliver the updSqlstr and condSqlStr seperately. |
|
211 { |
|
212 m_pIRDB->chgRowIRDB(insSqlStr, updSqlStr, cidUserDefined, condSqlStr, condUserCidStr, pImgList)?ret = false:true; |
|
213 } |
|
214 |
|
215 if(pImgList) |
|
216 { |
|
217 delete pImgList; |
|
218 pImgList = NULL; |
|
219 } |
|
220 |
|
221 return ret; |
|
222 } |
|
223 |
|
224 |
|
225 QList<QVariant*>* channelHistoryWrapper::getChannelHistory(const columnMap* const condAND, |
|
226 const columnMap* const condOR) |
|
227 { |
|
228 QString sltSqlStr; |
|
229 QList<QVariant*> *pDataSet = NULL; |
|
230 if( (NULL != condAND)&&(NULL != condOR) ) |
|
231 { |
|
232 return NULL; |
|
233 } |
|
234 |
|
235 if(condAND) |
|
236 { |
|
237 if(condAND->isEmpty()) |
|
238 { |
|
239 return NULL; |
|
240 } |
|
241 } |
|
242 |
|
243 if(condOR) |
|
244 { |
|
245 if(condOR->isEmpty()) |
|
246 { |
|
247 return NULL; |
|
248 } |
|
249 } |
|
250 |
|
251 sltSqlStr = "select * from IRView_channelinfo "; |
|
252 combineGetStr(condAND, condOR, colNameView,sltSqlStr); |
|
253 pDataSet = new QList<QVariant*>(); |
|
254 if( m_pIRDB->selectRow(this, sltSqlStr, pDataSet) ) |
|
255 { |
|
256 delete pDataSet; |
|
257 pDataSet = NULL; |
|
258 } |
|
259 |
|
260 return pDataSet; |
|
261 } |
|
262 |