49 CntFilterUnion::CntFilterUnion(CContactDatabase& contactDatabase,CntSymbianSrvConnection &cntServer,CntDbInfo& dbInfo) : |
49 CntFilterUnion::CntFilterUnion(CContactDatabase& contactDatabase,CntSymbianSrvConnection &cntServer,CntDbInfo& dbInfo) : |
50 m_contactdatabase(contactDatabase), |
50 m_contactdatabase(contactDatabase), |
51 m_srvConnection(cntServer), |
51 m_srvConnection(cntServer), |
52 m_dbInfo(dbInfo) |
52 m_dbInfo(dbInfo) |
53 { |
53 { |
54 |
|
55 } |
54 } |
56 |
55 |
57 CntFilterUnion::~CntFilterUnion() |
56 CntFilterUnion::~CntFilterUnion() |
58 { |
57 { |
59 |
|
60 } |
58 } |
61 |
59 |
62 |
60 |
63 QList<QContactLocalId> CntFilterUnion::contacts( |
61 QList<QContactLocalId> CntFilterUnion::contacts(const QContactFilter &filter, |
64 const QContactFilter &filter, |
62 const QList<QContactSortOrder> &sortOrders, |
65 const QList<QContactSortOrder> &sortOrders, |
63 bool &filterSupportedflag, |
66 bool &filterSupportedflag, |
64 QContactManager::Error* error) |
67 QContactManager::Error* error) |
|
68 { |
65 { |
69 Q_UNUSED(sortOrders); |
66 Q_UNUSED(sortOrders); |
70 Q_UNUSED(filterSupportedflag); |
67 Q_UNUSED(filterSupportedflag); |
71 //Check if any invalid filter is passed |
68 //Check if any invalid filter is passed |
72 if(!filterSupported(filter)) |
69 if (!filterSupported(filter)) { |
73 { |
|
74 *error = QContactManager::NotSupportedError; |
70 *error = QContactManager::NotSupportedError; |
75 return QList<QContactLocalId>(); |
71 return QList<QContactLocalId>(); |
76 } |
72 } |
77 QList<QContactLocalId> idList; |
73 QList<QContactLocalId> idList; |
78 QString sqlQuery; |
74 QString sqlQuery; |
79 createSelectQuery(filter,sqlQuery,error); |
75 createSelectQuery(filter,sqlQuery,error); |
80 QString sortQuery = m_dbInfo.getSortQuery(sortOrders, sqlQuery, error); |
76 QString sortQuery = m_dbInfo.getSortQuery(sortOrders, sqlQuery, error); |
81 //fetch the contacts |
77 //fetch the contacts |
82 if(*error == QContactManager::NoError ) |
78 if (*error == QContactManager::NoError) { |
83 { |
79 idList = m_srvConnection.searchContacts(sortQuery, error); |
84 idList = m_srvConnection.searchContacts(sortQuery, error); |
80 } |
85 } |
81 return idList; |
86 return idList; |
|
87 } |
82 } |
88 |
83 |
89 |
84 |
90 bool CntFilterUnion::filterSupported(const QContactFilter& filter) |
85 bool CntFilterUnion::filterSupported(const QContactFilter& filter) |
91 { |
86 { |
92 bool result = false; |
87 bool result = false; |
93 if(QContactFilter::UnionFilter == filter.type()) |
88 if (QContactFilter::UnionFilter == filter.type()) { |
94 { |
89 result = true; |
95 result = true; |
90 } |
96 } |
91 return result; |
97 |
|
98 return result; |
|
99 } |
92 } |
100 |
93 |
101 |
94 |
102 |
95 |
103 void CntFilterUnion::createSelectQuery(const QContactFilter& filter, |
96 void CntFilterUnion::createSelectQuery(const QContactFilter& filter, |
104 QString& selectquery, |
97 QString& selectquery, |
105 QContactManager::Error* error) |
98 QContactManager::Error* error) |
106 |
99 |
107 { |
100 { |
108 const QContactUnionFilter& unionfilter = static_cast<const QContactUnionFilter&>(filter); |
101 const QContactUnionFilter& unionfilter = static_cast<const QContactUnionFilter&>(filter); |
109 if(!filterSupported(filter)) |
102 if (!filterSupported(filter)) { |
110 { |
|
111 *error = QContactManager::NotSupportedError; |
103 *error = QContactManager::NotSupportedError; |
112 return; |
104 return; |
|
105 } |
|
106 QList<QContactFilter> individualFilters = unionfilter.filters(); |
|
107 //QString selectquery; |
|
108 int fltrcnt = individualFilters.count(); |
|
109 if (fltrcnt) |
|
110 getSelectQueryforFilter(individualFilters[0],selectquery,error); |
|
111 |
|
112 for (int i=1; i< fltrcnt ; i++) { |
|
113 QString query; |
|
114 getSelectQueryforFilter(individualFilters[i],query,error); |
|
115 if (*error == QContactManager::NoError ) { |
|
116 selectquery.append(" UNION "); |
|
117 selectquery += query; |
113 } |
118 } |
114 QList<QContactFilter> individualFilters = unionfilter.filters(); |
119 } |
115 //QString selectquery; |
|
116 int fltrcnt = individualFilters.count(); |
|
117 if(fltrcnt) |
|
118 getSelectQueryforFilter(individualFilters[0],selectquery,error); |
|
119 |
|
120 for(int i=1; i< fltrcnt ; i++) |
|
121 { |
|
122 |
|
123 QString query; |
|
124 getSelectQueryforFilter(individualFilters[i],query,error); |
|
125 if(*error == QContactManager::NoError ) |
|
126 { |
|
127 selectquery.append(" UNION "); |
|
128 selectquery += query; |
|
129 } |
|
130 |
|
131 } |
|
132 |
|
133 |
|
134 } |
120 } |
135 |
121 |
136 void CntFilterUnion::getSelectQueryforFilter(const QContactFilter& filter,QString& sqlSelectQuery,QContactManager::Error* error) |
122 void CntFilterUnion::getSelectQueryforFilter(const QContactFilter& filter, |
137 { |
123 QString& sqlSelectQuery, |
138 switch(filter.type()) |
124 QContactManager::Error* error) |
139 { |
125 { |
140 case QContactFilter::DefaultFilter: |
126 switch (filter.type()) { |
141 { |
127 case QContactFilter::DefaultFilter: { |
142 CntFilterDefault defaultfltr(m_contactdatabase,m_srvConnection,m_dbInfo); |
128 CntFilterDefault defaultfltr(m_contactdatabase,m_srvConnection,m_dbInfo); |
143 defaultfltr.createSelectQuery(filter,sqlSelectQuery,error); |
129 defaultfltr.createSelectQuery(filter,sqlSelectQuery,error); |
144 break; |
130 break; |
145 } |
131 } |
146 case QContactFilter::ContactDetailFilter: |
132 case QContactFilter::ContactDetailFilter: { |
147 { |
133 QContactDetailFilter detailfilter(filter); |
148 QContactDetailFilter detailfilter(filter); |
134 if (detailfilter.detailDefinitionName() == QContactPhoneNumber::DefinitionName ) { |
149 if(detailfilter.detailDefinitionName() == QContactPhoneNumber::DefinitionName ) |
135 CntFilterDetail dtlfltr(m_contactdatabase,m_srvConnection,m_dbInfo); |
150 { |
136 dtlfltr.createMatchPhoneNumberQuery(filter,sqlSelectQuery,error); |
151 *error=QContactManager::NotSupportedError; |
|
152 } |
|
153 else |
|
154 { |
|
155 CntFilterDetail dtlfltr(m_contactdatabase,m_srvConnection,m_dbInfo); |
|
156 dtlfltr.createSelectQuery(filter,sqlSelectQuery,error); |
|
157 } |
|
158 break; |
|
159 } |
|
160 case QContactFilter::RelationshipFilter: |
|
161 { |
|
162 CntFilterRelationship relationfltr(m_contactdatabase,m_srvConnection,m_dbInfo); |
|
163 relationfltr.createSelectQuery(filter,sqlSelectQuery,error); |
|
164 break; |
|
165 } |
|
166 case QContactFilter::IntersectionFilter: |
|
167 { |
|
168 sqlSelectQuery += "SELECT DISTINCT contact_id FROM ("; |
|
169 CntFilterIntersection intersectionfltr(m_contactdatabase,m_srvConnection,m_dbInfo); |
|
170 intersectionfltr.createSelectQuery(filter,sqlSelectQuery,error); |
|
171 sqlSelectQuery += ')'; |
|
172 break; |
|
173 } |
|
174 case QContactFilter::UnionFilter: |
|
175 { |
|
176 sqlSelectQuery += "SELECT DISTINCT contact_id FROM ("; |
|
177 CntFilterUnion unionfltr(m_contactdatabase,m_srvConnection,m_dbInfo); |
|
178 unionfltr.createSelectQuery(filter,sqlSelectQuery,error); |
|
179 sqlSelectQuery += ')'; |
|
180 break; |
|
181 } |
|
182 default: |
|
183 { |
|
184 *error = QContactManager::NotSupportedError; |
|
185 break; |
|
186 } |
|
187 } |
137 } |
|
138 else { |
|
139 CntFilterDetail dtlfltr(m_contactdatabase,m_srvConnection,m_dbInfo); |
|
140 dtlfltr.createSelectQuery(filter,sqlSelectQuery,error); |
|
141 } |
|
142 break; |
|
143 } |
|
144 case QContactFilter::RelationshipFilter: { |
|
145 CntFilterRelationship relationfltr(m_contactdatabase,m_srvConnection,m_dbInfo); |
|
146 relationfltr.createSelectQuery(filter,sqlSelectQuery,error); |
|
147 break; |
|
148 } |
|
149 case QContactFilter::IntersectionFilter: { |
|
150 sqlSelectQuery += "SELECT DISTINCT contact_id FROM ("; |
|
151 CntFilterIntersection intersectionfltr(m_contactdatabase,m_srvConnection,m_dbInfo); |
|
152 intersectionfltr.createSelectQuery(filter,sqlSelectQuery,error); |
|
153 sqlSelectQuery += ')'; |
|
154 break; |
|
155 } |
|
156 case QContactFilter::UnionFilter: { |
|
157 sqlSelectQuery += "SELECT DISTINCT contact_id FROM ("; |
|
158 CntFilterUnion unionfltr(m_contactdatabase,m_srvConnection,m_dbInfo); |
|
159 unionfltr.createSelectQuery(filter,sqlSelectQuery,error); |
|
160 sqlSelectQuery += ')'; |
|
161 break; |
|
162 } |
|
163 default: { |
|
164 *error = QContactManager::NotSupportedError; |
|
165 break; |
|
166 } |
188 } |
167 } |
189 |
168 } |
|
169 |