|
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 * Contributors: |
|
13 * |
|
14 * Description: Class to hold description about one property |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "mdspropertydef.h" |
|
19 |
|
20 #include "mdcdef.h" |
|
21 #include "mdssqliteconnection.h" |
|
22 #include "mdsindexer.h" |
|
23 #include "mdcserializationbuffer.h" |
|
24 #include "mdeinternalerror.h" |
|
25 |
|
26 /** |
|
27 * NewLC |
|
28 */ |
|
29 CMdsPropertyDef* CMdsPropertyDef::NewLC( const TDesC& aName, TPropertyType aType, |
|
30 TBool aReadOnly, TBool aMandatory, TBool aIndexed ) |
|
31 { |
|
32 CMdsPropertyDef* ret = new( ELeave ) CMdsPropertyDef( aType ); |
|
33 CleanupStack::PushL( ret ); |
|
34 ret->ConstructL( aName, aReadOnly, aMandatory, aIndexed ); |
|
35 return ret; |
|
36 } |
|
37 |
|
38 /** |
|
39 * NewL |
|
40 */ |
|
41 CMdsPropertyDef* CMdsPropertyDef::NewL( const TDesC& aName, TPropertyType aType, |
|
42 TBool aReadOnly, TBool aMandatory, TBool aIndexed ) |
|
43 { |
|
44 CMdsPropertyDef* ret = CMdsPropertyDef::NewLC( aName, aType, aReadOnly, aMandatory, aIndexed ); |
|
45 CleanupStack::Pop( ret ); |
|
46 return ret; |
|
47 } |
|
48 |
|
49 CMdsPropertyDef* CMdsPropertyDef::NewL( const TDesC& aName, TPropertyType aType, TUint32 aFlags ) |
|
50 { |
|
51 return CMdsPropertyDef::NewL( aName, aType, aFlags & EPropertyReadOnly, aFlags & EPropertyMandatory, EFalse ); |
|
52 } |
|
53 |
|
54 CMdsPropertyDef* CMdsPropertyDef::NewLC( const TDesC& aName, TPropertyType aType, TUint32 aFlags ) |
|
55 { |
|
56 return CMdsPropertyDef::NewLC( aName, aType, aFlags & EPropertyReadOnly, aFlags & EPropertyMandatory, EFalse ); |
|
57 } |
|
58 |
|
59 /** |
|
60 * default constructor |
|
61 */ |
|
62 inline CMdsPropertyDef::CMdsPropertyDef( TPropertyType aType ) |
|
63 : iType( aType ) |
|
64 {} |
|
65 |
|
66 /** |
|
67 * ConstructL |
|
68 */ |
|
69 void CMdsPropertyDef::ConstructL( const TDesC& aName, TBool aReadOnly, TBool aMandatory, |
|
70 TBool aIndexed ) |
|
71 { |
|
72 // check that only allowed characters (A-Z, a-z, 0-9) are used |
|
73 CheckAllowerCharatersL( aName, ETrue ); |
|
74 |
|
75 CMdsItemDef::ConstructL( aName ); |
|
76 |
|
77 if ( aMandatory ) |
|
78 { |
|
79 iPropertyFlags |= EPropertyMandatory; |
|
80 } |
|
81 |
|
82 if ( aReadOnly ) |
|
83 { |
|
84 iPropertyFlags |= EPropertyReadOnly; |
|
85 } |
|
86 |
|
87 iIndexed = aIndexed; |
|
88 } |
|
89 |
|
90 /** |
|
91 * Destructor |
|
92 */ |
|
93 CMdsPropertyDef::~CMdsPropertyDef() |
|
94 { |
|
95 } |
|
96 |
|
97 /** |
|
98 * AddMinMaxValueL |
|
99 */ |
|
100 void CMdsPropertyDef::AddMinMaxValueL( const TInt32& aMinValue, const TInt32& aMaxValue ) |
|
101 { |
|
102 if( iType == EPropertyBool || iType == EPropertyInt8 || iType == EPropertyUint8 || |
|
103 iType == EPropertyInt16 || iType == EPropertyUint16 || iType == EPropertyInt32 || |
|
104 iType == EPropertyText ) |
|
105 { |
|
106 iMinValue.iInt32 = aMinValue; |
|
107 iMaxValue.iInt32 = aMaxValue; |
|
108 } |
|
109 else |
|
110 { |
|
111 #ifdef _DEBUG |
|
112 User::Panic( _L("MdSPDAd1") , KErrMdEUnknownPropertyType ); |
|
113 #endif |
|
114 User::Leave( KErrMdEUnknownPropertyType ); |
|
115 } |
|
116 } |
|
117 |
|
118 /** |
|
119 * AddMinMaxValueL |
|
120 */ |
|
121 void CMdsPropertyDef::AddMinMaxValueL( const TUint32& aMinValue, const TUint32& aMaxValue ) |
|
122 { |
|
123 if( iType == EPropertyUint32 ) |
|
124 { |
|
125 iMinValue.iUint32 = aMinValue; |
|
126 iMaxValue.iUint32 = aMaxValue; |
|
127 } |
|
128 else |
|
129 { |
|
130 #ifdef _DEBUG |
|
131 User::Panic( _L("MdSPDAd2") , KErrMdEUnknownPropertyType ); |
|
132 #endif |
|
133 User::Leave( KErrMdEUnknownPropertyType ); |
|
134 } |
|
135 } |
|
136 |
|
137 /** |
|
138 * AddMinMaxValueL |
|
139 */ |
|
140 void CMdsPropertyDef::AddMinMaxValueL( const TInt64& aMinValue, const TInt64& aMaxValue ) |
|
141 { |
|
142 if( iType == EPropertyInt64 || iType == EPropertyTime ) |
|
143 { |
|
144 iMinValue.iInt64 = aMinValue; |
|
145 iMaxValue.iInt64 = aMaxValue; |
|
146 } |
|
147 else |
|
148 { |
|
149 #ifdef _DEBUG |
|
150 User::Panic( _L("MdSPDAd3") , KErrMdEUnknownPropertyType ); |
|
151 #endif |
|
152 User::Leave( KErrMdEUnknownPropertyType ); |
|
153 } |
|
154 } |
|
155 |
|
156 /** |
|
157 * AddMinMaxValueL |
|
158 */ |
|
159 void CMdsPropertyDef::AddMinMaxValueL( const TReal& aMinValue, const TReal& aMaxValue ) |
|
160 { |
|
161 if( iType == EPropertyReal32 || iType == EPropertyReal64 ) |
|
162 { |
|
163 iMinValue.iReal = aMinValue; |
|
164 iMaxValue.iReal = aMaxValue; |
|
165 } |
|
166 else |
|
167 { |
|
168 #ifdef _DEBUG |
|
169 User::Panic( _L("MdSPDAd4") , KErrMdEUnknownPropertyType ); |
|
170 #endif |
|
171 User::Leave( KErrMdEUnknownPropertyType ); |
|
172 } |
|
173 } |
|
174 |
|
175 |
|
176 /** |
|
177 * Get SQLite type name |
|
178 * @return type name |
|
179 */ |
|
180 const TDesC& CMdsPropertyDef::GetSqlTypeName() const |
|
181 { |
|
182 _LIT( KMdsSqlTypeInt, "INTEGER" ); |
|
183 _LIT( KMdsSqlTypeBigInt, "LARGEINT" ); |
|
184 _LIT( KMdsSqlTypeReal, "REAL" ); |
|
185 _LIT( KMdsSqlTypeText, "TEXT" ); |
|
186 |
|
187 switch( iType ) |
|
188 { |
|
189 case EPropertyBool: case EPropertyInt8: case EPropertyUint8: case EPropertyInt16: |
|
190 case EPropertyUint16: case EPropertyInt32: |
|
191 { |
|
192 return KMdsSqlTypeInt; |
|
193 } |
|
194 case EPropertyUint32: case EPropertyInt64: case EPropertyTime: |
|
195 { |
|
196 return KMdsSqlTypeBigInt; |
|
197 } |
|
198 case EPropertyReal32: |
|
199 case EPropertyReal64: |
|
200 { |
|
201 return KMdsSqlTypeReal; |
|
202 } |
|
203 case EPropertyText: |
|
204 { |
|
205 return KMdsSqlTypeText; |
|
206 } |
|
207 default: |
|
208 return KMdsSqlTypeText; |
|
209 } |
|
210 } |
|
211 |
|
212 TColumnDataType CMdsPropertyDef::GetSqlType() const |
|
213 { |
|
214 switch( iType ) |
|
215 { |
|
216 case EPropertyBool: |
|
217 return EColumnBool; |
|
218 case EPropertyInt8: |
|
219 case EPropertyInt16: |
|
220 case EPropertyInt32: |
|
221 return EColumnInt32; |
|
222 case EPropertyUint8: |
|
223 case EPropertyUint16: |
|
224 case EPropertyUint32: |
|
225 return EColumnUint32; |
|
226 case EPropertyInt64: |
|
227 return EColumnInt64; |
|
228 case EPropertyTime: |
|
229 return EColumnTime; |
|
230 case EPropertyReal32: |
|
231 return EColumnReal32; |
|
232 case EPropertyReal64: |
|
233 return EColumnReal64; |
|
234 case EPropertyText: |
|
235 return EColumnDes16; |
|
236 default: |
|
237 return EColumnDes16; |
|
238 } |
|
239 } |
|
240 |
|
241 void CMdsPropertyDef::StoreToDBL( TDefId aObjectDefId ) |
|
242 { |
|
243 _LIT( KMdsSqlClauseAddPropertyDef, "INSERT INTO PropertyDef(ObjectDefId,Flags,Type,MinValue,MaxValue,Name) Values(?,?,?,?,?,?);" ); |
|
244 |
|
245 if ( GetStoredInDB() ) |
|
246 { |
|
247 return; |
|
248 } |
|
249 |
|
250 RRowData rowData; |
|
251 CleanupClosePushL( rowData ); |
|
252 rowData.AppendL( TColumn( aObjectDefId ) ); |
|
253 rowData.AppendL( TColumn( iPropertyFlags ) ); |
|
254 rowData.AppendL( TColumn( iType ) ); |
|
255 switch( iType ) |
|
256 { |
|
257 case EPropertyBool: case EPropertyInt8: case EPropertyUint8: case EPropertyInt16: |
|
258 case EPropertyUint16: case EPropertyInt32: case EPropertyText: |
|
259 { |
|
260 rowData.AppendL( TColumn( iMinValue.iInt32 ) ); |
|
261 rowData.AppendL( TColumn( iMaxValue.iInt32 ) ); |
|
262 break; |
|
263 } |
|
264 case EPropertyUint32: |
|
265 { |
|
266 rowData.AppendL( TColumn( (TInt64)iMinValue.iUint32 ) ); |
|
267 rowData.AppendL( TColumn( (TInt64)iMaxValue.iUint32 ) ); |
|
268 break; |
|
269 } |
|
270 case EPropertyInt64: case EPropertyTime: |
|
271 { |
|
272 rowData.AppendL( TColumn( iMinValue.iInt64 ) ); |
|
273 rowData.AppendL( TColumn( iMaxValue.iInt64 ) ); |
|
274 break; |
|
275 } |
|
276 case EPropertyReal32: case EPropertyReal64: |
|
277 { |
|
278 rowData.AppendL( TColumn( iMinValue.iReal ) ); |
|
279 rowData.AppendL( TColumn( iMaxValue.iReal ) ); |
|
280 break; |
|
281 } |
|
282 default: |
|
283 #ifdef _DEBUG |
|
284 User::Panic( _L("MdSPDSto") , KErrMdEUnknownPropertyType ); |
|
285 #endif |
|
286 User::Leave( KErrMdEUnknownPropertyType ); |
|
287 } |
|
288 rowData.AppendL( TColumn( GetName().AllocL() ) ); |
|
289 |
|
290 TDefId id; |
|
291 id = MMdSIndexer::ExecuteAndGetIndexL( KMdsSqlClauseAddPropertyDef, rowData ); |
|
292 SetId( id ); |
|
293 |
|
294 SetStoredInDB(); |
|
295 CleanupStack::PopAndDestroy( &rowData ); |
|
296 } |
|
297 |
|
298 TBool CMdsPropertyDef::operator==( const CMdsPropertyDef& aPropertyDef ) const |
|
299 { |
|
300 if ( iType != aPropertyDef.iType || iPropertyFlags != aPropertyDef.iPropertyFlags || |
|
301 GetName() != aPropertyDef.GetName() ) |
|
302 { |
|
303 return EFalse; |
|
304 } |
|
305 switch( iType ) |
|
306 { |
|
307 case EPropertyBool: case EPropertyInt8: case EPropertyUint8: case EPropertyInt16: |
|
308 case EPropertyUint16: case EPropertyInt32: case EPropertyText: |
|
309 { |
|
310 return ( iMinValue.iInt32 == aPropertyDef.iMinValue.iInt32 && |
|
311 iMaxValue.iInt32 == aPropertyDef.iMaxValue.iInt32 ) ; |
|
312 } |
|
313 case EPropertyUint32: |
|
314 { |
|
315 return ( iMinValue.iUint32 == aPropertyDef.iMinValue.iUint32 && |
|
316 iMaxValue.iUint32 == aPropertyDef.iMaxValue.iUint32 ) ; |
|
317 } |
|
318 case EPropertyReal32: |
|
319 case EPropertyReal64: |
|
320 { |
|
321 return ( iMinValue.iReal == aPropertyDef.iMinValue.iReal && |
|
322 iMaxValue.iReal == aPropertyDef.iMaxValue.iReal ) ; |
|
323 } |
|
324 case EPropertyInt64: |
|
325 case EPropertyTime: |
|
326 { |
|
327 return ( iMinValue.iInt64 == aPropertyDef.iMinValue.iInt64 && |
|
328 iMaxValue.iInt64 == aPropertyDef.iMaxValue.iInt64 ) ; |
|
329 } |
|
330 default: |
|
331 return EFalse; |
|
332 } |
|
333 |
|
334 } |
|
335 |
|
336 TUint32 CMdsPropertyDef::RequiredBufferSize() |
|
337 { |
|
338 return sizeof(TMdCPropertyDef) + CMdsItemDef::RequiredBufferSize(); |
|
339 } |
|
340 |
|
341 TMdCOffset CMdsPropertyDef::SerializeL(CMdCSerializationBuffer& aBuffer, TMdCOffset aFreeSpace) |
|
342 { |
|
343 TMdCPropertyDef propertyDef; |
|
344 propertyDef.iDefId = GetId(); |
|
345 propertyDef.iFlags = iPropertyFlags; |
|
346 propertyDef.iValueType = iType; |
|
347 propertyDef.iMinValue = iMinValue; |
|
348 propertyDef.iMaxValue = iMaxValue; |
|
349 |
|
350 // store name |
|
351 propertyDef.iName.iPtr.iCount = GetName().Length(); |
|
352 propertyDef.iName.iPtr.iOffset = aFreeSpace; |
|
353 propertyDef.SerializeL( aBuffer ); |
|
354 |
|
355 aBuffer.PositionL( aFreeSpace ); |
|
356 return CMdsItemDef::SerializeL( aBuffer ); |
|
357 } |