|
1 /* |
|
2 * Copyright (c) 2003 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: calss which directly deal with notepad database. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef NSMLNOTEPADDATABASE_H |
|
20 #define NSMLNOTEPADDATABASE_H |
|
21 |
|
22 //INCLUDES |
|
23 #include <d32dbms.h> |
|
24 #include <badesca.h> |
|
25 |
|
26 //CLASS Forward declarations |
|
27 class CNpdItem; |
|
28 |
|
29 //Constants |
|
30 const TInt KNpdSqlStringMaxLength(128); |
|
31 |
|
32 |
|
33 _LIT(KNpdDataFile, "c:Notepad.dat"); //from npdlib.rsg |
|
34 |
|
35 const TUid KSecureUid = {0x101F8878}; |
|
36 _LIT(KSecure, "SECURE"); |
|
37 |
|
38 _LIT(KNpdSqlInsert, "SELECT * FROM Table1"); |
|
39 _LIT(KNpdSqlFormatSeek, "SELECT * FROM Table1 WHERE key=%d"); |
|
40 _LIT(KNpdSqlDeleteHead, "DELETE FROM Table1 WHERE key="); //39 chars |
|
41 _LIT(KNpdSqlDeleteAll, "DELETE FROM Table1"); // 20 chars |
|
42 |
|
43 _LIT(KNpdTableName, "Table1"); |
|
44 _LIT(KNpdKey, "key"); |
|
45 _LIT(KNpdUpdateTime, "time"); |
|
46 _LIT(KNpdMemo, "memo"); |
|
47 |
|
48 |
|
49 const TInt KNpdSqlDeleteHeadSize(49); // %d costs 10 chars in max |
|
50 const TInt KMaxFileLength(255); |
|
51 |
|
52 //Class declarations |
|
53 |
|
54 class CNSmlNotepadDatabase : public CBase |
|
55 { |
|
56 public: |
|
57 /** |
|
58 * Creates new instance of CNpdSmlDbModel based class. |
|
59 * @return CNpdSmlDbModel* Newly created instance. |
|
60 */ |
|
61 static CNSmlNotepadDatabase* NewL(); |
|
62 |
|
63 virtual ~CNSmlNotepadDatabase(); |
|
64 private: |
|
65 // Constructor |
|
66 CNSmlNotepadDatabase(); |
|
67 /** |
|
68 * 2-phase constructor |
|
69 */ |
|
70 void ConstructL(); |
|
71 |
|
72 public: |
|
73 |
|
74 /** |
|
75 * Opens notepad database file. If file does not exist, or is corrupted, |
|
76 * a new, empty file is created. |
|
77 * @return KErrNone if successful, a system wide error code otherwise. |
|
78 */ |
|
79 void OpenL(); |
|
80 |
|
81 /** |
|
82 * Opens notepad database file. If file does not exist, or is corrupted, |
|
83 * a new, empty file is created. |
|
84 * @param aStoreName, name of the notepad database file name |
|
85 */ |
|
86 void OpenL(const TDesC& aStoreName); |
|
87 |
|
88 /** |
|
89 * Adds a note to the database. |
|
90 * @param aNote the note to be added. |
|
91 * @param aKey database index of the newly added note. |
|
92 */ |
|
93 void AddNoteL(CNpdItem& aNote, TInt &aKey); |
|
94 |
|
95 /** |
|
96 * Deletes a note from the database. |
|
97 * @param aKey database index of the note to be deleted. |
|
98 */ |
|
99 void DeleteNoteL(const TInt aKey); |
|
100 |
|
101 |
|
102 /** |
|
103 * Closes the database. |
|
104 */ |
|
105 void Close(); |
|
106 |
|
107 /** |
|
108 * Reads a note from the database. |
|
109 * @param aKey database index of the desired note. |
|
110 * @param aNote reference to note object, used to return note data. |
|
111 */ |
|
112 void GetNoteL(const TInt aKey, CNpdItem& aNote); |
|
113 |
|
114 /** |
|
115 * Updates a note in the database. |
|
116 * @param aKey database index of the note to be updated. |
|
117 * @param aNote note data. This data overrides existing note. |
|
118 */ |
|
119 void UpdateNoteL(const TInt aKey, CNpdItem& aItem); |
|
120 |
|
121 |
|
122 /** |
|
123 * Empties the database. All notes are deleted and the database is |
|
124 * compacted. |
|
125 * @return KErrNone if successful, a system wide error code otherwise. |
|
126 */ |
|
127 TInt Reset(); |
|
128 |
|
129 /** |
|
130 * Checks if the database has been succesfully openend |
|
131 * @return ETrue if database has been succesfully opened, EFalse otherwise |
|
132 */ |
|
133 TBool IsOpen(); |
|
134 /** |
|
135 * gets teh default database storename of the notepad database |
|
136 * @Param aStoreName holds the default notepad database's file name. |
|
137 */ |
|
138 void GetDefaultDatastoreName(TDes& aStoreName); |
|
139 /** |
|
140 * lists the notepad database file names |
|
141 * @returns available notepad database file names. |
|
142 */ |
|
143 CDesCArray* ListDatabasesL(); |
|
144 /** |
|
145 * Get the id of the first record in the table |
|
146 * @returns id of the first record, if no records then returns -1. |
|
147 */ |
|
148 TInt FirstL(); |
|
149 /** |
|
150 * Get the id of the next record in the table |
|
151 * @returns id of the next record, if no records then returns -1. |
|
152 */ |
|
153 TInt NextL(); |
|
154 /** |
|
155 * Get the id of the last record in the table |
|
156 * @returns id of the last record, if no records then returns -1. |
|
157 */ |
|
158 TInt LastL(); |
|
159 |
|
160 |
|
161 private: |
|
162 |
|
163 |
|
164 /** |
|
165 * Creates a column set used to create a new database file. |
|
166 * @return column set. |
|
167 */ |
|
168 CDbColSet* CreateColSetLC(); |
|
169 |
|
170 |
|
171 /** |
|
172 * Creates a new database file. |
|
173 */ |
|
174 void CreateDBL(); |
|
175 |
|
176 /** |
|
177 * Rolls back last database transaction. |
|
178 */ |
|
179 void Rollback(); |
|
180 |
|
181 private: // Data |
|
182 // Interface to database |
|
183 RDbNamedDatabase iDatabase; |
|
184 // Session to database server |
|
185 RDbs iDbs; |
|
186 // Flag for whether database has been opened |
|
187 TBool iOpened; |
|
188 HBufC* iDataFile; |
|
189 RDbTable iTable; |
|
190 |
|
191 enum TNotepadColumnType |
|
192 { |
|
193 ENotepadKey = 1, // this must be 1 (DBMS/SQL restriction) |
|
194 ENotepadUpdateTime, |
|
195 ENotepadMemo |
|
196 }; |
|
197 }; |
|
198 |
|
199 class CNpdItem : public CBase |
|
200 { |
|
201 public: |
|
202 // Destructor |
|
203 virtual ~CNpdItem(); |
|
204 |
|
205 /** |
|
206 * Creates new instance of CNpdItem based class. |
|
207 * @return CNpdItem* Newly created instance. |
|
208 */ |
|
209 static CNpdItem* NewLC(); |
|
210 |
|
211 /** |
|
212 * Creates new instance of CNpdItem based class. |
|
213 * @param aKey database index key |
|
214 * @param aLastModified timestamp |
|
215 * @param aContent content (text) of the note |
|
216 * @return CNpdItem* Newly created instance. |
|
217 */ |
|
218 static CNpdItem* NewLC(TInt aKey, const TTime& aLastModified, HBufC* aContent); |
|
219 private: |
|
220 // Constructor |
|
221 CNpdItem(); |
|
222 //Overloaded Constructor |
|
223 CNpdItem(TInt aKey, const TTime& aLastModified, HBufC *content); |
|
224 |
|
225 public: |
|
226 /** |
|
227 * Returns database key. |
|
228 * @return key value. |
|
229 */ |
|
230 TInt Key() const; |
|
231 |
|
232 /** |
|
233 * Returns the time stamp of the note. |
|
234 * @return when note was last modified. |
|
235 */ |
|
236 TTime LastModified() const; |
|
237 |
|
238 /** |
|
239 * Returns content of the note |
|
240 * @return text of the note. |
|
241 */ |
|
242 HBufC* Content(); |
|
243 |
|
244 /** |
|
245 * Set note data. |
|
246 * @param aKey database index |
|
247 * @param aModTime time note was last modified |
|
248 * @param aContent content of the note |
|
249 */ |
|
250 void Set(TInt aKey, const TTime& aModTime, HBufC* aContent); |
|
251 |
|
252 /** |
|
253 * Set content of the note |
|
254 * @param aContent text of the note. |
|
255 */ |
|
256 void SetContent(HBufC* aContent); |
|
257 |
|
258 /** |
|
259 * Returns timestamp of the note |
|
260 * @param aLastModified time note was last modified. |
|
261 */ |
|
262 void SetModified(const TTime& aLastModified); |
|
263 |
|
264 private: |
|
265 TInt iKey; |
|
266 TTime iLastModified; |
|
267 HBufC* iContent; // owned |
|
268 }; |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 #endif // NSMLNOTEPADDATABASE_H |