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